/ext-4.0.7/docs/source/Load.html
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 * <p>A class which handles loading of data from a server into the Fields of an {@link Ext.form.Basic}.</p>
22 * <p>Instances of this class are only created by a {@link Ext.form.Basic Form} when
23 * {@link Ext.form.Basic#load load}ing.</p>
24 * <p><u><b>Response Packet Criteria</b></u></p>
25 * <p>A response packet <b>must</b> contain:
26 * <div class="mdetail-params"><ul>
27 * <li><b><code>success</code></b> property : Boolean</li>
28 * <li><b><code>data</code></b> property : Object</li>
29 * <div class="sub-desc">The <code>data</code> 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.</div></li>
32 * </ul></div>
33 * <p><u><b>JSON Packets</b></u></p>
34 * <p>By default, response packets are assumed to be JSON, so for the following form load call:<pre><code>
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("Load failed", action.result.errorMessage);
55 }
56});
57</code></pre>
58 * a <b>success response</b> packet may look like this:</p><pre><code>
59{
60 success: true,
61 data: {
62 clientName: "Fred. Olsen Lines",
63 portOfLoading: "FXT",
64 portOfDischarge: "OSL"
65 }
66}</code></pre>
67 * while a <b>failure response</b> packet may look like this:</p><pre><code>
68{
69 success: false,
70 errorMessage: "Consignment reference not found"
71}</code></pre>
72 * <p>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.</p>
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 && 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>