1 | define([
|
---|
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 |
|
---|
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 | },
|
---|
122 | _addCategory: function(item) {
|
---|
123 | this._categories.push(item);
|
---|
124 | this._list.insertItem(item);
|
---|
125 | },
|
---|
126 | _removeCategory: function(item) {
|
---|
127 | this._categories.splice(this._categories.indexOf(item), 1);
|
---|
128 | },
|
---|
129 | _contentItems: function() {
|
---|
130 | // Returns an array of objects, from which to generate buttons to populate the ToolkitContentSource list.
|
---|
131 | return [
|
---|
132 | {
|
---|
133 | label: "Header",
|
---|
134 | objectData: {
|
---|
135 | _id: null,
|
---|
136 | type: "HeaderItem",
|
---|
137 | widgetProps: {}
|
---|
138 | },
|
---|
139 | icon: "Header"
|
---|
140 | },
|
---|
141 | {
|
---|
142 | label: "Text",
|
---|
143 | objectData: {
|
---|
144 | _id: null,
|
---|
145 | type: "TextItem",
|
---|
146 | widgetProps: {}
|
---|
147 | },
|
---|
148 | icon: "TextBox"
|
---|
149 | },
|
---|
150 | {
|
---|
151 | label: "Image",
|
---|
152 | objectData: {
|
---|
153 | _id: null,
|
---|
154 | widgetType: "rft.surveyContent.ImageDialog",
|
---|
155 | widgetProps: {}
|
---|
156 | },
|
---|
157 | icon: "Image"
|
---|
158 | },
|
---|
159 | {
|
---|
160 | label: "External media",
|
---|
161 | objectData: {
|
---|
162 | _id: null,
|
---|
163 | widgetType: "rft.surveyContent.ExternalDialog",
|
---|
164 | widgetProps: {}
|
---|
165 | },
|
---|
166 | icon: "External"
|
---|
167 | },
|
---|
168 | {
|
---|
169 | label: "Divider",
|
---|
170 | objectData: {
|
---|
171 | _id: null,
|
---|
172 | widgetType: "rft.surveyContent.Divider",
|
---|
173 | widgetProps: {}
|
---|
174 | },
|
---|
175 | icon: "Divider"
|
---|
176 | }];
|
---|
177 | },
|
---|
178 | _inputsItems: function() {
|
---|
179 | // Returns an array of objects, from which to generate buttons to populate the ToolkitInputsSource list.
|
---|
180 | return [
|
---|
181 | {
|
---|
182 | label: "Free text",
|
---|
183 | objectData: {
|
---|
184 | _id: null,
|
---|
185 | widgetType: "rft.surveyContent.TextInput",
|
---|
186 | widgetProps: {}
|
---|
187 | },
|
---|
188 | icon: "Text"
|
---|
189 | },
|
---|
190 | {
|
---|
191 | label: "Integer",
|
---|
192 | objectData: {
|
---|
193 | _id: null,
|
---|
194 | widgetType: "rft.surveyContent.IntegerInput",
|
---|
195 | widgetProps: {}
|
---|
196 | },
|
---|
197 | icon: "Integer"
|
---|
198 | },
|
---|
199 | {
|
---|
200 | label: "Scale",
|
---|
201 | objectData: {
|
---|
202 | _id: null,
|
---|
203 | widgetType: "rft.surveyContent.ScaleInput",
|
---|
204 | widgetProps: {}
|
---|
205 | },
|
---|
206 | icon: "Scale"
|
---|
207 | },
|
---|
208 | {
|
---|
209 | label: "Cards",
|
---|
210 | objectData: {
|
---|
211 | _id: null,
|
---|
212 | widgetType: "rft.surveyContent.CardsInput",
|
---|
213 | widgetProps: {}
|
---|
214 | },
|
---|
215 | icon: "Cards"
|
---|
216 | },
|
---|
217 | {
|
---|
218 | label: "Multiple Choice",
|
---|
219 | objectData: {
|
---|
220 | _id: null,
|
---|
221 | widgetType: "rft.surveyContent.MultipleChoiceInput",
|
---|
222 | widgetProps: {}
|
---|
223 | },
|
---|
224 | icon: "MultipleChoice"
|
---|
225 | }
|
---|
226 | ];
|
---|
227 | }
|
---|
228 |
|
---|
229 | });
|
---|
230 | }); |
---|