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

Last change on this file since 492 was 492, checked in by hendrikvanantwerpen, 11 years ago
  • Enable/disable buttons on content change.
  • One place to do date formatting, because it was going wrong again.
  • Serialize questions in survey properly.
  • _ComplexValueMixin consumes submit events, but does trigger outer forms if present.
  • Trigger dialog show/hide for login only after previous effect is finished.
  • Check that documents are actually valid, not just that validator returned a result.
  • Validate email and timestamp formats.
  • Prepared for live runs.
File size: 3.0 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);
28            this.contentList.set('value',this.object.content);
29        },
30        _handlePropertiesChange: function() {
31            lang.mixin(this.object,this.propertiesForm.get('value'));
32            this.markDirty();
33            this._refresh();
34        },
35        _handleContentChange: function() {
36            this.object.content = this.contentList.get('value');
37            this.markDirty();
38            this._refresh();
39        },
40        _save: function() {
41            if ( this._isValid ) {
42                return this.inherited(arguments);
43            } else {
44                return new Deferred().reject();
45            }
46        },
47        _onSave: function(evt) {
48            this._save();
49            if ( evt ) { event.stop( evt ); }
50            return false;
51        },
52        _onSaveAndClose: function(evt) {
53            this._save()
54            .then(function(){
55                Router.go(questions.getCollectionPath());
56            });
57            if ( evt ) { event.stop( evt ); }
58            return false;
59        },
60        _onDiscard: function(evt) {
61            this.markClean();
62            Router.go(questions.getCollectionPath());
63            if ( evt ) { event.stop( evt ); }
64            return false;
65        },
66        markDirty: function() {
67            this._isValid = this.propertiesForm.validate() &&
68                            this.contentList.validate();
69            this.saveBtn.set('disabled',!this._isValid);
70            this.saveAndCloseBtn.set('disabled',!this._isValid);
71            this.discardBtn.set('label','Discard & Close');
72            this.inherited(arguments);
73        },
74        markClean: function() {
75            this._isValid = true;
76            this.saveBtn.set('disabled',true);
77            this.saveAndCloseBtn.set('disabled',true);
78            this.discardBtn.set('label','Close');
79            this.inherited(arguments);
80        },
81        _ignore: function(evt) {
82            if ( evt ) { event.stop( evt ); }
83            return false;
84        }
85    });
86});
Note: See TracBrowser for help on using the repository browser.