Changeset 362
- Timestamp:
- 07/16/12 16:27:40 (13 years ago)
- Location:
- Dev/branches/rest-dojo-ui/client
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/rest-dojo-ui/client/config/db.js
r361 r362 20 20 parser.parse(); 21 21 22 query("#log").forEach(function(n){ logNode = n;});22 query("#log").forEach(function(n){logNode = n;}); 23 23 usernameInput = registry.byId('username'); 24 24 passwordInput = registry.byId('password'); … … 31 31 32 32 log("Give CouchDB admin username & password and click 'Configure' to start.\nIf the database already exists, rft_admin password will suffice.",true); 33 34 33 35 34 function configure(){ 35 var docs; 36 36 37 log("Configuring CouchDB for RFT:",true); 37 38 … … 40 41 var reset = resetInput.get('value'); 41 42 42 var docs = json.fromJson(docsJson); 43 log("Downloading most recent configuration."); 44 xhr('GET',{ 45 url: 'docs.json', 46 handleAs: 'json', 47 sync: true 48 },true) 49 .then(function(result){ 50 docs = result; 51 }); 43 52 44 53 function req(method,url,body) { … … 47 56 contentType: 'application/json', 48 57 handleAs: 'json', 49 sync: true, 50 error: function(err) { 51 log("ERROR: "+err); 52 } 58 sync: true 53 59 }; 54 60 if ( !body || lang.isObject(body) ) { -
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 }); -
Dev/branches/rest-dojo-ui/client/rft/store.js
r359 r362 97 97 if ( query === undefined ) { 98 98 query = '_all_docs'; 99 queryOpts.include_docs = true;100 99 } 101 100 … … 126 125 127 126 // Custom options 128 if (options.key ) {127 if (options.key !== undefined) { 129 128 queryOpts.key = options.key; 130 } else if (options.keys ) {129 } else if (options.keys !== undefined) { 131 130 queryOpts.keys = options.keys; 132 } else if (options.startkey || options.endkey) {131 } else if (options.startkey !== undefined || options.endkey !== undefined) { 133 132 queryOpts.startkey = options.startkey; 134 133 queryOpts.endkey = options.endkey; 134 } 135 if (options.include_docs !== undefined) { 136 queryOpts.include_docs = options.include_docs; 137 } 138 if (options.reduce !== undefined) { 139 queryOpts.reduce = options.reduce; 140 } 141 if (options.group !== undefined) { 142 queryOpts.group = options.group; 143 if (options.group_level !== undefined) { 144 queryOpts.group_level = options.group_level; 145 } 135 146 } 136 147 … … 152 163 dfd.resolve( 153 164 array.map(result.rows, 154 function(result){ return result.value; })); 165 function(result){ 166 return [result.key, options.include_docs === true ? result.doc : result.value]; 167 })); 155 168 } 156 169 },function(err){ 157 170 dfd.reject(err); 158 171 }); 159 return QueryResults(dfd.promise);172 return CouchResults(dfd.promise); 160 173 } 161 174 }); 162 175 176 function CouchResults(results) { 177 if (!results) { 178 return results; 179 } 180 181 if(results.then){ 182 results = lang.delegate(results); 183 } 184 185 if (!results.forEach) { 186 results.forEach = function(callback) { 187 return Deferred.when(results, function(results) { 188 array.forEach(results, function(result) { 189 callback(result[1],result[0]); 190 }); 191 }); 192 } 193 } 194 195 return results; 196 } 197 163 198 return new CouchStore({target: 'data/rft/'}); 164 199 -
Dev/branches/rest-dojo-ui/client/rft/ui/Selector.js
r360 r362 64 64 actions: { 65 65 "Toggle dropdown" : { 66 callback: lang.hitch(this, this. _onToggleDropdown),66 callback: lang.hitch(this, this.onToggle), 67 67 properties: { 68 68 blockButton: true, … … 75 75 },this.selectedItemNode); 76 76 this._selectorLine.startup(); 77 this._selectorLine.on('click',lang.hitch(this, this.onToggle)); 77 78 78 79 fx.wipeOut({ … … 82 83 _onSelect: function(item, widget) { 83 84 this._selectedItem = item; 84 this. _onToggleDropdown();85 this.onToggle(); 85 86 this._selectorLine.set("title", item.title); 86 87 baseArray.forEach(this.optionsNode.childNodes, function(node){ … … 101 102 } 102 103 }, 103 _onToggleDropdown: function(evt) {104 onToggle: function(evt) { 104 105 if (this._folded) { 105 106 var downArrowIcon = dojo.query(".rftBlockButton .rftIconHalfArrowDown", this._selectorLine.buttonsNode)[0];
Note: See TracChangeset
for help on using the changeset viewer.