define([ "../app/Page", "dojo/_base/declare", "dojo/_base/event", "dojo/_base/lang", "require" ], function(Page, declare, event, lang, require) { return declare([Page],{ objectId: null, object: null, classStore: null, constructor: function() { if ( !this.classStore ) { throw new Error("Subclasses must specify a classStore."); } }, startup: function() { if ( this._started ) { return; } this.inherited(arguments); this.markClean(); }, _load: function() { if ( this.object ) { this._refresh(true); } else if ( this.objectId ) { if ( this.objectId === "new" ) { this.object = this.classStore.create(); this.markDirty(); this._refresh(true); } else { this.classStore.load(this.objectId) .then(lang.hitch(this,function(object){ this._setObject(object,true); }),lang.hitch(this,function(err){ this.die(err.error); })); } } else { this.die("No valid id or object passed!"); } }, _setObject: function(object,initial) { this.object = object; if ( this.objectId === "new" ) { this.go(this.classStore.getObjectPath(this.object),{},true); } this.markClean(); this._refresh(initial); }, _refresh: function(initial) {}, _save: function() { return this.classStore.save(this.object) .then(lang.hitch(this,function(object){ this._setObject(object); this.notify(this.classStore.getName()+" successfully saved."); }),lang.hitch(this,function(e){ this.notify(e.error,'error'); })); } }); });