Ignore:
Timestamp:
03/12/14 15:16:54 (11 years ago)
Author:
hendrikvanantwerpen
Message:
  • Factored out general object mapping and iteration.
  • Split widgets for multiplechoice and singlechoice.
  • Restored readOnly/disabled setting for QuestionEditorPreviewItem? on innerWidget (since view innerWidget is not a form anymore, we cannot just set it on that, we iterate over all form children now).
Location:
Dev/trunk/src/client/qed-client/widgets
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/src/client/qed-client/widgets/LineWithActionsWidget.js

    r494 r510  
    1 define(['dojo/_base/declare',
    2     'dojo/_base/lang',
    3     'dojo/on',
    4     'dojo/dom',
    5     'dojo/_base/event',
    6     'dojo/dom-class',
    7     'dijit/form/Button',
    8     'dijit/_WidgetBase',
    9     'dijit/_TemplatedMixin',
    10     'dijit/_WidgetsInTemplateMixin',
    11     'dojo/text!./templates/LineWithActionsWidget.html'
    12 ],function(declare,lang,on,dom,event,domClass,Button,_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,templateString){
     1define([
     2    "../lib/object",
     3    "dijit/_TemplatedMixin",
     4    "dijit/_WidgetBase",
     5    "dijit/_WidgetsInTemplateMixin",
     6    "dijit/form/Button",
     7    "dojo/_base/declare",
     8    "dojo/_base/event",
     9    "dojo/_base/lang",
     10    "dojo/dom",
     11    "dojo/dom-class",
     12    "dojo/on",
     13    "dojo/text!./templates/LineWithActionsWidget.html"
     14], function(objectFuns, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, Button, declare, event, lang, dom, domClass, on, templateString) {
    1315    return declare([_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin],{
    1416        templateString: templateString,
     
    3335                return;
    3436            }
    35             for (var action in this.actions) {
    36                 if ( this.actions.hasOwnProperty(action) ) {
    37                     var properties;
    38                     if (this.actions[action].properties.blockButton === true) {
    39                         properties = lang.mixin({
    40                             baseClass: 'rftBlockButton',
    41                             label: "Default",
    42                             iconClass: 'rftIcon rftIcon'+this.actions[action].properties.icon,
    43                             title: this.actions[action].properties.tooltip,
    44                             onClick: lang.hitch(this, function(action, e){
    45                                 if ( action.callback ) { action.callback(e); }
    46                                 if ( e ) { event.stop(e); }
    47                                 return false;
    48                             }, this.actions[action])
    49                         }, this.actions[action].properties);
    50                         new Button(properties).placeAt(this.buttonsNode);
    51                     } else {
    52                         properties = lang.mixin({
    53                             baseClass: 'rftInlineButton',
    54                             label: "Default",
    55                             showLabel: false,
    56                             iconClass: 'rftIcon rftIcon'+this.actions[action].properties.icon,
    57                             title: this.actions[action].properties.tooltip,
    58                             onClick: lang.hitch(this, function(action, e){
    59                                 if ( action.callback ) { action.callback(e); }
    60                                 if ( e ) { event.stop(e); }
    61                                 return false;
    62                             }, this.actions[action])
    63                         }, this.actions[action].properties);
    64                         new Button(properties).placeAt(this.buttonsNode);
    65                     }
     37            objectFuns.forEach(this.actions, function(value,action){
     38                var properties;
     39                if (value.properties.blockButton === true) {
     40                    properties = lang.mixin({
     41                        baseClass: 'rftBlockButton',
     42                        label: "Default",
     43                        iconClass: 'rftIcon rftIcon'+value.properties.icon,
     44                        title: value.properties.tooltip,
     45                        onClick: lang.hitch(this, function(action, e){
     46                            if ( action.callback ) { action.callback(e); }
     47                            if ( e ) { event.stop(e); }
     48                            return false;
     49                        }, value)
     50                    }, value.properties);
     51                    new Button(properties).placeAt(this.buttonsNode);
     52                } else {
     53                    properties = lang.mixin({
     54                        baseClass: 'rftInlineButton',
     55                        label: "Default",
     56                        showLabel: false,
     57                        iconClass: 'rftIcon rftIcon'+value.properties.icon,
     58                        title: value.properties.tooltip,
     59                        onClick: lang.hitch(this, function(action, e){
     60                            if ( action.callback ) { action.callback(e); }
     61                            if ( e ) { event.stop(e); }
     62                            return false;
     63                        }, value)
     64                    }, value.properties);
     65                    new Button(properties).placeAt(this.buttonsNode);
    6666                }
    67             }
     67            },this);
    6868        },
    6969        refresh: function() {
  • Dev/trunk/src/client/qed-client/widgets/ObjectBox.js

    r472 r510  
    11define([
    2     'dojo/_base/declare',
    3     'dojo/_base/lang',
    4     'dijit/_WidgetBase',
    5     'dijit/_TemplatedMixin',
    6     'dijit/_WidgetsInTemplateMixin',
    7     './LineWithActionsWidget',
    8     'dojo/text!./templates/ObjectBox.html'
    9 ], function(declare, lang, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, LineWithActionsWidget, template){
     2    "../lib/object",
     3    "./LineWithActionsWidget",
     4    "dijit/_TemplatedMixin",
     5    "dijit/_WidgetBase",
     6    "dijit/_WidgetsInTemplateMixin",
     7    "dojo/_base/declare",
     8    "dojo/_base/lang",
     9    "dojo/text!./templates/ObjectBox.html"
     10], function(objectFuns, LineWithActionsWidget, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, declare, lang, template) {
    1011    return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
    1112        baseClass: "rftObjectBox",
     
    3940        },
    4041        _createLine3Actions: function() {
    41             var line3Actions = {};
    42             for (var action in this.actions) {
    43                 if ( this.actions.hasOwnProperty(action) ) {
    44                     line3Actions[action] = {
    45                         callback: lang.hitch(this, function(callback){
    46                             if ( this.value ) { callback(this.value); }
    47                         }, this.actions[action]),
    48                         properties: {
    49                             blockButton: true,
    50                             label: action,
    51                             icon: action.charAt(0).toUpperCase()+action.slice(1)
    52                         }
    53                     };
    54                 }
    55             }
    56             return line3Actions;
     42            return objectFuns.map(this.actions,function(value,name){
     43                return {
     44                    callback: lang.hitch(this, function(callback){
     45                        if ( this.value ) { callback(this.value); }
     46                    }, value),
     47                    properties: {
     48                        blockButton: true,
     49                        label: name,
     50                        icon: name.charAt(0).toUpperCase()+name.slice(1)
     51                    }
     52                };
     53            },this);
    5754        },
    5855        _showInfoBox: function() {},
  • Dev/trunk/src/client/qed-client/widgets/Selector.js

    r495 r510  
    11define([
     2    "../lib/object",
    23    "./LineWithActionsWidget",
    34    "dijit/_Container",
     
    1617    "dojo/query",
    1718    "dojo/text!./templates/Selector.html"
    18 ], function(LineWithActionsWidget, _Container, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, registry, baseArray, declare, event, lang, Source, domClass, domConstruct, fx, query, templateString) {
     19], function(objectFuns, LineWithActionsWidget, _Container, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, registry, baseArray, declare, event, lang, Source, domClass, domConstruct, fx, query, templateString) {
    1920
    2021    function get(selector, item) {
     
    6263        },
    6364        _createTitleLine: function() {
    64             var actions = {};
    65             var action = null;
    6665            var userActions =
    6766                    lang.isFunction(this.selectedActions) ?
    6867                    this.selectedActions() :
    6968                    this.selectedActions;
    70             if ( userActions ) {
    71                 for (var actionName in userActions) {
    72                     if ( userActions.hasOwnProperty(actionName) ) {
    73                         action = userActions[actionName];
    74                         actions[actionName] = {
    75                             callback: action.callback &&
    76                                       lang.hitch(this,this._onSelectedAction,
    77                                                  action.callback),
    78                             properties: {
    79                                 blockButton: true,
    80                                 label: action.title || actionName,
    81                                 icon: action.icon,
    82                                 tooltip: action.description
    83                             }
    84 
    85                         };
    86                     }
    87                 }
    88             }
    89 
     69
     70            var actions = objectFuns.map(userActions||{},function(action,actionName){
     71                return {
     72                    callback: action.callback &&
     73                              lang.hitch(this,this._onSelectedAction,
     74                                         action.callback),
     75                    properties: {
     76                        blockButton: true,
     77                        label: action.title || actionName,
     78                        icon: action.icon,
     79                        tooltip: action.description
     80                    }
     81
     82                };
     83            }, this);
    9084            this._titleLine = new LineWithActionsWidget({
    9185                title: this.title,
     
    205199        },
    206200        _createLineNode: function(item) {
    207             var actions = {};
    208201            var userActions =
    209202                    lang.isFunction(this.itemActions) ?
    210203                    this.itemActions(item) :
    211204                    this.itemActions;
    212             if (userActions) {
    213                 for (var actionName in userActions) {
    214                     if ( userActions.hasOwnProperty(actionName) ) {
    215                         var action = userActions[actionName];
    216                         actions[actionName] = {
    217                             callback: action.callback &&
    218                                       lang.partial(action.callback,item,this),
    219                             properties: {
    220                                 blockButton: false,
    221                                 showLabel: false,
    222                                 icon: action.icon + " black",
    223                                 tooltip: action.description
    224                             }
    225                         };
    226                     }
    227                 }
    228             }
     205            var actions = objectFuns.map(userActions||{},function(action,actionName){
     206                return {
     207                    callback: action.callback &&
     208                              lang.partial(action.callback,item,this),
     209                    properties: {
     210                        blockButton: false,
     211                        showLabel: false,
     212                        icon: action.icon + " black",
     213                        tooltip: action.description
     214                    }
     215                };
     216            }, this);
    229217            var w = new LineWithActionsWidget({
    230218                title: get(this.itemTitle,item),
  • Dev/trunk/src/client/qed-client/widgets/TabbedBrowser.js

    r495 r510  
    11define([
     2    "../lib/object",
    23    "./Selector",
    34    "dijit/layout/ContentPane",
     
    910    "dojo/when",
    1011    "dojox/widget/Standby"
    11 ], function(Selector, ContentPane, TabContainer, array, declare, lang, win, when, Standby) {
     12], function(objectFuns, Selector, ContentPane, TabContainer, array, declare, lang, win, when, Standby) {
    1213    return declare([TabContainer],{
    1314        tabPosition: 'left-h',
     
    121122        removeItem: function(item) {
    122123            var cmap = this._dataMap;
    123             for ( var cat in cmap ) {
    124                 if ( cmap.hasOwnProperty(cat) ) {
    125                     var tmap = cmap[cat];
    126                     for ( var top in tmap ) {
    127                         if ( tmap.hasOwnProperty(top) ) {
    128                             var widget = tmap[top]._widget;
    129                             if ( widget ) { widget.removeItem(item); }
    130                         }
    131                     }
    132                 }
    133             }
     124            objectFuns.forEach(cmap,function(tmap,cat){
     125                objectFuns.forEach(tmap,function(topObj,top){
     126                    var widget = topObj._widget;
     127                    if ( widget ) { widget.removeItem(item); }
     128                },this);
     129            },this);
    134130        },
    135131        _busy: function() {
Note: See TracChangeset for help on using the changeset viewer.