source: Dev/trunk/src/client/qed-client/pages/_ObjectPage.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: 1.9 KB
Line 
1define([
2    "../app/Page",
3    "dojo/_base/declare",
4    "dojo/_base/event",
5    "dojo/_base/lang",
6    "require"
7], function(Page, declare, event, lang, require) {
8    return declare([Page],{
9        objectId: null,
10        object: null,
11        classStore: null,
12        constructor: function() {
13            if ( !this.classStore ) {
14                throw new Error("Subclasses must specify a classStore.");
15            }
16        },
17        startup: function() {
18            if ( this._started ) { return; }
19            this.inherited(arguments);
20            this.markClean();
21        },
22        _load: function() {
23            if ( this.object ) {
24                this._refresh();
25            } else if ( this.objectId ) {
26                if ( this.objectId === "new" ) {
27                    this.object = this.classStore.create();
28                    this._refresh();
29                } else {
30                    this.classStore.load(this.objectId)
31                    .then(lang.hitch(this,'_setObject'),
32                          lang.hitch(this,function(err){
33                                this.die(err.error);
34                            }));
35                }
36            } else {
37                this.die("No valid uid or object passed!");
38            }
39        },
40        _setObject: function(object) {
41            this.object = object;
42            if ( this.objectId === "new" ) {
43                this.go(this.classStore.getObjectPath(this.object),{},true);
44            }
45            this._refresh();
46        },
47        _refresh: function() {},
48        _save: function() {
49            return this.classStore.save(this.object)
50            .then(lang.hitch(this,function(object){
51                this.markClean();
52                this._setObject(object);
53                this.notify(this.classStore.getName()+" successfully saved.");
54            }),lang.hitch(this,function(e){
55                this.notify(e.error,'error');
56            }));
57        }
58    });
59});
Note: See TracBrowser for help on using the repository browser.