source: Dev/trunk/src/client/qed-client/pages/_ObjectPage.js @ 500

Last change on this file since 500 was 500, checked in by hendrikvanantwerpen, 11 years ago
  • Indicate of refresh is due to load or due to save in _ObjectPage.
  • _ComplexValueMixin & ListWidget? catch all change events and drops them if still being created.
File size: 2.0 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(true);
25            } else if ( this.objectId ) {
26                if ( this.objectId === "new" ) {
27                    this.object = this.classStore.create();
28                    this.markDirty();
29                    this._refresh(true);
30                } else {
31                    this.classStore.load(this.objectId)
32                    .then(lang.hitch(this,function(object){
33                        this._setObject(object,true);
34                    }),lang.hitch(this,function(err){
35                        this.die(err.error);
36                    }));
37                }
38            } else {
39                this.die("No valid id or object passed!");
40            }
41        },
42        _setObject: function(object,initial) {
43            this.object = object;
44            if ( this.objectId === "new" ) {
45                this.go(this.classStore.getObjectPath(this.object),{},true);
46            }
47            this.markClean();
48            this._refresh(initial);
49        },
50        _refresh: function(initial) {},
51        _save: function() {
52            return this.classStore.save(this.object)
53            .then(lang.hitch(this,function(object){
54                this._setObject(object);
55                this.notify(this.classStore.getName()+" successfully saved.");
56            }),lang.hitch(this,function(e){
57                this.notify(e.error,'error');
58            }));
59        }
60    });
61});
Note: See TracBrowser for help on using the repository browser.