3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.form.action.Load
17 * @extends Ext.form.action.Action
18 * <p>A class which handles loading of data from a server into the Fields of an {@link Ext.form.Basic}.</p>
19 * <p>Instances of this class are only created by a {@link Ext.form.Basic Form} when
20 * {@link Ext.form.Basic#load load}ing.</p>
21 * <p><u><b>Response Packet Criteria</b></u></p>
22 * <p>A response packet <b>must</b> contain:
23 * <div class="mdetail-params"><ul>
24 * <li><b><code>success</code></b> property : Boolean</li>
25 * <li><b><code>data</code></b> property : Object</li>
26 * <div class="sub-desc">The <code>data</code> property contains the values of Fields to load.
27 * The individual value object for each Field is passed to the Field's
28 * {@link Ext.form.field.Field#setValue setValue} method.</div></li>
30 * <p><u><b>JSON Packets</b></u></p>
31 * <p>By default, response packets are assumed to be JSON, so for the following form load call:<pre><code>
32 var myFormPanel = new Ext.form.Panel({
33 title: 'Client and routing info',
38 fieldLabel: 'Port of loading',
41 fieldLabel: 'Port of discharge',
42 name: 'portOfDischarge'
45 myFormPanel.{@link Ext.form.Panel#getForm getForm}().{@link Ext.form.Basic#load load}({
46 url: '/getRoutingInfo.php',
48 consignmentRef: myConsignmentRef
50 failure: function(form, action) {
51 Ext.Msg.alert("Load failed", action.result.errorMessage);
55 * a <b>success response</b> packet may look like this:</p><pre><code>
59 clientName: "Fred. Olsen Lines",
61 portOfDischarge: "OSL"
64 * while a <b>failure response</b> packet may look like this:</p><pre><code>
67 errorMessage: "Consignment reference not found"
69 * <p>Other data may be placed into the response for processing the {@link Ext.form.Basic Form}'s
70 * callback or event handler methods. The object decoded from this JSON is available in the
71 * {@link Ext.form.action.Action#result result} property.</p>
73 Ext.define('Ext.form.action.Load', {
74 extend:'Ext.form.action.Action',
75 requires: ['Ext.data.Connection'],
76 alternateClassName: 'Ext.form.Action.Load',
77 alias: 'formaction.load',
85 Ext.Ajax.request(Ext.apply(
86 this.createCallback(),
88 method: this.getMethod(),
90 headers: this.headers,
91 params: this.getParams()
99 onSuccess: function(response){
100 var result = this.processResponse(response),
102 if (result === true || !result.success || !result.data) {
103 this.failureType = Ext.form.action.Action.LOAD_FAILURE;
104 form.afterAction(this, false);
108 form.setValues(result.data);
109 form.afterAction(this, true);
115 handleResponse: function(response) {
116 var reader = this.form.reader,
119 rs = reader.read(response);
120 data = rs.records && rs.records[0] ? rs.records[0].data : null;
122 success : rs.success,
126 return Ext.decode(response.responseText);