Changeset 360 for Dev/branches/rest-dojo-ui/client/rft/ui/Selector.js
- Timestamp:
- 07/13/12 15:13:46 (13 years ago)
- Location:
- Dev/branches/rest-dojo-ui/client
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/rest-dojo-ui/client
-
Property
svn:ignore
set to
-
Property
svn:ignore
set to
-
Dev/branches/rest-dojo-ui/client/rft/ui/Selector.js
r358 r360 4 4 'dijit/registry', 5 5 'dojo/_base/lang', 6 'dojo/_base/event', 6 7 'dojo/fx', 7 8 'dijit/_WidgetBase', … … 17 18 registry, 18 19 lang, 20 event, 19 21 fx, 20 22 _WidgetBase, … … 28 30 return declare('rft.ui.Selector',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{ 29 31 templateString: templateString, 30 title: " ERROR: NULL_TOPIC",32 title: "", 31 33 baseClass: 'rftSelector', 32 34 modifiers: 'blue', 33 currentlySelectedId: null, 34 controller: null, // Use events/pubsub instead of a controller variable? Decoupling! 35 _folded: true, 36 _titleLine: null, 37 _selectorLine: null, 38 _selectedItem: null, 35 39 36 postCreate: function() {40 startup: function() { 37 41 domClass.add(this.domNode, this.modifiers); 38 42 domClass.add(this.selectedColorNode, "pending"); 39 this.domNode.dataset["topic"] = this.topic;40 43 41 new LineWithActionsWidget({42 title: this.t opic,44 this._titleLine = new LineWithActionsWidget({ 45 title: this.title, 43 46 modifiers: this.modifiers, 44 47 actions: { 45 " AddToSurvey" : {46 callback: lang.hitch(this, this. includeQuestion),48 "Include in survey" : { 49 callback: lang.hitch(this, this._onInclude), 47 50 properties: { 48 51 blockButton: true, … … 54 57 } 55 58 },this.titleNode); 59 this._titleLine.startup(); 56 60 57 this. selectorLine = new LineWithActionsWidget({61 this._selectorLine = new LineWithActionsWidget({ 58 62 title: 'None', 59 63 modifiers: this.modifiers, 60 64 actions: { 61 "Toggle Dropdown" : {62 callback: lang.hitch(this, this._ toggleDropdown()),65 "Toggle dropdown" : { 66 callback: lang.hitch(this, this._onToggleDropdown), 63 67 properties: { 64 68 blockButton: true, … … 70 74 } 71 75 },this.selectedItemNode); 76 this._selectorLine.startup(); 77 78 fx.wipeOut({ 79 node: this.optionsNode 80 }).play(); 72 81 }, 73 _toggleDropdown: function() { 74 var node = this.optionsNode; 75 var show = fx.wipeIn({ 76 node: node 77 }); 78 var hide = fx.wipeOut({ 79 node: node 80 }); 81 hide.play(); 82 var folded = true; 83 return function(e) { 84 if ( folded ) { 85 var downArrowIcon = dojo.query(".rftBlockButton .rftIconHalfArrowDown", this.selectorLine.buttonsNode)[0]; 86 if (downArrowIcon){ 87 domClass.replace(downArrowIcon, "rftIconHalfArrowUp", "rftIconHalfArrowDown"); 82 _onSelect: function(item, widget) { 83 this._selectedItem = item; 84 this._onToggleDropdown(); 85 this._selectorLine.set("title", item.title); 86 baseArray.forEach(this.optionsNode.childNodes, function(node){ 87 var line = registry.byNode(node); 88 if (line) { 89 if (line === widget) { 90 domClass.add(line.domNode, "inheritBgColor light"); 91 } else { 92 domClass.remove(line.domNode, "inheritBgColor light"); 88 93 } 89 show.play();90 folded = false;91 } else {92 var upArrowIcon = dojo.query(".rftBlockButton .rftIconHalfArrowUp", this.selectorLine.buttonsNode)[0];93 if (upArrowIcon){94 domClass.replace(upArrowIcon, "rftIconHalfArrowDown", "rftIconHalfArrowUp");95 }96 hide.play();97 folded = true;98 99 94 } 100 e.preventDefault(); 101 e.stopPropagation(); 102 }; 95 }, this); 96 this.onSelect(item); 103 97 }, 104 addQuestion: function(questionId) { 105 var question = this.controller.getQuestion(questionId); 106 if (question) { 107 var w = new LineWithActionsWidget({ 108 title: question.title, 109 questionId: questionId, 110 actions: { 111 "InfoHover" : { 112 callback: dojo.partial(this.infoFunction, this), 113 properties: { 114 blockButton: false, 115 showLabel: false, 116 icon: "Inspect" 117 } 98 _onInclude: function() { 99 if (this._selectedItem) { 100 this.onInclude(this._selectedItem); 101 } 102 }, 103 _onToggleDropdown: function(evt) { 104 if (this._folded) { 105 var downArrowIcon = dojo.query(".rftBlockButton .rftIconHalfArrowDown", this._selectorLine.buttonsNode)[0]; 106 if (downArrowIcon){ 107 domClass.replace(downArrowIcon, "rftIconHalfArrowUp", "rftIconHalfArrowDown"); 108 } 109 fx.wipeIn({ 110 node: this.optionsNode 111 }).play(); 112 this._folded = false; 113 } else { 114 var upArrowIcon = dojo.query(".rftBlockButton .rftIconHalfArrowUp", this._selectorLine.buttonsNode)[0]; 115 if (upArrowIcon){ 116 domClass.replace(upArrowIcon, "rftIconHalfArrowDown", "rftIconHalfArrowUp"); 117 } 118 fx.wipeOut({ 119 node: this.optionsNode 120 }).play(); 121 this._folded = true; 122 } 123 evt && event.stop(evt); 124 return false; 125 }, 126 addItem: function(item) { 127 var w = new LineWithActionsWidget({ 128 title: item.title, 129 actions: { 130 "Info" : { 131 callback: function() { 132 item.description && alert(item.description); 133 }, 134 properties: { 135 blockButton: false, 136 showLabel: false, 137 icon: "Inspect" 118 138 } 119 139 } 120 }); 121 w.placeAt(this.optionsNode); 122 w.on("click", lang.hitch(this, function(){ 123 this.selectQuestion(questionId); 124 this._toggleDropdown(); 125 }, questionId)); 126 127 } 140 } 141 }).placeAt(this.optionsNode); 142 w.startup(); 143 w.on("click", lang.hitch(this, this._onSelect, item, w)); 128 144 }, 129 infoFunction: function(selector) { 130 var question = selector.controller.getQuestion(this.questionId); 131 console.log(question); 132 alert("Some info here!"); 133 }, 134 includeQuestion: function() { 135 if (this.currentlySelectedId) { 136 this.controller.IncludeQuestion(this.currentlySelectedId) 137 } else { 138 return false; 139 } 140 }, 141 selectQuestion: function(questionId) { 142 /* TODO: TEST THOROUGHLY! */ 143 var question = this.controller.getQuestion(questionId); 144 if (question) { 145 this.currentlySelectedId = questionId; 146 this.selectorLine.questionId = questionId; 147 this.selectorLine.set("title", question.title); 148 // Iterate through optionsNode, add "selected" class to currently selected node 149 baseArray.forEach(this.optionsNode.childNodes, function(node, index){ 150 var line = registry.byNode(node); 151 if (line) { 152 if (line.questionId == this.currentlySelectedId) { 153 domClass.add(line.domNode, "inheritBgColor light"); 154 } else { 155 domClass.remove(line.domNode, "inheritBgColor light"); 156 } 157 } 158 }, this); 159 } 160 } 145 onSelect: function(item) {}, 146 onInclude: function(item) {} 161 147 }); 162 148 });
Note: See TracChangeset
for help on using the changeset viewer.