Ignore:
Timestamp:
04/29/13 19:35:10 (12 years ago)
Author:
hendrikvanantwerpen
Message:

Big cleanup of the question content.

  • Replaced old list implementations with a new one that behaves like a form widget.
  • All question content is now in separate widgets, not in the factory itself.
  • Added form and widget validation for question editing.
Location:
Dev/trunk/client/qed/model/widgets/questions
Files:
1 added
1 moved

Legend:

Unmodified
Added
Removed
  • Dev/trunk/client/qed/model/widgets/questions/ScaleInputConfigWidget.js

    r435 r441  
    11define([
    2     "dijit/_Container",
    3     "dijit/_TemplatedMixin",
    4     "dijit/_WidgetBase",
    5     "dijit/_WidgetsInTemplateMixin",
     2    "../../../widgets/ListWidget",
     3    "../../../widgets/_ComplexValueWidget",
    64    "dijit/form/Button",
    75    "dijit/form/RadioButton",
    86    "dijit/form/TextBox",
    97    "dijit/form/ValidationTextBox",
    10     "dijit/form/_FormMixin",
    118    "dojo/_base/array",
    129    "dojo/_base/declare",
     
    2017    "dijit/form/NumberTextBox",
    2118    "dijit/form/TextBox"
    22 ], function(_Container, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, Button, RadioButton, TextBox, ValidationTextBox, _FormMixin, array, declare, event, lang, domAttr, domConstruct, domStyle, rowTemplate, template) {
     19], function(ListWidget, _ComplexValueWidget, Button, RadioButton, TextBox, ValidationTextBox, array, declare, event, lang, domAttr, domConstruct, domStyle, rowTemplate, template) {
    2320
    24     var Row = declare([_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container,_FormMixin],{
     21    var Row = declare([_ComplexValueWidget],{
    2522        templateString: rowTemplate,
    2623        hasNA: true,
     
    2926            this.inherited(arguments);
    3027        },
    31         onDestroy: function(e) {
    32             this.destroyRecursive();
    33             event.stop(e);
    34             return false;
    35         },
     28        onDestroy: function(evt) {},
    3629        _setHasNAAttr: function(value) {
    3730            if ( value === true ) {
     
    4336    });
    4437   
    45     return declare([_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container,_FormMixin],{
     38    return declare([_ComplexValueWidget],{
    4639        templateString: template,
    4740        baseClass: "qedScaleWidget",
    48         value: null,
    4941        _hasNA: false,
    5042        constuctor: function() {
     
    5244            this.value = {};
    5345        },
    54         onAddItem: function(e) {
    55             this._addItem();
     46        buildRendering: function() {
     47            this.inherited(arguments);
     48            this.itemsWidget = new ListWidget({
     49                name: "items",
     50                type: "ScaleItem",
     51                delay: 5,
     52                skipForm: true,
     53                createListElement: lang.hitch(this, "_createRowWidget"),
     54                createAvatar: lang.hitch(this, "_createAvatar")
     55            }, this.itemsNode);
     56        },
     57        _createRowWidget: function(id, item) {
     58            var widget = new Row({
     59                value: item,
     60                hasNA: this._hasNA,
     61                id: id,
     62                onDestroy: lang.hitch(this,function(evt){
     63                    this.itemsWidget.removeItem(id);
     64                    event.stop(evt);
     65                    return false;
     66                })
     67            });
     68            widget.startup();
     69            return widget;
     70        },
     71        _createAvatar: function(id, item) {
     72            return domConstruct.create("div", {
     73                innerHTML: item.text || "(empty item)"
     74            });
     75        },
     76        onAddNewItem: function(e) {
     77            this.itemsWidget.appendItem({});
    5678            event.stop(e);
    5779            return false;
    5880        },
    59         _clearItems: function() {
    60             domConstruct.empty(this.itemsNode);
    61         },
    62         _addItem: function(value) {
    63             var item = new Row({
    64                 name: 'items',
    65                 value: value,
    66                 hasNA: this._hasNA
    67             });
    68             item.placeAt(this.itemsNode);
    69             return item;
    70         },
    71         _setValueAttr: function(value) {
    72             this.inherited(arguments);
    73             this._clearItems();
    74             array.forEach(value.items, function(value){
    75                 this._addItem(value);
    76             }, this);
    77         },
    7881        _getValueAttr: function(){
    7982            var value = this.inherited(arguments);
    80             if ( value.items && !lang.isArray(value.items) ) {
    81                 value.items = [value.items];
    82             }
    8383            value.type = 'ScaleInput';
    8484            return value;
     
    8989        },
    9090        _updateNA: function(value) {
    91             array.forEach(this.getChildren(), function(child) {
     91            array.forEach(this.itemsWidget.getChildren(), function(child) {
    9292                child.set('hasNA', this._hasNA);
    9393            }, this);
Note: See TracChangeset for help on using the changeset viewer.