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/ui/QuestionEditorPreviewItem',
|
---|
9 | 'dijit/_TemplatedMixin',
|
---|
10 | 'dijit/_WidgetsInTemplateMixin',
|
---|
11 | 'dojo/text!./templates/QuestionEditorPreview.html'
|
---|
12 | ], function(declare, lang, baseArray, _WidgetBase, _Container, domConstruct, QuestionEditorPreviewItem, _TemplatedMixin, _WidgetsInTemplateMixin, template) {
|
---|
13 | return declare("rft.ui.QuestionEditorPreview", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _Container], {
|
---|
14 |
|
---|
15 | templateString: template,
|
---|
16 | dndSource: null,
|
---|
17 |
|
---|
18 | postCreate: function(){
|
---|
19 | this.dndSource = new dojo.dnd.Source(this.dndSourceNode, {
|
---|
20 | isSource: true,
|
---|
21 | //accept: ["ToolkitItem", "PreviewItem"],
|
---|
22 | horizontal: false,
|
---|
23 | withHandles: false,
|
---|
24 | copyOnly: false,
|
---|
25 | selfCopy: false,
|
---|
26 | selfAccept: true,
|
---|
27 | delay: 0,
|
---|
28 | skipForm: true,
|
---|
29 | creator: lang.hitch(this, this._sourceCreatorMethod)
|
---|
30 | });
|
---|
31 | this.dndSource.startup();
|
---|
32 | },
|
---|
33 | _sourceCreatorMethod: function(item, hint){
|
---|
34 | var node;
|
---|
35 | switch(hint){
|
---|
36 |
|
---|
37 | case "avatar":
|
---|
38 | node = document.createElement("span");
|
---|
39 | node.innerHTML = item.title || "Dragging!!!";
|
---|
40 | return {node: node, data: item, type: "PreviewItem"};
|
---|
41 | break;
|
---|
42 |
|
---|
43 | default:
|
---|
44 | var previewItem = new rft.ui.QuestionEditorPreviewItem({
|
---|
45 | item: item
|
---|
46 | });
|
---|
47 | return {node: previewItem.domNode, data: previewItem, type: item.type};
|
---|
48 | break;
|
---|
49 | }
|
---|
50 | },
|
---|
51 | _createInnerWidget: function(item) {
|
---|
52 | var innerWidget;
|
---|
53 | switch (item.widgetType) {
|
---|
54 | default:
|
---|
55 | innerWidget = new dijit.form.Button({});
|
---|
56 | break;
|
---|
57 | }
|
---|
58 |
|
---|
59 | return innerWidget;
|
---|
60 | },
|
---|
61 | insertObjects: function(/*Array*/objects) {
|
---|
62 | // This takes an array of objects {data:{//props}, type:[//types]}. Node is NOT included!
|
---|
63 | objects.forEach(function(item){
|
---|
64 | this.dndSource.insertNodes(false, [item]);
|
---|
65 | }, this);
|
---|
66 | },
|
---|
67 | getContent: function() {
|
---|
68 | content = [];
|
---|
69 | var nodes = this.dndSource.getAllNodes();
|
---|
70 | for (var i = 0; i < nodes.length; i++) {
|
---|
71 | content.push(this.dndSource.getItem(nodes[i].id).data.getContent());
|
---|
72 | }
|
---|
73 | return content;
|
---|
74 | },
|
---|
75 | getNodeList: function() {
|
---|
76 | return this.dndSource.getAllNodes();
|
---|
77 | },
|
---|
78 | onDropInternal: function() {
|
---|
79 | topic.publish("/QuestionEditor/Preview/MoveItem");
|
---|
80 | },
|
---|
81 | onDropExternal: function() {
|
---|
82 | // This is fired when something from the Toolkit is dropped into the Preview -- add operation.
|
---|
83 | topic.publish("/QuestionEditor/Preview/AddItem");
|
---|
84 | }
|
---|
85 |
|
---|
86 | });
|
---|
87 | }); |
---|