aboutsummaryrefslogtreecommitdiffstats
path: root/src/Model.js
diff options
context:
space:
mode:
authorMisko Hevery2010-01-25 20:02:24 -0800
committerMisko Hevery2010-01-25 20:02:24 -0800
commit0b630972b15676b1c1b6c59edd564e4ee331ec70 (patch)
treebd31ca5b69b6ea03d906a3107dfe38a8c1adcb8e /src/Model.js
parent19bbee030ba012b8fc4835c1d17e039804b2b94b (diff)
parent473e57e22532f9b85fc9dcc1bcc53e12a10154c2 (diff)
downloadangular.js-0b630972b15676b1c1b6c59edd564e4ee331ec70.tar.bz2
merge
Diffstat (limited to 'src/Model.js')
-rw-r--r--src/Model.js88
1 files changed, 44 insertions, 44 deletions
diff --git a/src/Model.js b/src/Model.js
index 5e48251f..b09efd0e 100644
--- a/src/Model.js
+++ b/src/Model.js
@@ -1,16 +1,14 @@
-// Copyright (C) 2009 BRAT Tech LLC
-
// Single $ is special and does not get searched
// Double $$ is special an is client only (does not get sent to server)
-nglr.Model = function(entity, initial) {
- this.$$entity = entity;
- this.$loadFrom(initial||{});
- this.$entity = entity.title;
- this.$migrate();
+function Model(entity, initial) {
+ this['$$entity'] = entity;
+ this['$loadFrom'](initial||{});
+ this['$entity'] = entity['title'];
+ this['$migrate']();
};
-nglr.Model.copyDirectFields = function(src, dst) {
+Model.copyDirectFields = function(src, dst) {
if (src === dst || !src || !dst) return;
var isDataField = function(src, dst, field) {
return (field.substring(0,2) !== '$$') &&
@@ -27,39 +25,41 @@ nglr.Model.copyDirectFields = function(src, dst) {
}
};
-nglr.Model.prototype.$migrate = function() {
- nglr.merge(this.$$entity.defaults, this);
- return this;
-};
-
-nglr.Model.prototype.$merge = function(other) {
- nglr.merge(other, this);
- return this;
-};
-
-nglr.Model.prototype.$save = function(callback) {
- this.$$entity.datastore.save(this, callback === true ? undefined : callback);
- if (callback === true) this.$$entity.datastore.flush();
- return this;
-};
-
-nglr.Model.prototype.$delete = function(callback) {
- this.$$entity.datastore.remove(this, callback === true ? undefined : callback);
- if (callback === true) this.$$entity.datastore.flush();
- return this;
-};
-
-nglr.Model.prototype.$loadById = function(id, callback) {
- this.$$entity.datastore.load(this, id, callback);
- return this;
-};
-
-nglr.Model.prototype.$loadFrom = function(other) {
- nglr.Model.copyDirectFields(other, this);
- return this;
-};
-
-nglr.Model.prototype.$saveTo = function(other) {
- nglr.Model.copyDirectFields(this, other);
- return this;
-};
+extend(Model.prototype, {
+ '$migrate': function() {
+ merge(this['$$entity']['defaults'], this);
+ return this;
+ },
+
+ '$merge': function(other) {
+ merge(other, this);
+ return this;
+ },
+
+ '$save': function(callback) {
+ this['$$entity'].datastore.save(this, callback === true ? undefined : callback);
+ if (callback === true) this['$$entity'].datastore.flush();
+ return this;
+ },
+
+ '$delete': function(callback) {
+ this['$$entity'].datastore.remove(this, callback === true ? undefined : callback);
+ if (callback === true) this['$$entity'].datastore.flush();
+ return this;
+ },
+
+ '$loadById': function(id, callback) {
+ this['$$entity'].datastore.load(this, id, callback);
+ return this;
+ },
+
+ '$loadFrom': function(other) {
+ Model.copyDirectFields(other, this);
+ return this;
+ },
+
+ '$saveTo': function(other) {
+ Model.copyDirectFields(this, other);
+ return this;
+ }
+}); \ No newline at end of file