Changeset 354 for Dev/branches/rest-dojo-ui/client/rft/pages/survey.js
- Timestamp:
- 07/09/12 19:24:56 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/rest-dojo-ui/client/rft/pages/survey.js
r343 r354 1 define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/event', 2 'dojo/_base/Deferred','rft/ui/AccordionList','rft/ui/LineWithActionsWidget', 3 'rft/store','rft/ui/_Page','rft/api'], 4 function(declare,lang,event,Deferred,AccordionList,LineWithActionsWidget,store,_Page,api){ 1 define(['dojo/_base/declare', 2 'dojo/_base/lang', 3 'dojo/_base/event', 4 'dojo/_base/Deferred', 5 'rft/ui/AccordionList', 6 'rft/ui/LineWithActionsWidget', 7 'rft/store', 8 'rft/ui/_Page', 9 'rft/api', 10 'dijit/registry', 11 'rft/content', 12 'dojo/on', 13 'dojo/query'], 14 function(declare,lang,event,Deferred,AccordionList,LineWithActionsWidget,store,_Page,api,registry,content, on, query){ 5 15 return declare('rft.pages.survey',[_Page],{ 6 16 object: null, … … 9 19 Deferred.when(store.get(this.pageArgs.uid)) 10 20 .then(lang.hitch(this,function(obj){ 11 this.object = obj; 12 this.setFields(obj); 13 return Deferred.when( obj.creator && store.dereference(obj.creator) ); 14 })) 15 .then(lang.hitch(this,function(obj){ 16 this.creator.innerHTML = (obj && obj.email) || 'unknown'; 17 })); 18 Deferred.when(store.query('_design/default/_view/by_type',{key:'Question'})) 19 .then(lang.hitch(this,function(items){ 20 this._questionList = new AccordionList({ 21 actions: { 22 'Add': lang.hitch(this,'_addQuestion') 23 }, 24 categoryProperty: 'category', 25 titleProperty: 'title' 26 },this.allQuestions); 27 this._questionList.startup(); 28 this._questionList.setItems(items); 29 })); 21 this.object = obj; 22 return Deferred.when( obj.creator && store.dereference(obj.creator) ); 23 })); 24 this._createQuestionBrowser(); 30 25 } else { 31 this.header.innerHTML = "Error: no uid for survey!"26 //this.header.innerHTML = "Error: no uid for survey!" 32 27 } 28 this._setupButtons(this); 29 this._insertQuestion({title: "This is the question title!", sorting: {categories: ['CategoryOne', 'CategoryB123'], topic: 'The first question topic'}}); 30 this._insertQuestion({title: "BLablabla question text!", sorting: {categories: ['CategoryOne'], topic: 'The first question topic'}}); 31 this._insertQuestion({title: "Yaddayaddayaddaa ... sigh", sorting: {categories: ['CategoryThree', 'CategoryB123'], topic: 'Another topic'}}); 32 }, 33 onLeave: function() { 34 this.inherited(arguments); 33 35 }, 34 36 onReset: function() { … … 36 38 }, 37 39 onSave: function(evt) { 38 lang.mixin(this.object,this.form.get('value'));40 /*lang.mixin(this.object,this.form.get('value')); 39 41 Deferred.when( store.put(this.object) ) 40 42 .then(lang.hitch(this,function(obj){ … … 48 50 evt.stopPropagation(); 49 51 return false; 52 */ 50 53 }, 51 setFields: function(obj) { 52 this.form.reset(); 53 this.header.innerHTML = "Edit survey '"+(obj.title || '(undefined)')+"'"; 54 obj && this.form.set('value',obj); 54 _goToPreview: function() { 55 content.goTo('surveyAdvanced', {uid: this.object._id}); 56 /* 57 * TODO: How to prevent widgets with identical id's on different pages clashing? 58 * For example: btnSave clashes when going from survey to surveyAdvanced, since both contain one. survey.btnSave is not destroyed when loading surveyAdvanced.btnSave! 59 * Since there is no page reload, only a contentPane content swap! 60 * Talk to Hendrik about this! 61 * TEMPORARY FIX IN THIS.ONLEAVE! 62 */ 55 63 }, 56 _addQuestion: function(obj) { 57 var d = {}; 58 d.widget = new LineWithActionsWidget({ 59 title:obj.title, 60 userObj: obj, 61 actions:{ 62 "Remove": lang.hitch(this,'_removeQuestion',d) 64 _setupButtons: function() { 65 // Setup button events 66 registry.byId("btnSave").on("click", lang.hitch(this, function(){ 67 this.onSave(arguments); 68 })); 69 registry.byId("btnPreview").on("click", lang.hitch(this, function(){ 70 this._goToPreview(); 71 })); 72 }, 73 _createQuestionBrowser: function() { 74 Deferred.when(store.query('_design/default/_view/by_type',{key:'Question'})) 75 .then(lang.hitch(this,function(questions){ 76 questions.forEach(function(question) { 77 this._insertQuestion(question); 78 }, this); 79 })); 80 }, 81 _insertQuestion: function(question) { 82 // MASSIVE TODO: The question categories cannot have spaces currently, due to the way we append them to the ID property of the container. ID's cannot have spaces. 83 // Easy fix: Replace spaces with underscores for the time being? The alternative is to make these containers have an actual "questioncategory" property in the governing widget. Not fun. 84 var tabs = registry.byId("tabList"); 85 for (var c in question.sorting.categories) { 86 var cat = question.sorting.categories[c]; 87 var catPane = query("#tab"+cat, tabs.containerNode)[0]; 88 if (catPane) { 89 this._insertIntoCategory(question, catPane); 90 } else { 91 catPane = this._createCategoryTab(cat); 92 if (catPane) { 93 this._insertIntoCategory(question, catPane); 94 } else { 95 throw "Error: could not find or create category pane!"; 96 } 63 97 } 98 } 99 }, 100 _createCategoryTab: function(category) { 101 var tabs = registry.byId("tabList"); 102 var newCat = new dijit.layout.ContentPane({ 103 title: category 64 104 }); 65 d.widget.placeAt(this.surveyQuestions); 105 newCat.domNode.id = "tab"+category; 106 tabs.addChild(newCat); 107 var pane = query("#tab"+category, tabs.containerNode)[0]; 108 return (pane) ? pane : false; 66 109 }, 67 _removeQuestion: function(data,obj) { 68 data.widget.destroy(); 69 } 110 _insertIntoCategory: function(question, container) { 111 debugger; 112 var selector = query(".rftSelector[title='"+question.sorting.topic+"']", container)[0]; 113 var selectorWidget; 114 if (selector) { 115 selectorWidget = registry.byNode(selector); 116 117 } else { 118 selectorWidget = new rft.ui.Selector({ 119 title: question.sorting.topic 120 }); 121 selectorWidget.placeAt(container); 122 } 123 selectorWidget.addQuestion(question); 124 }, 125 126 127 128 70 129 }); 71 130 }); 72 131
Note: See TracChangeset
for help on using the changeset viewer.