Mercurial > pub > ImplabJs
diff src/implab/data/_ModelBase.js @ 0:fc2517695ee1
Initial commit, draft import of existing work
author | cin |
---|---|
date | Thu, 01 Jun 2017 13:20:03 +0300 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/implab/data/_ModelBase.js Thu Jun 01 13:20:03 2017 +0300 @@ -0,0 +1,37 @@ +define(["dojo/_base/declare"], function(declare) { + + return declare(null, { + dataContext : null, + idField : "id", + loaded : false, + + constructor : function(opts){ + if (opts) { + if(opts.dataContext) + this.dataContext = opts.dataContext; + if(opts.id) + this[this.idField] = opts.id; + } + }, + + getId : function() { + return this[this.idField]; + }, + + attach : function(id, dc) { + if (this.dataContext) + throw new Error("The object is already attached"); + this[this.idField] = id; + this.dataContext = dc; + }, + + isAttached : function() { + return this.dataContext ? true : false; + }, + + onPopulate : function() { + this.loaded = true; + } + + }); +}); \ No newline at end of file