Changeset 379 for Dev/branches/rest-dojo-ui/client/rft/ui/OrderedDndList.js
- Timestamp:
- 07/26/12 21:57:20 (13 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/rest-dojo-ui/client/rft/ui/OrderedDndList.js
r378 r379 1 1 define([ 2 2 'dojo/_base/declare', 3 'dojo/_base/lang', 4 'dojo/dnd/Source', 5 'dojo/dom-construct', 6 'dijit/_Container', 7 'dijit/_TemplatedMixin', 3 8 'dijit/_WidgetBase', 4 'dijit/_TemplatedMixin',5 'dojo/_base/lang',6 'dojo/fx',7 'dojo/_base/fx',8 9 'dijit/_WidgetsInTemplateMixin', 9 'dijit/ _Container',10 'dijit/form/Button', 10 11 'rft/ui/LineWithActionsWidget', 11 'dojo/text!./templates/ SurveyListView.html'12 'dojo/text!./templates/OrderedDndList.html' 12 13 ],function( 13 14 declare, 15 lang, 16 Source, 17 domConstruct, 18 _Container, 19 _TemplatedMixin, 14 20 _WidgetBase, 15 _TemplatedMixin,16 lang,17 fx,18 baseFx,19 21 _WidgetsInTemplateMixin, 20 _Container,22 Button, 21 23 LineWithActionsWidget, 22 24 templateString 23 24 return declare('rft.ui. SurveyListView',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{25 ){ 26 return declare('rft.ui.OrderedDndList',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{ 25 27 templateString: templateString, 26 28 baseClass: 'rftSurveyListView', 29 type: 'text', 27 30 source: null, 28 region: 'center',29 31 30 32 postCreate: function() { … … 35 37 } 36 38 37 this.source = new dojo.dnd.Source(this.sourceNode, { 38 isSource: true, 39 accept: ["SurveyListViewItem"], 39 this.source = new Source(this.sourceNode, { 40 accept: [this.type], 40 41 horizontal: false, 41 withHandles: false,42 copyOnly: false,43 selfCopy: false,44 selfAccept: true,45 delay: 0,46 42 singular: true, 47 creator: lang.hitch(this, this. creatorMethod)43 creator: lang.hitch(this, this._createQuestionDndItem) 48 44 }); 49 45 50 new dijit.form.Button({46 new Button({ 51 47 label: "Move up", 52 48 showLabel: false, … … 55 51 'class': "trans", 56 52 onClick: lang.hitch(this, function() { 57 this. moveItem("up");53 this._moveSelectedItem("up"); 58 54 }) 59 55 }, this.btnListMoveUp); 60 56 61 new dijit.form.Button({57 new Button({ 62 58 label: "Move down", 63 59 showLabel: false, … … 66 62 'class': "trans", 67 63 onClick: lang.hitch(this, function() { 68 this. moveItem("down");64 this._moveSelectedItem("down"); 69 65 }) 70 66 }, this.btnListMoveDown); 71 67 }, 72 creatorMethod: function(item, hint) {68 _createQuestionDndItem: function(item, hint) { 73 69 var node; 74 70 75 71 if (hint == "avatar") { 76 node = document.createElement("div"); 77 node.className = "dragAvatar"; 78 node.innerHTML = item.title; 72 node = domConstruct.create("div",{ 73 'class': 'dragAvatar', 74 innerHTML: item.title 75 }); 79 76 } else { 80 77 var w = new LineWithActionsWidget({ … … 83 80 actions: { 84 81 "Remove" : { 82 // w not bound in hitch, because it's 83 // not initialized when hitch is called. 85 84 callback: lang.hitch(this, function(){ 86 this. removeItem(item,w);85 this._removeItem(w); 87 86 }), 88 87 properties: { … … 107 106 node = w.domNode; 108 107 } 109 var fullItem ={108 return { 110 109 node: node, 111 110 data: item, 112 type: " SurveyListViewItem"111 type: "question" 113 112 }; 114 return fullItem;115 113 }, 116 moveItem: function(dir) {114 _moveSelectedItem: function(dir) { 117 115 var node = this.source.getSelectedNodes()[0]; 118 116 if (node) { … … 142 140 this.source.insertNodes(false,[item], false, anchor); 143 141 } else { 144 this. source.insertNodes(false,[item]);142 this.appendItem(item); 145 143 } 146 144 }, 147 removeItem: function(item,widget){ 145 appendItem: function(item) { 146 this.source.insertNodes(false,[item]); 147 }, 148 getItems: function() { 149 return this.source.getAllNodes() 150 .map(function(node){ 151 return this.source.getItem(node.id).data; 152 },this); 153 }, 154 deleteItems: function() { 155 this.source.getAllNodes() 156 .forEach(function(node){ 157 node.destroy(); 158 }); 159 this.source.sync(); 160 }, 161 _removeItem: function(widget){ 148 162 widget.destroy(); 163 this.source.sync(); 149 164 } 150 165 }); 151 });166 });
Note: See TracChangeset
for help on using the changeset viewer.