RemotingMethod.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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-direct-RemotingMethod'>/**
  19. </span> * Small utility class used internally to represent a Direct method.
  20. * @private
  21. */
  22. Ext.define('Ext.direct.RemotingMethod', {
  23. constructor: function(config){
  24. var me = this,
  25. params = Ext.isDefined(config.params) ? config.params : config.len,
  26. name, pLen, p, param;
  27. me.name = config.name;
  28. me.formHandler = config.formHandler;
  29. if (Ext.isNumber(params)) {
  30. // given only the number of parameters
  31. me.len = params;
  32. me.ordered = true;
  33. } else {
  34. /*
  35. * Given an array of either
  36. * a) String
  37. * b) Objects with a name property. We may want to encode extra info in here later
  38. */
  39. me.params = [];
  40. pLen = params.length;
  41. for (p = 0; p &lt; pLen; p++) {
  42. param = params[p];
  43. name = Ext.isObject(param) ? param.name : param;
  44. me.params.push(name);
  45. }
  46. }
  47. },
  48. getArgs: function(params, paramOrder, paramsAsHash){
  49. var args = [],
  50. i,
  51. len;
  52. if (this.ordered) {
  53. if (this.len &gt; 0) {
  54. // If a paramOrder was specified, add the params into the argument list in that order.
  55. if (paramOrder) {
  56. for (i = 0, len = paramOrder.length; i &lt; len; i++) {
  57. args.push(params[paramOrder[i]]);
  58. }
  59. } else if (paramsAsHash) {
  60. // If paramsAsHash was specified, add all the params as a single object argument.
  61. args.push(params);
  62. }
  63. }
  64. } else {
  65. args.push(params);
  66. }
  67. return args;
  68. },
  69. <span id='Ext-direct-RemotingMethod-method-getCallData'> /**
  70. </span> * Takes the arguments for the Direct function and splits the arguments
  71. * from the scope and the callback.
  72. * @param {Array} args The arguments passed to the direct call
  73. * @return {Object} An object with 3 properties, args, callback &amp; scope.
  74. */
  75. getCallData: function(args){
  76. var me = this,
  77. data = null,
  78. len = me.len,
  79. params = me.params,
  80. callback,
  81. scope,
  82. name;
  83. if (me.ordered) {
  84. callback = args[len];
  85. scope = args[len + 1];
  86. if (len !== 0) {
  87. data = args.slice(0, len);
  88. }
  89. } else {
  90. data = Ext.apply({}, args[0]);
  91. callback = args[1];
  92. scope = args[2];
  93. // filter out any non-existent properties
  94. for (name in data) {
  95. if (data.hasOwnProperty(name)) {
  96. if (!Ext.Array.contains(params, name)) {
  97. delete data[name];
  98. }
  99. }
  100. }
  101. }
  102. return {
  103. data: data,
  104. callback: callback,
  105. scope: scope
  106. };
  107. }
  108. });
  109. </pre>
  110. </body>
  111. </html>