| Package: | CQ.Ext.data |
| Class: | DataWriter |
| Subclasses: | JsonWriter, XmlWriter |
| Extends: | Object |
| Clientlib: | cq.widgets |
CQ.Ext.data.DataWriter facilitates create, update, and destroy actions between an CQ.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.
CQ.Ext.data.DataWriter is an abstract base class which is intended to be extended and should not be created directly. For existing implementations, see CQ.Ext.data.JsonWriter.
Creating a writer is simple:
var writer = new CQ.Ext.data.JsonWriter({
encode: false // <--- false causes data to be printed to jsonData config-property of CQ.Ext.Ajax#reqeust
});
Same old JsonReader as Ext-2.x:
var reader = new CQ.Ext.data.JsonReader({idProperty: 'id'}, [{name: 'first'}, {name: 'last'}, {name: 'email'}]);
The proxy for a writer enabled store can be configured with a simple url:
// Create a standard HttpProxy instance.
var proxy = new CQ.Ext.data.HttpProxy({
url: 'app.php/users' // <--- Supports "provides"-type urls, such as '/users.json', '/products.xml' (Hello Rails/Merb)
});
For finer grained control, the proxy may also be configured with an API:
// Maximum flexibility with the API-configuration
var proxy = new CQ.Ext.data.HttpProxy({
api: {
read : 'app.php/users/read',
create : 'app.php/users/create',
update : 'app.php/users/update',
destroy : { // <--- Supports object-syntax as well
url: 'app.php/users/destroy',
method: "DELETE"
}
}
});
Pulling it all together into a Writer-enabled Store:
var store = new CQ.Ext.data.Store({
proxy: proxy,
reader: reader,
writer: writer,
autoLoad: true,
autoSave: true // -- Cell-level updates.
});
Initiating write-actions automatically, using the existing Ext2.0 Store/Record API:
var rec = store.getAt(0);
rec.set('email', 'foo@bar.com'); // <--- Immediately initiates an UPDATE action through configured proxy.
store.remove(rec); // <---- Immediately initiates a DESTROY action through configured proxy.
For record/batch updates, use the Store-configuration autoSave:false
var store = new CQ.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(); | Config Options | Defined By | |
|---|---|---|
|
createRecord : Function Abstract method that should be implemented in all subclasses (e.g.: JsonWriter.createRecord)
Abstract method that should be implemented in all subclasses (e.g.: JsonWriter.createRecord)
|
DataWriter | |
|
destroyRecord : Function Abstract method that should be implemented in all subclasses (e.g.: JsonWriter.destroyRecord)
Abstract method that should be implemented in all subclasses (e.g.: JsonWriter.destroyRecord)
|
DataWriter | |
|
listful : Boolean false by default. Set true to have the DataWriter always write HTTP params as a list, even when acting upon a single ...
false by default. Set true to have the DataWriter always write HTTP params as a list, even when acting upon a single record.
|
DataWriter | |
|
updateRecord : Function Abstract method that should be implemented in all subclasses (e.g.: JsonWriter.updateRecord
Abstract method that should be implemented in all subclasses (e.g.: JsonWriter.updateRecord
|
DataWriter | |
|
writeAllFields : Boolean false by default. Set true to have DataWriter return ALL fields of a modified record -- not just those that changed. ...
false by default. Set true to have DataWriter return ALL fields of a modified record -- not just those that changed. false to have DataWriter only request modified fields from a record.
|
DataWriter | |
| Method | Defined By | |
|---|---|---|
DataWriter( Object meta, Object recordType ) Create a new DataWriter
Create a new DataWriter
Parameters:
|
DataWriter | |
apply( Object params, Object baseParams, String action, Record/Record[] rs ) : void Compiles a Store recordset into a data-format defined by an extension such as CQ.Ext.data.JsonWriter or CQ.Ext.data.X...
Compiles a Store recordset into a data-format defined by an extension such as CQ.Ext.data.JsonWriter or CQ.Ext.data.XmlWriter in preparation for a server-write action. The first two params are similar similar in nature to CQ.Ext.apply,
Where the first parameter is the receiver of paramaters and the second, baseParams, the source.
Parameters:
|
DataWriter | |
toArray( Hash data ) : Array Converts a Hashed CQ.Ext.data.Record to fields-array array suitable
for encoding to xml via XTemplate, eg:
<tpl f...
Converts a Hashed CQ.Ext.data.Record to fields-array array suitable
for encoding to xml via XTemplate, eg:
eg, non-phantom:
Phantom records will have had their idProperty omitted in toHash if determined to be auto-generated.
Non AUTOINCREMENT pks should have been protected.
Parameters:
|
DataWriter | |
toHash( CQ.Ext.data.Record rec, Object config ) : Object Converts a Record to a hash, taking into account the state of the CQ.Ext.data.Record along with configuration propert...
Converts a Record to a hash, taking into account the state of the CQ.Ext.data.Record along with configuration properties
related to its rendering, such as writeAllFields, phantom, getChanges and
idProperty
Parameters:
|
DataWriter | |