Changeset 490 for Dev/trunk/src/client/qed-client/pages/question.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/question.js
r487 r490 1 1 define([ 2 "../app/Content",3 "../app/Page",4 2 "../app/Router", 5 3 "../model/classes/questions", 6 "../model/widgets/QuestionEditorPreview", 7 "../model/widgets/QuestionEditorToolkit", 8 "../widgets/_ComplexValueMixin", 4 "./_ObjectPage", 5 "dojo/Deferred", 9 6 "dojo/_base/declare", 10 7 "dojo/_base/event", 11 8 "dojo/_base/lang", 12 " dojo/when",9 "require", 13 10 "dojo/text!./templates/question.html" 14 ], function(Content, Page, Router, questions, QuestionEditorPreview, QuestionEditorToolkit, _ComplexValueMixin, declare, event, lang, when, template) { 15 return declare([Page,_ComplexValueMixin], { 11 ], function(Router, questions, _ObjectPage, Deferred, declare, event, lang, require, template) { 12 return declare([_ObjectPage], { 13 contextRequire: require, 16 14 templateString: template, 17 15 _toolkit: null, 18 16 _preview: null, 19 value: null, 20 21 buildRendering: function() { 22 this.inherited(arguments); 23 24 this._toolkit = new QuestionEditorToolkit({ 25 },this.QuestionEditorToolkitNode); 26 this._toolkit.on('submit',lang.hitch(this,"_onSave")); 27 this._toolkit.startup(); 28 29 this._preview = new QuestionEditorPreview({ 30 name: 'content', 31 delay: 5, 32 region: 'center' 33 }); 34 this._preview.startup(); 35 this.addChild(this._preview); 36 }, 17 classStore: questions, 37 18 startup: function() { 38 19 if ( this._started ) { return; } 39 20 this.inherited(arguments); 40 if ( !this.questionId ) { 41 throw new Error("Error: no reference to object set!"); 21 this.propertiesForm.on('change',lang.hitch(this,'_handlePropertiesChange')); 22 this.contentList.on('change',lang.hitch(this,'_handleContentChange')); 23 this._load(); 24 }, 25 _refresh: function() { 26 this.titleNode.innerHTML = this.object.title || ""; 27 this.propertiesForm.set('value',this.object); 28 this.contentList.set('value',this.object.content); 29 }, 30 _handlePropertiesChange: function() { 31 if ( this.propertiesForm.validate() ) { 32 lang.mixin(this.object,this.propertiesForm.get('value')); 42 33 } 43 if (this.questionId === "new") { 44 this.set('value', questions.create()); 34 this.markDirty(); 35 }, 36 _handleContentChange: function() { 37 if ( this.contentList.validate() ) { 38 this.object.content = this.contentList.get('value'); 39 } 40 this.markDirty(); 41 }, 42 _save: function() { 43 if ( this.propertiesForm.validate() && this.contentList.validate() ) { 44 lang.mixin(this.object,this.propertiesForm.get('value')); 45 this.object.content = this.contentList.get('value'); 46 return this.inherited(arguments); 45 47 } else { 46 when(questions.load(this.questionId)) 47 .then(lang.hitch(this, function(value) { 48 this.set('value', value); 49 })); 48 return new Deferred().reject(); 50 49 } 51 50 }, 52 _setValueAttr: function(value) {53 this.value = value;54 this.inherited(arguments);55 this.titleNode.innerHTML = value.title || "";56 },57 _getValueAttr: function() {58 var value = this.inherited(arguments);59 lang.mixin(this.value, value);60 return this.value;61 },62 51 _onSave: function(evt) { 63 if ( this.validate() ) { 64 questions.save(this.get('value')) 65 .then(function() { 66 Router.go('/questions'); 67 },function(err){ 68 Content.notify(err,'error'); 69 }); 70 } 52 this._save(); 71 53 if ( evt ) { event.stop( evt ); } 72 54 return false; 73 55 }, 74 _onDiscard: function() { 75 Router.go('/questions'); 76 return true; 56 _onSaveAndClose: function(evt) { 57 this._save() 58 .then(function(){ 59 Router.go(questions.getCollectionPath()); 60 }); 61 if ( evt ) { event.stop( evt ); } 62 return false; 63 }, 64 _onDiscard: function(evt) { 65 this.markClean(); 66 Router.go(questions.getCollectionPath()); 67 if ( evt ) { event.stop( evt ); } 68 return false; 69 }, 70 _ignore: function(evt) { 71 if ( evt ) { event.stop( evt ); } 72 return false; 77 73 } 78 74 });
Note: See TracChangeset
for help on using the changeset viewer.