[443] | 1 | define([
|
---|
| 2 | "../app/Router",
|
---|
[487] | 3 | "../model/classes/questions",
|
---|
[490] | 4 | "./_ObjectPage",
|
---|
| 5 | "dojo/Deferred",
|
---|
[443] | 6 | "dojo/_base/declare",
|
---|
| 7 | "dojo/_base/event",
|
---|
| 8 | "dojo/_base/lang",
|
---|
[490] | 9 | "require",
|
---|
[443] | 10 | "dojo/text!./templates/question.html"
|
---|
[490] | 11 | ], function(Router, questions, _ObjectPage, Deferred, declare, event, lang, require, template) {
|
---|
| 12 | return declare([_ObjectPage], {
|
---|
| 13 | contextRequire: require,
|
---|
[443] | 14 | templateString: template,
|
---|
| 15 | _preview: null,
|
---|
[490] | 16 | classStore: questions,
|
---|
[443] | 17 | startup: function() {
|
---|
| 18 | if ( this._started ) { return; }
|
---|
| 19 | this.inherited(arguments);
|
---|
[502] | 20 | this.own(this.QuestionEditorToolkit.on('change',lang.hitch(this,'_handlePropertiesChange')));
|
---|
[494] | 21 | this.own(this.contentList.on('change',lang.hitch(this,'_handleContentChange')));
|
---|
[490] | 22 | this._load();
|
---|
| 23 | },
|
---|
[500] | 24 | _refresh: function(initial) {
|
---|
| 25 | if ( initial === true ) {
|
---|
[502] | 26 | this.QuestionEditorToolkit.set('value',this.object,null);
|
---|
[500] | 27 | this.contentList.set('value',this.object.content,null);
|
---|
| 28 | }
|
---|
[498] | 29 | this.titleNode.innerHTML = this.object.title || "";
|
---|
[502] | 30 | if ( this.object.publicationDate ) {
|
---|
| 31 | this.QuestionEditorToolkit.set('readOnly',true);
|
---|
| 32 | this.contentList.set('readOnly',true);
|
---|
| 33 | }
|
---|
[498] | 34 | },
|
---|
[490] | 35 | _handlePropertiesChange: function() {
|
---|
[493] | 36 | this._updateObject();
|
---|
[490] | 37 | this.markDirty();
|
---|
[500] | 38 | this._refresh();
|
---|
[490] | 39 | },
|
---|
| 40 | _handleContentChange: function() {
|
---|
[493] | 41 | this._updateObject();
|
---|
[490] | 42 | this.markDirty();
|
---|
[500] | 43 | this._refresh();
|
---|
[490] | 44 | },
|
---|
[493] | 45 | _updateObject: function() {
|
---|
[502] | 46 | var pValid = this.QuestionEditorToolkit.validate();
|
---|
| 47 | lang.mixin(this.object,this.QuestionEditorToolkit.get('value'));
|
---|
[493] | 48 | var cValid = this.contentList.validate();
|
---|
[494] | 49 | this.object.content = this.contentList.get('value');
|
---|
[493] | 50 | this._isValid = pValid && cValid;
|
---|
| 51 | return this._isValid;
|
---|
| 52 | },
|
---|
[490] | 53 | _save: function() {
|
---|
[493] | 54 | if ( this._updateObject() ) {
|
---|
[490] | 55 | return this.inherited(arguments);
|
---|
[443] | 56 | } else {
|
---|
[506] | 57 | return new Deferred().reject({error:"Please correct invalid values."});
|
---|
[443] | 58 | }
|
---|
| 59 | },
|
---|
[490] | 60 | _onSave: function(evt) {
|
---|
| 61 | this._save();
|
---|
| 62 | if ( evt ) { event.stop( evt ); }
|
---|
| 63 | return false;
|
---|
[443] | 64 | },
|
---|
[490] | 65 | _onSaveAndClose: function(evt) {
|
---|
| 66 | this._save()
|
---|
| 67 | .then(function(){
|
---|
| 68 | Router.go(questions.getCollectionPath());
|
---|
| 69 | });
|
---|
| 70 | if ( evt ) { event.stop( evt ); }
|
---|
| 71 | return false;
|
---|
[443] | 72 | },
|
---|
[490] | 73 | _onDiscard: function(evt) {
|
---|
| 74 | this.markClean();
|
---|
| 75 | Router.go(questions.getCollectionPath());
|
---|
[443] | 76 | if ( evt ) { event.stop( evt ); }
|
---|
| 77 | return false;
|
---|
| 78 | },
|
---|
[492] | 79 | markDirty: function() {
|
---|
| 80 | this.saveBtn.set('disabled',!this._isValid);
|
---|
| 81 | this.saveAndCloseBtn.set('disabled',!this._isValid);
|
---|
| 82 | this.discardBtn.set('label','Discard & Close');
|
---|
| 83 | this.inherited(arguments);
|
---|
| 84 | },
|
---|
| 85 | markClean: function() {
|
---|
| 86 | this.saveBtn.set('disabled',true);
|
---|
| 87 | this.saveAndCloseBtn.set('disabled',true);
|
---|
| 88 | this.discardBtn.set('label','Close');
|
---|
| 89 | this.inherited(arguments);
|
---|
| 90 | },
|
---|
[490] | 91 | _ignore: function(evt) {
|
---|
| 92 | if ( evt ) { event.stop( evt ); }
|
---|
| 93 | return false;
|
---|
[443] | 94 | }
|
---|
| 95 | });
|
---|
| 96 | });
|
---|