tvheadend/vendor/ext-3.4.1/docs/source/DirectProxy.html
Adam Sutton bafcfff42d webui: restructure webui/extjs source files
I want to keep the 3rd-party packages away from the main source
where possible.
2013-06-03 17:11:01 +01:00

187 lines
8.1 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-data-DirectProxy'>/**
</span> * @class Ext.data.DirectProxy
* @extends Ext.data.DataProxy
*/
Ext.data.DirectProxy = function(config){
Ext.apply(this, config);
if(typeof this.paramOrder == 'string'){
this.paramOrder = this.paramOrder.split(/[\s,|]/);
}
Ext.data.DirectProxy.superclass.constructor.call(this, config);
};
Ext.extend(Ext.data.DirectProxy, Ext.data.DataProxy, {
<span id='Ext-data-DirectProxy-cfg-paramOrder'> /**
</span> * @cfg {Array/String} paramOrder Defaults to &lt;tt&gt;undefined&lt;/tt&gt;. A list of params to be executed
* server side. Specify the params in the order in which they must be executed on the server-side
* as either (1) an Array of String values, or (2) a String of params delimited by either whitespace,
* comma, or pipe. For example,
* any of the following would be acceptable:&lt;pre&gt;&lt;code&gt;
paramOrder: ['param1','param2','param3']
paramOrder: 'param1 param2 param3'
paramOrder: 'param1,param2,param3'
paramOrder: 'param1|param2|param'
&lt;/code&gt;&lt;/pre&gt;
*/
paramOrder: undefined,
<span id='Ext-data-DirectProxy-cfg-paramsAsHash'> /**
</span> * @cfg {Boolean} paramsAsHash
* Send parameters as a collection of named arguments (defaults to &lt;tt&gt;true&lt;/tt&gt;). Providing a
* &lt;tt&gt;{@link #paramOrder}&lt;/tt&gt; nullifies this configuration.
*/
paramsAsHash: true,
<span id='Ext-data-DirectProxy-cfg-directFn'> /**
</span> * @cfg {Function} directFn
* Function to call when executing a request. directFn is a simple alternative to defining the api configuration-parameter
* for Store's which will not implement a full CRUD api.
*/
directFn : undefined,
<span id='Ext-data-DirectProxy-method-doRequest'> /**
</span> * DirectProxy implementation of {@link Ext.data.DataProxy#doRequest}
* @param {String} action The crud action type (create, read, update, destroy)
* @param {Ext.data.Record/Ext.data.Record[]} rs If action is load, rs will be null
* @param {Object} params An object containing properties which are to be used as HTTP parameters
* for the request to the remote server.
* @param {Ext.data.DataReader} reader The Reader object which converts the data
* object into a block of Ext.data.Records.
* @param {Function} callback
* &lt;div class=&quot;sub-desc&quot;&gt;&lt;p&gt;A function to be called after the request.
* The &lt;tt&gt;callback&lt;/tt&gt; is passed the following arguments:&lt;ul&gt;
* &lt;li&gt;&lt;tt&gt;r&lt;/tt&gt; : Ext.data.Record[] The block of Ext.data.Records.&lt;/li&gt;
* &lt;li&gt;&lt;tt&gt;options&lt;/tt&gt;: Options object from the action request&lt;/li&gt;
* &lt;li&gt;&lt;tt&gt;success&lt;/tt&gt;: Boolean success indicator&lt;/li&gt;&lt;/ul&gt;&lt;/p&gt;&lt;/div&gt;
* @param {Object} scope The scope (&lt;code&gt;this&lt;/code&gt; reference) in which the callback function is executed. Defaults to the browser window.
* @param {Object} arg An optional argument which is passed to the callback as its second parameter.
* @protected
*/
doRequest : function(action, rs, params, reader, callback, scope, options) {
var args = [],
directFn = this.api[action] || this.directFn;
switch (action) {
case Ext.data.Api.actions.create:
args.push(params.jsonData); // &lt;-- create(Hash)
break;
case Ext.data.Api.actions.read:
// If the method has no parameters, ignore the paramOrder/paramsAsHash.
if(directFn.directCfg.method.len &gt; 0){
if(this.paramOrder){
for(var i = 0, len = this.paramOrder.length; i &lt; len; i++){
args.push(params[this.paramOrder[i]]);
}
}else if(this.paramsAsHash){
args.push(params);
}
}
break;
case Ext.data.Api.actions.update:
args.push(params.jsonData); // &lt;-- update(Hash/Hash[])
break;
case Ext.data.Api.actions.destroy:
args.push(params.jsonData); // &lt;-- destroy(Int/Int[])
break;
}
var trans = {
params : params || {},
request: {
callback : callback,
scope : scope,
arg : options
},
reader: reader
};
args.push(this.createCallback(action, rs, trans), this);
directFn.apply(window, args);
},
// private
createCallback : function(action, rs, trans) {
var me = this;
return function(result, res) {
if (!res.status) {
// @deprecated fire loadexception
if (action === Ext.data.Api.actions.read) {
me.fireEvent(&quot;loadexception&quot;, me, trans, res, null);
}
me.fireEvent('exception', me, 'remote', action, trans, res, null);
trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);
return;
}
if (action === Ext.data.Api.actions.read) {
me.onRead(action, trans, result, res);
} else {
me.onWrite(action, trans, result, res, rs);
}
};
},
<span id='Ext-data-DirectProxy-method-onRead'> /**
</span> * Callback for read actions
* @param {String} action [Ext.data.Api.actions.create|read|update|destroy]
* @param {Object} trans The request transaction object
* @param {Object} result Data object picked out of the server-response.
* @param {Object} res The server response
* @protected
*/
onRead : function(action, trans, result, res) {
var records;
try {
records = trans.reader.readRecords(result);
}
catch (ex) {
// @deprecated: Fire old loadexception for backwards-compat.
this.fireEvent(&quot;loadexception&quot;, this, trans, res, ex);
this.fireEvent('exception', this, 'response', action, trans, res, ex);
trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);
return;
}
this.fireEvent(&quot;load&quot;, this, res, trans.request.arg);
trans.request.callback.call(trans.request.scope, records, trans.request.arg, true);
},
<span id='Ext-data-DirectProxy-method-onWrite'> /**
</span> * Callback for write actions
* @param {String} action [{@link Ext.data.Api#actions create|read|update|destroy}]
* @param {Object} trans The request transaction object
* @param {Object} result Data object picked out of the server-response.
* @param {Object} res The server response
* @param {Ext.data.Record/Ext.data.Record[]} rs The Store resultset associated with the action.
* @protected
*/
onWrite : function(action, trans, result, res, rs) {
var data = trans.reader.extractData(trans.reader.getRoot(result), false);
var success = trans.reader.getSuccess(result);
success = (success !== false);
if (success){
this.fireEvent(&quot;write&quot;, this, action, data, res, rs, trans.request.arg);
}else{
this.fireEvent('exception', this, 'remote', action, trans, result, rs);
}
trans.request.callback.call(trans.request.scope, data, res, success);
}
});
</pre>
</body>
</html>