Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / data / JsonPStore.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * @class Ext.data.JsonPStore
17  * @extends Ext.data.Store
18  * @private
19  * <p>Small helper class to make creating {@link Ext.data.Store}s from different domain JSON data easier.
20  * A JsonPStore will be automatically configured with a {@link Ext.data.reader.Json} and a {@link Ext.data.proxy.JsonP JsonPProxy}.</p>
21  * <p>A store configuration would be something like:<pre><code>
22 var store = new Ext.data.JsonPStore({
23     // store configs
24     autoDestroy: true,
25     storeId: 'myStore',
26
27     // proxy configs
28     url: 'get-images.php',
29
30     // reader configs
31     root: 'images',
32     idProperty: 'name',
33     fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
34 });
35  * </code></pre></p>
36  * <p>This store is configured to consume a returned object of the form:<pre><code>
37 stcCallback({
38     images: [
39         {name: 'Image one', url:'/GetImage.php?id=1', size:46.5, lastmod: new Date(2007, 10, 29)},
40         {name: 'Image Two', url:'/GetImage.php?id=2', size:43.2, lastmod: new Date(2007, 10, 30)}
41     ]
42 })
43  * </code></pre>
44  * <p>Where stcCallback is the callback name passed in the request to the remote domain. See {@link Ext.data.proxy.JsonP JsonPProxy}
45  * for details of how this works.</p>
46  * An object literal of this form could also be used as the {@link #data} config option.</p>
47  * <p><b>*Note:</b> Although not listed here, this class accepts all of the configuration options of
48  * <b>{@link Ext.data.reader.Json JsonReader}</b> and <b>{@link Ext.data.proxy.JsonP JsonPProxy}</b>.</p>
49  * @xtype jsonpstore
50  */
51 Ext.define('Ext.data.JsonPStore', {
52     extend: 'Ext.data.Store',
53     alias : 'store.jsonp',
54
55     /**
56      * @cfg {Ext.data.DataReader} reader @hide
57      */
58     constructor: function(config) {
59         this.callParent(Ext.apply(config, {
60             reader: Ext.create('Ext.data.reader.Json', config),
61             proxy : Ext.create('Ext.data.proxy.JsonP', config)
62         }));
63     }
64 });
65