define([ "../app/Router", "../model/classes/questions", "./_ObjectPage", "dojo/Deferred", "dojo/_base/declare", "dojo/_base/event", "dojo/_base/lang", "require", "dojo/text!./templates/question.html" ], function(Router, questions, _ObjectPage, Deferred, declare, event, lang, require, template) { return declare([_ObjectPage], { contextRequire: require, templateString: template, _preview: null, classStore: questions, startup: function() { if ( this._started ) { return; } this.inherited(arguments); this.own(this.QuestionEditorToolkit.on('change',lang.hitch(this,'_handlePropertiesChange'))); this.own(this.contentList.on('change',lang.hitch(this,'_handleContentChange'))); this._load(); }, _refresh: function(initial) { if ( initial === true ) { this.QuestionEditorToolkit.set('value',this.object,null); this.contentList.set('value',this.object.content,null); } this.titleNode.innerHTML = this.object.title || ""; if ( this.object.publicationDate ) { this.QuestionEditorToolkit.set('readOnly',true); this.contentList.set('readOnly',true); } }, _handlePropertiesChange: function() { this._updateObject(); this.markDirty(); this._refresh(); }, _handleContentChange: function() { this._updateObject(); this.markDirty(); this._refresh(); }, _updateObject: function() { var pValid = this.QuestionEditorToolkit.validate(); lang.mixin(this.object,this.QuestionEditorToolkit.get('value')); var cValid = this.contentList.validate(); this.object.content = this.contentList.get('value'); this._isValid = pValid && cValid; return this._isValid; }, _save: function() { if ( this._updateObject() ) { return this.inherited(arguments); } else { return new Deferred().reject({error:"Please correct invalid values."}); } }, _onSave: function(evt) { this._save(); if ( evt ) { event.stop( evt ); } return false; }, _onSaveAndClose: function(evt) { this._save() .then(function(){ Router.go(questions.getCollectionPath()); }); if ( evt ) { event.stop( evt ); } return false; }, _onDiscard: function(evt) { this.markClean(); Router.go(questions.getCollectionPath()); if ( evt ) { event.stop( evt ); } return false; }, markDirty: function() { this.saveBtn.set('disabled',!this._isValid); this.saveAndCloseBtn.set('disabled',!this._isValid); this.discardBtn.set('label','Discard & Close'); this.inherited(arguments); }, markClean: function() { this.saveBtn.set('disabled',true); this.saveAndCloseBtn.set('disabled',true); this.discardBtn.set('label','Close'); this.inherited(arguments); }, _ignore: function(evt) { if ( evt ) { event.stop( evt ); } return false; } }); });