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 | 'dojo/store/Memory',
|
---|
9 | 'rft/ui/SurveyEditorPreviewItem',
|
---|
10 | 'dijit/_TemplatedMixin',
|
---|
11 | 'dijit/_WidgetsInTemplateMixin',
|
---|
12 | 'dojo/text!./templates/SurveyEditorPreview.html'
|
---|
13 | ], function(declare, lang, baseArray, _WidgetBase, _Container, domConstruct, Memory, SurveyEditorPreviewItem, _TemplatedMixin, _WidgetsInTemplateMixin, template) {
|
---|
14 | return declare("rft.ui.SurveyEditorToolkit", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _Container], {
|
---|
15 |
|
---|
16 | templateString: template,
|
---|
17 | store: null,
|
---|
18 | dndSource: null,
|
---|
19 |
|
---|
20 | postCreate: function(){
|
---|
21 | this.dndSource = new dojo.dnd.Source(this.dndSourceNode, {
|
---|
22 | isSource: true,
|
---|
23 | //accept: ["editorToolkitItem", "editorPreviewItem"],
|
---|
24 | horizontal: false,
|
---|
25 | withHandles: false,
|
---|
26 | copyOnly: false,
|
---|
27 | selfCopy: false,
|
---|
28 | selfAccept: true,
|
---|
29 | delay: 0,
|
---|
30 | skipForm: true,
|
---|
31 | parent: this.dndSourceContainerNode,
|
---|
32 | creator: lang.hitch(this, this._sourceCreatorMethod)
|
---|
33 | });
|
---|
34 | this.dndSource.startup();
|
---|
35 |
|
---|
36 | this.store = new Memory({
|
---|
37 | data: [],
|
---|
38 | idProperty: "code"
|
---|
39 | });
|
---|
40 | },
|
---|
41 | _sourceCreatorMethod: function(item, hint){
|
---|
42 | switch(hint){
|
---|
43 | case "avatar":
|
---|
44 | debugger;
|
---|
45 | var node = document.createElement("div");
|
---|
46 | node.innerHTML = item.title || "Dragging!!!";
|
---|
47 | item.node = node;
|
---|
48 | break;
|
---|
49 | default:
|
---|
50 | var widget = new rft.ui.SurveyEditorPreviewItem({
|
---|
51 | data: item.data,
|
---|
52 | title: (item.data.title || "Untitled"),
|
---|
53 | description: (item.data.description || "No description"),
|
---|
54 | type: item.type,
|
---|
55 | code: item.data.code
|
---|
56 | });
|
---|
57 | item.node = widget.domNode;
|
---|
58 | break;
|
---|
59 | }
|
---|
60 | console.log(item);
|
---|
61 | return item;
|
---|
62 |
|
---|
63 |
|
---|
64 | /* TODO: Create widgetFactory method that handles creation of PreviewItem Dialogs and Views */
|
---|
65 | },
|
---|
66 |
|
---|
67 | InsertObjects: function(/*Array*/objects) {
|
---|
68 | // This takes an array of objects {data:{//props}, type:[//types]}. Node is NOT included!
|
---|
69 | objects.forEach(function(item){
|
---|
70 | this.dndSource.insertNodes(false, [item]);
|
---|
71 | }, this);
|
---|
72 | },
|
---|
73 |
|
---|
74 | RemoveObject: function(widget) {
|
---|
75 | },
|
---|
76 | GetNodeList: function() {
|
---|
77 | return this.dndSource.getAllNodes();
|
---|
78 | },
|
---|
79 | onDropInternal: function() {
|
---|
80 | topic.publish("/SurveyEditor/Preview/MoveItem");
|
---|
81 | },
|
---|
82 | onDropExternal: function() {
|
---|
83 | // This is fired when something from the Toolkit is dropped into the Preview -- add operation.
|
---|
84 | topic.publish("/SurveyEditor/Preview/AddItem");
|
---|
85 | }
|
---|
86 |
|
---|
87 | });
|
---|
88 | }); |
---|