Load.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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> * A class which handles loading of data from a server into the Fields of an {@link Ext.form.Basic}.
  20. *
  21. * Instances of this class are only created by a {@link Ext.form.Basic Form} when {@link Ext.form.Basic#load load}ing.
  22. *
  23. * ## Response Packet Criteria
  24. *
  25. * A response packet **must** contain:
  26. *
  27. * - **`success`** property : Boolean
  28. * - **`data`** property : Object
  29. *
  30. * The `data` property contains the values of Fields to load. The individual value object for each Field is passed to
  31. * the Field's {@link Ext.form.field.Field#setValue setValue} method.
  32. *
  33. * ## JSON Packets
  34. *
  35. * By default, response packets are assumed to be JSON, so for the following form load call:
  36. *
  37. * var myFormPanel = new Ext.form.Panel({
  38. * title: 'Client and routing info',
  39. * renderTo: Ext.getBody(),
  40. * defaults: {
  41. * xtype: 'textfield'
  42. * },
  43. * items: [{
  44. * fieldLabel: 'Client',
  45. * name: 'clientName'
  46. * }, {
  47. * fieldLabel: 'Port of loading',
  48. * name: 'portOfLoading'
  49. * }, {
  50. * fieldLabel: 'Port of discharge',
  51. * name: 'portOfDischarge'
  52. * }]
  53. * });
  54. * myFormPanel.{@link Ext.form.Panel#getForm getForm}().{@link Ext.form.Basic#load load}({
  55. * url: '/getRoutingInfo.php',
  56. * params: {
  57. * consignmentRef: myConsignmentRef
  58. * },
  59. * failure: function(form, action) {
  60. * Ext.Msg.alert(&quot;Load failed&quot;, action.result.errorMessage);
  61. * }
  62. * });
  63. *
  64. * a **success response** packet may look like this:
  65. *
  66. * {
  67. * success: true,
  68. * data: {
  69. * clientName: &quot;Fred. Olsen Lines&quot;,
  70. * portOfLoading: &quot;FXT&quot;,
  71. * portOfDischarge: &quot;OSL&quot;
  72. * }
  73. * }
  74. *
  75. * while a **failure response** packet may look like this:
  76. *
  77. * {
  78. * success: false,
  79. * errorMessage: &quot;Consignment reference not found&quot;
  80. * }
  81. *
  82. * Other data may be placed into the response for processing the {@link Ext.form.Basic Form}'s callback or event handler
  83. * methods. The object decoded from this JSON is available in the {@link Ext.form.action.Action#result result} property.
  84. */
  85. Ext.define('Ext.form.action.Load', {
  86. extend:'Ext.form.action.Action',
  87. requires: ['Ext.data.Connection'],
  88. alternateClassName: 'Ext.form.Action.Load',
  89. alias: 'formaction.load',
  90. type: 'load',
  91. <span id='Ext-form-action-Load-method-run'> /**
  92. </span> * @private
  93. */
  94. run: function() {
  95. Ext.Ajax.request(Ext.apply(
  96. this.createCallback(),
  97. {
  98. method: this.getMethod(),
  99. url: this.getUrl(),
  100. headers: this.headers,
  101. params: this.getParams()
  102. }
  103. ));
  104. },
  105. <span id='Ext-form-action-Load-method-onSuccess'> /**
  106. </span> * @private
  107. */
  108. onSuccess: function(response){
  109. var result = this.processResponse(response),
  110. form = this.form;
  111. if (result === true || !result.success || !result.data) {
  112. this.failureType = Ext.form.action.Action.LOAD_FAILURE;
  113. form.afterAction(this, false);
  114. return;
  115. }
  116. form.clearInvalid();
  117. form.setValues(result.data);
  118. form.afterAction(this, true);
  119. },
  120. <span id='Ext-form-action-Load-method-handleResponse'> /**
  121. </span> * @private
  122. */
  123. handleResponse: function(response) {
  124. var reader = this.form.reader,
  125. rs, data;
  126. if (reader) {
  127. rs = reader.read(response);
  128. data = rs.records &amp;&amp; rs.records[0] ? rs.records[0].data : null;
  129. return {
  130. success : rs.success,
  131. data : data
  132. };
  133. }
  134. return Ext.decode(response.responseText);
  135. }
  136. });
  137. </pre>
  138. </body>
  139. </html>