Changeset 442 for Dev/trunk/client/qed/pages/question.js
- Timestamp:
- 05/02/13 13:13:13 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/client/qed/pages/question.js
r441 r442 1 1 define([ 2 'dojo/_base/declare', 3 'dojo/_base/event', 4 'dojo/_base/lang', 5 'dojo/when', 6 '../store', 7 '../app/Content', 8 '../app/Router', 9 '../app/Page', 10 '../model/classes/Question', 11 '../model/widgets/QuestionEditorPreview', 12 '../model/widgets/QuestionEditorToolkit', 13 'dojo/text!./templates/question.html' 14 ],function(declare, event, lang, when, store, Content, Router, Page, Question, QuestionEditorPreview, QuestionEditorToolkit, template){ 15 return declare([Page], { 2 "../app/Content", 3 "../app/Page", 4 "../app/Router", 5 "../model/classes/Question", 6 "../model/widgets/QuestionEditorPreview", 7 "../model/widgets/QuestionEditorToolkit", 8 "../store", 9 "../widgets/_ComplexValueMixin", 10 "dojo/_base/declare", 11 "dojo/_base/event", 12 "dojo/_base/lang", 13 "dojo/when", 14 "dojo/text!./templates/question.html" 15 ], function(Content, Page, Router, Question, QuestionEditorPreview, QuestionEditorToolkit, store, _ComplexValueMixin, declare, event, lang, when, template) { 16 return declare([Page,_ComplexValueMixin], { 16 17 templateString: template, 17 question: null,18 18 _toolkit: null, 19 19 _preview: null, 20 value: null, 20 21 22 buildRendering: function() { 23 this.inherited(arguments); 24 25 this._toolkit = new QuestionEditorToolkit({ 26 },this.QuestionEditorToolkitNode); 27 this._toolkit.on('submit',lang.hitch(this,"_onSave")); 28 this._toolkit.startup(); 29 30 this._preview = new QuestionEditorPreview({ 31 name: 'content', 32 delay: 5, 33 region: 'center' 34 }); 35 this._preview.startup(); 36 this.addChild(this._preview); 37 }, 21 38 startup: function() { 22 39 if ( this._started ) { return; } … … 25 42 throw new Error("Error: no reference to object set!"); 26 43 } 27 this._setupEditor();28 44 if (this.questionId === "new") { 29 this.question = Question.create(); 30 this._refresh(); 45 this.set('value', Question.create()); 31 46 } else { 32 47 when(store.get(this.questionId)) 33 .then(lang.hitch(this, function(obj) { 34 this.question = obj; 35 this._refresh(); 48 .then(lang.hitch(this, function(value) { 49 this.set('value', value); 36 50 })); 37 51 } 38 52 }, 39 onLeave: function() { 53 _setValueAttr: function(value) { 54 this.value = value; 40 55 this.inherited(arguments); 56 this.titleNode.innerHTML = Question.DisplayTitle.get(value); 41 57 }, 42 _ refresh: function() {43 this.titleNode.innerHTML = Question.DisplayTitle.get(this.question);44 this._toolkit.set('value', this.question);45 this._preview.set('value', Question.Content.get(this.question));58 _getValueAttr: function() { 59 var value = this.inherited(arguments); 60 lang.mixin(this.value, value); 61 return this.value; 46 62 }, 47 63 _onSave: function(evt) { 48 if ( this._preview.validate() ) { 49 lang.mixin(this.question, this._toolkit.get('value')); 50 Question.Content.set(this.question, this._preview.get('value')); 51 store.put(this.question) 64 if ( this.validate() ) { 65 var value = this.get('value'); 66 store.put(value) 52 67 .then(function() { 53 68 Router.go('/questions'); … … 62 77 Router.go('/questions'); 63 78 return true; 64 },65 _setupEditor: function() {66 this._toolkit = new QuestionEditorToolkit({67 },this.QuestionEditorToolkitNode);68 this._toolkit.on('submit',lang.hitch(this,"_onSave"));69 this._toolkit.startup();70 71 this._preview = new QuestionEditorPreview({72 name: 'content',73 delay: 5,74 region: 'center'75 });76 this._preview.startup();77 this.addChild(this._preview);78 79 } 79 80 });
Note: See TracChangeset
for help on using the changeset viewer.