Ignore:
Timestamp:
07/30/12 00:19:37 (13 years ago)
Author:
hendrikvanantwerpen
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/rest-dojo-ui/client/rft/ui/QuestionEditorPreview.js

    r377 r387  
    11define([
    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], {
     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], {
    1414
    15                         templateString: template,
    16                         dndSource: null,
     15            templateString: template,
     16            dndSource: null,
    1717
    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.item.data || "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                                 }
     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            }
    5863
    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 });
     64        });
     65    });
Note: See TracChangeset for help on using the changeset viewer.