[491] | 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() { |
---|
[492] | 13 | if ( !this.classStore ) { |
---|
| 14 | throw new Error("Subclasses must specify a classStore."); |
---|
| 15 | } |
---|
[491] | 16 | }, |
---|
[492] | 17 | startup: function() { |
---|
| 18 | if ( this._started ) { return; } |
---|
| 19 | this.inherited(arguments); |
---|
| 20 | this.markClean(); |
---|
| 21 | }, |
---|
[491] | 22 | _load: function() { |
---|
| 23 | if ( this.object ) { |
---|
[500] | 24 | this._refresh(true); |
---|
[491] | 25 | } else if ( this.objectId ) { |
---|
| 26 | if ( this.objectId === "new" ) { |
---|
| 27 | this.object = this.classStore.create(); |
---|
[500] | 28 | this.markDirty(); |
---|
| 29 | this._refresh(true); |
---|
[491] | 30 | } else { |
---|
| 31 | this.classStore.load(this.objectId) |
---|
[500] | 32 | .then(lang.hitch(this,function(object){ |
---|
| 33 | this._setObject(object,true); |
---|
| 34 | }),lang.hitch(this,function(err){ |
---|
| 35 | this.die(err.error); |
---|
| 36 | })); |
---|
[491] | 37 | } |
---|
| 38 | } else { |
---|
[500] | 39 | this.die("No valid id or object passed!"); |
---|
[491] | 40 | } |
---|
| 41 | }, |
---|
[500] | 42 | _setObject: function(object,initial) { |
---|
[491] | 43 | this.object = object; |
---|
| 44 | if ( this.objectId === "new" ) { |
---|
| 45 | this.go(this.classStore.getObjectPath(this.object),{},true); |
---|
| 46 | } |
---|
[500] | 47 | this.markClean(); |
---|
| 48 | this._refresh(initial); |
---|
[491] | 49 | }, |
---|
[500] | 50 | _refresh: function(initial) {}, |
---|
[491] | 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 | }); |
---|