source: Dev/branches/rest-dojo-ui/client/rft/ui/QuestionEditorPreview.js @ 387

Last change on this file since 387 was 387, checked in by hendrikvanantwerpen, 13 years ago
File size: 2.6 KB
Line 
1define([
2    'dojo/_base/declare',
3    'dojo/_base/lang',
4    'dojo/dnd/Source',
5    'dojo/dom-construct',
6    'dijit/_Container',
7    'dijit/_TemplatedMixin',
8    'dijit/_WidgetBase',
9    'dijit/_WidgetsInTemplateMixin',
10    'rft/ui/QuestionEditorPreviewItem',
11    'dojo/text!./templates/QuestionEditorPreview.html'
12    ], function(declare, lang, Source, domConstruct, _Container, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, QuestionEditorPreviewItem, template) {
13        return declare("rft.ui.QuestionEditorPreview", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _Container], {
14
15            templateString: template,
16            dndSource: null,
17
18            postCreate: function(){
19                this.inherited(arguments);
20                this.dndSource = new Source(this.dndSourceNode, {
21                    accept: ["questionContent"],
22                    skipForm: true,
23                    creator: lang.hitch(this, this._sourceCreatorMethod)
24                });
25                this.dndSource.startup();
26            },
27            _sourceCreatorMethod: function(item, hint){
28                var node;
29                switch(hint){
30                case "avatar":
31                    node = domConstruct.create("span",{
32                        innerHTML: item.type || "Dragging!!!"
33                    });
34                default:
35                    var previewItem = new QuestionEditorPreviewItem({
36                        item: item.content
37                    });
38                    node = previewItem.domNode;
39                }               
40                return {node: node, data: item, type: ["questionContent"]};
41            },
42            insertObjects: function(/*Array*/items) {
43                this.dndSource.insertNodes(false, items);
44            },
45            getContent: function() {
46                var content = [];
47                var nodes = this.dndSource.getAllNodes();
48                for (var i = 0; i < nodes.length; i++) {
49                    content.push(this.dndSource.getItem(nodes[i].id).data.getContent());
50                }
51                return content;
52            },
53            getNodeList: function() {
54                return this.dndSource.getAllNodes();
55            },
56            onDropInternal: function() {
57                topic.publish("/QuestionEditor/Preview/MoveItem");
58            },
59            onDropExternal: function() {
60                // This is fired when something from the Toolkit is dropped into the Preview -- add operation.
61                topic.publish("/QuestionEditor/Preview/AddItem");
62            }
63
64        });
65    });
Note: See TracBrowser for help on using the repository browser.