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

Last change on this file since 498 was 498, checked in by hendrikvanantwerpen, 11 years ago

Do limited refresh when change is local in the page.

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.own(this.propertiesForm.on('change',lang.hitch(this,'_handlePropertiesChange')));
22            this.own(this.contentList.on('change',lang.hitch(this,'_handleContentChange')));
23            this._load();
24        },
25        _refresh: function() {
26            this.propertiesForm.set('value',this.object,null);
27            this.contentList.set('value',this.object.content,null);
28            this._internalRefresh();
29        },
30        _internalRefresh: function(){
31            this.titleNode.innerHTML = this.object.title || "";
32        },
33        _handlePropertiesChange: function() {
34            this._updateObject();
35            this.markDirty();
36            this._internalRefresh();
37        },
38        _handleContentChange: function() {
39            this._updateObject();
40            this.markDirty();
41            this._internalRefresh();
42        },
43        _updateObject: function() {
44            var pValid = this.propertiesForm.validate();
45            lang.mixin(this.object,this.propertiesForm.get('value'));
46            var cValid = this.contentList.validate();
47            this.object.content = this.contentList.get('value');
48            this._isValid = pValid && cValid;
49            return this._isValid;
50        },
51        _save: function() {
52            if ( this._updateObject() ) {
53                return this.inherited(arguments);
54            } else {
55                return new Deferred().reject();
56            }
57        },
58        _onSave: function(evt) {
59            this._save();
60            if ( evt ) { event.stop( evt ); }
61            return false;
62        },
63        _onSaveAndClose: function(evt) {
64            this._save()
65            .then(function(){
66                Router.go(questions.getCollectionPath());
67            });
68            if ( evt ) { event.stop( evt ); }
69            return false;
70        },
71        _onDiscard: function(evt) {
72            this.markClean();
73            Router.go(questions.getCollectionPath());
74            if ( evt ) { event.stop( evt ); }
75            return false;
76        },
77        markDirty: function() {
78            this.saveBtn.set('disabled',!this._isValid);
79            this.saveAndCloseBtn.set('disabled',!this._isValid);
80            this.discardBtn.set('label','Discard & Close');
81            this.inherited(arguments);
82        },
83        markClean: function() {
84            this.saveBtn.set('disabled',true);
85            this.saveAndCloseBtn.set('disabled',true);
86            this.discardBtn.set('label','Close');
87            this.inherited(arguments);
88        },
89        _ignore: function(evt) {
90            if ( evt ) { event.stop( evt ); }
91            return false;
92        }
93    });
94});
Note: See TracBrowser for help on using the repository browser.