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; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
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>
35 var myFormPanel = new Ext.form.Panel({
36 title: 'Client and routing info',
41 fieldLabel: 'Port of loading',
44 fieldLabel: 'Port of discharge',
45 name: 'portOfDischarge'
48 myFormPanel.{@link Ext.form.Panel#getForm getForm}().{@link Ext.form.Basic#load load}({
49 url: '/getRoutingInfo.php',
51 consignmentRef: myConsignmentRef
53 failure: function(form, action) {
54 Ext.Msg.alert("Load failed", action.result.errorMessage);
57 </code></pre>
58 * a <b>success response</b> packet may look like this:</p><pre><code>
62 clientName: "Fred. Olsen Lines",
63 portOfLoading: "FXT",
64 portOfDischarge: "OSL"
66 }</code></pre>
67 * while a <b>failure response</b> packet may look like this:</p><pre><code>
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>
76 Ext.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',
84 <span id='Ext-form-action-Load-method-run'> /**
88 Ext.Ajax.request(Ext.apply(
89 this.createCallback(),
91 method: this.getMethod(),
93 headers: this.headers,
94 params: this.getParams()
99 <span id='Ext-form-action-Load-method-onSuccess'> /**
102 onSuccess: function(response){
103 var result = this.processResponse(response),
105 if (result === true || !result.success || !result.data) {
106 this.failureType = Ext.form.action.Action.LOAD_FAILURE;
107 form.afterAction(this, false);
111 form.setValues(result.data);
112 form.afterAction(this, true);
115 <span id='Ext-form-action-Load-method-handleResponse'> /**
118 handleResponse: function(response) {
119 var reader = this.form.reader,
122 rs = reader.read(response);
123 data = rs.records && rs.records[0] ? rs.records[0].data : null;
125 success : rs.success,
129 return Ext.decode(response.responseText);