Changeset 490 for Dev/trunk/src/client/qed-client/pages/surveyRun.js
- Timestamp:
- 03/08/14 22:51:23 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/src/client/qed-client/pages/surveyRun.js
r487 r490 1 1 define([ 2 2 "../app/Content", 3 "../app/Pa ge",3 "../app/Path", 4 4 "../app/Router", 5 5 "../lib/func", 6 6 "../model/classes/responses", 7 7 "../model/classes/surveyRuns", 8 "../model/classes/surveys", 8 9 "../widgets/LineWithActionsWidget", 10 "./_ObjectPage", 11 "dojo/Deferred", 9 12 "dojo/_base/array", 10 13 "dojo/_base/declare", … … 14 17 "require", 15 18 "dojo/text!./templates/surveyRun.html" 16 ], function(Content, Pa ge, Router, func, responses, surveyRuns, LineWithActionsWidget, array, declare, event, lang, when, require, template) {17 return declare([ Page],{19 ], function(Content, Path, Router, func, responses, surveyRuns, surveys, LineWithActionsWidget, _ObjectPage, Deferred, array, declare, event, lang, when, require, template) { 20 return declare([_ObjectPage],{ 18 21 contextRequire: require, 19 22 templateString: template, 20 surveyRun: null,23 classStore: surveyRuns, 21 24 startup: function() { 22 25 if ( this._started ) { return; } 23 26 this.inherited(arguments); 24 this.surveyRunWidget.on("blur",lang.hitch(this,'_onPropChange')); 25 if ( this.surveyRunId ) { 26 this._loadSurveyRun(); 27 this.surveyRunWidget.on("change",lang.hitch(this,'_onPropChange')); 28 this._load(); 29 }, 30 _refresh: function() { 31 this.titleNode.innerHTML = this.object.title || ""; 32 this.surveySummaryWidget.set('value',this.object.survey); 33 this.surveyRunWidget.set('value',this.object); 34 this._refreshURL(); 35 this._loadResponses(); 36 }, 37 _refreshURL: function() { 38 if ( this.object.mode === "open" ) { 39 this.runURLNode.innerHTML = 40 this._link(this._buildGeneralURL(this.object)); 27 41 } else { 28 throw "No valid uid or survey passed!"; 42 this.runURLNode.innerHTML = 43 "No general URL. Add individual respondents below."; 29 44 } 30 45 }, 31 _loadSurveyRun: function() {32 when(surveyRuns.load(this.surveyRunId))33 .then(lang.hitch(this,function(surveyRun){34 this.surveyRun = surveyRun;35 this.refreshSurveyRun();36 this._loadResponses();37 }));38 },39 refreshSurveyRun: function() {40 this.titleNode.innerHTML = this.surveyRun.title || "";41 this.surveySummaryWidget.set('value',this.surveyRun.survey);42 this.surveyRunWidget.set('value',this.surveyRun);43 this._onPropChange();44 },45 46 _loadResponses: function() { 46 responses.query({surveyRunId:surveyRuns.getId(this. surveyRun)})47 responses.query({surveyRunId:surveyRuns.getId(this.object)}) 47 48 .then(lang.hitch(this,function(allResponses){ 48 49 array.forEach(allResponses, function(response){ … … 73 74 }, 74 75 _onPropChange: function(e) { 75 var surveyRun = this.surveyRunWidget.get('value'); 76 if ( surveyRun.mode === "open" ) { 77 this.runURLNode.innerHTML = 78 this._link(this._buildGeneralURL(this.surveyRun)); 79 } else { 80 this.runURLNode.innerHTML = 81 "No general URL. Add individual respondents below."; 76 if ( this.surveyRunWidget.validate() ) { 77 lang.mixin(this.object,this.surveyRunWidget.get('value')); 78 this._refreshURL(); 82 79 } 80 this.markDirty(); 83 81 }, 84 82 _buildGeneralURL: function(surveyRun) { 85 return 'response.html# !/surveyRuns/'+surveyRuns.getId(surveyRun)+'!secret='+surveyRun.secret;83 return 'response.html#'+Path.format(surveyRuns.getObjectPath(surveyRun),{secret:surveyRun.secret}); 86 84 }, 87 85 _buildResponseURL: function(response) { 88 return 'response.html# !/responses/'+responses.getId(response)+'!secret='+response.secret;86 return 'response.html#'+Path.format(responses.getObjectPath(response),{secret:response.secret}); 89 87 }, 90 88 _link: function(url,label) { 91 89 return '<a target="_blank" href="'+url+'">'+(label || url)+'</a>'; 92 90 }, 91 _save: function() { 92 if ( this.surveyRunWidget.validate() ) { 93 lang.mixin(this.object,this.surveyRunWidget.get('value')); 94 return this.inherited(arguments); 95 } else { 96 return new Deferred.reject(); 97 } 98 }, 93 99 _onSave: function(evt) { 94 if ( this.surveyRunWidget.validate() ) { 95 lang.mixin(this.surveyRun,this.surveyRunWidget.get('value')); 96 97 surveyRuns.save(this.surveyRun) 98 .then(function() { 99 Router.go('/surveys'); 100 },function(err){ 101 Content.notify(err); 102 }); 103 } 100 this._save(); 101 if ( evt ) { event.stop(evt); } 102 return false; 103 }, 104 _onSaveAndClose: function(evt) { 105 this._save() 106 .then(function() { 107 Router.go(surveys.getCollectionPath()); 108 }); 104 109 if ( evt ) { event.stop(evt); } 105 110 return false; 106 111 }, 107 112 _onDiscard: function(evt) { 108 Router.go('/surveys'); 113 this.markClean(); 114 Router.go(surveys.getCollectionPath()); 109 115 if ( evt ) { event.stop(evt); } 110 116 return false;
Note: See TracChangeset
for help on using the changeset viewer.