webgui/www/extras/yui-ext/docs/output/Record.jss.html
2007-07-05 04:23:55 +00:00

209 lines
No EOL
8.6 KiB
HTML

<html><head><title>Record.js</title><link rel="stylesheet" type="text/css" href="../resources/style.css" media="screen"/></head><body><h1>Record.js</h1><pre class="highlighted"><code><i>/**
* @class Ext.data.Record
* Instances of <b>this</b> class encapsulate both record &lt;em&gt;definition&lt;/em&gt; information, and record
* &lt;em&gt;value&lt;/em&gt; information <b>for</b> use <b>in</b> {@link Ext.data.Store} objects, or any code which needs
* to access Records cached <b>in</b> an {@link Ext.data.Store} object.
* &lt;p&gt;
* Constructors <b>for</b> this class are generated by passing an Array of field definition objects to {@link #create}
* and instances are usually only created by {@link Ext.data.Reader} objects when processing unformatted data
* objects.
* &lt;p&gt;
* Record objects generated by <b>this</b> constructor inherit all the methods of Ext.data.Record listed below.
* @constructor
* This constructor should not be used to create Record objects. Instead, use the constructor generated by
* {@link #create}. The parameters are the same.
* @param data {Array} An associative Array of data values keyed by the field name.
* @param id (Optional) The id of the record. This id should be unique, and is used by the
* @link Ext.data.Store} object which owns the Record to index its collection of Records. If
* not specified an integer id is generated.
*/</i>
Ext.data.Record = <b>function</b>(data, id){
<b>this</b>.id = (id || id === 0) ? id : ++Ext.data.Record.AUTO_ID;
<b>this</b>.data = data;
};
<i>/**
* Generate a constructor <b>for</b> a specific record layout.
* @param {Array} o An Array of field definition objects which specify field names, and optionally,
* data types, and a mapping <b>for</b> an {@link Ext.data.Reader} to extract the field's value from a data object.
* Each field definition object may contain the following properties: &lt;ul&gt;
* &lt;li&gt;name {String} The name by which the field is referenced within the Record. This is referenced by,
* <b>for</b> example the &lt;em&gt;dataIndex&lt;/em&gt; property <b>in</b> column definition objects passed to {@link Ext.grid.ColumnModel}&lt;/li&gt;
* &lt;li&gt;mapping {String} (Optional) A path specification <b>for</b> use by the {@link Ext.data.Reader} implementation
* that is creating the Record to access the data value from the data object. If an {@link Ext.data.JsonReader}
* is being used, then <b>this</b> is a string containing the javascript expression to reference the data relative to
* the record item's root. If an {@link Ext.data.XmlReader} is being used, <b>this</b> is an {@link Ext.DomQuery} path
* to the data item relative to the record element. If the mapping expression is the same as the field name,
* <b>this</b> may be omitted.&lt;/li&gt;
* &lt;li&gt;type {String} (Optional) The data type <b>for</b> conversion to displayable value. Possible values are
* &lt;ul&gt;&lt;li&gt;auto (Default, implies no conversion)&lt;/li&gt;
* &lt;li&gt;string&lt;/li&gt;
* &lt;li&gt;int&lt;/li&gt;
* &lt;li&gt;float&lt;/li&gt;
* &lt;li&gt;boolean&lt;/li&gt;
* &lt;li&gt;date&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
* &lt;li&gt;sortType {Mixed} (Optional) A member of {@link Ext.data.SortTypes}.&lt;/li&gt;
* &lt;li&gt;sortDir {String} (Optional) Initial direction to sort. &quot;ASC&quot; or &quot;DESC&quot;&lt;/li&gt;
* &lt;li&gt;convert {Function} (Optional) A <b>function</b> which accepts a data value and returns it formatted <b>for</b> display.&lt;/li&gt;
* &lt;li&gt;dateFormat {String} (Optional) A format String <b>for</b> the Date.parseDate <b>function</b>.&lt;/li&gt;
* &lt;/ul&gt;
* &lt;br&gt;usage:&lt;br&gt;&lt;pre&gt;&lt;code&gt;
<b>var</b> TopicRecord = Ext.data.Record.create(
{name: 'title', mapping: 'topic_title'},
{name: 'author', mapping: 'username'},
{name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
{name: 'lastPost', mapping: 'post_time', type: 'date'},
{name: 'lastPoster', mapping: 'user2'},
{name: 'excerpt', mapping: 'post_text'}
);
<b>var</b> myNewRecord = <b>new</b> TopicRecord({
title: 'Do my job please',
author: 'noobie',
totalPosts: 1,
lastPost: <b>new</b> Date(),
lastPoster: 'Animal',
excerpt: 'No way dude!'
});
myStore.add(myNewRecord);
&lt;/code&gt;&lt;/pre&gt;
*/</i>
Ext.data.Record.create = <b>function</b>(o){
<b>var</b> f = <b>function</b>(){
f.superclass.constructor.apply(<b>this</b>, arguments);
};
Ext.extend(f, Ext.data.Record);
<b>var</b> p = f.prototype;
p.fields = <b>new</b> Ext.util.MixedCollection(false, <b>function</b>(field){
<b>return</b> field.name;
});
<b>for</b>(var i = 0, len = o.length; i &lt; len; i++){
p.fields.add(<b>new</b> Ext.data.Field(o[i]));
}
f.getField = <b>function</b>(name){
<b>return</b> p.fields.get(name);
};
<b>return</b> f;
};
Ext.data.Record.AUTO_ID = 1000;
Ext.data.Record.EDIT = 'edit';
Ext.data.Record.REJECT = 'reject';
Ext.data.Record.COMMIT = 'commit';
Ext.data.Record.prototype = {
<i>/**
* Readonly flag - true <b>if</b> this record has been modified.
* @type Boolean
*/</i>
dirty : false,
editing : false,
error: null,
modified: null,
<i>// private</i>
join : <b>function</b>(store){
<b>this</b>.store = store;
},
<i>/**
* Set the named field to the specified value.
* @param name {String} The name of the field to set.
* @param value {Object} The value to set the field to.
*/</i>
set : <b>function</b>(name, value){
<b>if</b>(this.data[name] == value){
<b>return</b>;
}
<b>this</b>.dirty = true;
<b>if</b>(!<b>this</b>.modified){
<b>this</b>.modified = {};
}
<b>if</b>(typeof <b>this</b>.modified[name] == 'undefined'){
<b>this</b>.modified[name] = <b>this</b>.data[name];
}
<b>this</b>.data[name] = value;
<b>if</b>(!<b>this</b>.editing){
<b>this</b>.store.afterEdit(<b>this</b>);
}
},
<i>/**
* Get the value of the named field.
* @param name {String} The name of the field to get the value of.
* @<b>return</b> {Object} The value of the field.
*/</i>
get : <b>function</b>(name){
<b>return</b> this.data[name];
},
<i>// private</i>
beginEdit : <b>function</b>(){
<b>this</b>.editing = true;
<b>this</b>.modified = {};
},
<i>// private</i>
cancelEdit : <b>function</b>(){
<b>this</b>.editing = false;
<b>delete</b> this.modified;
},
<i>// private</i>
endEdit : <b>function</b>(){
<b>this</b>.editing = false;
<b>if</b>(this.dirty &amp;&amp; <b>this</b>.store){
<b>this</b>.store.afterEdit(<b>this</b>);
}
},
<i>/**
* Usually called by the {@link Ext.data.Store} which owns the Record.
* Rejects all changes made to the Record since either creation, or the last commit operation.
* Modified fields are reverted to their original values.
* &lt;p&gt;
* Developers should subscribe to the {@link Ext.data.Store#update} event to have their code notified
* of reject operations.
*/</i>
reject : <b>function</b>(){
<b>var</b> m = <b>this</b>.modified;
<b>for</b>(var n <b>in</b> m){
<b>if</b>(typeof m[n] != &quot;<b>function</b>&quot;){
<b>this</b>.data[n] = m[n];
}
}
<b>this</b>.dirty = false;
<b>delete</b> this.modified;
<b>this</b>.editing = false;
<b>if</b>(this.store){
<b>this</b>.store.afterReject(<b>this</b>);
}
},
<i>/**
* Usually called by the {@link Ext.data.Store} which owns the Record.
* Commits all changes made to the Record since either creation, or the last commit operation.
* &lt;p&gt;
* Developers should subscribe to the {@link Ext.data.Store#update} event to have their code notified
* of commit operations.
*/</i>
commit : <b>function</b>(){
<b>this</b>.dirty = false;
<b>delete</b> this.modified;
<b>this</b>.editing = false;
<b>if</b>(this.store){
<b>this</b>.store.afterCommit(<b>this</b>);
}
},
<i>// private</i>
hasError : <b>function</b>(){
<b>return</b> this.error != null;
},
<i>// private</i>
clearError : <b>function</b>(){
<b>this</b>.error = null;
}
};</code></pre><hr><div style="font-size:10px;text-align:center;color:gray;">Ext - Copyright &copy; 2006-2007 Ext JS, LLC<br />All rights reserved.</div>
</body></html>