X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/7a654f8d43fdb43d78b63d90528bed6e86b608cc..6746dc89c47ed01b165cc1152533605f97eb8e8d:/docs/source/Model.html diff --git a/docs/source/Model.html b/docs/source/Model.html index 596a172b..fce03bc1 100644 --- a/docs/source/Model.html +++ b/docs/source/Model.html @@ -1,4 +1,21 @@ -Sencha Documentation Project
/**
+
+
+
+  
+  The source code
+  
+  
+  
+  
+
+
+  
/**
  * @author Ed Spencer
  * @class Ext.data.Model
  *
@@ -219,7 +236,7 @@ store.load();
  *
  * @constructor
  * @param {Object} data An object containing keys corresponding to this model's fields, and their associated values
- * @param {Number} id Optional unique ID to assign to this model instance
+ * @param {Number} id (optional) Unique ID to assign to this model instance
  */
 Ext.define('Ext.data.Model', {
     alternateClassName: 'Ext.data.Record',
@@ -369,11 +386,11 @@ Ext.define('Ext.data.Model', {
                 // Fire the onModelDefined template method on ModelManager
                 Ext.ModelManager.onModelDefined(cls);
             });
-        }
+        };
     },
 
     inheritableStatics: {
-        /**
+        /**
          * Sets the Proxy to use for this model. Accepts any options that can be accepted by {@link Ext#createByAlias Ext.createByAlias}
          * @param {String/Object/Ext.data.proxy.Proxy} proxy The proxy
          * @static
@@ -394,7 +411,7 @@ Ext.define('Ext.data.Model', {
             return proxy;
         },
 
-        /**
+        /**
          * Returns the configured Proxy for this Model
          * @return {Ext.data.proxy.Proxy} The proxy
          */
@@ -402,7 +419,7 @@ Ext.define('Ext.data.Model', {
             return this.proxy;
         },
 
-        /**
+        /**
          * <b>Static</b>. Asynchronously loads a model instance by id. Sample usage:
     <pre><code>
     MyApp.User = Ext.define('User', {
@@ -465,7 +482,7 @@ Ext.define('Ext.data.Model', {
         REJECT : 'reject',
         COMMIT : 'commit',
 
-        /**
+        /**
          * Generates a sequential id. This method is typically called when a record is {@link #create}d
          * and {@link #Record no id has been specified}. The id will automatically be assigned
          * to the record. The returned id takes the form:
@@ -487,29 +504,29 @@ Ext.define('Ext.data.Model', {
         }
     },
     
-    /**
+    /**
      * Internal flag used to track whether or not the model instance is currently being edited. Read-only
      * @property editing
      * @type Boolean
      */
     editing : false,
 
-    /**
+    /**
      * Readonly flag - true if this Record has been modified.
      * @type Boolean
      */
     dirty : false,
 
-    /**
-     * @cfg {String} persistanceProperty The property on this Persistable object that its data is saved to.
+    /**
+     * @cfg {String} persistenceProperty The property on this Persistable object that its data is saved to.
      * Defaults to 'data' (e.g. all persistable data resides in this.data.)
      */
-    persistanceProperty: 'data',
+    persistenceProperty: 'data',
 
     evented: false,
     isModel: true,
 
-    /**
+    /**
      * <tt>true</tt> when the record does not yet exist in a server-side database (see
      * {@link #setDirty}).  Any record which has a real database pk set as its id property
      * is NOT a phantom -- it's real.
@@ -518,25 +535,26 @@ Ext.define('Ext.data.Model', {
      */
     phantom : false,
 
-    /**
+    /**
      * @cfg {String} idProperty The name of the field treated as this Model's unique id (defaults to 'id').
      */
     idProperty: 'id',
 
-    /**
+    /**
      * The string type of the default Model Proxy. Defaults to 'ajax'
      * @property defaultProxyType
      * @type String
      */
     defaultProxyType: 'ajax',
 
-    /**
+    /**
      * An array of the fields defined on this model
      * @property fields
      * @type {Array}
      */
 
-    constructor: function(data, id) {
+    // raw not documented intentionally, meant to be used internally.
+    constructor: function(data, id, raw) {
         data = data || {};
         
         var me = this,
@@ -548,26 +566,42 @@ Ext.define('Ext.data.Model', {
             isArray = Ext.isArray(data),
             newData = isArray ? {} : null; // to hold mapped array data if needed
 
-        /**
+        /**
          * An internal unique ID for each Model instance, used to identify Models that don't have an ID yet
          * @property internalId
          * @type String
          * @private
          */
         me.internalId = (id || id === 0) ? id : Ext.data.Model.id(me);
+        
+        /**
+         * The raw data used to create this model if created via a reader.
+         * @property raw
+         * @type Object
+         */
+        me.raw = raw;
 
         Ext.applyIf(me, {
             data: {}    
         });
         
-        /**
+        /**
          * Key: value pairs of all fields whose values have changed
          * @property modified
          * @type Object
          */
         me.modified = {};
 
-        me[me.persistanceProperty] = {};
+        // Deal with spelling error in previous releases
+        if (me.persistanceProperty) {
+            //<debug>
+            if (Ext.isDefined(Ext.global.console)) {
+                Ext.global.console.warn('Ext.data.Model: persistanceProperty has been deprecated. Use persistenceProperty instead.');
+            }
+            //</debug>
+            me.persistenceProperty = me.persistanceProperty;
+        }
+        me[me.persistenceProperty] = {};
 
         me.mixins.observable.constructor.call(me);
 
@@ -603,20 +637,18 @@ Ext.define('Ext.data.Model', {
         }
 
         me.id = me.modelName + '-' + me.internalId;
-
-        Ext.ModelManager.register(me);
     },
     
-    /**
+    /**
      * Returns the value of the given field
      * @param {String} fieldName The field to fetch the value for
      * @return {Mixed} The value
      */
     get: function(field) {
-        return this[this.persistanceProperty][field];
+        return this[this.persistenceProperty][field];
     },
     
-    /**
+    /**
      * Sets the given field to the given value, marks the instance as dirty
      * @param {String|Object} fieldName The field to set, or an object containing key/value pairs
      * @param {Mixed} value The value to set
@@ -662,11 +694,28 @@ Ext.define('Ext.data.Model', {
                 }
             }
             currentValue = me.get(fieldName);
-            me[me.persistanceProperty][fieldName] = value;
+            me[me.persistenceProperty][fieldName] = value;
             
             if (field && field.persist && !me.isEqual(currentValue, value)) {
-                me.dirty = true;
-                me.modified[fieldName] = currentValue;
+                if (me.isModified(fieldName)) {
+                    if (me.isEqual(modified[fieldName], value)) {
+                        // the original value in me.modified equals the new value, so the
+                        // field is no longer modified
+                        delete modified[fieldName];
+                        // we might have removed the last modified field, so check to see if
+                        // there are any modified fields remaining and correct me.dirty:
+                        me.dirty = false;
+                        for (key in modified) {
+                            if (modified.hasOwnProperty(key)){
+                                me.dirty = true;
+                                break;
+                            }
+                        }
+                    }
+                } else {
+                    me.dirty = true;
+                    modified[fieldName] = currentValue;
+                }
             }
 
             if (!me.editing) {
@@ -675,7 +724,7 @@ Ext.define('Ext.data.Model', {
         }
     },
     
-    /**
+    /**
      * Checks if two values are equal, taking into account certain
      * special factors, for example dates.
      * @private
@@ -690,7 +739,7 @@ Ext.define('Ext.data.Model', {
         return a === b;
     },
     
-    /**
+    /**
      * Begin an edit. While in edit mode, no events (e.g.. the <code>update</code> event)
      * are relayed to the containing store. When an edit has begun, it must be followed
      * by either {@link #endEdit} or {@link #cancelEdit}.
@@ -700,12 +749,12 @@ Ext.define('Ext.data.Model', {
         if (!me.editing) {
             me.editing = true;
             me.dirtySave = me.dirty;
-            me.dataSave = Ext.apply({}, me[me.persistanceProperty]);
+            me.dataSave = Ext.apply({}, me[me.persistenceProperty]);
             me.modifiedSave = Ext.apply({}, me.modified);
         }
     },
     
-    /**
+    /**
      * Cancels all changes made in the current edit operation.
      */
     cancelEdit : function(){
@@ -714,7 +763,7 @@ Ext.define('Ext.data.Model', {
             me.editing = false;
             // reset the modified state, nothing changed since the edit began
             me.modified = me.modifiedSave;
-            me[me.persistanceProperty] = me.dataSave;
+            me[me.persistenceProperty] = me.dataSave;
             me.dirty = me.dirtySave;
             delete me.modifiedSave;
             delete me.dataSave;
@@ -722,7 +771,7 @@ Ext.define('Ext.data.Model', {
         }
     },
     
-    /**
+    /**
      * End an edit. If any data was modified, the containing store is notified
      * (ie, the store's <code>update</code> event will fire).
      * @param {Boolean} silent True to not notify the store of the change
@@ -740,7 +789,7 @@ Ext.define('Ext.data.Model', {
         }
     },
     
-    /**
+    /**
      * Gets a hash of only the fields that have been modified since this Model was created or commited.
      * @return Object
      */
@@ -758,7 +807,7 @@ Ext.define('Ext.data.Model', {
         return changes;
     },
     
-    /**
+    /**
      * Returns <tt>true</tt> if the passed field name has been <code>{@link #modified}</code>
      * since the load or last commit.
      * @param {String} fieldName {@link Ext.data.Field#name}
@@ -768,7 +817,7 @@ Ext.define('Ext.data.Model', {
         return this.modified.hasOwnProperty(fieldName);
     },
     
-    /**
+    /**
      * <p>Marks this <b>Record</b> as <code>{@link #dirty}</code>.  This method
      * is used interally when adding <code>{@link #phantom}</code> records to a
      * {@link Ext.data.Store#writer writer enabled store}.</p>
@@ -800,7 +849,7 @@ Ext.define('Ext.data.Model', {
     },
     //</debug>
     
-    /**
+    /**
      * Usually called by the {@link Ext.data.Store} to which this model instance has been {@link #join joined}.
      * Rejects all changes made to the model instance since either creation, or the last commit operation.
      * Modified fields are reverted to their original values.
@@ -817,7 +866,7 @@ Ext.define('Ext.data.Model', {
         for (field in modified) {
             if (modified.hasOwnProperty(field)) {
                 if (typeof modified[field] != "function") {
-                    me[me.persistanceProperty][field] = modified[field];
+                    me[me.persistenceProperty][field] = modified[field];
                 }
             }
         }
@@ -831,7 +880,7 @@ Ext.define('Ext.data.Model', {
         }
     },
 
-    /**
+    /**
      * Usually called by the {@link Ext.data.Store} which owns the model instance.
      * Commits all changes made to the instance since either creation or the last commit operation.
      * <p>Developers should subscribe to the {@link Ext.data.Store#update} event
@@ -852,7 +901,7 @@ Ext.define('Ext.data.Model', {
         }
     },
 
-    /**
+    /**
      * Creates a copy (clone) of this Model instance.
      * @param {String} id (optional) A new id, defaults to the id
      * of the instance being copied. See <code>{@link #id}</code>.
@@ -865,10 +914,10 @@ Ext.data.Model.id(rec); // automatically generate a unique sequential id
     copy : function(newId) {
         var me = this;
         
-        return new me.self(Ext.apply({}, me[me.persistanceProperty]), newId || me.internalId);
+        return new me.self(Ext.apply({}, me[me.persistenceProperty]), newId || me.internalId);
     },
 
-    /**
+    /**
      * Sets the Proxy to use for this model. Accepts any options that can be accepted by {@link Ext#createByAlias Ext.createByAlias}
      * @param {String/Object/Ext.data.proxy.Proxy} proxy The proxy
      * @static
@@ -889,7 +938,7 @@ Ext.data.Model.id(rec); // automatically generate a unique sequential id
         return proxy;
     },
 
-    /**
+    /**
      * Returns the configured Proxy for this Model
      * @return {Ext.data.proxy.Proxy} The proxy
      */
@@ -897,7 +946,7 @@ Ext.data.Model.id(rec); // automatically generate a unique sequential id
         return this.proxy;
     },
 
-    /**
+    /**
      * Validates the current data against all of its configured {@link #validations} and returns an
      * {@link Ext.data.Errors Errors} object
      * @return {Ext.data.Errors} The errors object
@@ -929,7 +978,7 @@ Ext.data.Model.id(rec); // automatically generate a unique sequential id
         return errors;
     },
 
-    /**
+    /**
      * Checks if the model is valid. See {@link #validate}.
      * @return {Boolean} True if the model is valid.
      */
@@ -937,7 +986,7 @@ Ext.data.Model.id(rec); // automatically generate a unique sequential id
         return this.validate().isValid();
     },
 
-    /**
+    /**
      * Saves the model instance using the configured proxy
      * @param {Object} options Options to pass to the proxy
      * @return {Ext.data.Model} The Model instance
@@ -980,7 +1029,7 @@ Ext.data.Model.id(rec); // automatically generate a unique sequential id
         return me;
     },
 
-    /**
+    /**
      * Destroys the model using the configured proxy
      * @param {Object} options Options to pass to the proxy
      * @return {Ext.data.Model} The Model instance
@@ -1013,7 +1062,7 @@ Ext.data.Model.id(rec); // automatically generate a unique sequential id
         return me;
     },
 
-    /**
+    /**
      * Returns the unique ID allocated to this model instance as defined by {@link #idProperty}
      * @return {Number} The id
      */
@@ -1021,7 +1070,7 @@ Ext.data.Model.id(rec); // automatically generate a unique sequential id
         return this.get(this.idProperty);
     },
 
-    /**
+    /**
      * Sets the model instance's id field to the given id
      * @param {Number} id The new id
      */
@@ -1029,12 +1078,12 @@ Ext.data.Model.id(rec); // automatically generate a unique sequential id
         this.set(this.idProperty, id);
     },
 
-    /**
+    /**
      * Tells this model instance that it has been added to a store
      * @param {Ext.data.Store} store The store that the model has been added to
      */
     join : function(store) {
-        /**
+        /**
          * The {@link Ext.data.Store} to which this Record belongs.
          * @property store
          * @type {Ext.data.Store}
@@ -1042,14 +1091,14 @@ Ext.data.Model.id(rec); // automatically generate a unique sequential id
         this.store = store;
     },
 
-    /**
+    /**
      * Tells this model instance that it has been removed from the store
      */
     unjoin: function() {
         delete this.store;
     },
 
-    /**
+    /**
      * @private
      * If this Model instance has been {@link #join joined} to a {@link Ext.data.Store store}, the store's
      * afterEdit method is called
@@ -1058,7 +1107,7 @@ Ext.data.Model.id(rec); // automatically generate a unique sequential id
         this.callStore('afterEdit');
     },
 
-    /**
+    /**
      * @private
      * If this Model instance has been {@link #join joined} to a {@link Ext.data.Store store}, the store's
      * afterReject method is called
@@ -1067,7 +1116,7 @@ Ext.data.Model.id(rec); // automatically generate a unique sequential id
         this.callStore("afterReject");
     },
 
-    /**
+    /**
      * @private
      * If this Model instance has been {@link #join joined} to a {@link Ext.data.Store store}, the store's
      * afterCommit method is called
@@ -1076,7 +1125,7 @@ Ext.data.Model.id(rec); // automatically generate a unique sequential id
         this.callStore('afterCommit');
     },
 
-    /**
+    /**
      * @private
      * Helper function used by afterEdit, afterReject and afterCommit. Calls the given method on the
      * {@link Ext.data.Store store} that this instance has {@link #join joined}, if any. The store function
@@ -1091,7 +1140,7 @@ Ext.data.Model.id(rec); // automatically generate a unique sequential id
         }
     },
 
-    /**
+    /**
      * Gets all of the data from this Models *loaded* associations.
      * It does this recursively - for example if we have a User which
      * hasMany Orders, and each Order hasMany OrderItems, it will return an object like this:
@@ -1112,7 +1161,7 @@ Ext.data.Model.id(rec); // automatically generate a unique sequential id
         return this.prepareAssociatedData(this, [], null);
     },
 
-    /**
+    /**
      * @private
      * This complex-looking method takes a given Model instance and returns an object containing all data from
      * all of that Model's *loaded* associations. See (@link #getAssociatedData}
@@ -1181,4 +1230,6 @@ Ext.data.Model.id(rec); // automatically generate a unique sequential id
         return associationData;
     }
 });
-
\ No newline at end of file +
+ +