/ext-4.0.7/docs/source/Load.html

https://bitbucket.org/srogerf/javascript · 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. * &lt;p&gt;A class which handles loading of data from a server into the Fields of an {@link Ext.form.Basic}.&lt;/p&gt;
  22. * &lt;p&gt;Instances of this class are only created by a {@link Ext.form.Basic Form} when
  23. * {@link Ext.form.Basic#load load}ing.&lt;/p&gt;
  24. * &lt;p&gt;&lt;u&gt;&lt;b&gt;Response Packet Criteria&lt;/b&gt;&lt;/u&gt;&lt;/p&gt;
  25. * &lt;p&gt;A response packet &lt;b&gt;must&lt;/b&gt; contain:
  26. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  27. * &lt;li&gt;&lt;b&gt;&lt;code&gt;success&lt;/code&gt;&lt;/b&gt; property : Boolean&lt;/li&gt;
  28. * &lt;li&gt;&lt;b&gt;&lt;code&gt;data&lt;/code&gt;&lt;/b&gt; property : Object&lt;/li&gt;
  29. * &lt;div class=&quot;sub-desc&quot;&gt;The &lt;code&gt;data&lt;/code&gt; 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.&lt;/div&gt;&lt;/li&gt;
  32. * &lt;/ul&gt;&lt;/div&gt;
  33. * &lt;p&gt;&lt;u&gt;&lt;b&gt;JSON Packets&lt;/b&gt;&lt;/u&gt;&lt;/p&gt;
  34. * &lt;p&gt;By default, response packets are assumed to be JSON, so for the following form load call:&lt;pre&gt;&lt;code&gt;
  35. var 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. });
  48. myFormPanel.{@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(&quot;Load failed&quot;, action.result.errorMessage);
  55. }
  56. });
  57. &lt;/code&gt;&lt;/pre&gt;
  58. * a &lt;b&gt;success response&lt;/b&gt; packet may look like this:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
  59. {
  60. success: true,
  61. data: {
  62. clientName: &quot;Fred. Olsen Lines&quot;,
  63. portOfLoading: &quot;FXT&quot;,
  64. portOfDischarge: &quot;OSL&quot;
  65. }
  66. }&lt;/code&gt;&lt;/pre&gt;
  67. * while a &lt;b&gt;failure response&lt;/b&gt; packet may look like this:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
  68. {
  69. success: false,
  70. errorMessage: &quot;Consignment reference not found&quot;
  71. }&lt;/code&gt;&lt;/pre&gt;
  72. * &lt;p&gt;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.&lt;/p&gt;
  75. */
  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',
  81. type: 'load',
  82. <span id='Ext-form-action-Load-method-run'> /**
  83. </span> * @private
  84. */
  85. run: function() {
  86. Ext.Ajax.request(Ext.apply(
  87. this.createCallback(),
  88. {
  89. method: this.getMethod(),
  90. url: this.getUrl(),
  91. headers: this.headers,
  92. params: this.getParams()
  93. }
  94. ));
  95. },
  96. <span id='Ext-form-action-Load-method-onSuccess'> /**
  97. </span> * @private
  98. */
  99. onSuccess: function(response){
  100. var result = this.processResponse(response),
  101. form = this.form;
  102. if (result === true || !result.success || !result.data) {
  103. this.failureType = Ext.form.action.Action.LOAD_FAILURE;
  104. form.afterAction(this, false);
  105. return;
  106. }
  107. form.clearInvalid();
  108. form.setValues(result.data);
  109. form.afterAction(this, true);
  110. },
  111. <span id='Ext-form-action-Load-method-handleResponse'> /**
  112. </span> * @private
  113. */
  114. handleResponse: function(response) {
  115. var reader = this.form.reader,
  116. rs, data;
  117. if (reader) {
  118. rs = reader.read(response);
  119. data = rs.records &amp;&amp; rs.records[0] ? rs.records[0].data : null;
  120. return {
  121. success : rs.success,
  122. data : data
  123. };
  124. }
  125. return Ext.decode(response.responseText);
  126. }
  127. });
  128. </pre>
  129. </body>
  130. </html>