Commit 26e54f94 authored by ecrombag's avatar ecrombag

Clean up of TUIDefs

- Removed 'old' definitions as they are replaced with more specialized TUI-controls
- Added ChoiceControl to handle (multiple)-choice tasks

git-svn-id: https://svn.cs.ru.nl/repos/iTask-system/trunk@1097 63da3aa8-80fd-4f01-9db8-e6ea747a3da2
parent a2d06c0b
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
,{"text":"UsernameControl.js","path":"src/js/tui/"} ,{"text":"UsernameControl.js","path":"src/js/tui/"}
,{"text":"HiddenControl.js","path":"src/js/tui/"} ,{"text":"HiddenControl.js","path":"src/js/tui/"}
,{"text":"FormButtonControl.js","path":"src/js/tui/"} ,{"text":"FormButtonControl.js","path":"src/js/tui/"}
,{"text":"ChoiceControl.js","path":"src/js/tui/"}
,{"text":"TUICommon.js","path":"src/js/tui/"} ,{"text":"TUICommon.js","path":"src/js/tui/"}
,{"text":"ListContainer.js","path":"src/js/tui/"} ,{"text":"ListContainer.js","path":"src/js/tui/"}
......
...@@ -63,6 +63,8 @@ itasks.Application = function () { ...@@ -63,6 +63,8 @@ itasks.Application = function () {
this.loginWindow.show(); this.loginWindow.show();
}, },
loadSkin: function() { loadSkin: function() {
if(this.skinLoaded) return;
var link = document.createElement("link"); var link = document.createElement("link");
link.rel = "stylesheet"; link.rel = "stylesheet";
link.type = "text/css"; link.type = "text/css";
...@@ -70,6 +72,8 @@ itasks.Application = function () { ...@@ -70,6 +72,8 @@ itasks.Application = function () {
document.body.appendChild(link); document.body.appendChild(link);
document.title = itasks.config.appTitle; document.title = itasks.config.appTitle;
this.skinLoaded = true;
}, },
/** /**
* Loads and builds the GUI * Loads and builds the GUI
......
...@@ -93,9 +93,9 @@ itasks.ApplicationPanel = Ext.extend(Ext.Panel, { ...@@ -93,9 +93,9 @@ itasks.ApplicationPanel = Ext.extend(Ext.Panel, {
var wlTStamp = node.attributes.latestExtEvent var wlTStamp = node.attributes.latestExtEvent
if(tab != null){ if(tab != null){
//var tTStamp = tab.properties.systemProperties.latestEvent || tab.systemProperties.latestEvent;
var tTStamp = tab.properties.systemProperties.latestEvent; //if(wlTStamp > tTStamp) tab.refresh();
if(wlTStamp > tTStamp) tab.refresh(); tab.refresh(); //TODO: Fix props!
} }
return true; return true;
......
...@@ -87,6 +87,8 @@ itasks.WorkListPanel = Ext.extend(Ext.Panel,{ ...@@ -87,6 +87,8 @@ itasks.WorkListPanel = Ext.extend(Ext.Panel,{
var children = []; var children = [];
if(!treeData) return [];
for(var i=0; i < treeData.length; i++){ for(var i=0; i < treeData.length; i++){
var d = treeData[i]; var d = treeData[i];
......
...@@ -56,7 +56,22 @@ itasks.ttc.common.attachTaskHandlers = function(comp,taskId){ ...@@ -56,7 +56,22 @@ itasks.ttc.common.attachTaskHandlers = function(comp,taskId){
ct.addUpdate(this.name, this.value); ct.addUpdate(this.name, this.value);
ct.sendUpdates(); ct.sendUpdates();
}; };
var choiceTaskEvent = function(){
var ct = this.findParentByType(itasks.ttc.FormContainer);
if (!ct)
ct = this.findParentByType(itasks.ttc.InstructionContainer);
if(!ct)
ct = this.findParentByType(itasks.ttc.MessageContainer);
// if element is not inside form/instr/message it's a group's toolbar
if (!ct)
ct = this.findParentByType(itasks.ttc.GroupContainer);
if(!ct) return;
ct.addUpdate(this.name, Ext.encode(comp.getValue()));
ct.sendUpdates(true);
}
switch(comp.getXType()) { switch(comp.getXType()) {
case "textfield": case "textfield":
...@@ -99,6 +114,9 @@ itasks.ttc.common.attachTaskHandlers = function(comp,taskId){ ...@@ -99,6 +114,9 @@ itasks.ttc.common.attachTaskHandlers = function(comp,taskId){
case "itasks.tui.SourceCode": case "itasks.tui.SourceCode":
comp.on("update",changeTaskEvent); comp.on("update",changeTaskEvent);
break; break;
case "itasks.tui.Choice":
comp.on("change",choiceTaskEvent);
break;
} }
if(comp.buttons) { if(comp.buttons) {
var num = comp.buttons.length; var num = comp.buttons.length;
......
Ext.ns('itasks.tui');
itasks.tui.ChoiceControl = Ext.extend(Ext.form.CheckboxGroup,{
blankText : 'Please select at least one option',
initComponent : function(){
if(this.staticDisplay) {
//...
}
this.hideLabel = this.fieldLabel == null;
this.fieldLabel = itasks.util.fieldLabel(this.optional,this.fieldLabel);
itasks.tui.ChoiceControl.superclass.initComponent.call(this);
},
onRender: function(ct, position){
var me = this;
if(!this.el && !this.staticDisplay){
var panelCfg = {
autoEl : { id: this.id },
renderTo: ct,
bufferResize: false,
layout: 'auto',
cls: (this.allowMultiple)?'x-form-check-group':'x-form-radio-group'
};
var items = [];
var isSelected = function(idx){
for(var i=0; i<me.selection.length; i++){
if(idx == me.selection[i]) return true;
}
return false;
};
//build the subitems based on 'allowMultiple': true = checkboxes / false = radiobuttons
for(var i=0; i < this.options.length; i++){
if(this.allowMultiple){
items.push({
xtype: 'checkbox',
boxLabel: this.options[i],
id: this.id+'-cb-'+i,
name: 'sel-'+i,
value: i,
checked: isSelected(i)
});
}else{
items.push({
xtype: 'radio',
boxLabel: this.options[i],
name: this.name,
value: i,
checked: isSelected(i)
});
}
}
Ext.apply(panelCfg,{
items: items,
defaults: this.defaults
});
this.panel = new Ext.Container(panelCfg);
this.panel.ownerCt = this;
this.el = this.panel.getEl();
var fields = this.panel.findBy(function(c){
return c.isFormField;
}, this);
this.items = new Ext.util.MixedCollection();
this.items.addAll(fields);
}
itasks.tui.ChoiceControl.superclass.onRender.call(this, ct, position);
},
afterRender : function(){
itasks.tui.ChoiceControl.superclass.afterRender.call(this);
this.eachItem(function(item){
item.on('check',this.fireChecked, this);
item.inGroup = true;
});
},
//buffer to prevent radio group buttons firing twice (uncheck of previous -> check of new)
fireChecked : function() {
if(!this.checkTask){
this.checkTask = new Ext.util.DelayedTask(this.bufferChecked, this);
}
this.checkTask.delay(10);
},
bufferChecked : function(){
var arr = [];
this.eachItem(function(item){
if(item.checked){
arr.push(item);
}
});
this.fireEvent('change', this, arr);
},
doLayout: function(){
if(this.rendered){
this.panel.forceLayout = this.ownerCt.forceLayout;
this.panel.doLayout();
}
},
//returns a list of checked indices
getValue : function(){
var out = [];
var multiple = this.allowMultiple;
this.eachItem(function(item){
if(item.checked){
out.push(item.value);
if(!multiple) return false;
}
});
return out;
}
});
Ext.reg('itasks.tui.Choice', itasks.tui.ChoiceControl);
\ No newline at end of file
...@@ -78,6 +78,7 @@ ...@@ -78,6 +78,7 @@
<script type="text/javascript" src="../js/tui/SourceCodeControl.js"></script> <script type="text/javascript" src="../js/tui/SourceCodeControl.js"></script>
<script type="text/javascript" src="../js/tui/ColorChooser.js"></script> <script type="text/javascript" src="../js/tui/ColorChooser.js"></script>
<script type="text/javascript" src="../js/tui/FormButtonControl.js"></script> <script type="text/javascript" src="../js/tui/FormButtonControl.js"></script>
<script type="text/javascript" src="../js/tui/ChoiceControl.js"></script>
<script type="text/javascript" src="../js/tui/ListContainer.js"></script> <script type="text/javascript" src="../js/tui/ListContainer.js"></script>
<script type="text/javascript" src="../js/tui/RecordContainer.js"></script> <script type="text/javascript" src="../js/tui/RecordContainer.js"></script>
......
...@@ -4,7 +4,7 @@ implementation module Toolbox ...@@ -4,7 +4,7 @@ implementation module Toolbox
This toolbox contains a number of workflows which can be handle unforseen situations. Or can be used as 'units' in other workflows. This toolbox contains a number of workflows which can be handle unforseen situations. Or can be used as 'units' in other workflows.
*/ */
import iTasks import iTasks, GenEq
import CommonDomain, Messaging import CommonDomain, Messaging
from HRM import getUserGroups from HRM import getUserGroups
......
...@@ -154,23 +154,15 @@ makeChoiceTask question options initsel context actions tst=:{taskNr, newTask} ...@@ -154,23 +154,15 @@ makeChoiceTask question options initsel context actions tst=:{taskNr, newTask}
# buttonActions = getButtonActions actions # buttonActions = getButtonActions actions
# (anyUpd,tst) = anyUpdates tst # (anyUpd,tst) = anyUpdates tst
| newTask || not anyUpd | newTask || not anyUpd
// generate TUI definition # form = [TUIChoiceControl {TUIChoiceControl
# radios = [TUIRadio {TUIRadio | name = selectionId | name = selectionId
, id = "" , id = selectionId
, value = toString i , fieldLabel = Nothing
, boxLabel = Just (toString (SpanTag [ClassAttr "task-choice"] (visualizeAsHtmlLabel option))) , optional = False
, fieldLabel = Nothing , allowMultiple = False
, hideLabel = True , options = [toString (SpanTag [ClassAttr "task-choice"] (visualizeAsHtmlLabel option)) \\ option <- options]
, checked = (i == selection) , selection = [selection]
} \\ option <- options & i <- [0..] ] }]
# form = [TUIRadioGroup {TUIRadioGroup | name = selectionId
, id = selectionId
, fieldLabel = Nothing
, hideLabel = True
, columns = 1
, items = radios
}]
# menuActions = evaluateConditions (getMenuActions actions) valid (if valid (options !! selection) (hd options)) # menuActions = evaluateConditions (getMenuActions actions) valid (if valid (options !! selection) (hd options))
# buttonActions = evaluateConditions buttonActions valid (if valid (options !! selection) (hd options)) # buttonActions = evaluateConditions buttonActions valid (if valid (options !! selection) (hd options))
# tst = setTUIDef (taskPanel taskId (html question) context (Just form) (makeButtons editorId buttonActions)) (html question) menuActions tst # tst = setTUIDef (taskPanel taskId (html question) context (Just form) (makeButtons editorId buttonActions)) (html question) menuActions tst
...@@ -190,7 +182,8 @@ makeChoiceTask question options initsel context actions tst=:{taskNr, newTask} ...@@ -190,7 +182,8 @@ makeChoiceTask question options initsel context actions tst=:{taskNr, newTask}
// The selection was updated // The selection was updated
Nothing Nothing
// The selection was updated // The selection was updated
# index = toInt (http_getValue selectionId updates "-1") # upd = parseUpdate selectionId updates
# index = if(isEmpty upd) -1 (hd upd)
| index <> -1 | index <> -1
# valid = index >= 0 && index < length options //Recompute validity # valid = index >= 0 && index < length options //Recompute validity
# tst = setTaskStore "selection" index tst # tst = setTaskStore "selection" index tst
...@@ -202,6 +195,11 @@ makeChoiceTask question options initsel context actions tst=:{taskNr, newTask} ...@@ -202,6 +195,11 @@ makeChoiceTask question options initsel context actions tst=:{taskNr, newTask}
| otherwise | otherwise
# tst = setTUIUpdates [] [] tst # tst = setTUIUpdates [] [] tst
= (TaskBusy, tst) = (TaskBusy, tst)
where
parseUpdate :: !String ![(String,String)] -> [Int]
parseUpdate selectionId updates
# mbList = fromJSON(fromString (http_getValue selectionId updates "[]"))
= case mbList of Nothing = []; Just list = list
enterMultipleChoice :: question [a] -> Task [a] | html question & iTask a enterMultipleChoice :: question [a] -> Task [a] | html question & iTask a
enterMultipleChoice question options = mkInteractiveTask "enterMultipleChoice" (ignoreActionA (makeMultipleChoiceTask question options [] Nothing [ButtonAction (ActionOk, IfValid)])) enterMultipleChoice question options = mkInteractiveTask "enterMultipleChoice" (ignoreActionA (makeMultipleChoiceTask question options [] Nothing [ButtonAction (ActionOk, IfValid)]))
...@@ -241,17 +239,16 @@ makeMultipleChoiceTask question options initsel context actions tst=:{taskNr, ne ...@@ -241,17 +239,16 @@ makeMultipleChoiceTask question options initsel context actions tst=:{taskNr, ne
= (TaskFinished (ActionOk,[]),tst) = (TaskFinished (ActionOk,[]),tst)
| newTask || not anyUpd | newTask || not anyUpd
// generate TUI definition // generate TUI definition
# checks = [isMember i selection \\ i <- [0..(length options) - 1]] # checks = [isMember i selection \\ i <- [0..(length options) - 1]]
# cboxes = [TUICheckBox # form = [TUIChoiceControl { TUIChoiceControl
{TUICheckBox | name = "selection"
| name = "sel-" +++ toString i , id = editorId +++ "-selection"
, id = editorId +++ "-cb-" +++ toString i , fieldLabel = Nothing
, value = toString i , allowMultiple = True
, fieldLabel = Nothing , optional = False
, hideLabel = True , options = [toString (SpanTag [ClassAttr "task-choice"] (visualizeAsHtmlLabel option)) \\ option <- options]
, boxLabel = Just (visualizeAsTextLabel o) , selection = selection
, checked = c} \\ o <- options & i <- [0..] & c <- checks ] }]
# form = [ TUICheckBoxGroup {TUICheckBoxGroup |name = "selection", id = editorId +++ "-selection", fieldLabel = Nothing, hideLabel = True, columns = 1, items = cboxes}]
# menuActions = evaluateConditions (getMenuActions actions) True (select selection options) # menuActions = evaluateConditions (getMenuActions actions) True (select selection options)
# tst = setTUIDef (taskPanel taskId (html question) context (Just form) (makeButtons editorId buttonActions)) (html question) menuActions tst # tst = setTUIDef (taskPanel taskId (html question) context (Just form) (makeButtons editorId buttonActions)) (html question) menuActions tst
= (TaskBusy, tst) = (TaskBusy, tst)
...@@ -269,18 +266,18 @@ makeMultipleChoiceTask question options initsel context actions tst=:{taskNr, ne ...@@ -269,18 +266,18 @@ makeMultipleChoiceTask question options initsel context actions tst=:{taskNr, ne
Just action = (TaskFinished (action, select selection options),tst) Just action = (TaskFinished (action, select selection options),tst)
Nothing Nothing
// Perhaps the selection was changed // Perhaps the selection was changed
# mbSel = parseSelection updates # mbSel = parseSelection updates
# selection = case mbSel of Nothing = selection; Just sel = map toInt sel # selection = case mbSel of Nothing = selection; Just sel = map toInt sel
# tst = setTaskStore "selection" (sort selection) tst # tst = setTaskStore "selection" (sort selection) tst
# tst = setTUIUpdates [] (evaluateConditions (getMenuActions actions) True (select selection options)) tst # tst = setTUIUpdates [] (evaluateConditions (getMenuActions actions) True (select selection options)) tst
= (TaskBusy, tst) = (TaskBusy, tst)
where where
parseSelection :: [(String,String)] -> Maybe [String] parseSelection :: [(String,String)] -> Maybe [Int]
parseSelection updates = fromJSON (fromString (http_getValue "selection" updates "[]")) parseSelection updates = fromJSON (fromString (http_getValue "selection" updates "[]"))
select :: [Int] [a] -> [a] select :: [Int] [a] -> [a]
select indices options = [options !! index \\ index <- indices] select indices options = [options !! index \\ index <- indices]
//Output tasks //Output tasks
showMessage :: message -> Task Void | html message showMessage :: message -> Task Void | html message
showMessage message = mkInteractiveTask "showMessage" (ignoreActionV (makeMessageTask message Nothing [ButtonAction (ActionOk, IfValid)])) showMessage message = mkInteractiveTask "showMessage" (ignoreActionV (makeMessageTask message Nothing [ButtonAction (ActionOk, IfValid)]))
......
...@@ -3,6 +3,7 @@ implementation module WorkflowService ...@@ -3,6 +3,7 @@ implementation module WorkflowService
import Http, TSt import Http, TSt
import HtmlUtil, Text import HtmlUtil, Text
import StdArray, StdString, StdInt, StdList, StdBool, StdClass import StdArray, StdString, StdInt, StdList, StdBool, StdClass
import GenEq
from Util import mb2list from Util import mb2list
......
...@@ -13,7 +13,6 @@ derive JSONEncode TUIDef, TUIUpdate ...@@ -13,7 +13,6 @@ derive JSONEncode TUIDef, TUIUpdate
derive gEq TUIDef derive gEq TUIDef
:: TUIId :== String :: TUIId :== String
:: PlaceholderId :== String
:: TUIUpdate :: TUIUpdate
= TUIAdd TUIId TUIDef // Add the additional component *after* the component with indicated id = TUIAdd TUIId TUIDef // Add the additional component *after* the component with indicated id
...@@ -28,6 +27,7 @@ derive gEq TUIDef ...@@ -28,6 +27,7 @@ derive gEq TUIDef
:: TUIDef :: TUIDef
= TUILabel = TUILabel
| TUIButton TUIButton
| TUIStringControl TUIBasicControl | TUIStringControl TUIBasicControl
| TUICharControl TUIBasicControl | TUICharControl TUIBasicControl
| TUIIntControl TUIBasicControl | TUIIntControl TUIBasicControl
...@@ -36,7 +36,8 @@ derive gEq TUIDef ...@@ -36,7 +36,8 @@ derive gEq TUIDef
| TUINoteControl TUIBasicControl | TUINoteControl TUIBasicControl
| TUIDateControl TUIBasicControl | TUIDateControl TUIBasicControl
| TUITimeControl TUIBasicControl | TUITimeControl TUIBasicControl
| TUIPasswordControl TUIBasicControl | TUIPasswordControl TUIBasicControl
| TUIChoiceControl TUIChoiceControl
| TUICurrencyControl TUICurrencyControl | TUICurrencyControl TUICurrencyControl
| TUIUserControl TUIBasicControl | TUIUserControl TUIBasicControl
| TUIDocumentControl TUIDocumentControl | TUIDocumentControl TUIDocumentControl
...@@ -48,29 +49,11 @@ derive gEq TUIDef ...@@ -48,29 +49,11 @@ derive gEq TUIDef
| TUITupleContainer TUITupleContainer | TUITupleContainer TUITupleContainer
| TUIRecordContainer TUIRecordContainer | TUIRecordContainer TUIRecordContainer
| TUIListContainer TUIListContainer | TUIListContainer TUIListContainer
//-- OLD --
| TUIButton TUIButton
| TUINumberField TUINumberField
| TUITextArea TUITextArea
| TUIUserField TUIUserField
| TUIComboBox TUIComboBox
| TUICheckBox TUICheckBox
| TUICheckBoxGroup TUICheckBoxGroup
| TUIRadio TUIRadio
| TUIRadioGroup TUIRadioGroup
| TUITimeField TUITimeField
| TUIDateField TUIDateField
| TUIHtmlEditor
| TUIFieldSet TUIFieldSet
| TUIPanel TUIPanel
| TUIBox TUIBox
| TUIHtmlPanel TUIHtmlPanel | TUIHtmlPanel TUIHtmlPanel
| TUIMenuButton TUIMenuButton | TUIMenuButton TUIMenuButton
| TUIMenuItem TUIMenuItem | TUIMenuItem TUIMenuItem
| TUIMenuSeparator | TUIMenuSeparator
| TUITuple TUITuple
| TUICustom JSONNode | TUICustom JSONNode
:: TUIBasicControl = :: TUIBasicControl =
...@@ -83,6 +66,15 @@ derive gEq TUIDef ...@@ -83,6 +66,15 @@ derive gEq TUIDef
, errorMsg :: !String , errorMsg :: !String
, hintMsg :: !String , hintMsg :: !String
} }
:: TUIChoiceControl =
{ name :: !String
, id :: !String
, fieldLabel :: !Maybe String
, allowMultiple :: !Bool
, optional :: !Bool
, options :: ![String]
, selection :: ![Int]
}
:: TUICurrencyControl = :: TUICurrencyControl =
{ name :: !String { name :: !String
, id :: !String , id :: !String
...@@ -177,126 +169,6 @@ derive gEq TUIDef ...@@ -177,126 +169,6 @@ derive gEq TUIDef
, hintMsg :: !String , hintMsg :: !String
, optional :: !Bool , optional :: !Bool
} }
//-- OLD --
:: TUIButton =
{ name :: !String
, id :: !String
, text :: !String
, value :: !String
, disabled :: !Bool
, iconCls :: !String
}
:: TUINumberField =
{ name :: !String
, id :: !String
, value :: !String
, fieldLabel :: !Maybe String
, hideLabel :: !Bool
, allowDecimals :: !Bool
, numDecimals :: !Int
}
:: TUITextArea =
{ name :: !String
, id :: !String
, value :: !String
, fieldLabel :: !Maybe String
, hideLabel :: !Bool
, width :: !Int
, height :: !Int
}
:: TUIUserField =
{ name :: !String
, id :: !String
, value :: !String
, fieldLabel :: !Maybe String
, hideLabel :: !Bool
}
:: TUIComboBox =
{ name :: !String
, id :: !String
, value :: !String
, fieldLabel :: !Maybe String
, hideLabel :: !Bool
, store :: ![(String,String)]
, triggerAction :: !String
, editable :: !Bool
}
:: TUICheckBox =
{ name :: !String
, id :: !String
, value :: !String
, boxLabel :: !Maybe String
, fieldLabel :: !Maybe String
, hideLabel :: !Bool
, checked :: !Bool
}
:: TUICheckBoxGroup =
{ name :: !String
, id :: !String
, fieldLabel :: !Maybe String
, hideLabel :: !Bool
, columns :: !Int
, items :: ![TUIDef]
}
:: TUIRadio =
{ name :: !String
, id :: !String
, value :: !String
, boxLabel :: !Maybe String
, fieldLabel :: !Maybe String
, hideLabel :: !Bool
, checked :: !Bool
}
:: TUIRadioGroup =
{ name :: !String
, id :: !String
, fieldLabel ::