Changeset 487 for Dev/trunk/src/client/qed-client/pages/response.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/response.js
r478 r487 3 3 "../app/Page", 4 4 "../lib/async", 5 "../model/classes/Response", 6 "../model/classes/Survey", 7 "../model/classes/SurveyRun", 8 "../store", 5 "../model/classes/responses", 9 6 "dojo/_base/declare", 10 7 "dojo/_base/event", … … 16 13 "require", 17 14 "dojo/text!./templates/response.html" 18 ], function(Content, Page, async, Response, Survey, SurveyRun, store, declare, event, json, lang, all, request, when, require, template) {15 ], function(Content, Page, async, responses, declare, event, json, lang, all, request, when, require, template) { 19 16 return declare([Page],{ 20 17 contextRequire: require, … … 28 25 this.inherited(arguments); 29 26 this._disableSubmit(); 30 var surveyRunId = this.surveyRunId; 31 var responseId = this.options && this.options.id; 32 if ( surveyRunId && responseId ) { 33 this._loadSurveyAndResponse(surveyRunId,responseId) 34 .then(lang.hitch(this, function() { 35 if ( this.response.publicationDate ) { 36 this._showInfo("<div>You already submitted your survey and cannot change it anymore. You can still view your answers here.</div>"); 37 this._disableSubmit(); 38 } else { 39 this._enableSubmit(); 40 } 41 }), lang.hitch(this,function() { 42 this._showInfo("<div>The url seems to be incorrect, no survey found.</div>"); 43 })); 27 if ( !this.response ) { 28 this._showInfo("<div>The url seems to be incorrect, no response found.</div>"); 44 29 } else { 45 throw new Error("No valid uid or survey passed!"); 30 this.titleNode.innerHTML = this.response._surveyRun.survey.title || ""; 31 this.surveyWidget.set('survey', this.response._surveyRun.survey); 32 this.surveyWidget.set('value', this.response.answers || {}); 33 if ( this.response.publicationDate ) { 34 this._showInfo("<div>You already submitted your survey and cannot change it anymore. You can still view your answers here.</div>"); 35 this._disableSubmit(); 36 } else { 37 this._enableSubmit(); 38 } 46 39 } 47 },48 _loadSurveyAndResponse: function(surveyRunId,responseId){49 return all([request.get('/api/surveyRuns/'+surveyRunId,{handleAs:'json'}),50 request.get('/api/responses/'+responseId,{handleAs:'json'})])51 .then(lang.hitch(this,function(surveyAndResponse){52 var surveyRun = surveyAndResponse[0];53 this.response = surveyAndResponse[1];54 if ( this.response.surveyRunId !== surveyRunId ) {55 throw "Survey does not match the response...";56 }57 this.titleNode.innerHTML = Survey.DisplayTitle.get(surveyRun.survey);58 this.surveyWidget.set('survey', surveyRun.survey);59 this.surveyWidget.set('value', this.response.answers || {});60 }));61 40 }, 62 41 _enableSubmit: function() { … … 78 57 var answers = this.surveyWidget.get('value'); 79 58 this.response.answers = answers; 80 return request.put('/api/responses/'+store.getIdentity(this.response),{ 81 handleAs:'json', 82 data:json.toJson(this.response), 83 headers:{"Content-Type": "application/json"} 84 }).then(lang.hitch(this,function(res){ 85 this.response._rev = res.rev; 59 return responses.putWithSecret(this.response,this.response.secret) 60 .then(lang.hitch(this,function(response){ 61 this.response = response; 86 62 Content.notify("Your response is saved."); 87 63 }), function(err){ … … 90 66 }, 91 67 _onSubmit: function(e) { 92 this.response.publicationDate = store.timestamp();68 this.response.publicationDate = new Date(); 93 69 this._getAnswersAndSaveResponse() 94 70 .then(lang.hitch(this,function(){ … … 110 86 this._disableSubmit(); 111 87 this.surveyWidget.destroy(); 112 request('/api/responses/'+store.getIdentity(this.response)+'?rev='+store.getRevision(this.response),{ 113 method: 'DELETE', 114 handleAs:'json', 115 data:json.toJson(this.response), 116 headers:{"Content-Type": "application/json"} 117 }).then(lang.hitch(this,function(res){ 88 responses.removeWithSecret(this.response,this.response.secret) 89 .then(lang.hitch(this,function(res){ 118 90 this._showInfo("<div>Your response has been deleted, no answers have been saved.</div>"); 119 91 Content.notify("Your response is deleted.");
Note: See TracChangeset
for help on using the changeset viewer.