Changeset 510 for Dev


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
Files:
9 added
28 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/src/client/qed-client/css/qed.less

    r506 r510  
    3232@import "widgets/LineWithActions.less";
    3333@import "model/widgets/ScaleWidget.less";
     34@import "model/widgets/StringInput.less";
     35@import "model/widgets/TextInput.less";
     36@import "model/widgets/NumberInput.less";
    3437@import "model/widgets/MultipleChoiceWidget.less";
    3538@import "model/widgets/QuestionListView.less";
  • Dev/trunk/src/client/qed-client/model/classes/_Class.js

    r506 r510  
    11define([
     2    "../../lib/object",
    23    "./_View",
    34    "dojo/_base/array",
     
    56    "dojo/_base/lang",
    67    "dojo/date/stamp"
    7 ], function(_View, array, declare, lang, stamp) {
     8], function(objectFuns, _View, array, declare, lang, stamp) {
    89
    910    var _Class = declare([_View],{
     
    2425            obj = lang.clone(obj);
    2526            obj = this._serialize(obj) || obj;
    26             this._strip(obj);
     27            this._sanitize(obj);
    2728            return obj;
    2829        },
     
    6566            return stamp.toISOString(date,{zulu:true,milliseconds:false});
    6667        },
    67         _strip: function(obj) {
     68        _sanitize: function(obj) {
    6869            if ( lang.isArray(obj) ) {
    69                 array.forEach(obj,this._strip,this);
     70                array.forEach(obj,this._sanitize,this);
    7071            } else if ( lang.isObject(obj) ) {
    71                 for ( var prop in obj ) {
    72                     if ( obj.hasOwnProperty(prop) ) {
    73                         var v = obj[prop];
    74                         if ( v === null || v === "" || (typeof v === "number" && isNaN(v)) ) {
    75                             delete obj[prop];
    76                         } else {
    77                             this._strip(v);
    78                         }
     72                objectFuns.forEach(obj,function(v,prop){
     73                    if ( v === null ||
     74                         v === "" ||
     75                         (typeof v === "number" && isNaN(v)) ) {
     76                        delete obj[prop];
     77                    } else {
     78                        this._sanitize(v);
    7979                    }
    80                 }
     80
     81                },this);
    8182            }
    82 
    8383        }
    8484    });
  • Dev/trunk/src/client/qed-client/model/classes/responses.js

    r509 r510  
    11define([
     2    "../../lib/object",
    23    "./_Class",
    34    "./surveyRuns",
     
    78    "dojo/_base/lang",
    89    "dojo/_base/xhr"
    9 ], function(_Class, surveyRuns, Deferred, declare, json, lang, xhr) {
     10], function(objectFuns, _Class, surveyRuns, Deferred, declare, json, lang, xhr) {
    1011
    1112    var Responses = declare([_Class],{
     
    2930        },
    3031        _serialize: function(obj) {
     32            this._convertCheckAndRadio(obj.answers);
    3133            if (obj._surveyRun) {
    3234                obj._surveyRun = surveyRuns._doSerialize(obj._surveyRun);
     
    8486                return result;
    8587            },lang.hitch(this,'_deserializeError'));
     88        },
     89        _convertCheckAndRadio: function(answers) {
     90            // When we encounter an array, we assume it's really a
     91            // checkbox value.
     92            objectFuns.forEach(answers,function(v,prop){
     93                if ( lang.isArray(v) ) {
     94                    switch (v.length) {
     95                    case 0:
     96                    case 1:
     97                        answers[prop] = v[0];
     98                        break;
     99                    default:
     100                        throw new Error("Responses cannot exist of array values.");
     101                    }
     102                }
     103            },this);
    86104        }
    87105    });
  • Dev/trunk/src/client/qed-client/model/widgets/QuestionEditorPreview.js

    r490 r510  
    2323                value: item
    2424            });
     25            previewItem.showEdit();
    2526            this.own(previewItem.on('destroy',
    2627                                    lang.hitch(this,'removeItem',id,true)));
  • Dev/trunk/src/client/qed-client/model/widgets/QuestionEditorPreviewItem.js

    r508 r510  
    66    "dijit/_WidgetBase",
    77    "dijit/_WidgetsInTemplateMixin",
     8    "dojo/_base/array",
    89    "dojo/_base/declare",
    910    "dojo/_base/event",
     
    1516    "dojo/on",
    1617    "dojo/text!./templates/QuestionEditorPreviewItem.html"
    17 ], function(_ComplexValueWidget, QuestionWidgetFactory, _Container, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, declare, event, fx, lang, domClass, domGeom, domStyle, on, template) {
     18], function(_ComplexValueWidget, QuestionWidgetFactory, _Container, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, array, declare, event, fx, lang, domClass, domGeom, domStyle, on, template) {
    1819    return declare([_ComplexValueWidget], {
    1920        templateString: template,
     
    2425        foldDuration: [250, 250],
    2526        animation: null,
    26         _editing: false,
     27        _editing: null,
    2728        _factory: new QuestionWidgetFactory(),
    2829
     
    3637            this.own(this.editButton.on('click',
    3738                        lang.hitch(this, 'onToggleEdit')));
    38             this.showEdit();
     39            this.showView();
    3940        },
    4041        _handleDestroy: function(evt) {
     
    4445        },
    4546        _getValueAttr: function(value) {
    46             if ( this._editing ) {
     47            if ( this._editing === true ) {
    4748                this.value = this.innerWidget.get('value');
    4849            }
     
    5152        _setValueAttr: function(value) {
    5253            this.value = value;
    53             if ( this._editing ) {
     54            if ( this._editing  === true ) {
    5455                this._showEditWidget();
    5556            } else {
     
    5758            }
    5859        },
    59         _setReadOnlyAttr: function() {
    60             this.inherited(arguments);
     60        _setReadOnlyAttr: function(readOnly) {
     61            this._set('readOnly',readOnly);
     62            this._setReadOnlyChildren(this.readOnly);
    6163            this._updateRemoveBtn();
    6264        },
    63         _setDisabledAttr: function() {
    64             this.inherited(arguments);
     65        _setDisabledAttr: function(disabled) {
     66            this._set('disabled',disabled);
     67            this._setDisabledChildren(this.disabled);
    6568            this._updateRemoveBtn();
    6669        },
    6770        _updateRemoveBtn: function() {
     71            var node = this.removeButton.domNode;
    6872            if ( this.readOnly || this.disabled ) {
    69                 domClass.add(this.removeButton.domNode, 'dijitHidden');
     73                domClass.add(node, 'dijitHidden');
    7074            } else {
    71                 domClass.remove(this.removeButton.domNode, 'dijitHidden');
     75                domClass.remove(node, 'dijitHidden');
    7276            }
    7377        },
     78        _setDisabledChildren: function(disabled) {
     79            array.forEach(this._getDescendantFormWidgets(),function(widget){
     80                widget.set('disabled',disabled);
     81            });
     82        },
     83        _setReadOnlyChildren: function(readOnly) {
     84            array.forEach(this._getDescendantFormWidgets(),function(widget){
     85                widget.set('readOnly',readOnly);
     86            });
     87        },
    7488        validate: function() {
    75             return !this._editing || this.innerWidget.validate();
     89            return this._editing === false || this.innerWidget.validate();
    7690        },
    7791        focus: function() {
    78             if ( this._editing ) {
     92            if ( this._editing === true ) {
    7993                this.innerWidget.focus();
    8094            }
    8195        },
    8296        showView: function() {
    83             if ( this._editing ) {
     97            if ( this._editing === true ) {
    8498                if (!this.innerWidget.validate || this.innerWidget.validate() ) {
    8599                    this.value = this.innerWidget.get('value');
     
    89103        },
    90104        showEdit: function() {
    91             if (!this._editing) {
     105            if ( this._editing === false ) {
    92106                this._showEditWidget();
    93107            }
    94108        },
    95109        onToggleEdit: function(evt) {
    96             if (this._editing) {
     110            if ( this._editing === true ) {
    97111                this.showView();
    98112            } else {
     
    106120            // on it,but we don't know the actual code here.
    107121            var newWidget = this._factory.createViewWidget( lang.mixin({code:""},this.value) );
    108             if ( newWidget !== null ) {
     122            if ( newWidget ) {
    109123                this._destroyInnerWidget();
    110124                this.innerWidget = newWidget;
    111                 this.innerWidget.set('readOnly',true);
    112125                this.addChild(this.innerWidget);
     126                this._setReadOnlyChildren(true);
     127                this._setDisabledChildren(true);
    113128                this.titleNode.innerHTML = this.value.type+" [preview]";
    114129                domClass.replace(this.editButton.iconNode, "rftIconEdit", "rftIconAccept");
     
    119134        _showEditWidget: function() {
    120135            var newWidget = this._factory.createEditWidget( this.value );
    121             if ( newWidget !== null ) {
     136            if ( newWidget ) {
    122137                this._destroyInnerWidget();
    123138                this.innerWidget = newWidget;
    124                 this.innerWidget.set('readOnly',this.readOnly);
    125                 this.innerWidget.set('disabled',this.disabled);
    126139                this.addChild(this.innerWidget);
     140                this._setReadOnlyChildren(this.readOnly);
     141                this._setDisabledChildren(this.disabled);
    127142                this.titleNode.innerHTML = this.value.type+" [editing]";
    128143                domClass.replace(this.editButton.iconNode, "rftIconAccept", "rftIconEdit");
  • Dev/trunk/src/client/qed-client/model/widgets/QuestionEditorToolkit.js

    r502 r510  
    3434            { type: "NumberInput" },
    3535            { type: "ScaleInput" },
     36            { type: "SingleChoiceInput" },
    3637            { type: "MultipleChoiceInput" }
    3738        ],
     
    4445            "NumberInput": "Number",
    4546            "ScaleInput": "Scale",
     47            "SingleChoiceInput": "Single choice",
    4648            "MultipleChoiceInput": "Multiple choice"
    4749        },
     
    5456            "NumberInput": "Number",
    5557            "ScaleInput": "Scale",
     58            "SingleChoiceInput": "MultipleChoice",
    5659            "MultipleChoiceInput": "MultipleChoice"
    5760        },
  • Dev/trunk/src/client/qed-client/model/widgets/questions/Factory.js

    r443 r510  
    11define([
     2    "../../../lib/object",
    23    "./HeaderConfigWidget",
    34    "./HeaderWidget",
     
    89    "./ScaleInputConfigWidget",
    910    "./ScaleInputWidget",
     11    "./SingleChoiceInputConfigWidget",
     12    "./SingleChoiceInputWidget",
    1013    "./StringInputConfigWidget",
    1114    "./StringInputWidget",
     
    1619    "dijit/_WidgetBase",
    1720    "dojo/_base/declare"
    18 ], function(HeaderConfigWidget, HeaderWidget, MultipleChoiceInputConfigWidget, MultipleChoiceInputWidget, NumberInputConfigWidget, NumberInputWidget, ScaleInputConfigWidget, ScaleInputWidget, StringInputConfigWidget, StringInputWidget, TextConfigWidget, TextInputConfigWidget, TextInputWidget, TextWidget, _WidgetBase, declare) {
     21], function(objectFuns, HeaderConfigWidget, HeaderWidget, MultipleChoiceInputConfigWidget, MultipleChoiceInputWidget, NumberInputConfigWidget, NumberInputWidget, ScaleInputConfigWidget, ScaleInputWidget, SingleChoiceInputConfigWidget, SingleChoiceInputWidget, StringInputConfigWidget, StringInputWidget, TextConfigWidget, TextInputConfigWidget, TextInputWidget, TextWidget, _WidgetBase, declare) {
     22   
     23    var DividerWidget = declare([_WidgetBase], {
     24        postCreate: function() {
     25            this.domNode.innerHTML = "<hr>";
     26        }
     27    });
     28
     29    var viewMap = {
     30        Header: HeaderWidget,
     31        Text: TextWidget,
     32        Divider: DividerWidget,
     33        StringInput: StringInputWidget,
     34        TextInput: TextInputWidget,
     35        NumberInput: NumberInputWidget,
     36        MultipleChoiceInput: MultipleChoiceInputWidget,
     37        SingleChoiceInput: SingleChoiceInputWidget,
     38        ScaleInput: ScaleInputWidget
     39    };
     40    var editMap = {
     41        Header: HeaderConfigWidget,
     42        Text: TextConfigWidget,
     43        StringInput: StringInputConfigWidget,
     44        TextInput: TextInputConfigWidget,
     45        NumberInput: NumberInputConfigWidget,
     46        MultipleChoiceInput: MultipleChoiceInputConfigWidget,
     47        SingleChoiceInput: SingleChoiceInputConfigWidget,
     48        ScaleInput: ScaleInputConfigWidget
     49    };
     50
     51    editMap = objectFuns.map(editMap,function(Ctor,type){
     52        return declare([Ctor],{
     53            _getValueAttr: function() {
     54                var value = this.inherited(arguments);
     55                value.type = type;
     56                return value;
     57            }
     58        });
     59    });
     60
    1961    var factory = declare(null, {
    2062        createViewWidget: function(/*Object*/options) {
     
    2264            //            type: "Header", "Text", "TextInput", etc.
    2365            //            other type specific fields
    24             var fun = this['create'+options.type+'ViewWidget'];
    25             var view = fun !== undefined ? fun(options) : null;
     66            var Ctor = viewMap[options.type];
     67            var view = Ctor && new Ctor(options) || null;
    2668            return view;
    2769        },
    2870        createEditWidget: function(/*Object*/options) {
    29             var fun = this['create'+options.type+'EditWidget'];
    30             var view = fun !== undefined ? fun(options) : null;
    31             return view;
    32         },
    33 
    34         createHeaderViewWidget: function(config) {
    35             return new HeaderWidget(config);
    36         },
    37         createHeaderEditWidget: function(config) {
    38             return new HeaderConfigWidget({
    39                 value: config
     71            var Ctor = editMap[options.type];
     72            var edit = Ctor && new Ctor({
     73                value: options
    4074            });
    41         },
    42 
    43         createTextViewWidget: function(config) {
    44             return new TextWidget(config);
    45         },
    46         createTextEditWidget: function(config) {
    47             return new TextConfigWidget({
    48                 value: config
    49             });
    50         },
    51 
    52         createDividerViewWidget: function(options) {
    53             return new DividerView({
    54                 options: options
    55             });
    56         },
    57 
    58         createStringInputViewWidget: function(config) {
    59             return new StringInputWidget(config);
    60         },
    61         createStringInputEditWidget: function(config) {
    62             return new StringInputConfigWidget({
    63                 value: config
    64             });
    65         },
    66 
    67         createTextInputViewWidget: function(config) {
    68             return new TextInputWidget(config);
    69         },
    70         createTextInputEditWidget: function(config) {
    71             return new TextInputConfigWidget({
    72                 value: config
    73             });
    74         },
    75 
    76         createNumberInputViewWidget: function(config) {
    77             return new NumberInputWidget(config);
    78         },
    79         createNumberInputEditWidget: function(config) {
    80             return new NumberInputConfigWidget({
    81                 value: config
    82             });
    83         },
    84 
    85         createMultipleChoiceInputViewWidget: function(config) {
    86             return new MultipleChoiceInputWidget(config);
    87         },
    88         createMultipleChoiceInputEditWidget: function(config) {
    89             return new MultipleChoiceInputConfigWidget({
    90                 value: config
    91             });
    92         },
    93 
    94         createScaleInputViewWidget: function(options) {
    95             return new ScaleInputWidget(options);
    96         },
    97         createScaleInputEditWidget: function(options) {
    98             return new ScaleInputConfigWidget({
    99                 value: options || {}
    100             });
    101         }
    102     });
    103 
    104     var DividerView = declare([_WidgetBase], {
    105         postCreate: function() {
    106             this.domNode.innerHTML = "<hr>";
     75            return edit || null;
    10776        }
    10877    });
  • Dev/trunk/src/client/qed-client/model/widgets/questions/MultipleChoiceInputConfigWidget.js

    r506 r510  
    1919   
    2020    return declare([_ComplexValueWidget],{
    21         type: 'MultipleChoiceInput',
    2221        baseClass: 'qedMultipleChoiceWidget',
    2322        templateString: template,
     
    5150            });
    5251        },
    53         _getValueAttr: function() {
    54             var value = this.inherited(arguments);
    55             value.type = this.type;
    56             value.allowMultiple = value.allowMultiple.length > 0;
    57             return value;
    58         },
    59         _setValueAttr: function(value) {
    60             value.allowMultiple = value.allowMultiple ? ["on"] : [];
    61             return this.inherited(arguments);
    62         },
    6352        onAddItem: function(evt) {
    6453            this.itemsWidget.appendItem({},true);
  • Dev/trunk/src/client/qed-client/model/widgets/questions/MultipleChoiceInputWidget.js

    r508 r510  
    55    "dijit/_WidgetsInTemplateMixin",
    66    "dijit/form/CheckBox",
    7     "dijit/form/RadioButton",
    87    "dojo/_base/array",
    98    "dojo/_base/declare",
    109    "dojo/dom-construct",
    1110    "dojo/text!./templates/MultipleChoiceInputWidget.html"
    12 ], function(_Container, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, CheckBox, RadioButton, array, declare, domConstruct, template) {
     11], function(_Container, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, CheckBox, array, declare, domConstruct, template) {
    1312    return declare([_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{
    1413        templateString: template,
     
    1817
    1918            domConstruct.empty(this.domNode);
    20             var Ctor = this.allowMultiple === true ? CheckBox : RadioButton;
    2119            array.forEach(this.items, function(item){
    2220                var div = domConstruct.create("div", {
    2321                }, this.domNode, "last");
    24                 var input = new Ctor({
    25                     name: this.code + (this.allowMultiple === true ? item.subcode : ''),
    26                     value: this.allowMultiple === true ? null : item.subcode
     22                var input = new CheckBox({
     23                    name: this.code + item.subcode,
     24                    value: 1
    2725                }).placeAt(div);
    2826                var label = domConstruct.create("label",{
  • Dev/trunk/src/client/qed-client/model/widgets/questions/NumberInputConfigWidget.js

    r506 r510  
    55], function(_ComplexValueWidget, declare, template) {
    66    return declare([_ComplexValueWidget],{
    7         type: 'NumberInput',
    8         templateString: template,
    9         _getValueAttr: function() {
    10             var value = this.inherited(arguments);
    11             value.type = this.type;
    12             return value;
    13         }
     7        baseClass: 'qedNumberInputConfig',
     8        templateString: template
    149    });
    1510});
  • Dev/trunk/src/client/qed-client/model/widgets/questions/NumberInputWidget.js

    r508 r510  
    1010        templateString: template,
    1111        text: '',
     12        subcode: '',
    1213        startup: function() {
    1314            if ( this._started ) { return; }
  • Dev/trunk/src/client/qed-client/model/widgets/questions/ScaleInputConfigWidget.js

    r490 r510  
    7979            return false;
    8080        },
    81         _getValueAttr: function(){
    82             var value = this.inherited(arguments);
    83             value.type = 'ScaleInput';
    84             return value;
    85         },
    8681        onNAChange: function(value) {
    8782            this._hasNA = value !== null && value !== "";
  • Dev/trunk/src/client/qed-client/model/widgets/questions/StringInputConfigWidget.js

    r443 r510  
    55], function(_ComplexValueWidget, declare, template) {
    66    return declare([_ComplexValueWidget],{
    7         type: 'StringInput',
    8         templateString: template,
    9         _getValueAttr: function() {
    10             var value = this.inherited(arguments);
    11             value.type = this.type;
    12             return value;
    13         }
     7        baseClass: 'qedStringInputConfig',
     8        templateString: template
    149    });
    1510});
  • Dev/trunk/src/client/qed-client/model/widgets/questions/StringInputWidget.js

    r508 r510  
    99    return declare([_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{
    1010        templateString: template,
    11         text: ''
     11        text: '',
     12        subcode: ''
    1213    });
    1314});
  • Dev/trunk/src/client/qed-client/model/widgets/questions/TextConfigWidget.js

    r443 r510  
    55], function(_ComplexValueWidget, declare, template) {
    66    return declare([_ComplexValueWidget],{
    7         type: 'Text',
    8         templateString: template,
    9         _getValueAttr: function() {
    10             var value = this.inherited(arguments);
    11             value.type = this.type;
    12             return value;
    13         }
     7        templateString: template
    148    });
    159});
  • Dev/trunk/src/client/qed-client/model/widgets/questions/TextInputConfigWidget.js

    r506 r510  
    55], function(_ComplexValueWidget, declare, template) {
    66    return declare([_ComplexValueWidget],{
    7         type: 'TextInput',
    8         templateString: template,
    9         _getValueAttr: function() {
    10             var value = this.inherited(arguments);
    11             value.type = this.type;
    12             return value;
    13         }
     7        baseClass: 'qedTextInputConfig',
     8        templateString: template
    149    });
    1510});
  • Dev/trunk/src/client/qed-client/model/widgets/questions/TextInputWidget.js

    r508 r510  
    1010        templateString: template,
    1111        text: '',
     12        subcode: '',
    1213        startup: function() {
    1314            if ( this._started ) { return; }
  • Dev/trunk/src/client/qed-client/model/widgets/questions/templates/MultipleChoiceInputConfigRowWidget.html

    r506 r510  
    11<form>
    2     <div data-dojo-type="dijit/form/ValidationTextBox"
    3          data-dojo-props="required: true, placeholder: 'Subcode'"
     2  <div data-dojo-type="dijit/form/CheckBox"
     3       data-dojo-props="disabled: true, readOnly: true"></div>
     4  <div data-dojo-type="dijit/form/ValidationTextBox"
     5       data-dojo-props="required: true, placeholder: 'Subcode'"
    46       class="subcode"
    5          name="subcode"></div>
     7       name="subcode"></div>
    68  <div data-dojo-type="dijit/form/ValidationTextBox"
    79       data-dojo-props="required: true, placeholder: 'Item text'"
  • Dev/trunk/src/client/qed-client/model/widgets/questions/templates/MultipleChoiceInputConfigWidget.html

    r506 r510  
    11<form class="${baseClass}">
    2   <div>
    3     <label class="qedLabel" for="allowMultiple">Allow multiple</label>
    4     <div name="allowMultiple" data-dojo-type="dijit/form/CheckBox"></div>
    5   </div>
    62  <div data-dojo-attach-point="itemsNode">
    73  </div>
  • Dev/trunk/src/client/qed-client/model/widgets/questions/templates/NumberInputConfigWidget.html

    r506 r510  
    1 <form>
     1<form class="${baseClass}">
    22  <div>
    33    <label class="qedLabel" for="text">Subcode</label>
    4     <div class="qedField"
     4    <div class="qedField subcode"
    55         data-dojo-attach-point="subcodeBox"
    66         data-dojo-type="dijit/form/ValidationTextBox"
  • Dev/trunk/src/client/qed-client/model/widgets/questions/templates/StringInputConfigWidget.html

    r506 r510  
    1 <form>
     1<form class="${baseClass}">
    22  <div>
    3     <label class="qedLabel" for="text">Subcode</label>
    4     <div class="qedField"
     3    <label class="qedLabel" for="subcode">Subcode</label>
     4    <div class="qedField subcode"
    55         data-dojo-attach-point="subcodeBox"
    66         data-dojo-type="dijit/form/ValidationTextBox"
  • Dev/trunk/src/client/qed-client/model/widgets/questions/templates/TextConfigWidget.html

    r461 r510  
    11<form>
    22  <label for="text" class="qedLabel">Text</label>
    3   <textarea class="qedField" data-dojo-type="dijit/form/Textarea" name="text"></textarea>
     3  <textarea class="qedField"
     4            data-dojo-type="dijit/form/Textarea"
     5            data-dojo-props="required: true"
     6            name="text"></textarea>
    47</form>
  • Dev/trunk/src/client/qed-client/model/widgets/questions/templates/TextInputConfigWidget.html

    r506 r510  
    1 <form>
     1<form class="${baseClass}">
    22  <div>
    33    <label class="qedLabel" for="text">Subcode</label>
    4     <div class="qedField"
     4    <div class="qedField subcode"
    55         data-dojo-attach-point="subcodeBox"
    66         data-dojo-type="dijit/form/ValidationTextBox"
  • 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() {
  • Dev/trunk/src/server/config/couchdb-schema.json

    r509 r510  
    114114          { "$ref": "#/definitions/content/NumberInput" },
    115115          { "$ref": "#/definitions/content/ScaleInput" },
     116          { "$ref": "#/definitions/content/SingleChoiceInput" },
    116117          { "$ref": "#/definitions/content/MultipleChoiceInput" }
    117118        ]
     
    200201        "additionalProperties": false
    201202      },
     203      "SingleChoiceInput": {
     204        "type": "object",
     205        "properties": {
     206          "type": { "type": "string", "pattern": "^SingleChoiceInput$" },
     207          "items": { "type": "array", "items": {
     208              "type": "object",
     209              "properties": {
     210                  "text": { "$ref": "#/definitions/nonEmptyString" },
     211                  "value": { "$ref": "#/definitions/nonEmptyString" }
     212              },
     213              "required": ["text","value"],
     214              "additionalProperties": false
     215          } },
     216          "otherItem": {
     217              "type": "object",
     218              "properties": {
     219                  "text": { "$ref": "#/definitions/nonEmptyString" },
     220                  "value": { "$ref": "#/definitions/nonEmptyString" }
     221              },
     222              "required": ["subcode","value"],
     223              "additionalProperties": false
     224          },
     225          "subcode": { "$ref": "#/definitions/codeString" }
     226        },
     227        "required":["type","items","subcode"],
     228        "additionalProperties": false
     229      },
    202230      "MultipleChoiceInput": {
    203231        "type": "object",
    204232        "properties": {
    205233          "type": { "type": "string", "pattern": "^MultipleChoiceInput$" },
    206           "allowMultiple": { "type": "boolean" },
    207234          "items": { "type": "array", "items": {
    208235              "type": "object",
Note: See TracChangeset for help on using the changeset viewer.