tvheadend/vendor/ext-3.4.1/docs/source/DataWriter.html
Adam Sutton bafcfff42d webui: restructure webui/extjs source files
I want to keep the 3rd-party packages away from the main source
where possible.
2013-06-03 17:11:01 +01:00

223 lines
11 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-data-DataWriter-method-constructor'><span id='Ext-data-DataWriter'>/**
</span></span> * @class Ext.data.DataWriter
* &lt;p&gt;Ext.data.DataWriter facilitates create, update, and destroy actions between
* an Ext.data.Store and a server-side framework. A Writer enabled Store will
* automatically manage the Ajax requests to perform CRUD actions on a Store.&lt;/p&gt;
* &lt;p&gt;Ext.data.DataWriter is an abstract base class which is intended to be extended
* and should not be created directly. For existing implementations, see
* {@link Ext.data.JsonWriter}.&lt;/p&gt;
* &lt;p&gt;Creating a writer is simple:&lt;/p&gt;
* &lt;pre&gt;&lt;code&gt;
var writer = new Ext.data.JsonWriter({
encode: false // &amp;lt;--- false causes data to be printed to jsonData config-property of Ext.Ajax#reqeust
});
* &lt;/code&gt;&lt;/pre&gt;
* * &lt;p&gt;Same old JsonReader as Ext-2.x:&lt;/p&gt;
* &lt;pre&gt;&lt;code&gt;
var reader = new Ext.data.JsonReader({idProperty: 'id'}, [{name: 'first'}, {name: 'last'}, {name: 'email'}]);
* &lt;/code&gt;&lt;/pre&gt;
*
* &lt;p&gt;The proxy for a writer enabled store can be configured with a simple &lt;code&gt;url&lt;/code&gt;:&lt;/p&gt;
* &lt;pre&gt;&lt;code&gt;
// Create a standard HttpProxy instance.
var proxy = new Ext.data.HttpProxy({
url: 'app.php/users' // &amp;lt;--- Supports &quot;provides&quot;-type urls, such as '/users.json', '/products.xml' (Hello Rails/Merb)
});
* &lt;/code&gt;&lt;/pre&gt;
* &lt;p&gt;For finer grained control, the proxy may also be configured with an &lt;code&gt;API&lt;/code&gt;:&lt;/p&gt;
* &lt;pre&gt;&lt;code&gt;
// Maximum flexibility with the API-configuration
var proxy = new Ext.data.HttpProxy({
api: {
read : 'app.php/users/read',
create : 'app.php/users/create',
update : 'app.php/users/update',
destroy : { // &amp;lt;--- Supports object-syntax as well
url: 'app.php/users/destroy',
method: &quot;DELETE&quot;
}
}
});
* &lt;/code&gt;&lt;/pre&gt;
* &lt;p&gt;Pulling it all together into a Writer-enabled Store:&lt;/p&gt;
* &lt;pre&gt;&lt;code&gt;
var store = new Ext.data.Store({
proxy: proxy,
reader: reader,
writer: writer,
autoLoad: true,
autoSave: true // -- Cell-level updates.
});
* &lt;/code&gt;&lt;/pre&gt;
* &lt;p&gt;Initiating write-actions &lt;b&gt;automatically&lt;/b&gt;, using the existing Ext2.0 Store/Record API:&lt;/p&gt;
* &lt;pre&gt;&lt;code&gt;
var rec = store.getAt(0);
rec.set('email', 'foo@bar.com'); // &amp;lt;--- Immediately initiates an UPDATE action through configured proxy.
store.remove(rec); // &amp;lt;---- Immediately initiates a DESTROY action through configured proxy.
* &lt;/code&gt;&lt;/pre&gt;
* &lt;p&gt;For &lt;b&gt;record/batch&lt;/b&gt; updates, use the Store-configuration {@link Ext.data.Store#autoSave autoSave:false}&lt;/p&gt;
* &lt;pre&gt;&lt;code&gt;
var store = new Ext.data.Store({
proxy: proxy,
reader: reader,
writer: writer,
autoLoad: true,
autoSave: false // -- disable cell-updates
});
var urec = store.getAt(0);
urec.set('email', 'foo@bar.com');
var drec = store.getAt(1);
store.remove(drec);
// Push the button!
store.save();
* &lt;/code&gt;&lt;/pre&gt;
* @constructor Create a new DataWriter
* @param {Object} meta Metadata configuration options (implementation-specific)
* @param {Object} recordType Either an Array of field definition objects as specified
* in {@link Ext.data.Record#create}, or an {@link Ext.data.Record} object created
* using {@link Ext.data.Record#create}.
*/
Ext.data.DataWriter = function(config){
Ext.apply(this, config);
};
Ext.data.DataWriter.prototype = {
<span id='Ext-data-DataWriter-cfg-writeAllFields'> /**
</span> * @cfg {Boolean} writeAllFields
* &lt;tt&gt;false&lt;/tt&gt; by default. Set &lt;tt&gt;true&lt;/tt&gt; to have DataWriter return ALL fields of a modified
* record -- not just those that changed.
* &lt;tt&gt;false&lt;/tt&gt; to have DataWriter only request modified fields from a record.
*/
writeAllFields : false,
<span id='Ext-data-DataWriter-cfg-listful'> /**
</span> * @cfg {Boolean} listful
* &lt;tt&gt;false&lt;/tt&gt; by default. Set &lt;tt&gt;true&lt;/tt&gt; to have the DataWriter &lt;b&gt;always&lt;/b&gt; write HTTP params as a list,
* even when acting upon a single record.
*/
listful : false, // &lt;-- listful is actually not used internally here in DataWriter. @see Ext.data.Store#execute.
<span id='Ext-data-DataWriter-method-apply'> /**
</span> * Compiles a Store recordset into a data-format defined by an extension such as {@link Ext.data.JsonWriter} or {@link Ext.data.XmlWriter} in preparation for a {@link Ext.data.Api#actions server-write action}. The first two params are similar similar in nature to {@link Ext#apply},
* Where the first parameter is the &lt;i&gt;receiver&lt;/i&gt; of paramaters and the second, baseParams, &lt;i&gt;the source&lt;/i&gt;.
* @param {Object} params The request-params receiver.
* @param {Object} baseParams as defined by {@link Ext.data.Store#baseParams}. The baseParms must be encoded by the extending class, eg: {@link Ext.data.JsonWriter}, {@link Ext.data.XmlWriter}.
* @param {String} action [{@link Ext.data.Api#actions create|update|destroy}]
* @param {Record/Record[]} rs The recordset to write, the subject(s) of the write action.
*/
apply : function(params, baseParams, action, rs) {
var data = [],
renderer = action + 'Record';
// TODO implement @cfg listful here
if (Ext.isArray(rs)) {
Ext.each(rs, function(rec){
data.push(this[renderer](rec));
}, this);
}
else if (rs instanceof Ext.data.Record) {
data = this[renderer](rs);
}
this.render(params, baseParams, data);
},
<span id='Ext-data-DataWriter-method-render'> /**
</span> * abstract method meant to be overridden by all DataWriter extensions. It's the extension's job to apply the &quot;data&quot; to the &quot;params&quot;.
* The data-object provided to render is populated with data according to the meta-info defined in the user's DataReader config,
* @param {String} action [Ext.data.Api.actions.create|read|update|destroy]
* @param {Record[]} rs Store recordset
* @param {Object} params Http params to be sent to server.
* @param {Object} data object populated according to DataReader meta-data.
*/
render : Ext.emptyFn,
<span id='Ext-data-DataWriter-cfg-updateRecord'> /**
</span> * @cfg {Function} updateRecord Abstract method that should be implemented in all subclasses
* (e.g.: {@link Ext.data.JsonWriter#updateRecord JsonWriter.updateRecord}
*/
updateRecord : Ext.emptyFn,
<span id='Ext-data-DataWriter-cfg-createRecord'> /**
</span> * @cfg {Function} createRecord Abstract method that should be implemented in all subclasses
* (e.g.: {@link Ext.data.JsonWriter#createRecord JsonWriter.createRecord})
*/
createRecord : Ext.emptyFn,
<span id='Ext-data-DataWriter-cfg-destroyRecord'> /**
</span> * @cfg {Function} destroyRecord Abstract method that should be implemented in all subclasses
* (e.g.: {@link Ext.data.JsonWriter#destroyRecord JsonWriter.destroyRecord})
*/
destroyRecord : Ext.emptyFn,
<span id='Ext-data-DataWriter-method-toHash'> /**
</span> * Converts a Record to a hash, taking into account the state of the Ext.data.Record along with configuration properties
* related to its rendering, such as {@link #writeAllFields}, {@link Ext.data.Record#phantom phantom}, {@link Ext.data.Record#getChanges getChanges} and
* {@link Ext.data.DataReader#idProperty idProperty}
* @param {Ext.data.Record} rec The Record from which to create a hash.
* @param {Object} config &lt;b&gt;NOT YET IMPLEMENTED&lt;/b&gt;. Will implement an exlude/only configuration for fine-control over which fields do/don't get rendered.
* @return {Object}
* @protected
* TODO Implement excludes/only configuration with 2nd param?
*/
toHash : function(rec, config) {
var map = rec.fields.map,
data = {},
raw = (this.writeAllFields === false &amp;&amp; rec.phantom === false) ? rec.getChanges() : rec.data,
m;
Ext.iterate(raw, function(prop, value){
if((m = map[prop])){
data[m.mapping ? m.mapping : m.name] = value;
}
});
// we don't want to write Ext auto-generated id to hash. Careful not to remove it on Models not having auto-increment pk though.
// We can tell its not auto-increment if the user defined a DataReader field for it *and* that field's value is non-empty.
// we could also do a RegExp here for the Ext.data.Record AUTO_ID prefix.
if (rec.phantom) {
if (rec.fields.containsKey(this.meta.idProperty) &amp;&amp; Ext.isEmpty(rec.data[this.meta.idProperty])) {
delete data[this.meta.idProperty];
}
} else {
data[this.meta.idProperty] = rec.id;
}
return data;
},
<span id='Ext-data-DataWriter-method-toArray'> /**
</span> * Converts a {@link Ext.data.DataWriter#toHash Hashed} {@link Ext.data.Record} to fields-array array suitable
* for encoding to xml via XTemplate, eg:
&lt;code&gt;&lt;pre&gt;&amp;lt;tpl for=&quot;.&quot;&gt;&amp;lt;{name}&gt;{value}&amp;lt;/{name}&amp;lt;/tpl&gt;&lt;/pre&gt;&lt;/code&gt;
* eg, &lt;b&gt;non-phantom&lt;/b&gt;:
&lt;code&gt;&lt;pre&gt;{id: 1, first: 'foo', last: 'bar'} --&gt; [{name: 'id', value: 1}, {name: 'first', value: 'foo'}, {name: 'last', value: 'bar'}]&lt;/pre&gt;&lt;/code&gt;
* {@link Ext.data.Record#phantom Phantom} records will have had their idProperty omitted in {@link #toHash} if determined to be auto-generated.
* Non AUTOINCREMENT pks should have been protected.
* @param {Hash} data Hashed by Ext.data.DataWriter#toHash
* @return {Object[]} Array of attribute-objects.
* @protected
*/
toArray : function(data) {
var fields = [];
Ext.iterate(data, function(k, v) {fields.push({name: k, value: v});},this);
return fields;
}
};</pre>
</body>
</html>