Changeset 487 for Dev/trunk/src/client/qed-client/pages/surveyRun.js
- Timestamp:
- 03/05/14 22:44:48 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/src/client/qed-client/pages/surveyRun.js
r466 r487 4 4 "../app/Router", 5 5 "../lib/func", 6 "../model/classes/ SurveyRun",7 "../ store",6 "../model/classes/responses", 7 "../model/classes/surveyRuns", 8 8 "../widgets/LineWithActionsWidget", 9 "dojo/_base/array", 9 10 "dojo/_base/declare", 10 11 "dojo/_base/event", … … 13 14 "require", 14 15 "dojo/text!./templates/surveyRun.html" 15 ], function(Content, Page, Router, func, SurveyRun, store, LineWithActionsWidget, declare, event, lang, when, require, template) {16 ], function(Content, Page, Router, func, responses, surveyRuns, LineWithActionsWidget, array, declare, event, lang, when, require, template) { 16 17 return declare([Page],{ 17 18 contextRequire: require, … … 24 25 if ( this.surveyRunId ) { 25 26 this._loadSurveyRun(); 26 this._loadResponses();27 27 } else { 28 28 throw "No valid uid or survey passed!"; … … 30 30 }, 31 31 _loadSurveyRun: function() { 32 when(s tore.get(this.surveyRunId))32 when(surveyRuns.load(this.surveyRunId)) 33 33 .then(lang.hitch(this,function(surveyRun){ 34 34 this.surveyRun = surveyRun; 35 35 this.refreshSurveyRun(); 36 this._loadResponses(); 36 37 })); 37 38 }, 38 39 refreshSurveyRun: function() { 39 this.titleNode.innerHTML = SurveyRun.DisplayTitle.get(this.surveyRun);40 this.surveySummaryWidget.set('value', SurveyRun.Survey.get(this.surveyRun));40 this.titleNode.innerHTML = this.surveyRun.title || ""; 41 this.surveySummaryWidget.set('value',this.surveyRun.survey); 41 42 this.surveyRunWidget.set('value',this.surveyRun); 42 43 this._onPropChange(); 43 44 }, 44 45 _loadResponses: function() { 45 when(store.query("_design/responses/_view/by_surveyrun",{key:this.surveyRunId})) 46 .forEach(lang.hitch(this,function(response){ 47 var actions = { 48 view: { 49 callback: function(){}, 50 properties: { 51 title: "View response" 52 } 53 } 54 }; 55 if ( !response.publicationDate ) { 56 actions.remove = { 57 callback: function(){}, 58 properties: { 59 title: "Remove response" 46 responses.query({surveyRunId:surveyRuns.getId(this.surveyRun)}) 47 .then(lang.hitch(this,function(allResponses){ 48 array.forEach(allResponses, function(response){ 49 var actions = { 50 view: { 51 callback: function(){}, 52 properties: { 53 title: "View response" 54 } 60 55 } 61 56 }; 62 } 63 var w = new LineWithActionsWidget({ 64 actions: actions 65 }); 66 var responseId = store.getIdentity(response); 67 w.set('title',this._link(this._getResponseURL(this.surveyRunId,responseId),responseId)); 68 w.placeAt(this.responsesNode); 57 if ( !response.publicationDate ) { 58 actions.remove = { 59 callback: function(){}, 60 properties: { 61 title: "Remove response" 62 } 63 }; 64 } 65 var w = new LineWithActionsWidget({ 66 actions: actions 67 }); 68 var rid = responses.getId(response); 69 w.set('title',this._link(this._buildResponseURL(response),rid),rid); 70 w.placeAt(this.responsesNode); 71 }, this); 69 72 })); 70 73 }, … … 73 76 if ( surveyRun.mode === "open" ) { 74 77 this.runURLNode.innerHTML = 75 this._link(this._ getGeneralURL(store.getIdentity(this.surveyRun)));78 this._link(this._buildGeneralURL(this.surveyRun)); 76 79 } else { 77 80 this.runURLNode.innerHTML = … … 79 82 } 80 83 }, 81 _ getGeneralURL: function(surveyRunId) {82 return 'response.html#!/ '+surveyRunId;84 _buildGeneralURL: function(surveyRun) { 85 return 'response.html#!/surveyRuns/'+surveyRuns.getId(surveyRun)+'!secret='+surveyRun.secret; 83 86 }, 84 _ getResponseURL: function(surveyRunId,responseId) {85 return 'response.html#!/ '+surveyRunId+'!id='+responseId;87 _buildResponseURL: function(response) { 88 return 'response.html#!/responses/'+responses.getId(response)+'!secret='+response.secret; 86 89 }, 87 90 _link: function(url,label) { … … 92 95 lang.mixin(this.surveyRun,this.surveyRunWidget.get('value')); 93 96 94 var SD = SurveyRun.StartDate; 95 var ED = SurveyRun.EndDate; 96 SD.set(this.surveyRun, SD.get(this.surveyRun)); 97 ED.set(this.surveyRun, ED.get(this.surveyRun)); 98 99 store.put(this.surveyRun) 97 surveyRuns.save(this.surveyRun) 100 98 .then(function() { 101 99 Router.go('/surveys');
Note: See TracChangeset
for help on using the changeset viewer.