-</code></pre>
- * a <b>success response</b> packet may look like this:</p><pre><code>
-{
- success: true,
- data: {
- clientName: "Fred. Olsen Lines",
- portOfLoading: "FXT",
- portOfDischarge: "OSL"
- }
-}</code></pre>
- * while a <b>failure response</b> packet may look like this:</p><pre><code>
-{
- success: false,
- errorMessage: "Consignment reference not found"
-}</code></pre>
- * <p>Other data may be placed into the response for processing the {@link Ext.form.BasicForm Form}'s
- * callback or event handler methods. The object decoded from this JSON is available in the
- * {@link Ext.form.Action#result result} property.</p>
- */
-Ext.form.Action.Load = function(form, options){
- Ext.form.Action.Load.superclass.constructor.call(this, form, options);
- this.reader = this.form.reader;
-};
-
-Ext.extend(Ext.form.Action.Load, Ext.form.Action, {
- // private
- type : 'load',
-
- // private
- run : function(){
- Ext.Ajax.request(Ext.apply(
- this.createCallback(this.options), {
- method:this.getMethod(),
- url:this.getUrl(false),
- headers: this.options.headers,
- params:this.getParams()
- }));
- },
-
- // private
- success : function(response){
- var result = this.processResponse(response);
- if(result === true || !result.success || !result.data){
- this.failureType = Ext.form.Action.LOAD_FAILURE;
- this.form.afterAction(this, false);
- return;
- }
- this.form.clearInvalid();
- this.form.setValues(result.data);
- this.form.afterAction(this, true);
- },
-
- // private
- handleResponse : function(response){
- if(this.form.reader){
- var rs = this.form.reader.read(response);
- var data = rs.records && rs.records[0] ? rs.records[0].data : null;
- return {
- success : rs.success,
- data : data
- };
- }
- return Ext.decode(response.responseText);
- }
-});
-
-
-
-<div id="cls-Ext.form.Action.DirectLoad"></div>/**
- * @class Ext.form.Action.DirectLoad
- * @extends Ext.form.Action.Load
- * Provides Ext.direct support for loading form data. This example illustrates usage
- * of Ext.Direct to load a submit a form through Ext.Direct.
- * <pre><code>
-var myFormPanel = new Ext.form.FormPanel({
- // configs for FormPanel
- title: 'Basic Information',
- border: false,
- padding: 10,
- buttons:[{
- text: 'Submit',
- handler: function(){
- basicInfo.getForm().submit({
- params: {
- uid: 5
- }
- });
- }
- }],
-
- // configs apply to child items
- defaults: {anchor: '100%'},
- defaultType: 'textfield',
- items: [
- // form fields go here
- ],
-
- // configs for BasicForm
- api: {
- load: Profile.getBasicInfo,
- // The server-side must mark the submit handler as a 'formHandler'
- submit: Profile.updateBasicInfo
- },
- paramOrder: ['uid']
-});
-
-// load the form
-myFormPanel.getForm().load({
- params: {
- uid: 5
- }
-});
- * </code></pre>
- */
-Ext.form.Action.DirectLoad = Ext.extend(Ext.form.Action.Load, {
- constructor: function(form, opts) {
- Ext.form.Action.DirectLoad.superclass.constructor.call(this, form, opts);
- },
- type: 'directload',
-
- run : function(){
- var args = this.getParams();
- args.push(this.success, this);
- this.form.api.load.apply(window, args);
- },
-
- getParams: function() {
- var buf = [], o = {};
- var bp = this.form.baseParams;
- var p = this.options.params;
- Ext.apply(o, p, bp);
- var paramOrder = this.form.paramOrder;
- if(paramOrder){
- for(var i = 0, len = paramOrder.length; i < len; i++){
- buf.push(o[paramOrder[i]]);
- }
- }else if(this.form.paramsAsHash){
- buf.push(o);
- }
- return buf;
- },
- // Direct actions have already been processed and therefore
- // we can directly set the result; Direct Actions do not have
- // a this.response property.
- processResponse: function(result) {
- this.result = result;
- return result;
- }
-});
-
-<div id="cls-Ext.form.Action.DirectSubmit"></div>/**
- * @class Ext.form.Action.DirectSubmit
- * @extends Ext.form.Action.Submit
- * Provides Ext.direct support for submitting form data.
- * See {@link Ext.form.Action.DirectLoad}.
- */
-Ext.form.Action.DirectSubmit = Ext.extend(Ext.form.Action.Submit, {
- constructor: function(form, opts) {
- Ext.form.Action.DirectSubmit.superclass.constructor.call(this, form, opts);
- },
- type: 'directsubmit',
- // override of Submit
- run : function(){
- var o = this.options;
- if(o.clientValidation === false || this.form.isValid()){
- // tag on any additional params to be posted in the
- // form scope
- this.success.params = this.getParams();
- this.form.api.submit(this.form.el.dom, this.success, this);
- }else if (o.clientValidation !== false){ // client validation failed
- this.failureType = Ext.form.Action.CLIENT_INVALID;
- this.form.afterAction(this, false);
- }
- },
-
- getParams: function() {
- var o = {};
- var bp = this.form.baseParams;
- var p = this.options.params;
- Ext.apply(o, p, bp);
- return o;
- },
- // Direct actions have already been processed and therefore
- // we can directly set the result; Direct Actions do not have
- // a this.response property.
- processResponse: function(result) {
- this.result = result;
- return result;
- }
-});
-
-
-Ext.form.Action.ACTION_TYPES = {
- 'load' : Ext.form.Action.Load,
- 'submit' : Ext.form.Action.Submit,
- 'directload': Ext.form.Action.DirectLoad,
- 'directsubmit': Ext.form.Action.DirectSubmit
-};
-</pre> \r
-</body>\r
-</html>
\ No newline at end of file