Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / source / data / Record.js
diff --git a/source/data/Record.js b/source/data/Record.js
deleted file mode 100644 (file)
index 4950b9f..0000000
+++ /dev/null
@@ -1,301 +0,0 @@
-/*\r
- * Ext JS Library 2.2.1\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-/**\r
-* @class Ext.data.Record\r
- * <p>Instances of this class encapsulate both Record <em>definition</em> information, and Record\r
- * <em>value</em> information for use in {@link Ext.data.Store} objects, or any code which needs\r
- * to access Records cached in an {@link Ext.data.Store} object.</p>\r
- * <p>Constructors for this class are generated by passing an Array of field definition objects to {@link #create}.\r
- * Instances are usually only created by {@link Ext.data.Reader} implementations when processing unformatted data\r
- * objects.</p>\r
- * <p>Note that an instance of a Record class may only belong to one {@link Ext.data.Store Store} at a time.\r
- * In order to copy data from one Store to another, use the {@link #copy} method to create an exact\r
- * copy of the Record, and insert the new instance into the other Store.</p>\r
- * <p>When serializing a Record for submission to the server, be aware that it contains many private\r
- * properties, and also a reference to its owning Store which in turn holds references to its Records.\r
- * This means that a Record may not be encoded using {@link Ext.util.JSON.encode}. Instead, use the\r
- * {@link data} and {@link id} properties.</p>\r
- * Record objects generated by this constructor inherit all the methods of Ext.data.Record listed below.\r
- * @constructor\r
- * This constructor should not be used to create Record objects. Instead, use the constructor generated by\r
- * {@link #create}. The parameters are the same.\r
- * @param {Array} data An object, the properties of which provide values for the new Record's fields.\r
- * @param {Object} id (Optional) The id of the Record. This id should be unique, and is used by the\r
- * {@link Ext.data.Store} object which owns the Record to index its collection of Records. If\r
- * not specified an integer id is generated.\r
- */\r
-Ext.data.Record = function(data, id){\r
-    this.id = (id || id === 0) ? id : ++Ext.data.Record.AUTO_ID;\r
-    this.data = data;\r
-};\r
-\r
-/**\r
- * Generate a constructor for a specific Record layout.\r
- * @param {Array} o An Array of field definition objects which specify field names, and optionally,\r
- * data types, and a mapping for an {@link Ext.data.Reader} to extract the field's value from a data object.\r
- * Each field definition object may contain the following properties: <ul>\r
- * <li><b>name</b> : String<div class="sub-desc">The name by which the field is referenced within the Record. This is referenced by,\r
- * for example, the <em>dataIndex</em> property in column definition objects passed to {@link Ext.grid.ColumnModel}</div></li>\r
- * <li><b>mapping</b> : String<div class="sub-desc">(Optional) A path specification for use by the {@link Ext.data.Reader} implementation\r
- * that is creating the Record to access the data value from the data object. If an {@link Ext.data.JsonReader}\r
- * is being used, then this is a string containing the javascript expression to reference the data relative to\r
- * the Record item's root. If an {@link Ext.data.XmlReader} is being used, this is an {@link Ext.DomQuery} path\r
- * to the data item relative to the Record element. If the mapping expression is the same as the field name,\r
- * this may be omitted.</div></li>\r
- * <li><b>type</b> : String<div class="sub-desc">(Optional) The data type for conversion to displayable value. Possible values are\r
- * <ul><li>auto (Default, implies no conversion)</li>\r
- * <li>string</li>\r
- * <li>int</li>\r
- * <li>float</li>\r
- * <li>boolean</li>\r
- * <li>date</li></ul></div></li>\r
- * <li><b>sortType</b> : Function<div class="sub-desc">(Optional) A function which converts a Field's value to a comparable value\r
- * in order to ensure correct sort ordering. Predefined functions are provided in {@link Ext.data.SortTypes}.</div></li>\r
- * <li><b>sortDir</b> : String<div class="sub-desc">(Optional) Initial direction to sort. "ASC" or "DESC"</div></li>\r
- * <li><b>convert</b> : Function<div class="sub-desc">(Optional) A function which converts the value provided\r
- * by the Reader into an object that will be stored in the Record. It is passed the\r
- * following parameters:<ul>\r
- * <li><b>v</b> : Mixed<div class="sub-desc">The data value as read by the Reader.</div></li>\r
- * <li><b>rec</b> : Mixed<div class="sub-desc">The data object containing the row as read by the Reader.\r
- * Depending on Reader type, this could be an Array, an object, or an XML element.</div></li>\r
- * </ul></div></li>\r
- * <li><b>dateFormat</b> : String<div class="sub-desc">(Optional) A format string for the {@link Date#parseDate Date.parseDate} function,\r
- * or "timestamp" if the value provided by the Reader is a UNIX timestamp, or "time" if the value provided by the Reader is a \r
- * javascript millisecond timestamp.</div></li>\r
- * <li><b>defaultValue</b> : Mixed<div class="sub-desc">(Optional) The default value used <b>when a Record is being created by a\r
- * {@link Ext.data.Reader Reader}</b> when the item referenced by the <b><tt>mapping</tt></b> does not exist in the data object\r
- * (i.e. undefined). (defaults to "")</div></li>\r
- * </ul>\r
- * The constructor generated by this method may be used to create new Record instances. The data object must contain properties\r
- * named after the field <b>names</b>. \r
- * <br>usage:<br><pre><code>\r
-var TopicRecord = Ext.data.Record.create([\r
-    {name: 'title', mapping: 'topic_title'},\r
-    {name: 'author', mapping: 'username'},\r
-    {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},\r
-    {name: 'lastPost', mapping: 'post_time', type: 'date'},\r
-    {name: 'lastPoster', mapping: 'user2'},\r
-    {name: 'excerpt', mapping: 'post_text'}\r
-]);\r
-\r
-var myNewRecord = new TopicRecord({\r
-    title: 'Do my job please',\r
-    author: 'noobie',\r
-    totalPosts: 1,\r
-    lastPost: new Date(),\r
-    lastPoster: 'Animal',\r
-    excerpt: 'No way dude!'\r
-});\r
-myStore.add(myNewRecord);\r
-</code></pre>\r
- * <p>In the simplest case, if no properties other than <tt>name</tt> are required, a field definition\r
- * may consist of just a field name string.</p>\r
- * @method create\r
- * @return {function} A constructor which is used to create new Records according\r
- * to the definition.\r
- * @static\r
- */\r
-Ext.data.Record.create = function(o){\r
-    var f = Ext.extend(Ext.data.Record, {});\r
-    var p = f.prototype;\r
-    p.fields = new Ext.util.MixedCollection(false, function(field){\r
-        return field.name;\r
-    });\r
-    for(var i = 0, len = o.length; i < len; i++){\r
-        p.fields.add(new Ext.data.Field(o[i]));\r
-    }\r
-    f.getField = function(name){\r
-        return p.fields.get(name);\r
-    };\r
-    return f;\r
-};\r
-\r
-Ext.data.Record.AUTO_ID = 1000;\r
-Ext.data.Record.EDIT = 'edit';\r
-Ext.data.Record.REJECT = 'reject';\r
-Ext.data.Record.COMMIT = 'commit';\r
-\r
-Ext.data.Record.prototype = {\r
-    /**\r
-     * <p><b>This property is stored in the Record definition's <u>prototype</u></b></p>\r
-     * A MixedCollection containing the defined {@link Ext.data.Field Field}s for this Record.  Read-only.\r
-     * @property fields\r
-     * @type Ext.util.MixedCollection\r
-     */\r
-    /**\r
-     * An object hash representing the data for this Record. Every field name in the Record definition\r
-     * is represented by a property of that name in this object. Note that unless you specified a field\r
-     * with name "id" in the Record definition, this will <b>not</b> contain an <tt>id</tt> property.\r
-     * @property data\r
-     * @type {Object}\r
-     */\r
-    /**\r
-     * The unique ID of the Record as specified at construction time.\r
-     * @property id\r
-     * @type {Object}\r
-     */\r
-    /**\r
-     * Readonly flag - true if this Record has been modified.\r
-     * @type Boolean\r
-     */\r
-    dirty : false,\r
-    editing : false,\r
-    error: null,\r
-    /**\r
-     * This object contains a key and value storing the original values of all modified fields or is null if no fields have been modified.\r
-     * @property modified\r
-     * @type {Object}\r
-     */\r
-    modified: null,\r
-\r
-    // private\r
-    join : function(store){\r
-        this.store = store;\r
-    },\r
-\r
-    /**\r
-     * Set the named field to the specified value.\r
-     * @param {String} name The name of the field to set.\r
-     * @param {Object} value The value to set the field to.\r
-     */\r
-    set : function(name, value){\r
-        if(String(this.data[name]) == String(value)){\r
-            return;\r
-        }\r
-        this.dirty = true;\r
-        if(!this.modified){\r
-            this.modified = {};\r
-        }\r
-        if(typeof this.modified[name] == 'undefined'){\r
-            this.modified[name] = this.data[name];\r
-        }\r
-        this.data[name] = value;\r
-        if(!this.editing && this.store){\r
-            this.store.afterEdit(this);\r
-        }\r
-    },\r
-\r
-    /**\r
-     * Get the value of the named field.\r
-     * @param {String} name The name of the field to get the value of.\r
-     * @return {Object} The value of the field.\r
-     */\r
-    get : function(name){\r
-        return this.data[name];\r
-    },\r
-\r
-    /**\r
-     * Begin an edit. While in edit mode, no events are relayed to the containing store.\r
-     */\r
-    beginEdit : function(){\r
-        this.editing = true;\r
-        this.modified = {};\r
-    },\r
-\r
-    /**\r
-     * Cancels all changes made in the current edit operation.\r
-     */\r
-    cancelEdit : function(){\r
-        this.editing = false;\r
-        delete this.modified;\r
-    },\r
-\r
-    /**\r
-     * End an edit. If any data was modified, the containing store is notified.\r
-     */\r
-    endEdit : function(){\r
-        this.editing = false;\r
-        if(this.dirty && this.store){\r
-            this.store.afterEdit(this);\r
-        }\r
-    },\r
-\r
-    /**\r
-     * Usually called by the {@link Ext.data.Store} which owns the Record.\r
-     * Rejects all changes made to the Record since either creation, or the last commit operation.\r
-     * Modified fields are reverted to their original values.\r
-     * <p>\r
-     * Developers should subscribe to the {@link Ext.data.Store#update} event to have their code notified\r
-     * of reject operations.\r
-     * @param {Boolean} silent (optional) True to skip notification of the owning store of the change (defaults to false)\r
-     */\r
-    reject : function(silent){\r
-        var m = this.modified;\r
-        for(var n in m){\r
-            if(typeof m[n] != "function"){\r
-                this.data[n] = m[n];\r
-            }\r
-        }\r
-        this.dirty = false;\r
-        delete this.modified;\r
-        this.editing = false;\r
-        if(this.store && silent !== true){\r
-            this.store.afterReject(this);\r
-        }\r
-    },\r
-\r
-    /**\r
-     * Usually called by the {@link Ext.data.Store} which owns the Record.\r
-     * Commits all changes made to the Record since either creation, or the last commit operation.\r
-     * <p>\r
-     * Developers should subscribe to the {@link Ext.data.Store#update} event to have their code notified\r
-     * of commit operations.\r
-     * @param {Boolean} silent (optional) True to skip notification of the owning store of the change (defaults to false)\r
-     */\r
-    commit : function(silent){\r
-        this.dirty = false;\r
-        delete this.modified;\r
-        this.editing = false;\r
-        if(this.store && silent !== true){\r
-            this.store.afterCommit(this);\r
-        }\r
-    },\r
-\r
-    /**\r
-     * Gets a hash of only the fields that have been modified since this Record was created or commited.\r
-     * @return Object\r
-     */\r
-    getChanges : function(){\r
-        var m = this.modified, cs = {};\r
-        for(var n in m){\r
-            if(m.hasOwnProperty(n)){\r
-                cs[n] = this.data[n];\r
-            }\r
-        }\r
-        return cs;\r
-    },\r
-\r
-    // private\r
-    hasError : function(){\r
-        return this.error != null;\r
-    },\r
-\r
-    // private\r
-    clearError : function(){\r
-        this.error = null;\r
-    },\r
-\r
-    /**\r
-     * Creates a copy of this Record.\r
-     * @param {String} id (optional) A new Record id if you don't want to use this Record's id\r
-     * @return {Record}\r
-     */\r
-    copy : function(newId) {\r
-        return new this.constructor(Ext.apply({}, this.data), newId || this.id);\r
-    },\r
-\r
-    /**\r
-     * Returns true if the field passed has been modified since the load or last commit.\r
-     * @param {String} fieldName\r
-     * @return {Boolean}\r
-     */\r
-    isModified : function(fieldName){\r
-        return !!(this.modified && this.modified.hasOwnProperty(fieldName));\r
-    }\r
-};
\ No newline at end of file