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

https://bitbucket.org/srogerf/javascript · HTML · 152 lines · 139 code · 13 blank · 0 comment · 0 complexity · a6324a6946bc21cf4b1345f02b4ee296 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-DirectLoad'>/**
  19. </span> * @class Ext.form.action.DirectLoad
  20. * @extends Ext.form.action.Load
  21. * &lt;p&gt;Provides {@link Ext.direct.Manager} support for loading form data.&lt;/p&gt;
  22. * &lt;p&gt;This example illustrates usage of Ext.direct.Direct to &lt;b&gt;load&lt;/b&gt; a form through Ext.Direct.&lt;/p&gt;
  23. * &lt;pre&gt;&lt;code&gt;
  24. var myFormPanel = new Ext.form.Panel({
  25. // configs for FormPanel
  26. title: 'Basic Information',
  27. renderTo: document.body,
  28. width: 300, height: 160,
  29. padding: 10,
  30. // configs apply to child items
  31. defaults: {anchor: '100%'},
  32. defaultType: 'textfield',
  33. items: [{
  34. fieldLabel: 'Name',
  35. name: 'name'
  36. },{
  37. fieldLabel: 'Email',
  38. name: 'email'
  39. },{
  40. fieldLabel: 'Company',
  41. name: 'company'
  42. }],
  43. // configs for BasicForm
  44. api: {
  45. // The server-side method to call for load() requests
  46. load: Profile.getBasicInfo,
  47. // The server-side must mark the submit handler as a 'formHandler'
  48. submit: Profile.updateBasicInfo
  49. },
  50. // specify the order for the passed params
  51. paramOrder: ['uid', 'foo']
  52. });
  53. // load the form
  54. myFormPanel.getForm().load({
  55. // pass 2 arguments to server side getBasicInfo method (len=2)
  56. params: {
  57. foo: 'bar',
  58. uid: 34
  59. }
  60. });
  61. * &lt;/code&gt;&lt;/pre&gt;
  62. * The data packet sent to the server will resemble something like:
  63. * &lt;pre&gt;&lt;code&gt;
  64. [
  65. {
  66. &quot;action&quot;:&quot;Profile&quot;,&quot;method&quot;:&quot;getBasicInfo&quot;,&quot;type&quot;:&quot;rpc&quot;,&quot;tid&quot;:2,
  67. &quot;data&quot;:[34,&quot;bar&quot;] // note the order of the params
  68. }
  69. ]
  70. * &lt;/code&gt;&lt;/pre&gt;
  71. * The form will process a data packet returned by the server that is similar
  72. * to the following format:
  73. * &lt;pre&gt;&lt;code&gt;
  74. [
  75. {
  76. &quot;action&quot;:&quot;Profile&quot;,&quot;method&quot;:&quot;getBasicInfo&quot;,&quot;type&quot;:&quot;rpc&quot;,&quot;tid&quot;:2,
  77. &quot;result&quot;:{
  78. &quot;success&quot;:true,
  79. &quot;data&quot;:{
  80. &quot;name&quot;:&quot;Fred Flintstone&quot;,
  81. &quot;company&quot;:&quot;Slate Rock and Gravel&quot;,
  82. &quot;email&quot;:&quot;fred.flintstone@slaterg.com&quot;
  83. }
  84. }
  85. }
  86. ]
  87. * &lt;/code&gt;&lt;/pre&gt;
  88. */
  89. Ext.define('Ext.form.action.DirectLoad', {
  90. extend:'Ext.form.action.Load',
  91. requires: ['Ext.direct.Manager'],
  92. alternateClassName: 'Ext.form.Action.DirectLoad',
  93. alias: 'formaction.directload',
  94. type: 'directload',
  95. run: function() {
  96. this.form.api.load.apply(window, this.getArgs());
  97. },
  98. <span id='Ext-form-action-DirectLoad-method-getArgs'> /**
  99. </span> * @private
  100. * Build the arguments to be sent to the Direct call.
  101. * @return Array
  102. */
  103. getArgs: function() {
  104. var me = this,
  105. args = [],
  106. form = me.form,
  107. paramOrder = form.paramOrder,
  108. params = me.getParams(),
  109. i, len;
  110. // If a paramOrder was specified, add the params into the argument list in that order.
  111. if (paramOrder) {
  112. for (i = 0, len = paramOrder.length; i &lt; len; i++) {
  113. args.push(params[paramOrder[i]]);
  114. }
  115. }
  116. // If paramsAsHash was specified, add all the params as a single object argument.
  117. else if (form.paramsAsHash) {
  118. args.push(params);
  119. }
  120. // Add the callback and scope to the end of the arguments list
  121. args.push(me.onSuccess, me);
  122. return args;
  123. },
  124. // Direct actions have already been processed and therefore
  125. // we can directly set the result; Direct Actions do not have
  126. // a this.response property.
  127. processResponse: function(result) {
  128. return (this.result = result);
  129. },
  130. onSuccess: function(result, trans) {
  131. if (trans.type == Ext.direct.Manager.self.exceptions.SERVER) {
  132. result = {};
  133. }
  134. this.callParent([result]);
  135. }
  136. });
  137. </pre>
  138. </body>
  139. </html>