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

Last change on this file since 500 was 500, checked in by hendrikvanantwerpen, 11 years ago
  • Indicate of refresh is due to load or due to save in _ObjectPage.
  • _ComplexValueMixin & ListWidget? catch all change events and drops them if still being created.
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(initial) {
26            if ( initial === true ) {
27                this.propertiesForm.set('value',this.object,null);
28                this.contentList.set('value',this.object.content,null);
29            }
30            this.titleNode.innerHTML = this.object.title || "";
31        },
32        _handlePropertiesChange: function() {
33            this._updateObject();
34            this.markDirty();
35            this._refresh();
36        },
37        _handleContentChange: function() {
38            this._updateObject();
39            this.markDirty();
40            this._refresh();
41        },
42        _updateObject: function() {
43            var pValid = this.propertiesForm.validate();
44            lang.mixin(this.object,this.propertiesForm.get('value'));
45            var cValid = this.contentList.validate();
46            this.object.content = this.contentList.get('value');
47            this._isValid = pValid && cValid;
48            return this._isValid;
49        },
50        _save: function() {
51            if ( this._updateObject() ) {
52                return this.inherited(arguments);
53            } else {
54                return new Deferred().reject();
55            }
56        },
57        _onSave: function(evt) {
58            this._save();
59            if ( evt ) { event.stop( evt ); }
60            return false;
61        },
62        _onSaveAndClose: function(evt) {
63            this._save()
64            .then(function(){
65                Router.go(questions.getCollectionPath());
66            });
67            if ( evt ) { event.stop( evt ); }
68            return false;
69        },
70        _onDiscard: function(evt) {
71            this.markClean();
72            Router.go(questions.getCollectionPath());
73            if ( evt ) { event.stop( evt ); }
74            return false;
75        },
76        markDirty: function() {
77            this.saveBtn.set('disabled',!this._isValid);
78            this.saveAndCloseBtn.set('disabled',!this._isValid);
79            this.discardBtn.set('label','Discard & Close');
80            this.inherited(arguments);
81        },
82        markClean: function() {
83            this.saveBtn.set('disabled',true);
84            this.saveAndCloseBtn.set('disabled',true);
85            this.discardBtn.set('label','Close');
86            this.inherited(arguments);
87        },
88        _ignore: function(evt) {
89            if ( evt ) { event.stop( evt ); }
90            return false;
91        }
92    });
93});
Note: See TracBrowser for help on using the repository browser.