1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-data.proxy.Proxy-method-constructor'><span id='Ext-data.proxy.Proxy'>/**
2 </span></span> * @author Ed Spencer
3 * @class Ext.data.proxy.Proxy
5 * <p>Proxies are used by {@link Ext.data.Store Stores} to handle the loading and saving of {@link Ext.data.Model Model} data.
6 * Usually developers will not need to create or interact with proxies directly.</p>
7 * <p><u>Types of Proxy</u></p>
9 * <p>There are two main types of Proxy - {@link Ext.data.proxy.Client Client} and {@link Ext.data.proxy.Server Server}. The Client proxies
10 * save their data locally and include the following subclasses:</p>
12 * <ul style="list-style-type: disc; padding-left: 25px">
13 * <li>{@link Ext.data.proxy.LocalStorage LocalStorageProxy} - saves its data to localStorage if the browser supports it</li>
14 * <li>{@link Ext.data.proxy.SessionStorage SessionStorageProxy} - saves its data to sessionStorage if the browsers supports it</li>
15 * <li>{@link Ext.data.proxy.Memory MemoryProxy} - holds data in memory only, any data is lost when the page is refreshed</li>
18 * <p>The Server proxies save their data by sending requests to some remote server. These proxies include:</p>
20 * <ul style="list-style-type: disc; padding-left: 25px">
21 * <li>{@link Ext.data.proxy.Ajax Ajax} - sends requests to a server on the same domain</li>
22 * <li>{@link Ext.data.proxy.JsonP JsonP} - uses JSON-P to send requests to a server on a different domain</li>
23 * <li>{@link Ext.data.proxy.Direct Direct} - uses {@link Ext.direct} to send requests</li>
26 * <p>Proxies operate on the principle that all operations performed are either Create, Read, Update or Delete. These four operations
27 * are mapped to the methods {@link #create}, {@link #read}, {@link #update} and {@link #destroy} respectively. Each Proxy subclass
28 * implements these functions.</p>
30 * <p>The CRUD methods each expect an {@link Ext.data.Operation Operation} object as the sole argument. The Operation encapsulates
31 * information about the action the Store wishes to perform, the {@link Ext.data.Model model} instances that are to be modified, etc.
32 * See the {@link Ext.data.Operation Operation} documentation for more details. Each CRUD method also accepts a callback function to be
33 * called asynchronously on completion.</p>
35 * <p>Proxies also support batching of Operations via a {@link Ext.data.Batch batch} object, invoked by the {@link #batch} method.</p>
39 * @param {Object} config Optional config object
41 Ext.define('Ext.data.proxy.Proxy', {
43 alternateClassName: ['Ext.data.DataProxy', 'Ext.data.Proxy'],
45 'Ext.data.reader.Json',
46 'Ext.data.writer.Json'
54 observable: 'Ext.util.Observable'
57 <span id='Ext-data.proxy.Proxy-cfg-batchOrder'> /**
58 </span> * @cfg {String} batchOrder
59 * Comma-separated ordering 'create', 'update' and 'destroy' actions when batching. Override this
60 * to set a different order for the batched CRUD actions to be executed in. Defaults to 'create,update,destroy'
62 batchOrder: 'create,update,destroy',
64 <span id='Ext-data.proxy.Proxy-cfg-batchActions'> /**
65 </span> * @cfg {Boolean} batchActions True to batch actions of a particular type when synchronizing the store.
66 * Defaults to <tt>true</tt>.
70 <span id='Ext-data.proxy.Proxy-cfg-defaultReaderType'> /**
71 </span> * @cfg {String} defaultReaderType The default registered reader type. Defaults to 'json'
74 defaultReaderType: 'json',
76 <span id='Ext-data.proxy.Proxy-cfg-defaultWriterType'> /**
77 </span> * @cfg {String} defaultWriterType The default registered writer type. Defaults to 'json'
80 defaultWriterType: 'json',
82 <span id='Ext-data.proxy.Proxy-cfg-model'> /**
83 </span> * @cfg {String/Ext.data.Model} model The name of the Model to tie to this Proxy. Can be either the string name of
84 * the Model, or a reference to the Model constructor. Required.
89 constructor: function(config) {
90 config = config || {};
92 if (config.model === undefined) {
96 this.mixins.observable.constructor.call(this, config);
98 if (this.model !== undefined && !(this.model instanceof Ext.data.Model)) {
99 this.setModel(this.model);
103 <span id='Ext-data.proxy.Proxy-method-setModel'> /**
104 </span> * Sets the model associated with this proxy. This will only usually be called by a Store
105 * @param {String|Ext.data.Model} model The new model. Can be either the model name string,
106 * or a reference to the model's constructor
107 * @param {Boolean} setOnStore Sets the new model on the associated Store, if one is present
109 setModel: function(model, setOnStore) {
110 this.model = Ext.ModelManager.getModel(model);
112 var reader = this.reader,
113 writer = this.writer;
115 this.setReader(reader);
116 this.setWriter(writer);
118 if (setOnStore && this.store) {
119 this.store.setModel(this.model);
123 <span id='Ext-data.proxy.Proxy-method-getModel'> /**
124 </span> * Returns the model attached to this Proxy
125 * @return {Ext.data.Model} The model
127 getModel: function() {
131 <span id='Ext-data.proxy.Proxy-method-setReader'> /**
132 </span> * Sets the Proxy's Reader by string, config object or Reader instance
133 * @param {String|Object|Ext.data.reader.Reader} reader The new Reader, which can be either a type string, a configuration object
134 * or an Ext.data.reader.Reader instance
135 * @return {Ext.data.reader.Reader} The attached Reader object
137 setReader: function(reader) {
140 if (reader === undefined || typeof reader == 'string') {
146 if (reader.isReader) {
147 reader.setModel(me.model);
149 Ext.applyIf(reader, {
152 type : me.defaultReaderType
155 reader = Ext.createByAlias('reader.' + reader.type, reader);
162 <span id='Ext-data.proxy.Proxy-method-getReader'> /**
163 </span> * Returns the reader currently attached to this proxy instance
164 * @return {Ext.data.reader.Reader} The Reader instance
166 getReader: function() {
170 <span id='Ext-data.proxy.Proxy-method-setWriter'> /**
171 </span> * Sets the Proxy's Writer by string, config object or Writer instance
172 * @param {String|Object|Ext.data.writer.Writer} writer The new Writer, which can be either a type string, a configuration object
173 * or an Ext.data.writer.Writer instance
174 * @return {Ext.data.writer.Writer} The attached Writer object
176 setWriter: function(writer) {
177 if (writer === undefined || typeof writer == 'string') {
183 if (!(writer instanceof Ext.data.writer.Writer)) {
184 Ext.applyIf(writer, {
186 type : this.defaultWriterType
189 writer = Ext.createByAlias('writer.' + writer.type, writer);
192 this.writer = writer;
197 <span id='Ext-data.proxy.Proxy-method-getWriter'> /**
198 </span> * Returns the writer currently attached to this proxy instance
199 * @return {Ext.data.writer.Writer} The Writer instance
201 getWriter: function() {
205 <span id='Ext-data.proxy.Proxy-property-create'> /**
206 </span> * Performs the given create operation.
207 * @param {Ext.data.Operation} operation The Operation to perform
208 * @param {Function} callback Callback function to be called when the Operation has completed (whether successful or not)
209 * @param {Object} scope Scope to execute the callback function in
213 <span id='Ext-data.proxy.Proxy-property-read'> /**
214 </span> * Performs the given read operation.
215 * @param {Ext.data.Operation} operation The Operation to perform
216 * @param {Function} callback Callback function to be called when the Operation has completed (whether successful or not)
217 * @param {Object} scope Scope to execute the callback function in
221 <span id='Ext-data.proxy.Proxy-property-update'> /**
222 </span> * Performs the given update operation.
223 * @param {Ext.data.Operation} operation The Operation to perform
224 * @param {Function} callback Callback function to be called when the Operation has completed (whether successful or not)
225 * @param {Object} scope Scope to execute the callback function in
229 <span id='Ext-data.proxy.Proxy-property-destroy'> /**
230 </span> * Performs the given destroy operation.
231 * @param {Ext.data.Operation} operation The Operation to perform
232 * @param {Function} callback Callback function to be called when the Operation has completed (whether successful or not)
233 * @param {Object} scope Scope to execute the callback function in
235 destroy: Ext.emptyFn,
237 <span id='Ext-data.proxy.Proxy-method-batch'> /**
238 </span> * Performs a batch of {@link Ext.data.Operation Operations}, in the order specified by {@link #batchOrder}. Used internally by
239 * {@link Ext.data.Store}'s {@link Ext.data.Store#sync sync} method. Example usage:
240 * <pre><code>
242 * create : [myModel1, myModel2],
243 * update : [myModel3],
244 * destroy: [myModel4, myModel5]
246 * </code></pre>
247 * Where the myModel* above are {@link Ext.data.Model Model} instances - in this case 1 and 2 are new instances and have not been
248 * saved before, 3 has been saved previously but needs to be updated, and 4 and 5 have already been saved but should now be destroyed.
249 * @param {Object} operations Object containing the Model instances to act upon, keyed by action name
250 * @param {Object} listeners Optional listeners object passed straight through to the Batch - see {@link Ext.data.Batch}
251 * @return {Ext.data.Batch} The newly created Ext.data.Batch object
253 batch: function(operations, listeners) {
255 batch = Ext.create('Ext.data.Batch', {
257 listeners: listeners || {}
259 useBatch = me.batchActions,
262 Ext.each(me.batchOrder.split(','), function(action) {
263 records = operations[action];
266 batch.add(Ext.create('Ext.data.Operation', {
271 Ext.each(records, function(record){
272 batch.add(Ext.create('Ext.data.Operation', {
285 // Ext.data.proxy.ProxyMgr.registerType('proxy', this);
287 //backwards compatibility
288 Ext.data.DataProxy = this;
289 // Ext.deprecate('platform', '2.0', function() {
290 // Ext.data.DataProxy = this;
293 </pre></pre></body></html>