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 @@
,{"text":"UsernameControl.js","path":"src/js/tui/"}
,{"text":"HiddenControl.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":"ListContainer.js","path":"src/js/tui/"}
......
......@@ -63,6 +63,8 @@ itasks.Application = function () {
this.loginWindow.show();
},
loadSkin: function() {
if(this.skinLoaded) return;
var link = document.createElement("link");
link.rel = "stylesheet";
link.type = "text/css";
......@@ -70,6 +72,8 @@ itasks.Application = function () {
document.body.appendChild(link);
document.title = itasks.config.appTitle;
this.skinLoaded = true;
},
/**
* Loads and builds the GUI
......
......@@ -93,9 +93,9 @@ itasks.ApplicationPanel = Ext.extend(Ext.Panel, {
var wlTStamp = node.attributes.latestExtEvent
if(tab != null){
var tTStamp = tab.properties.systemProperties.latestEvent;
if(wlTStamp > tTStamp) tab.refresh();
//var tTStamp = tab.properties.systemProperties.latestEvent || tab.systemProperties.latestEvent;
//if(wlTStamp > tTStamp) tab.refresh();
tab.refresh(); //TODO: Fix props!
}
return true;
......
......@@ -87,6 +87,8 @@ itasks.WorkListPanel = Ext.extend(Ext.Panel,{
var children = [];
if(!treeData) return [];
for(var i=0; i < treeData.length; i++){
var d = treeData[i];
......
......@@ -56,7 +56,22 @@ itasks.ttc.common.attachTaskHandlers = function(comp,taskId){
ct.addUpdate(this.name, this.value);
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()) {
case "textfield":
......@@ -99,6 +114,9 @@ itasks.ttc.common.attachTaskHandlers = function(comp,taskId){
case "itasks.tui.SourceCode":
comp.on("update",changeTaskEvent);
break;
case "itasks.tui.Choice":
comp.on("change",choiceTaskEvent);
break;
}
if(comp.buttons) {
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 @@
<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/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/RecordContainer.js"></script>
......
......@@ -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.
*/
import iTasks
import iTasks, GenEq
import CommonDomain, Messaging
from HRM import getUserGroups
......
......@@ -154,23 +154,15 @@ makeChoiceTask question options initsel context actions tst=:{taskNr, newTask}
# buttonActions = getButtonActions actions
# (anyUpd,tst) = anyUpdates tst
| newTask || not anyUpd
// generate TUI definition
# radios = [TUIRadio {TUIRadio | name = selectionId
, id = ""
, value = toString i
, boxLabel = Just (toString (SpanTag [ClassAttr "task-choice"] (visualizeAsHtmlLabel option)))
, fieldLabel = Nothing
, hideLabel = True
, checked = (i == selection)
} \\ option <- options & i <- [0..] ]
# form = [TUIRadioGroup {TUIRadioGroup | name = selectionId
, id = selectionId
, fieldLabel = Nothing
, hideLabel = True
, columns = 1
, items = radios
}]
# form = [TUIChoiceControl {TUIChoiceControl
| name = selectionId
, id = selectionId
, fieldLabel = Nothing
, optional = False
, allowMultiple = False
, options = [toString (SpanTag [ClassAttr "task-choice"] (visualizeAsHtmlLabel option)) \\ option <- options]
, selection = [selection]
}]
# menuActions = evaluateConditions (getMenuActions actions) 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
......@@ -190,7 +182,8 @@ makeChoiceTask question options initsel context actions tst=:{taskNr, newTask}
// The selection was updated
Nothing
// The selection was updated
# index = toInt (http_getValue selectionId updates "-1")
# upd = parseUpdate selectionId updates
# index = if(isEmpty upd) -1 (hd upd)
| index <> -1
# valid = index >= 0 && index < length options //Recompute validity
# tst = setTaskStore "selection" index tst
......@@ -202,6 +195,11 @@ makeChoiceTask question options initsel context actions tst=:{taskNr, newTask}
| otherwise
# tst = setTUIUpdates [] [] 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 options = mkInteractiveTask "enterMultipleChoice" (ignoreActionA (makeMultipleChoiceTask question options [] Nothing [ButtonAction (ActionOk, IfValid)]))
......@@ -241,17 +239,16 @@ makeMultipleChoiceTask question options initsel context actions tst=:{taskNr, ne
= (TaskFinished (ActionOk,[]),tst)
| newTask || not anyUpd
// generate TUI definition
# checks = [isMember i selection \\ i <- [0..(length options) - 1]]
# cboxes = [TUICheckBox
{TUICheckBox
| name = "sel-" +++ toString i
, id = editorId +++ "-cb-" +++ toString i
, value = toString i
, fieldLabel = Nothing
, hideLabel = True
, boxLabel = Just (visualizeAsTextLabel o)
, checked = c} \\ o <- options & i <- [0..] & c <- checks ]
# form = [ TUICheckBoxGroup {TUICheckBoxGroup |name = "selection", id = editorId +++ "-selection", fieldLabel = Nothing, hideLabel = True, columns = 1, items = cboxes}]
# checks = [isMember i selection \\ i <- [0..(length options) - 1]]
# form = [TUIChoiceControl { TUIChoiceControl
| name = "selection"
, id = editorId +++ "-selection"
, fieldLabel = Nothing
, allowMultiple = True
, optional = False
, options = [toString (SpanTag [ClassAttr "task-choice"] (visualizeAsHtmlLabel option)) \\ option <- options]
, selection = selection
}]
# menuActions = evaluateConditions (getMenuActions actions) True (select selection options)
# tst = setTUIDef (taskPanel taskId (html question) context (Just form) (makeButtons editorId buttonActions)) (html question) menuActions tst
= (TaskBusy, tst)
......@@ -269,18 +266,18 @@ makeMultipleChoiceTask question options initsel context actions tst=:{taskNr, ne
Just action = (TaskFinished (action, select selection options),tst)
Nothing
// Perhaps the selection was changed
# mbSel = parseSelection updates
# mbSel = parseSelection updates
# selection = case mbSel of Nothing = selection; Just sel = map toInt sel
# tst = setTaskStore "selection" (sort selection) tst
# tst = setTUIUpdates [] (evaluateConditions (getMenuActions actions) True (select selection options)) tst
= (TaskBusy, tst)
where
parseSelection :: [(String,String)] -> Maybe [String]
parseSelection :: [(String,String)] -> Maybe [Int]
parseSelection updates = fromJSON (fromString (http_getValue "selection" updates "[]"))
select :: [Int] [a] -> [a]
select indices options = [options !! index \\ index <- indices]
//Output tasks
showMessage :: message -> Task Void | html message
showMessage message = mkInteractiveTask "showMessage" (ignoreActionV (makeMessageTask message Nothing [ButtonAction (ActionOk, IfValid)]))
......
......@@ -3,6 +3,7 @@ implementation module WorkflowService
import Http, TSt
import HtmlUtil, Text
import StdArray, StdString, StdInt, StdList, StdBool, StdClass
import GenEq
from Util import mb2list
......
......@@ -13,7 +13,6 @@ derive JSONEncode TUIDef, TUIUpdate
derive gEq TUIDef
:: TUIId :== String
:: PlaceholderId :== String
:: TUIUpdate
= TUIAdd TUIId TUIDef // Add the additional component *after* the component with indicated id
......@@ -28,6 +27,7 @@ derive gEq TUIDef
:: TUIDef
= TUILabel
| TUIButton TUIButton
| TUIStringControl TUIBasicControl
| TUICharControl TUIBasicControl
| TUIIntControl TUIBasicControl
......@@ -36,7 +36,8 @@ derive gEq TUIDef
| TUINoteControl TUIBasicControl
| TUIDateControl TUIBasicControl
| TUITimeControl TUIBasicControl
| TUIPasswordControl TUIBasicControl
| TUIPasswordControl TUIBasicControl
| TUIChoiceControl TUIChoiceControl
| TUICurrencyControl TUICurrencyControl
| TUIUserControl TUIBasicControl
| TUIDocumentControl TUIDocumentControl
......@@ -48,29 +49,11 @@ derive gEq TUIDef
| TUITupleContainer TUITupleContainer
| TUIRecordContainer TUIRecordContainer
| 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
| TUIMenuButton TUIMenuButton
| TUIMenuItem TUIMenuItem
| TUIMenuSeparator
| TUITuple TUITuple
| TUICustom JSONNode
:: TUIBasicControl =
......@@ -83,6 +66,15 @@ derive gEq TUIDef
, errorMsg :: !String
, hintMsg :: !String
}
:: TUIChoiceControl =
{ name :: !String
, id :: !String
, fieldLabel :: !Maybe String
, allowMultiple :: !Bool
, optional :: !Bool
, options :: ![String]
, selection :: ![Int]
}
:: TUICurrencyControl =
{ name :: !String
, id :: !String
......@@ -177,126 +169,6 @@ derive gEq TUIDef
, hintMsg :: !String
, 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 :: !Maybe String
, hideLabel :: !Bool
, columns :: !Int
, items :: ![TUIDef]
}
:: TUIDateField =
{ name :: !String
, id :: !String
, value :: !String
, format :: !String
, fieldLabel :: !Maybe String
, hideLabel :: !Bool
}
:: TUITimeField =
{ name :: !String
, id :: !String
, value :: !String
, format :: !String
, fieldLabel :: !Maybe String
, hideLabel :: !Bool
}
:: TUIFieldSet =
{ title :: !String
, id :: !String
, layout :: !Maybe String
, items :: ![TUIDef]
, autoHeight :: !Bool
, border :: !Bool
, fieldLabel :: !Maybe String
, hideLabel :: !Bool
}
:: TUIPanel =
{ layout :: !String
, items :: ![TUIDef]
, buttons :: !Maybe [TUIDef]
, autoHeight :: !Bool
, autoWidth :: !Bool
, border :: !Bool
, bodyCssClass :: !String
, fieldLabel :: !Maybe String
, renderingHint :: !Int
, unstyled :: !Bool
}
:: TUIBox =
{ html :: !String
}
:: TUIHtmlPanel =
{ html :: !String
, border :: !Bool
......@@ -306,6 +178,15 @@ derive gEq TUIDef
, hideLabel :: !Bool
, unstyled :: !Bool
}
:: TUIButton =
{ name :: !String
, id :: !String
, text :: !String
, value :: !String
, disabled :: !Bool
, iconCls :: !String
}
:: TUIMenu =
{ items :: ![TUIDef]
}
......@@ -324,17 +205,4 @@ derive gEq TUIDef
, iconCls :: !Maybe String
, topGroupAction:: !Maybe Bool
, hotkey :: !Maybe Hotkey
}
:: TUITuple =
{ layout :: !String
, id :: !String
, items :: ![TUIDef]
, buttons :: !Maybe [TUIDef]
, autoHeight :: !Bool
, autoWidth :: !Bool
, border :: !Bool
, bodyCssClass :: !String
, fieldLabel :: !Maybe String
, renderingHint :: !Int
, unstyled :: !Bool
}
\ No newline at end of file
implementation module TUIDefinition
import JSON,StdList,GenEq
import JSON,StdList,StdBool,GenEq
from Types import :: Document, :: DocumentId
from ProcessDB import :: Hotkey
derive gEq TUIDef, TUIBasicControl, TUICurrencyControl, TUIDocumentControl, TUIConstructorControl, TUIButtonControl, TUIListItemControl
derive gEq TUITupleContainer, TUIRecordContainer, TUIListContainer, JSONNode, Maybe, Document
derive gEq TUIButton, TUITextArea, TUIUserField, TUINumberField, TUIComboBox, TUICheckBox, TUICheckBoxGroup, TUIRadio, TUIRadioGroup, TUIDateField, TUITimeField, TUIFieldSet, TUIPanel, TUIHtmlPanel, TUIMenuButton, TUIMenu, TUIMenuItem, Hotkey
derive gEq TUIUpdate, TUIBox, TUITuple
derive gEq TUIButton, TUIUpdate, TUIChoiceControl, TUIMenuButton, TUIMenu, TUIMenuItem, TUIHtmlPanel, Hotkey
//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, TUIMenuButton, TUIMenu, TUIMenuItem, Hotkey
derive JSONEncode TUIUpdate, TUIBox, TUITuple
derive JSONEncode TUIBasicControl, TUICurrencyControl, TUIDocumentControl, TUIConstructorControl, TUIButtonControl, TUIListItemControl
derive JSONEncode TUIButton, TUIUpdate, TUIMenuButton, TUIMenu, TUIMenuItem, TUIHtmlPanel, Hotkey
derive JSONEncode TUIBasicControl, TUICurrencyControl, TUIDocumentControl, TUIConstructorControl
derive JSONEncode TUIButtonControl, TUIListItemControl, TUIChoiceControl
derive JSONEncode TUITupleContainer, TUIRecordContainer, TUIListContainer