Ignore:
Timestamp:
02/24/12 16:09:22 (13 years ago)
Author:
hendrikvanantwerpen
Message:

[Client] MultipleChoiceWidget? for editing multiple choice questions
[Client] Move templates to separate directories.
[Client] Created QuestionWidget? to edit complete questions.
[Client] Fixed startup race condition where parsing was started before all classes were loaded.

File:
1 edited

Legend:

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

    r281 r288  
    1 require(['dojo/_base/declare','dijit/_WidgetBase','dijit/_TemplatedMixin','dijit/_WidgetsInTemplateMixin','dojo/text!rft/ui/QuestionWidget.html','dijit/form/TextBox'],
    2     function(declare,_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,templateString,TextBox){
    3         declare('rft.ui.QuestionWidget',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin],{
     1define(['dojo/_base/declare','dojo/dom-construct','dijit/_WidgetBase',
     2    'dijit/_TemplatedMixin','dijit/_WidgetsInTemplateMixin',
     3    'dojo/text!./templates/QuestionWidget.html','dijit/form/TextBox',
     4    'dijit/form/Textarea','./MultipleChoiceWidget'],
     5    function(declare,domConstruct,_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,templateString,TextBox,Textarea,MultipleChoiceWidget){
     6        return declare('rft.ui.QuestionWidget',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin],{
    47            templateString: templateString,
    58            mode: 'view', // view || edit
    6             type: 'string',
    7             _w: null,
     9            name: '',
     10            _type: null,
     11            _widgetCache: null,
     12            constructor: function() {
     13                this.inherited(arguments);
     14                this._widgetCache = {};
     15            },
    816            postCreate: function() {
    9                 this._setType(this.type);
     17                this.typeSelector.set('disabled', this.mode == 'edit');
    1018            },
    11             _setType: function(type) {
    12                 if ( !this._w || this.type != type ) {
    13                     if ( this._w ) {
    14                         this._w.destroy();
    15                         this._w = null;
    16                     }
    17                     this.type = type;
    18                     switch(type) {
    19                         case 'string':
    20                             this._getStringWidget().placeAt(this.typeDetails);
    21                             break;
    22                         case 'text':
    23                             break;
    24                         case 'multipleChoice':
    25                             break;
    26                     }
    27                 }
    28             },
    29             _getStringWidget: function() {
    30                 if ( !this._stringWidget ) {
    31                     this._stringWidget = new TextBox({
    32                         name: 'answers',
    33                         disabled: this.mode == 'view'
    34                     });
    35                 }
    36                 return this._stringWidget;
     19            _setValueAttr: function(value) {
     20                value.type && this._onTypeChange(value.type);
     21                this.ourForm.set('value',value);
    3722            },
    3823            _getValueAttr: function() {
    3924                return this.ourForm.get('value');
    4025            },
    41             _setValueAttr: function(value) {
    42                 return this.ourForm.set('value',value);
     26            _onTypeChange: function(type) {
     27                if ( this._type == type ) return;
     28                this._type = type;
     29                domConstruct.empty(this.typeDetails);
     30                var widget = this._getTypeWidget(type);
     31                widget && widget.placeAt(this.typeDetails,'only');
     32            },
     33            _getTypeWidget: function(type) {
     34                var widget = this._widgetCache[type];
     35                if (!widget) {
     36                    switch(type) {
     37                        case 'string':
     38                            widget = new TextBox({
     39                                name: 'answers',
     40                                disabled: this.mode == 'view'
     41                            });
     42                            break;
     43                        case 'text':
     44                            widget = new Textarea({
     45                                name: 'answers',
     46                                disabled: this.mode == 'view',
     47                                style: 'min-height: 120px'
     48                            });
     49                            break;
     50                        case 'singleChoice':
     51                        case 'multipleChoice':
     52                            widget = new MultipleChoiceWidget({
     53                                name: 'answers',
     54                                mode: this.mode,
     55                                allowMultiple: type == 'multipleChoice'
     56                            });
     57                            break;
     58                    }
     59                    this._widgetCache[type] = widget;
     60                }
     61                return widget;
    4362            }
    4463        });
Note: See TracChangeset for help on using the changeset viewer.