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

Last change on this file since 388 was 388, checked in by hendrikvanantwerpen, 13 years ago

Made QuestionEditorPreview? a ContentPane? that scales with the layout
correctly, no preset height in CSS needed anymore.
ISSUE: scrolling also starts a DnD event, Dojo bug?

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