source: Dev/branches/rest-dojo-ui/client/rft/ui/QuestionWidget.js @ 288

Last change on this file since 288 was 288, checked in by hendrikvanantwerpen, 13 years ago

[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 size: 2.8 KB
Line 
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],{
7            templateString: templateString,
8            mode: 'view', // view || edit
9            name: '',
10            _type: null,
11            _widgetCache: null,
12            constructor: function() {
13                this.inherited(arguments);
14                this._widgetCache = {};
15            },
16            postCreate: function() {
17                this.typeSelector.set('disabled', this.mode == 'edit');
18            },
19            _setValueAttr: function(value) {
20                value.type && this._onTypeChange(value.type);
21                this.ourForm.set('value',value);
22            },
23            _getValueAttr: function() {
24                return this.ourForm.get('value');
25            },
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;
62            }
63        });
64    });
Note: See TracBrowser for help on using the repository browser.