1 | define([ |
---|
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 | }); |
---|