PageRenderTime 452ms CodeModel.GetById 359ms app.highlight 77ms RepoModel.GetById 3ms app.codeStats 0ms

/ext-4.0.7/docs/source/Load.html

https://bitbucket.org/srogerf/javascript
HTML | 135 lines | 130 code | 5 blank | 0 comment | 0 complexity | d4d972e214c577221dd275b2bf7e3a54 MD5 | raw file
  1<!DOCTYPE html>
  2<html>
  3<head>
  4  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5  <title>The source code</title>
  6  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8  <style type="text/css">
  9    .highlight { display: block; background-color: #ddd; }
 10  </style>
 11  <script type="text/javascript">
 12    function highlight() {
 13      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
 14    }
 15  </script>
 16</head>
 17<body onload="prettyPrint(); highlight();">
 18  <pre class="prettyprint lang-js"><span id='Ext-form-action-Load'>/**
 19</span> * @class Ext.form.action.Load
 20 * @extends Ext.form.action.Action
 21 * &lt;p&gt;A class which handles loading of data from a server into the Fields of an {@link Ext.form.Basic}.&lt;/p&gt;
 22 * &lt;p&gt;Instances of this class are only created by a {@link Ext.form.Basic Form} when
 23 * {@link Ext.form.Basic#load load}ing.&lt;/p&gt;
 24 * &lt;p&gt;&lt;u&gt;&lt;b&gt;Response Packet Criteria&lt;/b&gt;&lt;/u&gt;&lt;/p&gt;
 25 * &lt;p&gt;A response packet &lt;b&gt;must&lt;/b&gt; contain:
 26 * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
 27 * &lt;li&gt;&lt;b&gt;&lt;code&gt;success&lt;/code&gt;&lt;/b&gt; property : Boolean&lt;/li&gt;
 28 * &lt;li&gt;&lt;b&gt;&lt;code&gt;data&lt;/code&gt;&lt;/b&gt; property : Object&lt;/li&gt;
 29 * &lt;div class=&quot;sub-desc&quot;&gt;The &lt;code&gt;data&lt;/code&gt; property contains the values of Fields to load.
 30 * The individual value object for each Field is passed to the Field's
 31 * {@link Ext.form.field.Field#setValue setValue} method.&lt;/div&gt;&lt;/li&gt;
 32 * &lt;/ul&gt;&lt;/div&gt;
 33 * &lt;p&gt;&lt;u&gt;&lt;b&gt;JSON Packets&lt;/b&gt;&lt;/u&gt;&lt;/p&gt;
 34 * &lt;p&gt;By default, response packets are assumed to be JSON, so for the following form load call:&lt;pre&gt;&lt;code&gt;
 35var myFormPanel = new Ext.form.Panel({
 36    title: 'Client and routing info',
 37    items: [{
 38        fieldLabel: 'Client',
 39        name: 'clientName'
 40    }, {
 41        fieldLabel: 'Port of loading',
 42        name: 'portOfLoading'
 43    }, {
 44        fieldLabel: 'Port of discharge',
 45        name: 'portOfDischarge'
 46    }]
 47});
 48myFormPanel.{@link Ext.form.Panel#getForm getForm}().{@link Ext.form.Basic#load load}({
 49    url: '/getRoutingInfo.php',
 50    params: {
 51        consignmentRef: myConsignmentRef
 52    },
 53    failure: function(form, action) {
 54        Ext.Msg.alert(&quot;Load failed&quot;, action.result.errorMessage);
 55    }
 56});
 57&lt;/code&gt;&lt;/pre&gt;
 58 * a &lt;b&gt;success response&lt;/b&gt; packet may look like this:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
 59{
 60    success: true,
 61    data: {
 62        clientName: &quot;Fred. Olsen Lines&quot;,
 63        portOfLoading: &quot;FXT&quot;,
 64        portOfDischarge: &quot;OSL&quot;
 65    }
 66}&lt;/code&gt;&lt;/pre&gt;
 67 * while a &lt;b&gt;failure response&lt;/b&gt; packet may look like this:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
 68{
 69    success: false,
 70    errorMessage: &quot;Consignment reference not found&quot;
 71}&lt;/code&gt;&lt;/pre&gt;
 72 * &lt;p&gt;Other data may be placed into the response for processing the {@link Ext.form.Basic Form}'s
 73 * callback or event handler methods. The object decoded from this JSON is available in the
 74 * {@link Ext.form.action.Action#result result} property.&lt;/p&gt;
 75 */
 76Ext.define('Ext.form.action.Load', {
 77    extend:'Ext.form.action.Action',
 78    requires: ['Ext.data.Connection'],
 79    alternateClassName: 'Ext.form.Action.Load',
 80    alias: 'formaction.load',
 81
 82    type: 'load',
 83
 84<span id='Ext-form-action-Load-method-run'>    /**
 85</span>     * @private
 86     */
 87    run: function() {
 88        Ext.Ajax.request(Ext.apply(
 89            this.createCallback(),
 90            {
 91                method: this.getMethod(),
 92                url: this.getUrl(),
 93                headers: this.headers,
 94                params: this.getParams()
 95            }
 96        ));
 97    },
 98
 99<span id='Ext-form-action-Load-method-onSuccess'>    /**
100</span>     * @private
101     */
102    onSuccess: function(response){
103        var result = this.processResponse(response),
104            form = this.form;
105        if (result === true || !result.success || !result.data) {
106            this.failureType = Ext.form.action.Action.LOAD_FAILURE;
107            form.afterAction(this, false);
108            return;
109        }
110        form.clearInvalid();
111        form.setValues(result.data);
112        form.afterAction(this, true);
113    },
114
115<span id='Ext-form-action-Load-method-handleResponse'>    /**
116</span>     * @private
117     */
118    handleResponse: function(response) {
119        var reader = this.form.reader,
120            rs, data;
121        if (reader) {
122            rs = reader.read(response);
123            data = rs.records &amp;&amp; rs.records[0] ? rs.records[0].data : null;
124            return {
125                success : rs.success,
126                data : data
127            };
128        }
129        return Ext.decode(response.responseText);
130    }
131});
132
133</pre>
134</body>
135</html>