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

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

Started work on loading questions into the question editor if the already exist.

File size: 4.1 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/ui/QuestionEditorPreviewItem',
9        'dijit/_TemplatedMixin',
10        'dijit/_WidgetsInTemplateMixin',
11        'dojo/text!./templates/QuestionEditorToolkit.html'
12        ], function(declare, lang, baseArray, _WidgetBase, _Container, domConstruct, QuestionEditorPreviewItem, _TemplatedMixin, _WidgetsInTemplateMixin, template) {
13                return declare("rft.ui.QuestionEditorToolkit", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _Container], {
14
15                        templateString: template,
16                        question: null,
17
18                        postCreate: function(){
19                                this.contentSource = new dojo.dnd.Source(this.ToolkitContentSourceNode, {
20                                        accept: [],
21                                        horizontal: false,
22                                        withHandles: false,
23                                        copyOnly: true,
24                                        selfCopy: false,
25                                        selfAccept: false,
26                                        singular: true,
27                                        creator: this._creator
28                                });
29                                this.inputsSource = new dojo.dnd.Source(this.ToolkitInputsSourceNode, {
30                                        accept: [],
31                                        horizontal: false,
32                                        withHandles: false,
33                                        copyOnly: true,
34                                        selfCopy: false,
35                                        selfAccept: false,
36                                        singular: true,
37                                        creator: this._creator
38                                });
39                                var contentItems = this._contentItems();
40                                var inputsItems = this._inputsItems();
41                                this.contentSource.insertNodes(false, contentItems);
42                                this.inputsSource.insertNodes(false, inputsItems);
43                        },
44                        _creator: function(item, hint) {
45                                var node;
46                                if (hint == "avatar") {
47                                        node = document.createElement("span");
48                                        node.innerHTML = item.widgetType;
49                                        // debugger;
50                                        return {node: node, data: item, type: "ToolkitItem"};
51                                } else {
52                                        var w = new dijit.form.Button({
53                                                baseClass: "rftLargeButton",
54                                                iconClass: "rftIcon rftIcon"+item.icon,
55                                                label: item.label,
56                                                showLabel: true,
57                                                class: "newline"
58                                        });
59                                        return {node: w.domNode, data: item.objectData, type: "ToolkitItem"};
60                                }
61                        },
62                        _contentItems: function() {
63                                // Returns an array of objects, from which to generate buttons to populate the ToolkitContentSource list.
64                                return [
65                                {
66                                        label: "Header",
67                                        objectData: {
68                                                _id: null,
69                                                widgetType: "rft.surveyContent.HeaderDialog",
70                                                widgetProps: {}
71                                        },
72                                        icon: "Header"
73                                },
74                                {
75                                        label: "Text",
76                                        objectData: {
77                                                _id: null,
78                                                widgetType: "rft.surveyContent.TextDialog",
79                                                widgetProps: {}
80                                        },
81                                        icon: "TextBox"
82                                },
83                                {
84                                        label: "Image",
85                                        objectData: {
86                                                _id: null,
87                                                widgetType: "rft.surveyContent.ImageDialog",
88                                                widgetProps: {}
89                                        },
90                                        icon: "Image"
91                                },
92                                {
93                                        label: "External media",
94                                        objectData: {
95                                                _id: null,
96                                                widgetType: "rft.surveyContent.ExternalDialog",
97                                                widgetProps: {}
98                                        },
99                                        icon: "External"
100                                },
101                                {
102                                        label: "Divider",
103                                        objectData: {
104                                                _id: null,
105                                                widgetType: "rft.surveyContent.Divider",
106                                                widgetProps: {}
107                                        },
108                                        icon: "Divider"
109                                }];
110                        },
111                        _inputsItems: function() {
112                                // Returns an array of objects, from which to generate buttons to populate the ToolkitInputsSource list.
113                                return [
114                                {
115                                        label: "Free text",
116                                        objectData: {
117                                                _id: null,
118                                                widgetType: "rft.surveyContent.TextInput",
119                                                widgetProps: {}
120                                        },
121                                        icon: "Text"
122                                },
123                                {
124                                        label: "Integer",
125                                        objectData: {
126                                                _id: null,
127                                                widgetType: "rft.surveyContent.IntegerInput",
128                                                widgetProps: {}
129                                        },
130                                        icon: "Integer"
131                                },
132                                {
133                                        label: "Scale",
134                                        objectData: {
135                                                _id: null,
136                                                widgetType: "rft.surveyContent.ScaleInput",
137                                                widgetProps: {}
138                                        },
139                                        icon: "Scale"
140                                },
141                                {
142                                        label: "Cards",
143                                        objectData: {
144                                                _id: null,
145                                                widgetType: "rft.surveyContent.CardsInput",
146                                                widgetProps: {}
147                                        },
148                                        icon: "Cards"
149                                },
150                                {
151                                        label: "Multiple Choice",
152                                        objectData: {
153                                                _id: null,
154                                                widgetType: "rft.surveyContent.MultipleChoiceInput",
155                                                widgetProps: {}
156                                        },
157                                        icon: "MultipleChoice"
158                                }
159                                ];
160                        }
161
162                });
163});
Note: See TracBrowser for help on using the repository browser.