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

Last change on this file since 494 was 494, checked in by hendrikvanantwerpen, 11 years ago
  • Removed all Coffeescript from codebase (build process is still there).
  • Nicer message on failed login.
  • Own all event subscriptions from widgets.
  • Update objects in _ObjectPage with invalid info too, or our refresh will overwrite what user did.
File size: 3.2 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.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            lang.mixin(this.object,this.propertiesForm.get('value'));
43            var cValid = this.contentList.validate();
44            this.object.content = this.contentList.get('value');
45            this._isValid = pValid && cValid;
46            return this._isValid;
47        },
48        _save: function() {
49            if ( this._updateObject() ) {
50                return this.inherited(arguments);
51            } else {
52                return new Deferred().reject();
53            }
54        },
55        _onSave: function(evt) {
56            this._save();
57            if ( evt ) { event.stop( evt ); }
58            return false;
59        },
60        _onSaveAndClose: function(evt) {
61            this._save()
62            .then(function(){
63                Router.go(questions.getCollectionPath());
64            });
65            if ( evt ) { event.stop( evt ); }
66            return false;
67        },
68        _onDiscard: function(evt) {
69            this.markClean();
70            Router.go(questions.getCollectionPath());
71            if ( evt ) { event.stop( evt ); }
72            return false;
73        },
74        markDirty: function() {
75            this.saveBtn.set('disabled',!this._isValid);
76            this.saveAndCloseBtn.set('disabled',!this._isValid);
77            this.discardBtn.set('label','Discard & Close');
78            this.inherited(arguments);
79        },
80        markClean: function() {
81            this.saveBtn.set('disabled',true);
82            this.saveAndCloseBtn.set('disabled',true);
83            this.discardBtn.set('label','Close');
84            this.inherited(arguments);
85        },
86        _ignore: function(evt) {
87            if ( evt ) { event.stop( evt ); }
88            return false;
89        }
90    });
91});
Note: See TracBrowser for help on using the repository browser.