source: trunk/web/addons/job_monarch/lib/extjs-30/src/data/DirectProxy.js @ 625

Last change on this file since 625 was 625, checked in by ramonb, 15 years ago

lib/extjs-30:

  • new ExtJS 3.0
File size: 5.1 KB
Line 
1/*!
2 * Ext JS Library 3.0.0
3 * Copyright(c) 2006-2009 Ext JS, LLC
4 * licensing@extjs.com
5 * http://www.extjs.com/license
6 */
7/**
8 * @class Ext.data.DirectProxy
9 * @extends Ext.data.DataProxy
10 */
11Ext.data.DirectProxy = function(config){
12    Ext.apply(this, config);
13    if(typeof this.paramOrder == 'string'){
14        this.paramOrder = this.paramOrder.split(/[\s,|]/);
15    }
16    Ext.data.DirectProxy.superclass.constructor.call(this, config);
17};
18
19Ext.extend(Ext.data.DirectProxy, Ext.data.DataProxy, {
20    /**
21     * @cfg {Array/String} paramOrder Defaults to <tt>undefined</tt>. A list of params to be executed
22     * server side.  Specify the params in the order in which they must be executed on the server-side
23     * as either (1) an Array of String values, or (2) a String of params delimited by either whitespace,
24     * comma, or pipe. For example,
25     * any of the following would be acceptable:<pre><code>
26paramOrder: ['param1','param2','param3']
27paramOrder: 'param1 param2 param3'
28paramOrder: 'param1,param2,param3'
29paramOrder: 'param1|param2|param'
30     </code></pre>
31     */
32    paramOrder: undefined,
33
34    /**
35     * @cfg {Boolean} paramsAsHash
36     * Send parameters as a collection of named arguments (defaults to <tt>true</tt>). Providing a
37     * <tt>{@link #paramOrder}</tt> nullifies this configuration.
38     */
39    paramsAsHash: true,
40
41    /**
42     * @cfg {Function} directFn
43     * Function to call when executing a request.  directFn is a simple alternative to defining the api configuration-parameter
44     * for Store's which will not implement a full CRUD api.
45     */
46    directFn : undefined,
47
48    // protected
49    doRequest : function(action, rs, params, reader, callback, scope, options) {
50        var args = [];
51        var directFn = this.api[action] || this.directFn;
52
53        switch (action) {
54            case Ext.data.Api.actions.create:
55                args.push(params[reader.meta.root]);            // <-- create(Hash)
56                break;
57            case Ext.data.Api.actions.read:
58                if(this.paramOrder){
59                    for(var i = 0, len = this.paramOrder.length; i < len; i++){
60                        args.push(params[this.paramOrder[i]]);
61                    }
62                }else if(this.paramsAsHash){
63                    args.push(params);
64                }
65                break;
66            case Ext.data.Api.actions.update:
67                args.push(params[reader.meta.idProperty]);  // <-- save(Integer/Integer[], Hash/Hash[])
68                args.push(params[reader.meta.root]);
69                break;
70            case Ext.data.Api.actions.destroy:
71                args.push(params[reader.meta.root]);        // <-- destroy(Int/Int[])
72                break;
73        }
74
75        var trans = {
76            params : params || {},
77            callback : callback,
78            scope : scope,
79            arg : options,
80            reader: reader
81        };
82
83        args.push(this.createCallback(action, rs, trans), this);
84        directFn.apply(window, args);
85    },
86
87    // private
88    createCallback : function(action, rs, trans) {
89        return function(result, res) {
90            if (!res.status) {
91                // @deprecated fire loadexception
92                if (action === Ext.data.Api.actions.read) {
93                    this.fireEvent("loadexception", this, trans, res, null);
94                }
95                this.fireEvent('exception', this, 'remote', action, trans, res, null);
96                trans.callback.call(trans.scope, null, trans.arg, false);
97                return;
98            }
99            if (action === Ext.data.Api.actions.read) {
100                this.onRead(action, trans, result, res);
101            } else {
102                this.onWrite(action, trans, result, res, rs);
103            }
104        };
105    },
106    /**
107     * Callback for read actions
108     * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]
109     * @param {Object} trans The request transaction object
110     * @param {Object} res The server response
111     * @private
112     */
113    onRead : function(action, trans, result, res) {
114        var records;
115        try {
116            records = trans.reader.readRecords(result);
117        }
118        catch (ex) {
119            // @deprecated: Fire old loadexception for backwards-compat.
120            this.fireEvent("loadexception", this, trans, res, ex);
121
122            this.fireEvent('exception', this, 'response', action, trans, res, ex);
123            trans.callback.call(trans.scope, null, trans.arg, false);
124            return;
125        }
126        this.fireEvent("load", this, res, trans.arg);
127        trans.callback.call(trans.scope, records, trans.arg, true);
128    },
129    /**
130     * Callback for write actions
131     * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]
132     * @param {Object} trans The request transaction object
133     * @param {Object} res The server response
134     * @private
135     */
136    onWrite : function(action, trans, result, res, rs) {
137        this.fireEvent("write", this, action, result, res, rs, trans.arg);
138        trans.callback.call(trans.scope, result, res, true);
139    }
140});
141
Note: See TracBrowser for help on using the repository browser.