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

Last change on this file since 373 was 366, checked in by tjcschipper, 13 years ago
  • AdaptiveForm? really isn't anything yet, but it's supposed to become a way to encapsulate forms that add/remove inputs based on other input's (selected) values.
  • Created a skeleton for the question editor. It's almost an exact copy of SurveyAdvanced?.
File size: 2.4 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: item, type: "PreviewItem"};
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                        RemoveObject: function(widget) {
68                        },
69                        GetNodeList: function() {
70                                return this.dndSource.getAllNodes();
71                        },
72                        onDropInternal: function() {
73                                topic.publish("/QuestionEditor/Preview/MoveItem");
74                        },
75                        onDropExternal: function() {
76                                // This is fired when something from the Toolkit is dropped into the Preview -- add operation.
77                                topic.publish("/QuestionEditor/Preview/AddItem");
78                        }
79
80                });
81});
Note: See TracBrowser for help on using the repository browser.