source: Dev/branches/rest-dojo-ui/client/rft/ui/QuestionEditorToolkit.js @ 384

Last change on this file since 384 was 384, checked in by hendrikvanantwerpen, 13 years ago
  • Cleanup of the differen ListViews?, List & OrderedList?. Based QuestionListView? on these base classes as well. Removed duplicate code.
  • Destroy busy indicator of TabbedQuestionBrowser? (because it's placed outside of the widgets DOM tree, this is not done automatically).
  • Use dojo/date/stamp module for uniform and parsable date formatting.
  • Added docs/ directory for database format documentation etc.
File size: 5.9 KB
Line 
1define([
2        'dojo/_base/declare',
3        'dojo/_base/lang',
4        'dojo/_base/array',
5        'dijit/_WidgetBase',
6        'dijit/_Container',
7        'dojo/dom-construct',
8        'rft/store',
9        'rft/ui/QuestionEditorPreviewItem',
10        'rft/ui/CategoryListView',
11        'dijit/_TemplatedMixin',
12        'dijit/_WidgetsInTemplateMixin',
13        'dijit/form/ComboBox',
14        'dojo/text!./templates/QuestionEditorToolkit.html'
15        ], function(declare, lang, baseArray, _WidgetBase, _Container, domConstruct, store, QuestionEditorPreviewItem, CategoryListView, _TemplatedMixin, _WidgetsInTemplateMixin, ComboBox, template) {
16                return declare("rft.ui.QuestionEditorToolkit", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _Container], {
17
18                        templateString: template,
19                        _list: null,
20                        _categorySelect: null,
21                        _categoryStore: null,
22                        _topicSelect: null,
23                        _topicStore: null,
24                        _categories : null,
25
26//                      constructor: function() {
27//                              lang.mixin(this, arguments);
28//                      },
29
30                        postCreate: function(){
31                                this.contentSource = new dojo.dnd.Source(this.ToolkitContentSourceNode, {
32                                        accept: [],
33                                        horizontal: false,
34                                        withHandles: false,
35                                        copyOnly: true,
36                                        selfCopy: false,
37                                        selfAccept: false,
38                                        singular: true,
39                                        creator: this._creator
40                                });
41                                this.inputsSource = new dojo.dnd.Source(this.ToolkitInputsSourceNode, {
42                                        accept: [],
43                                        horizontal: false,
44                                        withHandles: false,
45                                        copyOnly: true,
46                                        selfCopy: false,
47                                        selfAccept: false,
48                                        singular: true,
49                                        creator: this._creator
50                                });
51                                var contentItems = this._contentItems();
52                                var inputsItems = this._inputsItems();
53                                this.contentSource.insertNodes(false, contentItems);
54                                this.inputsSource.insertNodes(false, inputsItems);
55                        },
56                        loadQuestion: function(question) {
57                                this.propertiesForm.set('value', question);
58                                this._categories = question.categories;
59                                this._setupListView();
60                                this._setupCategories();
61                                this._setupTopic(question.topic);
62                        },
63                        onCategoryAdd: function() {
64                                this._addCategory(this._categorySelect.get('displayedValue'));
65                                this._categorySelect.reset();
66                        },
67                        _creator: function(item, hint) {
68                                var node;
69                                if (hint == "avatar") {
70                                        node = document.createElement("span");
71                                        node.innerHTML = item.widgetType;
72                                        return {node: node, data: item, type: "ToolkitItem"};
73                                } else {
74                                        var w = new dijit.form.Button({
75                                                baseClass: "rftLargeButton",
76                                                iconClass: "rftIcon rftIcon"+item.icon,
77                                                label: item.label,
78                                                showLabel: true,
79                                                class: "newline"
80                                        });
81                                        return {node: w.domNode, data: item.objectData, type: "ToolkitItem"};
82                                }
83                        },
84                        _setupListView: function() {
85                                this._list = new CategoryListView( {
86                                        removeCallback: lang.hitch(this, this._removeCategory)
87                                }).placeAt(this.listNode);
88                                for (var category in this._categories) {
89                                        this._list.appendItem(this._categories[category]);
90                                }       
91                                this._list.startup();
92                        },
93                        _setupCategories: function() {
94                                this._categoryStore = new dojo.store.Memory({data: [] });
95                                store.query("_design/default/_view/questions", {reduce:true, group:false, group_level:1})
96                                        .forPairs(lang.hitch(this, function(value, key) {
97                                                this._categoryStore.put({ id: key[0] });
98                                        }));
99                                this._categorySelect = new ComboBox( {
100                                        id: "categoriesBox",
101                                        name: "categories",
102                                        store: this._categoryStore,
103                                        searchAttr: "id"
104                                }, "categoriesBox");
105                                this._supportingWidgets.push(this._categorySelect);
106
107            },
108            _setupTopic: function(topic) {
109                                this._topicStore = new dojo.store.Memory( {data: [] });
110                                store.query("_design/default/_view/topics", {reduce:true, group:true})
111                                        .forPairs(lang.hitch(this, function(value, key) {
112                                                this._topicStore.put({ id: key });
113                                        }));
114                                this._topicSelect = new ComboBox( {
115                                        id: "topicBox",
116                                        name: "topic",
117                                        store: this._topicStore,
118                                        searchAttr: "id",
119                                        value: topic
120                                }, "topicBox");
121                                this._supportingWidgets.push(this._topicSelect);
122            },
123                        _addCategory: function(item) {
124                                this._categories.push(item);
125                                this._list.appendItem(item);
126                        },
127                        _removeCategory: function(item) {
128                                this._categories.splice(this._categories.indexOf(item), 1);
129                        },
130                        _contentItems: function() {
131                                // Returns an array of objects, from which to generate buttons to populate the ToolkitContentSource list.
132                                return [
133                                {
134                                        label: "Header",
135                                        objectData: {
136                                                widgetType: "Header",
137                                        },
138                                        icon: "Header"
139                                },
140                                {
141                                        label: "Text",
142                                        objectData: {
143                                                widgetType: "Text",
144                                        },
145                                        icon: "TextBox"
146                                },
147                                {
148                                        label: "Image",
149                                        objectData: {
150                                                widgetType: "Image",
151                                        },
152                                        icon: "Image"
153                                },
154                                {
155                                        label: "External media",
156                                        objectData: {
157                                                widgetType: "ExternalMedia",
158                                        },
159                                        icon: "External"
160                                },
161                                {
162                                        label: "Divider",
163                                        objectData: {
164                                                widgetType: "Divider",
165                                        },
166                                        icon: "Divider"
167                                }];
168                        },
169                        _inputsItems: function() {
170                                // Returns an array of objects, from which to generate buttons to populate the ToolkitInputsSource list.
171                                return [
172                                {
173                                        label: "Free text",
174                                        objectData: {
175                                                widgetType: "FreeTextInput",
176                                        },
177                                        icon: "Text"
178                                },
179                                {
180                                        label: "Integer",
181                                        objectData: {
182                                                _id: null,
183                                                widgetType: "IntegerInput",
184                                                widgetProps: {}
185                                        },
186                                        icon: "Integer"
187                                },
188                                {
189                                        label: "Scale",
190                                        objectData: {
191                                                _id: null,
192                                                widgetType: "ScaleInput",
193                                                widgetProps: {}
194                                        },
195                                        icon: "Scale"
196                                },
197                                {
198                                        label: "Cards",
199                                        objectData: {
200                                                _id: null,
201                                                widgetType: "CardsInput",
202                                                widgetProps: {}
203                                        },
204                                        icon: "Cards"
205                                },
206                                {
207                                        label: "Multiple Choice",
208                                        objectData: {
209                                                _id: null,
210                                                widgetType: "MultipleChoiceInput",
211                                                widgetProps: {}
212                                        },
213                                        icon: "MultipleChoice"
214                                }
215                                ];
216                        }
217
218                });
219});
Note: See TracBrowser for help on using the repository browser.