source: Dev/trunk/src/client/qed-client/pages/question.js @ 493

Last change on this file since 493 was 493, checked in by hendrikvanantwerpen, 11 years ago
  • _ComplexValueMixin propagates priorityChange to children.
  • Deserialize updated docs after save too.
  • Validate to false if definitions are missing.
File size: 3.3 KB
Line 
1define([
2    "../app/Router",
3    "../model/classes/questions",
4    "./_ObjectPage",
5    "dojo/Deferred",
6    "dojo/_base/declare",
7    "dojo/_base/event",
8    "dojo/_base/lang",
9    "require",
10    "dojo/text!./templates/question.html"
11], function(Router, questions, _ObjectPage, Deferred, declare, event, lang, require, template) {
12    return declare([_ObjectPage], {
13        contextRequire: require,
14        templateString: template,
15        _toolkit: null,
16        _preview: null,
17        classStore: questions,
18        startup: function() {
19            if ( this._started ) { return; }
20            this.inherited(arguments);
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,null);
28            this.contentList.set('value',this.object.content,null);
29        },
30        _handlePropertiesChange: function() {
31            this._updateObject();
32            this.markDirty();
33            this._refresh();
34        },
35        _handleContentChange: function() {
36            this._updateObject();
37            this.markDirty();
38            this._refresh();
39        },
40        _updateObject: function() {
41            var pValid = this.propertiesForm.validate();
42            if ( pValid ) {
43                lang.mixin(this.object,this.propertiesForm.get('value'));
44            }
45            var cValid = this.contentList.validate();
46            if ( cValid ) {
47                this.object.content = this.contentList.get('value');
48            }
49            this._isValid = pValid && cValid;
50            return this._isValid;
51        },
52        _save: function() {
53            if ( this._updateObject() ) {
54                return this.inherited(arguments);
55            } else {
56                return new Deferred().reject();
57            }
58        },
59        _onSave: function(evt) {
60            this._save();
61            if ( evt ) { event.stop( evt ); }
62            return false;
63        },
64        _onSaveAndClose: function(evt) {
65            this._save()
66            .then(function(){
67                Router.go(questions.getCollectionPath());
68            });
69            if ( evt ) { event.stop( evt ); }
70            return false;
71        },
72        _onDiscard: function(evt) {
73            this.markClean();
74            Router.go(questions.getCollectionPath());
75            if ( evt ) { event.stop( evt ); }
76            return false;
77        },
78        markDirty: function() {
79            this.saveBtn.set('disabled',!this._isValid);
80            this.saveAndCloseBtn.set('disabled',!this._isValid);
81            this.discardBtn.set('label','Discard & Close');
82            this.inherited(arguments);
83        },
84        markClean: function() {
85            this.saveBtn.set('disabled',true);
86            this.saveAndCloseBtn.set('disabled',true);
87            this.discardBtn.set('label','Close');
88            this.inherited(arguments);
89        },
90        _ignore: function(evt) {
91            if ( evt ) { event.stop( evt ); }
92            return false;
93        }
94    });
95});
Note: See TracBrowser for help on using the repository browser.