Commit e70d847c authored by Steffen Michels's avatar Steffen Michels

add type for formatted text & shared variable example with different views on formatted text

git-svn-id: https://svn.cs.ru.nl/repos/iTask-system/trunk@975 63da3aa8-80fd-4f01-9db8-e6ea747a3da2
parent a919e226
......@@ -17,6 +17,7 @@
,{"text":"GMapControl.js","path":"src/js/tui/"}
,{"text":"IntControl.js","path":"src/js/tui/"}
,{"text":"NoteControl.js","path":"src/js/tui/"}
,{"text":"FormattedTextControl.js","path":"src/js/tui/"}
,{"text":"PasswordControl.js","path":"src/js/tui/"}
,{"text":"RealControl.js","path":"src/js/tui/"}
,{"text":"StringControl.js","path":"src/js/tui/"}
......
......@@ -98,7 +98,8 @@ itasks.ttc.GroupContainer = Ext.extend(Ext.Panel,{
modal: behaviour == 'GBModal',
items: [cont],
title: title,
tools: tools
tools: tools,
minWidth: 300
});
break;
}
......@@ -163,7 +164,7 @@ itasks.ttc.GroupContainer = Ext.extend(Ext.Panel,{
cont = Ext.create(cont);
// fix size of window
var s = cont.getSize();
cont.setSize(s.width, s.height);
cont.setSize(s.width > cont.minWidth ? s.width : cont.minWidth, s.height);
//hack: make sure the ownerCt is set to reference the parent, so that findParentByType works.
cont.ownerCt = this;
......
......@@ -30,10 +30,8 @@ itasks.ttc.common.attachTaskHandlers = function(comp,taskId){
var value;
switch(this.xtype) {
case "radiogroup": value = this.getValue().value; break;
case "checkboxgroup": value = checkboxValues(arguments[1]); break;
case "datefield": value = this.getRawValue(); break;
default: value = this.getValue();
}
ct.addUpdate(this.name, value);
......@@ -94,6 +92,9 @@ itasks.ttc.common.attachTaskHandlers = function(comp,taskId){
if(comp.name)
comp.on("click",clickTaskEvent);
break;
case "itasks.tui.FormattedText":
comp.on("sync",changeTaskEvent);
break;
}
if(comp.buttons) {
var num = comp.buttons.length;
......
Ext.ns("itasks.tui");
itasks.tui.FormattedTextControl = Ext.extend(Ext.form.HtmlEditor,{
width: 700,
height: 300,
initComponent: function() {
this.hideLabel = this.fieldLabel == null;
this.fieldLabel = itasks.util.fieldLabel(this.optional,this.fieldLabel);
this.allowBlank = this.optional;
itasks.tui.FormattedTextControl.superclass.initComponent.apply(this,arguments);
},
getValue: function() {
return this.getRawValue();
}
});
Ext.reg("itasks.tui.FormattedText",itasks.tui.FormattedTextControl);
\ No newline at end of file
......@@ -36,7 +36,7 @@ import FlowEditor
import LaunchFlow
//Shared Value Examples
import SharedValues
import SharedVariables
Start :: *World -> *World
Start world = startEngine workflows world
......@@ -64,4 +64,4 @@ where
, launchFlow
]
, sharedValueExamples
]
\ No newline at end of file
]
definition module SharedValues
definition module SharedVariables
import iTasks
......
implementation module SharedValues
implementation module SharedVariables
import iTasks, CommonDomain, GeoDomain, Text
......@@ -136,9 +136,29 @@ autoSortedList = ignoreResult (updateSharedLocal "Automatically Sorted List" [qu
where
emptyL :: [String]
emptyL = []
//Different Views on Formatted Text
formattedText :: Task Void
formattedText =
setMenus [Menu "Example" [MenuItem "Quit" ActionQuit]]
>>| createDB (mkEmptyFormattedText {allControls & sourceEditControl = False})
>>= \sid. dynamicGroupAOnly [(ignoreResult t) <<@ GBFloating \\ t <- tasks sid] actions
>>| deleteDB sid
where
tasks sid =
[ updateShared "WYSIWYG Editor" [] sid [idEditor]
, updateShared "HTML-Source Editor" [] sid [editor { editorFrom = \(FormattedText src _) -> Note src
, editorTo = \(Note src) (FormattedText _ ctrls) -> FormattedText src ctrls
}]
, updateShared "Formatted Preview" [] sid [idListener]
, updateShared "Unformatted Preview" [] sid [listener {listenerFrom = \ft -> Note (toUnformattedString ft)}]
]
actions :: [GroupAction GOnlyAction Void Void]
actions = [GroupAction ActionQuit GOStop GroupAlways]
sharedValueExamples :: [Workflow]
sharedValueExamples = [ workflow "Examples/Shared Variables/Text-Lines (parallel tasks)" linesPar
sharedValueExamples = [ workflow "Examples/Shared Variables/Text-Lines (grouped tasks)" linesPar
, workflow "Examples/Shared Variables/Text-Lines (single editor)" linesSingle
, workflow "Examples/Shared Variables/Calculate Sum" calculateSum
, workflow "Examples/Shared Variables/Balanced Binary Tree" tree
......@@ -146,4 +166,5 @@ sharedValueExamples = [ workflow "Examples/Shared Variables/Text-Lines (parallel
, workflow "Examples/Shared Variables/Merge Test (Documents)" mergeTestDocuments
, workflow "Examples/Shared Variables/Google Maps Example" googleMaps
, workflow "Examples/Shared Variables/Sorted List" autoSortedList
, workflow "Examples/Shared Variables/Formatted Text" formattedText
]
\ No newline at end of file
......@@ -18,6 +18,23 @@ import GenCopy
// Plain text notes
:: Note = Note String
:: FormattedText = FormattedText String FormattedTextControls
:: FormattedTextControls =
{ alignmentControls :: Bool // Enable the left, center, right alignment buttons
, colorControls :: Bool // Enable the fore/highlight color buttons
, fontControl :: Bool // Enable font selection
, fontSizeControls :: Bool // Enable the increase/decrease font size buttons
, formatControls :: Bool // Enable the bold, italic and underline buttons
, linkControl :: Bool // Enable the create link button
, listControls :: Bool // Enable the bullet and numbered list buttons
, sourceEditControl :: Bool // Enable the switch to source edit button
}
mkEmptyFormattedText :: FormattedTextControls -> FormattedText
allControls :: FormattedTextControls
noControls :: FormattedTextControls
toUnformattedString :: FormattedText -> String
// Dates, times and intervals
:: Date =
{ day :: Int
......@@ -43,15 +60,16 @@ currentDateTime :: !*World -> (!DateTime,!*World)
| USD Int
| JPY Int
derive gPrint EmailAddress, Password, Note, Date, Time, DateTime, Currency
derive gParse EmailAddress, Password, Note, Date, Time, DateTime, Currency
derive gVisualize EmailAddress, Password, Note, Date, Time, DateTime, Currency
derive gUpdate EmailAddress, Password, Note, Date, Time, DateTime, Currency
derive gMerge EmailAddress, Password, Note, Date, Time, DateTime, Currency
derive gMakeSharedCopy EmailAddress, Password, Note, Date, Time, DateTime, Currency
derive gMakeLocalCopy EmailAddress, Password, Note, Date, Time, DateTime, Currency
derive gPrint EmailAddress, Password, Note, Date, Time, DateTime, Currency, FormattedText
derive gParse EmailAddress, Password, Note, Date, Time, DateTime, Currency, FormattedText
derive gVisualize EmailAddress, Password, Note, Date, Time, DateTime, Currency, FormattedText
derive gUpdate EmailAddress, Password, Note, Date, Time, DateTime, Currency, FormattedText
derive gMerge EmailAddress, Password, Note, Date, Time, DateTime, Currency, FormattedText
derive gMakeSharedCopy EmailAddress, Password, Note, Date, Time, DateTime, Currency, FormattedText
derive gMakeLocalCopy EmailAddress, Password, Note, Date, Time, DateTime, Currency, FormattedText
instance html Note
instance toString FormattedText
instance toString Date
instance toString Time
......@@ -71,4 +89,4 @@ instance + Date //Naive fieldwise addition
instance - Currency
instance - Time //Naive fieldwise subtraction
instance - Date //Naive fieldwise subtraction
instance zero Currency
\ No newline at end of file
instance zero Currency
......@@ -5,13 +5,13 @@ import StdOverloaded, StdClass, StdInt, StdMisc, StdArray
import GenPrint, GenParse, GenVisualize, GenUpdate, GenLexOrd
import Text, Time
derive gPrint EmailAddress, Password, Note, Date, Time, DateTime, Currency
derive gParse EmailAddress, Password, Note, Date, Time, DateTime, Currency
derive gPrint EmailAddress, Password, Note, Date, Time, DateTime, Currency, FormattedText, FormattedTextControls
derive gParse EmailAddress, Password, Note, Date, Time, DateTime, Currency, FormattedText, FormattedTextControls
derive gVisualize EmailAddress, DateTime
derive gUpdate EmailAddress, Note, DateTime
derive gMerge EmailAddress, Password, Note, Date, Time, DateTime, Currency
derive gMakeSharedCopy EmailAddress, Password, Note, Date, Time, DateTime, Currency
derive gMakeLocalCopy EmailAddress, Password, Note, Date, Time, DateTime, Currency
derive gUpdate EmailAddress, Note, DateTime, FormattedText, FormattedTextControls
derive gMerge EmailAddress, Password, Note, Date, Time, DateTime, Currency, FormattedText, FormattedTextControls
derive gMakeSharedCopy EmailAddress, Password, Note, Date, Time, DateTime, Currency, FormattedText, FormattedTextControls
derive gMakeLocalCopy EmailAddress, Password, Note, Date, Time, DateTime, Currency, FormattedText, FormattedTextControls
derive gLexOrd Currency
derive bimap Maybe, (,)
......@@ -81,6 +81,46 @@ where
id = dp2id idPrefix contentPath
oldV = value2s contentPath old
newV = value2s contentPath new
gVisualize{|FormattedText|} old new vst=:{vizType,label,idPrefix,currentPath,useLabels,optional,valid}
= case vizType of
VEditorDefinition = ([TUIFragment (TUIFormattedTextControl { name = dp2s contentPath
, id = id
, value = oldV
, fieldLabel = labelAttr useLabels label
, optional = optional
, enableAlignments = controls.alignmentControls
, enableColors = controls.colorControls
, enableFont = controls.fontControl
, enableFontSize = controls.fontSizeControls
, enableFormat = controls.formatControls
, enableLinks = controls.linkControl
, enableLists = controls.listControls
, enableSourceEdit = controls.sourceEditControl
}
)]
, 0
, {VSt|vst & currentPath = stepDataPath currentPath, valid= stillValid contentPath old optional valid})
VEditorUpdate
| oldV <> newV = ([TUIUpdate (TUISetValue id newV)]
, 0
, {VSt|vst & currentPath = stepDataPath currentPath, valid= stillValid contentPath new optional valid})
_ # htmlFrag = case old of
VBlank = [Text ""]
VValue v _ = html v
= ([HtmlFragment htmlFrag]
, 0
, {VSt|vst & currentPath = stepDataPath currentPath, valid= stillValid contentPath new optional valid})
where
// Use the path to the inner constructor instead of the current path.
// This way the generic gUpdate will work for this type
contentPath = shiftDataPath currentPath
id = dp2id idPrefix contentPath
oldV = value2s contentPath old
newV = value2s contentPath new
controls = case old of
VBlank = allControls
VValue (FormattedText _ controls) _ = controls
gVisualize{|Currency|} old new vst=:{vizType,label,idPrefix,currentPath,useLabels,optional,valid}
= case vizType of
......@@ -185,7 +225,11 @@ currentDateTime world
instance html Note
where
html (Note msg) = [Text msg]
instance html FormattedText
where
html (FormattedText txt _) = [RawText txt]
instance toString Time
where
toString {Time|hour,min,sec} = (pad 2 hour) +++ ":" +++ (pad 2 min) +++ ":" +++ (pad 2 sec)
......@@ -205,7 +249,26 @@ where
instance toString Note
where
toString (Note s) = s
instance toString FormattedText
where
toString (FormattedText s _) = s
toUnformattedString :: FormattedText -> String
toUnformattedString (FormattedText s _)
# s = replaceSubString "<br>" "\n" s
# s = replaceSubString "</li>" "\n" s
# s = stripHtmlTags s
= s
where
stripHtmlTags s
# fstOpen = indexOf "<" s
# fstClose = indexOf ">" s
| fstOpen <> -1 && fstClose <> -1 && fstOpen < fstClose
= stripHtmlTags (subString 0 fstOpen s +++ subString (fstClose + 1) (textSize s - fstClose) s)
| otherwise
= s
instance toString Currency
where
toString (EUR x) = "EUR " +++ decFormat x
......@@ -285,4 +348,28 @@ where
nums = toString num
decFormat :: Int -> String
decFormat x = toString (x / 100) +++ "." +++ pad 2 (x rem 100)
\ No newline at end of file
decFormat x = toString (x / 100) +++ "." +++ pad 2 (x rem 100)
mkEmptyFormattedText :: FormattedTextControls -> FormattedText
mkEmptyFormattedText controls = FormattedText "" controls
allControls :: FormattedTextControls
allControls = { alignmentControls = True
, colorControls = True
, fontControl = True
, fontSizeControls = True
, formatControls = True
, linkControl = True
, listControls = True
, sourceEditControl = True
}
noControls :: FormattedTextControls
noControls = { alignmentControls = False
, colorControls = False
, fontControl = False
, fontSizeControls = False
, formatControls = False
, linkControl = False
, listControls = False
, sourceEditControl = False
}
\ No newline at end of file
......@@ -28,6 +28,7 @@ derive JSONEncode TUIDef, TUIUpdate
| TUIRealControl TUIBasicControl
| TUIBoolControl TUIBasicControl
| TUINoteControl TUIBasicControl
| TUIFormattedTextControl TUIFormattedTextControl
| TUIDateControl TUIBasicControl
| TUITimeControl TUIBasicControl
| TUIPasswordControl TUIBasicControl
......@@ -260,4 +261,19 @@ derive JSONEncode TUIDef, TUIUpdate
, fieldLabel :: !Maybe String
, renderingHint :: !Int
, unstyled :: !Bool
}
:: TUIFormattedTextControl =
{ name :: !String
, id :: !String
, value :: !String
, fieldLabel :: !Maybe String
, optional :: !Bool
, enableAlignments :: !Bool
, enableColors :: !Bool
, enableFont :: !Bool
, enableFontSize :: !Bool
, enableFormat :: !Bool
, enableLinks :: !Bool
, enableLists :: !Bool
, enableSourceEdit :: !Bool
}
\ No newline at end of file
......@@ -4,7 +4,7 @@ import JSON,StdList
//JSON Encoding of TUI definitions is directly encoded as JSON data.
derive JSONEncode TUIButton, TUITextArea, TUIUserField, TUINumberField, TUIComboBox, TUICheckBox, TUICheckBoxGroup, TUIRadio, TUIRadioGroup, TUIDateField, TUITimeField, TUIFieldSet, TUIPanel, TUIHtmlPanel, TUIList, TUIMenuButton, TUIMenu, TUIMenuItem
derive JSONEncode TUIUpdate, TUIBox, TUIListItem, TUIDocument, TUITuple
derive JSONEncode TUIBasicControl, TUICurrencyControl, TUIDisplayControl
derive JSONEncode TUIBasicControl, TUICurrencyControl, TUIDisplayControl, TUIFormattedTextControl
JSONEncode{|TUIDef|} (TUIButton r) c = addXType "button" (JSONEncode{|*|} r c)
JSONEncode{|TUIDef|} (TUITextArea r) c = addXType "textarea" (JSONEncode{|*|} r c)
......@@ -36,6 +36,7 @@ JSONEncode{|TUIDef|} (TUIIntControl r) c = addXType "itasks.tui.Int" (JSONEncode
JSONEncode{|TUIDef|} (TUIRealControl r) c = addXType "itasks.tui.Real" (JSONEncode{|*|} r c)
JSONEncode{|TUIDef|} (TUIBoolControl r) c = addXType "itasks.tui.Bool" (JSONEncode{|*|} r c)
JSONEncode{|TUIDef|} (TUINoteControl r) c = addXType "itasks.tui.Note" (JSONEncode{|*|} r c)
JSONEncode{|TUIDef|} (TUIFormattedTextControl r) c = addXType "itasks.tui.FormattedText" (JSONEncode{|*|} r c)
JSONEncode{|TUIDef|} (TUIDateControl r) c = addXType "itasks.tui.Date" (JSONEncode{|*|} r c)
JSONEncode{|TUIDef|} (TUITimeControl r) c = addXType "itasks.tui.Time" (JSONEncode{|*|} r c)
JSONEncode{|TUIDef|} (TUICurrencyControl r) c = addXType "itasks.tui.Currency" (JSONEncode{|*|} r c)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment