source: Dev/trunk/client/qed/model/widgets/QuestionEditorToolkit.js @ 442

Last change on this file since 442 was 442, checked in by hendrikvanantwerpen, 12 years ago

Enable validation on all fields of question.

File size: 5.1 KB
Line 
1define([
2    'dojo/_base/declare',
3    'dojo/_base/lang',
4    'dojo/dnd/Source',
5    'dojo/dom-construct',
6    'dojo/store/Memory',
7    'dijit/_Container',
8    'dijit/_TemplatedMixin',
9    'dijit/_WidgetBase',
10    'dijit/_WidgetsInTemplateMixin',
11    'dijit/form/Button',
12    'dijit/form/ComboBox',
13    '../../store',
14    './CategoryListView',
15    'dojo/text!./templates/QuestionEditorToolkit.html'
16], function(declare, lang, Source, domConstruct, Memory, _Container,
17        _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, Button,
18        ComboBox, store, CategoryListView, template) {
19    return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _Container], {
20
21        templateString: template,
22        _categoryList: null,
23        _categorySelect: null,
24        _categoryStore: null,
25        _topicSelect: null,
26        _topicStore: null,
27
28        _contentItems: [
29            { type: "Header" },
30            { type: "Text" },
31            { type: "Image" },
32            { type: "ExternalMedia" },
33            { type: "Divider" }
34        ],
35        _inputsItems: [
36            { type: "StringInput" },
37            { type: "TextInput" },
38            { type: "NumberInput" },
39            { type: "ScaleInput" },
40            { type: "MultipleChoiceInput" }
41        ],
42        _labelMap: {
43            "Header": "Header",
44            "Text": "Text",
45            "Image": "Image",
46            "ExternalMedia": "External media",
47            "Divider": "Divider",
48            "StringInput": "Text line",
49            "TextInput": "Free text",
50            "NumberInput": "Number",
51            "ScaleInput": "Scale",
52            "MultipleChoiceInput": "Multiple choice"
53        },
54        _iconMap: {
55            "Header": "Header",
56            "Text": "TextBox",
57            "Image": "Image",
58            "ExternalMedia": "External",
59            "Divider": "Divider",
60            "StringInput": "Text",
61            "TextInput": "Text",
62            "NumberInput": "Number",
63            "ScaleInput": "Scale",
64            "MultipleChoiceInput": "MultipleChoice"
65        },
66
67        buildRendering: function() {
68            this.inherited(arguments);
69
70            this._categoryList = new CategoryListView({
71                name: "categories"
72            }).placeAt(this.categoryListNode);
73
74            this._categoryStore = new Memory({data: [] });
75            this._categorySelect = new ComboBox( {
76                store: this._categoryStore,
77                searchAttr: "id"
78            }, this.categoryBoxNode);
79
80            this._topicStore = new Memory( {data: [] });
81            this._topicSelect = new ComboBox({
82                name: "topic",
83                store: this._topicStore,
84                searchAttr: "id"
85            }, this.topicBoxNode);
86
87            var creator = lang.hitch(this,"_creator");
88            this.contentSource = new Source(this.ToolkitContentSourceNode, {
89                accept: [],
90                copyOnly: true,
91                selfAccept: false,
92                singular: true,
93                creator: creator
94            });
95            this.inputsSource = new Source(this.ToolkitInputsSourceNode, {
96                accept: [],
97                copyOnly: true,
98                selfAccept: false,
99                singular: true,
100                creator: creator
101            });
102            this.contentSource.insertNodes(false, this._contentItems);
103            this.inputsSource.insertNodes(false, this._inputsItems);
104        },
105        startup: function() {
106            if ( this._started ) { return; }
107            this.inherited(arguments);
108
109            store.query("_design/questions/_view/all", {reduce:true, group:false, group_level:1})
110            .forPairs(lang.hitch(this, function(value, key) {
111                this._categoryStore.put({ id: key[0] });
112            }));
113
114            store.query("_design/questions/_view/all_topics", {reduce:true, group:true})
115            .forPairs(lang.hitch(this, function(value, key) {
116                this._topicStore.put({ id: key });
117            }));
118        },
119        _onCategoryAdd: function() {
120            this._categoryList.appendItem(this._categorySelect.get('displayedValue'));
121            this._categorySelect.reset();
122        },
123        _creator: function(item, hint) {
124            var node;
125            if (hint === "avatar") {
126                node = domConstruct.create('span',{
127                    innerHTML: this._labelMap[item.type] || item.type
128                });
129            } else {
130                var w = new Button({
131                    baseClass: "rftLargeButton",
132                    iconClass: "rftIcon rftIcon"+(this._iconMap[item.type]||"Unknown"),
133                    label: this._labelMap[item.type] || item.type,
134                    showLabel: true,
135                    style: "display: block"
136                });
137                node = w.domNode;
138            }
139            return {
140                node: node,
141                data: item,
142                type: ["questionContent"]
143            };
144        }
145
146    });
147});
Note: See TracBrowser for help on using the repository browser.