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

Last change on this file since 377 was 377, checked in by jkraaijeveld, 13 years ago

QuestionEditorToolkit? now uses a TitleGroup? rather than an AccordionContainer? - they do the same but the TitlePanes? scales automatically (which was required for the list of categories of a question).

There still needs to be done some .css for this TitleGroup? stuff, but I'm not booking much progress on that.

File size: 6.3 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                                        controller: this,
87                                        removeCallback: lang.hitch(this, this._removeCategory),
88                                }).placeAt(this.listNode);
89                                for (category in this._categories) {
90                                        this._list.insertItem(this._categories[category]);
91                                }       
92                                this._list.startup();
93                        },
94                        _setupCategories: function() {
95                                this._categoryStore = new dojo.store.Memory({data: [] });
96                                store.query("_design/default/_view/questions", {reduce:true, group:false, group_level:1})
97                                        .forPairs(lang.hitch(this, function(value, key) {
98                                                this._categoryStore.put({ id: key[0] });
99                                        }));
100                                this._categorySelect = new ComboBox( {
101                                        id: "categoriesBox",
102                                        name: "categories",
103                                        store: this._categoryStore,
104                                        searchAttr: "id"
105                                }, "categoriesBox");
106                                this._supportingWidgets.push(this._categorySelect);
107
108            },
109            _setupTopic: function(topic) {
110                                this._topicStore = new dojo.store.Memory( {data: [] });
111                                store.query("_design/default/_view/topics", {reduce:true, group:true})
112                                        .forPairs(lang.hitch(this, function(value, key) {
113                                                this._topicStore.put({ id: key });
114                                        }));
115                                this._topicSelect = new ComboBox( {
116                                        id: "topicBox",
117                                        name: "topic",
118                                        store: this._topicStore,
119                                        searchAttr: "id",
120                                        value: topic
121                                }, "topicBox");
122                                this._supportingWidgets.push(this._topicSelect);
123            },
124                        _addCategory: function(item) {
125                                this._categories.push(item);
126                                this._list.insertItem(item);
127                        },
128                        _removeCategory: function(item) {
129                                this._categories.splice(this._categories.indexOf(item), 1);
130                        },
131                        _contentItems: function() {
132                                // Returns an array of objects, from which to generate buttons to populate the ToolkitContentSource list.
133                                return [
134                                {
135                                        label: "Header",
136                                        objectData: {
137                                                _id: null,
138                                                type: "HeaderItem",
139                                                widgetProps: {}
140                                        },
141                                        icon: "Header"
142                                },
143                                {
144                                        label: "Text",
145                                        objectData: {
146                                                _id: null,
147                                                type: "TextItem",
148                                                widgetProps: {}
149                                        },
150                                        icon: "TextBox"
151                                },
152                                {
153                                        label: "Image",
154                                        objectData: {
155                                                _id: null,
156                                                widgetType: "rft.surveyContent.ImageDialog",
157                                                widgetProps: {}
158                                        },
159                                        icon: "Image"
160                                },
161                                {
162                                        label: "External media",
163                                        objectData: {
164                                                _id: null,
165                                                widgetType: "rft.surveyContent.ExternalDialog",
166                                                widgetProps: {}
167                                        },
168                                        icon: "External"
169                                },
170                                {
171                                        label: "Divider",
172                                        objectData: {
173                                                _id: null,
174                                                widgetType: "rft.surveyContent.Divider",
175                                                widgetProps: {}
176                                        },
177                                        icon: "Divider"
178                                }];
179                        },
180                        _inputsItems: function() {
181                                // Returns an array of objects, from which to generate buttons to populate the ToolkitInputsSource list.
182                                return [
183                                {
184                                        label: "Free text",
185                                        objectData: {
186                                                _id: null,
187                                                widgetType: "rft.surveyContent.TextInput",
188                                                widgetProps: {}
189                                        },
190                                        icon: "Text"
191                                },
192                                {
193                                        label: "Integer",
194                                        objectData: {
195                                                _id: null,
196                                                widgetType: "rft.surveyContent.IntegerInput",
197                                                widgetProps: {}
198                                        },
199                                        icon: "Integer"
200                                },
201                                {
202                                        label: "Scale",
203                                        objectData: {
204                                                _id: null,
205                                                widgetType: "rft.surveyContent.ScaleInput",
206                                                widgetProps: {}
207                                        },
208                                        icon: "Scale"
209                                },
210                                {
211                                        label: "Cards",
212                                        objectData: {
213                                                _id: null,
214                                                widgetType: "rft.surveyContent.CardsInput",
215                                                widgetProps: {}
216                                        },
217                                        icon: "Cards"
218                                },
219                                {
220                                        label: "Multiple Choice",
221                                        objectData: {
222                                                _id: null,
223                                                widgetType: "rft.surveyContent.MultipleChoiceInput",
224                                                widgetProps: {}
225                                        },
226                                        icon: "MultipleChoice"
227                                }
228                                ];
229                        }
230
231                });
232});
Note: See TracBrowser for help on using the repository browser.