Changeset 362 for Dev/branches/rest-dojo-ui/client/rft/pages/survey.js
- Timestamp:
- 07/16/12 16:27:40 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/rest-dojo-ui/client/rft/pages/survey.js
r360 r362 3 3 'dojo/_base/event', 4 4 'dojo/_base/Deferred', 5 'dojo/on', 5 6 'rft/ui/Selector', 6 7 'rft/ui/SurveyListView', … … 11 12 'dojo/store/Cache', 12 13 'dojo/store/Memory' ], 13 function(declare,lang,event,Deferred, Selector,SurveyListView,ContentPane,store,_Page,content,Cache,Memory){14 function(declare,lang,event,Deferred,on,Selector,SurveyListView,ContentPane,store,_Page,content,Cache,Memory){ 14 15 return declare('rft.pages.survey',[_Page],{ 15 16 object: null, … … 26 27 return Deferred.when( obj.creator && store.dereference(obj.creator) ); 27 28 })); 28 this._createListView();29 this._createQuestionBrowser();30 29 this._setupButtons(); 30 this._setupQuestionBrowser(); 31 this._setupListView(); 31 32 } else { 32 33 throw "No valid uid or survey passed!"; … … 40 41 this.btnPreview.on("click", lang.hitch(this, this._goToPreview)); 41 42 }, 42 _createQuestionBrowser: function() { 43 store.query('_design/default/_view/by_type', {key:'Question'}) 44 .forEach(function(question){ 45 this._insertQuestion(question); 46 },this); 43 _setupQuestionBrowser: function() { 44 this.tabList.watch("selectedChildWidget",lang.hitch(this,function(name,oldTab,newTab){ 45 this._fillCategoryTab(newTab.__category); 46 })); 47 store.query('_design/default/_view/questions', {reduce:true,group:true,group_level:1}) 48 .forEach(lang.hitch(this,function(value,key){ 49 this._createCategoryTab(key[0],value); 50 })); 47 51 }, 48 _insertQuestion: function(question) { 49 for (var c in question.categories) { 50 var cat = question.categories[c]; 51 if (this._dataMap[cat] === undefined) { 52 this._dataMap[cat] = { 53 widget: this._createCategoryTab(cat), 54 topics: {} 55 } 56 } 57 this._insertIntoCategory(question,this._dataMap[cat]); 52 _createCategoryTab: function(category,count) { 53 if (this._dataMap[category] === undefined) { 54 var categoryTab = new ContentPane({ 55 __category: category, 56 title: category+" ("+count+")" 57 }); 58 categoryTab.startup(); 59 this._dataMap[category] = { 60 _widget: categoryTab 61 }; 62 this.tabList.addChild(categoryTab); 58 63 } 59 64 }, 60 _createCategoryTab: function(category) { 61 var categoryTab = new ContentPane({ 62 title: category 63 }); 64 categoryTab.startup(); 65 this.tabList.addChild(categoryTab); 66 return categoryTab; 65 _fillCategoryTab: function(category) { 66 var categoryMap = this._dataMap[category]; 67 if (!categoryMap._filled) { 68 categoryMap._filled = true; 69 store.query('_design/default/_view/questions', {reduce:true,group:true,group_level:2,startkey:[category],endkey:[category,{}]}) 70 .forEach(lang.hitch(this,function(value,key){ 71 this._createTopicSelector(key[1],category,value); 72 })); 73 } 67 74 }, 68 _insertIntoCategory: function(question, categoryMap) { 69 if (categoryMap[question.topic] === undefined) { 75 _createTopicSelector: function(topic,category,count){ 76 var categoryMap = this._dataMap[category]; 77 if (categoryMap[topic] === undefined) { 70 78 var w = new Selector({ 71 title: question.topic 72 }).placeAt(categoryMap.widget.containerNode); 79 __category: category, 80 __topic: topic, 81 title: topic+" ("+count+")" 82 }).placeAt(categoryMap._widget.containerNode); 73 83 w.startup(); 84 categoryMap[topic] = { 85 _widget: w 86 }; 87 this._fillTopicSelector(topic,category); 74 88 w.on('include',lang.hitch(this,this.includeQuestion)); 75 categoryMap[question.topic] = {76 widget: w77 };78 89 } 79 categoryMap[question.topic].widget.addItem(question); 90 }, 91 _fillTopicSelector: function(topic,category) { 92 var categoryMap = this._dataMap[category]; 93 var topicMap = categoryMap[topic]; 94 if (!topicMap._filled) { 95 store.query('_design/default/_view/questions', {reduce:false,include_docs:true,key:[category,topic]}) 96 .forEach(lang.hitch(this,function(value,key){ 97 topicMap._widget.addItem(value); 98 })); 99 } 80 100 }, 81 101 /* ListView code */ 82 _createListView: function() { 102 includeQuestion: function(question) { 103 this.listView.insertItem(question); 104 }, 105 _setupListView: function() { 83 106 this.listView = new SurveyListView({ 84 107 controller: this 85 108 }).placeAt(this.surveyListViewNode); 86 109 this.listView.startup(); 87 },88 includeQuestion: function(question) {89 this.listView.insertItem(question);90 110 } 91 111 });
Note: See TracChangeset
for help on using the changeset viewer.