3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
8 * @class Ext.data.JsonWriter
9 * @extends Ext.data.DataWriter
10 * DataWriter extension for writing an array or single {@link Ext.data.Record} object(s) in preparation for executing a remote CRUD action.
12 Ext.data.JsonWriter = function(config) {
13 Ext.data.JsonWriter.superclass.constructor.call(this, config);
15 // careful to respect "returnJson", renamed to "encode"
16 // TODO: remove after v3 final release
17 if (this.returnJson != undefined) {
18 this.encode = this.returnJson;
21 Ext.extend(Ext.data.JsonWriter, Ext.data.DataWriter, {
23 * @cfg {Boolean} returnJson <b>Deprecated</b>. Use {@link Ext.data.JsonWriter#encode} instead.
25 returnJson : undefined,
27 * @cfg {Boolean} encode <tt>true</tt> to {@link Ext.util.JSON#encode encode} the
28 * {@link Ext.data.DataWriter#toHash hashed data}. Defaults to <tt>true</tt>. When using
29 * {@link Ext.data.DirectProxy}, set this to <tt>false</tt> since Ext.Direct.JsonProvider will perform
30 * its own json-encoding. In addition, if you're using {@link Ext.data.HttpProxy}, setting to <tt>false</tt>
31 * will cause HttpProxy to transmit data using the <b>jsonData</b> configuration-params of {@link Ext.Ajax#request}
32 * instead of <b>params</b>. When using a {@link Ext.data.Store#restful} Store, some serverside frameworks are
33 * tuned to expect data through the jsonData mechanism. In those cases, one will want to set <b>encode: <tt>false</tt></b>, as in
34 * let the lower-level connection object (eg: Ext.Ajax) do the encoding.
39 * Final action of a write event. Apply the written data-object to params.
40 * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]
41 * @param {Record[]} rs
42 * @param {Object} http params
43 * @param {Object} data object populated according to DataReader meta-data "root" and "idProperty"
45 render : function(action, rs, params, data) {
46 if (this.encode === true) {
47 params[this.meta.root] = Ext.encode(data);
50 params.jsonData[this.meta.root] = data;
54 * Implements abstract Ext.data.DataWriter#createRecord
56 * @param {Ext.data.Record} rec
59 createRecord : function(rec) {
60 return this.toHash(rec);
63 * Implements abstract Ext.data.DataWriter#updateRecord
65 * @param {Ext.data.Record} rec
68 updateRecord : function(rec) {
69 return this.toHash(rec);
73 * Implements abstract Ext.data.DataWriter#destroyRecord
75 * @param {Ext.data.Record} rec
78 destroyRecord : function(rec) {