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

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

Started the QuestionEditorPreview? bit - now works with headers and texts, fully stores and restores this in order properly.

Note: there must be a better way for this, but seeing as all content pieces can differ greatly I couldn't think of a way to make it properly generic. @Hendrik: need discussion about this.

Note2: Currently I don't use any internal events in the question editor. Not sure if it would be a lot better we would.

File size: 2.6 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/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});
Note: See TracBrowser for help on using the repository browser.