Ignore:
Timestamp:
09/03/12 13:37:01 (13 years ago)
Author:
hendrikvanantwerpen
Message:

Enable configuring multiple choice question items.

Allow widgets in ordered list by using mixin. Used this to create multiple
choice options. The options widget itself needs some styling.

Show code in question item preview and label to stop editing is 'Done'
to stop confusion about saving.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/rest-dojo-ui/client/rft/ui/content/ContentWidgetFactory.js

    r402 r404  
    44    'dojo/_base/lang',
    55    'dojo/dom-construct',
     6    'dijit/_TemplatedMixin',
    67    'dijit/_WidgetBase',
    78    'dijit/_Container',
     
    1314    'dijit/form/TextBox',
    1415    'dojox/layout/TableContainer',
     16    './../lists/_EditableListMixin',
    1517    './../lists/OrderedList'
    16 ],function(array, declare, lang, domConstruct, _WidgetBase, _Container, Button, CheckBox, NumberSpinner, RadioButton, Textarea, TextBox, TableContainer, OrderedList) {
     18],function(array, declare, lang, domConstruct, _TemplatedMixin, _WidgetBase, _Container, Button, CheckBox, NumberSpinner, RadioButton, Textarea, TextBox, TableContainer, _EditableListMixin, OrderedList) {
    1719    var factory = declare('rft.ui.content.ContentWidgetFactory', [], {
    1820        /* No default type, all should be valid */
     
    331333
    332334            var ctor = this.options.multiple === true ? CheckBox : RadioButton;
    333             array.forEach(this.options.items || ["Aap", "Noot"],function(item){
     335            array.forEach(this.options.items ,function(item){
    334336                table.addChild(new ctor({
    335                     title: item
     337                        title: item
    336338                }));
    337339            },this);
     
    362364    });
    363365
    364     var MCOptionItem = declare([_WidgetBase,_Container],{
     366    var MCOptionItem = declare([_WidgetBase,_TemplatedMixin,_Container],{
     367        templateString: '<div><span class="dojoDndHandle">=</span></div>',
    365368        _textBox: null,
    366369        postCreate: function() {
    367             this.innerHTML = '<span class="dojoDndHandle">=</span>';
    368 
    369370            this._textBox = new TextBox({});
    370371            this.addChild(this._textBox);
     
    387388    });
    388389
     390    var MCOptionList = declare([OrderedList,_EditableListMixin],{
     391        type: 'multipleChoiceOption',
     392        withHandles: true,
     393        _createAvatarNode: function(item){
     394            return domConstruct.create("div",{
     395                'class': 'dragAvatar',
     396                innerHTML: item
     397            });
     398        },
     399        _createListNode: function(item) {
     400            var w = new MCOptionItem();
     401            w.startup();
     402            w.set('value',item);
     403            w.on('delete',lang.hitch(this,'_onRemove',w));
     404            return w.domNode;
     405        },
     406        _onRemove: function(w) {
     407            w.destroyRecursive();
     408            this.removeCallback && this.removeCallback(item);
     409            this.source.sync();
     410        }
     411    });
     412
    389413    var MultipleChoiceInputEdit = declare([_WidgetBase, _Container], {
    390414        _codeInput: null,
     
    412436            add.startup();
    413437
    414             this._optionsList = new OrderedList({
    415                 type: 'multipleChoiceOption',
    416                 withHandles: true,
    417                 _createAvatarNode: function(item){
    418                     return domConstruct.create("div",{
    419                         'class': 'dragAvatar',
    420                         innerHTML: item
    421                     });
    422                 },
    423                 _createListNode: function(item) {
    424                     var w = new MCOptionItem();
    425                     w.startup();
    426                     w.set('value',item);
    427                     w.on('delete',lang.hitch(this,function(){
    428                         this._optionsList.removeItem(w);
    429                     }));
    430                     return w.domNode;
    431                 }
    432             });
     438            this._optionsList = new MCOptionList();
    433439            table.addChild(this._optionsList);
    434440            this._optionsList.startup();
     
    436442            this.addChild(table);
    437443            table.startup();
     444        },
     445
     446        _addOption: function() {
     447            this._optionsList.appendItems([""]);
    438448        },
    439449
Note: See TracChangeset for help on using the changeset viewer.