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

Last change on this file since 491 was 490, checked in by hendrikvanantwerpen, 11 years ago
  • Mark content as dirty to prevent moving away from unsaved data.
  • Better change propagation from lists and our own widgets.
  • Generate notifications for errors and show correct message.
  • Moved all path/url generation to the class stores, not everywhere we use it.
  • Give user always a choice between Save and Save & Close.
  • Better refresh behaviour on form changes and saves.
  • Don't generate duplicate code error when existing object is the one you're storing.
File size: 2.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        _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            if ( this.propertiesForm.validate() ) {
32                lang.mixin(this.object,this.propertiesForm.get('value'));
33            }
34            this.markDirty();
35        },
36        _handleContentChange: function() {
37            if ( this.contentList.validate() ) {
38                this.object.content = this.contentList.get('value');
39            }
40            this.markDirty();
41        },
42        _save: function() {
43            if ( this.propertiesForm.validate() && this.contentList.validate() ) {
44                lang.mixin(this.object,this.propertiesForm.get('value'));
45                this.object.content = this.contentList.get('value');
46                return this.inherited(arguments);
47            } else {
48                return new Deferred().reject();
49            }
50        },
51        _onSave: function(evt) {
52            this._save();
53            if ( evt ) { event.stop( evt ); }
54            return false;
55        },
56        _onSaveAndClose: function(evt) {
57            this._save()
58            .then(function(){
59                Router.go(questions.getCollectionPath());
60            });
61            if ( evt ) { event.stop( evt ); }
62            return false;
63        },
64        _onDiscard: function(evt) {
65            this.markClean();
66            Router.go(questions.getCollectionPath());
67            if ( evt ) { event.stop( evt ); }
68            return false;
69        },
70        _ignore: function(evt) {
71            if ( evt ) { event.stop( evt ); }
72            return false;
73        }
74    });
75});
Note: See TracBrowser for help on using the repository browser.