PageRenderTime 78ms CodeModel.GetById 37ms RepoModel.GetById 10ms app.codeStats 0ms

/ext-4.0.7/src/direct/RemotingMethod.js

https://bitbucket.org/srogerf/javascript
JavaScript | 90 lines | 51 code | 7 blank | 32 comment | 8 complexity | d146ab83155b0f64e955e865d42568c2 MD5 | raw file
  1. /*
  2. This file is part of Ext JS 4
  3. Copyright (c) 2011 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  7. If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
  8. */
  9. /**
  10. * Small utility class used internally to represent a Direct method.
  11. * @class Ext.direct.RemotingMethod
  12. * @ignore
  13. */
  14. Ext.define('Ext.direct.RemotingMethod', {
  15. constructor: function(config){
  16. var me = this,
  17. params = Ext.isDefined(config.params) ? config.params : config.len,
  18. name;
  19. me.name = config.name;
  20. me.formHandler = config.formHandler;
  21. if (Ext.isNumber(params)) {
  22. // given only the number of parameters
  23. me.len = params;
  24. me.ordered = true;
  25. } else {
  26. /*
  27. * Given an array of either
  28. * a) String
  29. * b) Objects with a name property. We may want to encode extra info in here later
  30. */
  31. me.params = [];
  32. Ext.each(params, function(param){
  33. name = Ext.isObject(param) ? param.name : param;
  34. me.params.push(name);
  35. });
  36. }
  37. },
  38. /**
  39. * Takes the arguments for the Direct function and splits the arguments
  40. * from the scope and the callback.
  41. * @param {Array} args The arguments passed to the direct call
  42. * @return {Object} An object with 3 properties, args, callback & scope.
  43. */
  44. getCallData: function(args){
  45. var me = this,
  46. data = null,
  47. len = me.len,
  48. params = me.params,
  49. callback,
  50. scope,
  51. name;
  52. if (me.ordered) {
  53. callback = args[len];
  54. scope = args[len + 1];
  55. if (len !== 0) {
  56. data = args.slice(0, len);
  57. }
  58. } else {
  59. data = Ext.apply({}, args[0]);
  60. callback = args[1];
  61. scope = args[2];
  62. // filter out any non-existent properties
  63. for (name in data) {
  64. if (data.hasOwnProperty(name)) {
  65. if (!Ext.Array.contains(params, name)) {
  66. delete data[name];
  67. }
  68. }
  69. }
  70. }
  71. return {
  72. data: data,
  73. callback: callback,
  74. scope: scope
  75. };
  76. }
  77. });