define([ "../app/Page", "../lib/async", "../model/classes/Response", "../model/classes/Survey", "../model/classes/SurveyRun", "../store", "dojo/_base/declare", "dojo/_base/event", "dojo/_base/lang", "dojo/promise/all", "dojo/when", "require", "dojo/text!./templates/response.html" ], function(Page, async, Response, Survey, SurveyRun, store, declare, event, lang, all, when, require, template) { return declare([Page],{ contextRequire: require, templateString: template, response: null, postCreate: function(){ this.options = this.options || {}; }, startup: function() { if ( this._started ) { return; } this.inherited(arguments); this._disableButtons(); var surveyRunId = this.surveyRunId; var responseId = this.options && this.options.id; if ( surveyRunId && responseId ) { this._loadSurveyAndResponse(surveyRunId,responseId) .then(lang.hitch(this,"_enableButtons")); } else { throw new Error("No valid uid or survey passed!"); } }, _loadSurveyAndResponse: function(surveyRunId,responseId){ return all([store.get(surveyRunId),store.get(responseId)]) .then(lang.hitch(this,function(surveyAndResponse){ var surveyRun = surveyAndResponse[0]; this.response = surveyAndResponse[1]; if ( this.response.surveyRunId !== surveyRunId ) { throw "Survey does not match the response..."; } this.titleNode.innerHTML = Survey.DisplayTitle.get(surveyRun.survey); this.surveyWidget.set('survey',surveyRun.survey); this.responseForm.set('value',this.response.answers || {}); })); }, _enableButtons: function() { this.submitButton.set('disabled',false); this.continueButton.set('disabled',false); }, _disableButtons: function() { this.submitButton.set('disabled',true); this.continueButton.set('disabled',true); }, _getAnswersAndSaveResponse: function() { this.response.answers = this.responseForm.get('value'); console.log(this.response); return store.put(this.response); }, _onSubmit: function(e) { this.response.publicationDate = store.timestamp(); this._getAnswersAndSaveResponse(); this.content.domNode.innerHTML = "