Requires

Provides

Request.js

Make various requests to back end

License:
Public domain (http://unlicense.org).
  1. 24
  2. 25
  3. 26
  4. 27
  5. 28
  6. 29
  7. 30
  8. 31
  9. 32
  10. 33
  11. 34
  12. 35
  13. 36
  14. 37
  15. 38
  16. 39
  17. 40
  18. 41
  19. 42
  20. 43
  21. 44
  22. 45
  23. 46
  24. 47
  25. 48
  26. 49
  27. 50
  28. 51
  29. 52
  30. 53
  31. 54
  32. 55
  33. 56
  34. 57
  35. 58
  36. 59
  37. 60
  38. 61
  39. 62
  40. 63
  41. 64
  42. 65
  43. 66
  44. 67
  45. 68
  46. 69
  47. 70
  48. 71
  49. 72
  50. 73
  51. 74
  52. 75
  53. 76
  54. 77
  55. 78
  56. 79
  57. 80
  58. 81
  59. 82
  60. 83
  61. 84
  62. 85
  63. 86
  64. 87
  65. 88
  66. 89
  67. 90
  68. 91
  69. 92
  70. 93
  71. 94
  72. 95
  73. 96
  74. 97
  75. 98
  76. 99
  77. 100
  78. 101
  79. 102
  80. 103
  81. 104
  82. 105
  83. 106
  84. 107
  85. 108
  86. 109
  87. 110
  88. 111
  89. 112
  90. 113
  91. 114
  92. 115
  93. 116
  94. 117
  95. 118
  96. 119
  97. 120
  98. 121
  99. 122
  100. 123
  101. 124
  102. 125
  103. 126
  104. 127
  105. 128
  106. 129
  107. 130
  108. 131
  109. 132
LSD.Mixin.Request = new Class({ behaviour: '[action], [src], [href]', options: { request: { method: 'get' }, targetAction: 'update', states: { working: { enabler: 'busy', disabler: 'idle' } } }, initialize: function() { this.parent.apply(this, arguments); if (this.attributes.autosend) this.callChain(); }, send: function() { var args = Array.prototype.slice.call(arguments, 0); for (var i = 0, j = args.length, arg; i < j; i++) { var arg = args[i]; if (arg && (arg.call || arg.event)) { if (arg.call) var callback = arg; args.splice(i--, 1); j--; } else if (typeof arg == 'object') { if (!arg.url && !arg.data && !arg.method && !arg.data) args[i] = {data: arg}; } } var request = this.getRequest.apply(this, args); if (callback) request.addEvent('complete:once', callback); return request.send.apply(request, args); }, getRequest: function(opts) { var options = Object.append({data: this.getRequestData(), url: this.getRequestURL()}, this.options.request, {type: this.getRequestType(), method: this.getRequestMethod()}, opts); if (!this.request || this.request.type != options.type) { this.request = this[options.type == 'xhr' ? 'getXHRRequest' : 'getFormRequest'](options) if (!this.request.type) { this.request.type = options.type; if (!this.events._request) { var events = { request: 'onRequest', complete: 'onRequestComplete', success: 'onRequestSuccess', failure: 'onRequestFailure' }; this.events._request = this.bindEvents(events); } if (this.events.request) this.request.addEvents(this.events.request); if (this.events.$request) this.request.addEvents(this.events.$request); this.request.addEvents(this.events._request) } } return this.request; }, onRequestSuccess: function() { if (this.chainPhase == -1 && this.getCommandAction() == 'send') this.callOptionalChain.apply(this, arguments); }, onRequest: function() { this.busy(); }, onRequestComplete: function() { this.idle(); }, getRequestData: Macro.defaults(function() { return null; }), getXHRRequest: function(options) { return new Request.Auto(options); }, getFormRequest: function(options) { return new Request.Form(options); }, getRequestType: function() { return this.attributes.transport || this.options.request.type; }, getRequestMethod: function() { return this.attributes.method || this.options.request.method; }, getRequestURL: function() { return this.attributes.href || this.attributes.src || this.attributes.action; }, isRequestURLLocal: function(base, host) { if (!host) host = location.host; if (!base) base = location.pathname; var url = this.getRequestURL(); return (url.charAt(0) == "#") || url.match(new RegExp('(?:' + host + ')?' + base + '/?#')); }, getCommandAction: function() { if (!this.isRequestURLLocal()) return 'send'; } });