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

Last change on this file since 502 was 502, checked in by hendrikvanantwerpen, 11 years ago
  • ListWidget? can be disabled/readOnyl now.
  • Disable question and survey pages when published.
  • Removed weird dialog from survey page and just put a form there. Not very nice, but more consistent with the rest I would say.
File size: 3.6 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        _preview: null,
16        classStore: questions,
17        startup: function() {
18            if ( this._started ) { return; }
19            this.inherited(arguments);
20            this.own(this.QuestionEditorToolkit.on('change',lang.hitch(this,'_handlePropertiesChange')));
21            this.own(this.contentList.on('change',lang.hitch(this,'_handleContentChange')));
22            this._load();
23        },
24        _refresh: function(initial) {
25            if ( initial === true ) {
26                this.QuestionEditorToolkit.set('value',this.object,null);
27                this.contentList.set('value',this.object.content,null);
28            }
29            this.titleNode.innerHTML = this.object.title || "";
30            if ( this.object.publicationDate ) {
31                this.QuestionEditorToolkit.set('readOnly',true);
32                this.QuestionEditorToolkit.set('disabled',true);
33                this.contentList.set('readOnly',true);
34                this.contentList.set('disabled',true);
35            }
36        },
37        _handlePropertiesChange: function() {
38            this._updateObject();
39            this.markDirty();
40            this._refresh();
41        },
42        _handleContentChange: function() {
43            this._updateObject();
44            this.markDirty();
45            this._refresh();
46        },
47        _updateObject: function() {
48            var pValid = this.QuestionEditorToolkit.validate();
49            lang.mixin(this.object,this.QuestionEditorToolkit.get('value'));
50            var cValid = this.contentList.validate();
51            this.object.content = this.contentList.get('value');
52            this._isValid = pValid && cValid;
53            return this._isValid;
54        },
55        _save: function() {
56            if ( this._updateObject() ) {
57                return this.inherited(arguments);
58            } else {
59                return new Deferred().reject();
60            }
61        },
62        _onSave: function(evt) {
63            this._save();
64            if ( evt ) { event.stop( evt ); }
65            return false;
66        },
67        _onSaveAndClose: function(evt) {
68            this._save()
69            .then(function(){
70                Router.go(questions.getCollectionPath());
71            });
72            if ( evt ) { event.stop( evt ); }
73            return false;
74        },
75        _onDiscard: function(evt) {
76            this.markClean();
77            Router.go(questions.getCollectionPath());
78            if ( evt ) { event.stop( evt ); }
79            return false;
80        },
81        markDirty: function() {
82            this.saveBtn.set('disabled',!this._isValid);
83            this.saveAndCloseBtn.set('disabled',!this._isValid);
84            this.discardBtn.set('label','Discard & Close');
85            this.inherited(arguments);
86        },
87        markClean: function() {
88            this.saveBtn.set('disabled',true);
89            this.saveAndCloseBtn.set('disabled',true);
90            this.discardBtn.set('label','Close');
91            this.inherited(arguments);
92        },
93        _ignore: function(evt) {
94            if ( evt ) { event.stop( evt ); }
95            return false;
96        }
97    });
98});
Note: See TracBrowser for help on using the repository browser.