Changeset 281 for Dev/branches/rest-dojo-ui/client/rft/pages/questions.js
- Timestamp:
- 02/22/12 12:54:44 (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:externals set to
-
Dev/branches/rest-dojo-ui/client/rft/pages/questions.js
r275 r281 1 1 define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/array','dojo/_base/event', 2 'dojo/_base/Deferred','dojo/store/JsonRest','dijit/layout/ContentPane', 2 'dojo/_base/Deferred','dojo/store/JsonRest','dijit/layout/ContentPane','dijit/TitlePane', 3 3 'rft/ui/_Page','rft/ui/LineWithActionsWidget'], 4 function(declare,lang,array,event,Deferred,JsonRest,ContentPane, _Page,LineWithActionsWidget) {4 function(declare,lang,array,event,Deferred,JsonRest,ContentPane,TitlePane,_Page,LineWithActionsWidget) { 5 5 return declare('rft.pages.questions',[_Page],{ 6 6 constructor: function() { 7 7 this.inherited(arguments); 8 this.containers = {};9 8 this.questions = {}; 10 9 }, … … 20 19 array.forEach(results,lang.hitch(this,'_addQuestion')); 21 20 })); 22 },23 _getContainerForQuestion: function(q) {24 var category = q.category || 'Unsorted';25 var categoryContainer = this.containers[category];26 if ( !categoryContainer ) {27 var ac = new ContentPane({28 title:category,29 doLayout: false30 });31 categoryContainer = this.containers[category] = {32 container: ac33 };34 ac.placeAt(this.accordion);35 ac.startup();36 }37 return categoryContainer.container;38 21 }, 39 22 _addQuestion: function(q) { … … 62 45 var container = this._getContainerForQuestion(q); 63 46 question.widget.placeAt(container.containerNode); 47 this._cleanupEmptyContainers(); 48 }, 49 _getContainerForQuestion: function(q) { 50 var category = q.category || 'Unsorted'; 51 var widgets = this.accordion.getChildren(); 52 var containerWidget; 53 var lastIndex = 'last'; 54 array.some(widgets,lang.hitch(this,function(widget,idx) { 55 if ( widget.title == category ) { 56 containerWidget = widget; 57 return true; 58 } else if ( widget.title > category ) { 59 lastIndex = idx; 60 return true; 61 } 62 return false; 63 })); 64 if ( !containerWidget ) { 65 containerWidget = new TitlePane({ 66 title:category 67 }); 68 containerWidget.startup(); 69 this.accordion.addChild(containerWidget,lastIndex); 70 } 71 return containerWidget; 72 }, 73 _cleanupEmptyContainers: function() { 74 var widgets = this.accordion.getChildren(); 75 array.forEach(widgets,lang.hitch(this,function(widget){ 76 if ( !widget.getChildren().length ) { 77 this.accordion.removeChild(widget).destroy(); 78 } 79 })); 64 80 }, 65 81 onNewQuestion: function() { … … 72 88 this.questionForm.reset(); 73 89 this.questionForm.set('value',question); 90 this.questionWidget.set('value',question); 74 91 this.questionDialog.show(); 75 92 }, 76 93 onSaveQuestion: function(evt) { 77 94 var value = this.questionForm.get('value'); 95 var subvalue = this.questionWidget.get('value'); 96 lang.mixin(value,subvalue); 78 97 Deferred.when( this._store.put(value) ) 79 98 .then(lang.hitch(this,function(){ … … 88 107 this.questionDialog.hide(); 89 108 this.questionForm.reset(); 90 this._refresh();91 109 } 92 110 });
Note: See TracChangeset
for help on using the changeset viewer.