source: Dev/trunk/src/client/qed-client/model/widgets/QuestionEditorToolkit.js

Last change on this file was 529, checked in by hendrikvanantwerpen, 11 years ago
  • Added grey icons for better highlighting, synced block and large buttons.
  • Introduced extra color for text, now disabled/inactive/hovered -> it's not very clear though.
  • Added confirmation on irrevertable actions.
  • Added support for query string in our new request implementation.
File size: 5.0 KB
Line 
1define([
2    "../../widgets/_ComplexValueWidget",
3    "../classes/categories",
4    "../classes/topics",
5    "./CategoryListView",
6    "dijit/form/Button",
7    "dijit/form/ComboBox",
8    "dojo/_base/declare",
9    "dojo/_base/lang",
10    "dojo/dnd/Source",
11    "dojo/dom-construct",
12    "dojo/store/Memory",
13    "require",
14    "dojo/text!./templates/QuestionEditorToolkit.html"
15], function(_ComplexValueWidget, categories, topics, CategoryListView, Button, ComboBox, declare, lang, Source, domConstruct, Memory, require, template) {
16    return declare([_ComplexValueWidget], {
17
18        contextRequire: require,
19        templateString: template,
20        _categoryList: null,
21        _categorySelect: null,
22        _categoryStore: null,
23        _topicSelect: null,
24        _topicStore: null,
25
26        _contentItems: [
27            { type: "Header" },
28            { type: "Text" },
29            { type: "Divider" }
30        ],
31        _inputsItems: [
32            { type: "StringInput" },
33            { type: "TextInput" },
34            { type: "NumberInput" },
35            { type: "ScaleInput" },
36            { type: "SingleChoiceInput" },
37            { type: "MultipleChoiceInput" }
38        ],
39        _labelMap: {
40            "Header": "Header",
41            "Text": "Text",
42            "Divider": "Divider",
43            "StringInput": "Text line",
44            "TextInput": "Free text",
45            "NumberInput": "Number",
46            "ScaleInput": "Scale",
47            "SingleChoiceInput": "Single choice",
48            "MultipleChoiceInput": "Multiple choice"
49        },
50        _iconMap: {
51            "Header": "Header",
52            "Text": "TextBox",
53            "Divider": "Divider",
54            "StringInput": "Text",
55            "TextInput": "Text",
56            "NumberInput": "Number",
57            "ScaleInput": "Scale",
58            "SingleChoiceInput": "MultipleChoice",
59            "MultipleChoiceInput": "MultipleChoice"
60        },
61
62        buildRendering: function() {
63            this.inherited(arguments);
64
65            this._categoryList = new CategoryListView({
66                name: "categories"
67            }).placeAt(this.categoryListNode);
68
69            this._categoryStore = new Memory({data: [] });
70            this._categorySelect = new ComboBox( {
71                store: this._categoryStore,
72                searchAttr: "id"
73            }, this.categoryBoxNode);
74
75            this._topicStore = new Memory( {data: [] });
76            this._topicSelect = new ComboBox({
77                name: "topic",
78                store: this._topicStore,
79                searchAttr: "id"
80            }, this.topicBoxNode);
81
82            var creator = lang.hitch(this,"_creator");
83            this.contentSource = new Source(this.ToolkitContentSourceNode, {
84                accept: [],
85                copyOnly: true,
86                selfAccept: false,
87                singular: true,
88                creator: creator
89            });
90            this.inputsSource = new Source(this.ToolkitInputsSourceNode, {
91                accept: [],
92                copyOnly: true,
93                selfAccept: false,
94                singular: true,
95                creator: creator
96            });
97            this.contentSource.insertNodes(false, this._contentItems);
98            this.inputsSource.insertNodes(false, this._inputsItems);
99        },
100        startup: function() {
101            if ( this._started ) { return; }
102            this.inherited(arguments);
103
104            categories.query().forEach(lang.hitch(this,function(cat){
105                this._categoryStore.put({ id: cat });
106            }));
107
108            topics.query().forEach(lang.hitch(this,function(topic){
109                this._categoryStore.put({ id: topic });
110            }));
111        },
112        _onCategoryAdd: function() {
113            // it seems, the button is not disabled properly and still
114            // generates click events, that's why we chack here.
115            if ( this.disabled || this.readOnly ) { return; }
116            this._categoryList.appendItem(this._categorySelect.get('displayedValue'));
117            this._categorySelect.reset();
118        },
119        _creator: function(item, hint) {
120            var node;
121            if (hint === "avatar") {
122                node = domConstruct.create('span',{
123                    innerHTML: this._labelMap[item.type] || item.type
124                });
125            } else {
126                var w = new Button({
127                    baseClass: "rftLargeButton",
128                    iconClass: "rftIcon rftIcon"+(this._iconMap[item.type]||"Unknown"),
129                    label: this._labelMap[item.type] || item.type,
130                    showLabel: true,
131                    style: "display: block"
132                });
133                node = w.domNode;
134            }
135            return {
136                node: node,
137                data: item,
138                type: ["questionContent"]
139            };
140        }
141
142    });
143});
Note: See TracBrowser for help on using the repository browser.