Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

datasource-function.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. Copyright (c) 2010, Yahoo! Inc. All rights reserved.
  3. Code licensed under the BSD License:
  4. http://developer.yahoo.com/yui/license.html
  5. version: 3.4.0
  6. build: nightly
  7. */
  8. YUI.add('datasource-function', function(Y) {
  9. /**
  10. * Provides a DataSource implementation which can be used to retrieve data from a custom function.
  11. *
  12. * @module datasource
  13. * @submodule datasource-function
  14. */
  15. /**
  16. * Function subclass for the DataSource Utility.
  17. * @class DataSource.Function
  18. * @extends DataSource.Local
  19. * @constructor
  20. */
  21. var LANG = Y.Lang,
  22. DSFn = function() {
  23. DSFn.superclass.constructor.apply(this, arguments);
  24. };
  25. /////////////////////////////////////////////////////////////////////////////
  26. //
  27. // DataSource.Function static properties
  28. //
  29. /////////////////////////////////////////////////////////////////////////////
  30. Y.mix(DSFn, {
  31. /**
  32. * Class name.
  33. *
  34. * @property NAME
  35. * @type String
  36. * @static
  37. * @final
  38. * @value "dataSourceFunction"
  39. */
  40. NAME: "dataSourceFunction",
  41. /////////////////////////////////////////////////////////////////////////////
  42. //
  43. // DataSource.Function Attributes
  44. //
  45. /////////////////////////////////////////////////////////////////////////////
  46. ATTRS: {
  47. /**
  48. * @attribute source
  49. * @description Pointer to live data.
  50. * @type MIXED
  51. * @default null
  52. */
  53. source: {
  54. validator: LANG.isFunction
  55. }
  56. }
  57. });
  58. Y.extend(DSFn, Y.DataSource.Local, {
  59. /**
  60. * Passes query string to IO. Fires <code>response</code> event when
  61. * response is received asynchronously.
  62. *
  63. * @method _defRequestFn
  64. * @param e {Event.Facade} Event Facade with the following properties:
  65. * <dl>
  66. * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
  67. * <dt>request (Object)</dt> <dd>The request.</dd>
  68. * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
  69. * <dl>
  70. * <dt>success (Function)</dt> <dd>Success handler.</dd>
  71. * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
  72. * </dl>
  73. * </dd>
  74. * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
  75. * </dl>
  76. * @protected
  77. */
  78. _defRequestFn: function(e) {
  79. var fn = this.get("source"),
  80. payload = e.details[0];
  81. if (fn) {
  82. try {
  83. payload.data = fn(e.request, this, e);
  84. } catch (ex) {
  85. payload.error = ex;
  86. }
  87. } else {
  88. payload.error = new Error("Function data failure");
  89. }
  90. this.fire("data", payload);
  91. return e.tId;
  92. }
  93. });
  94. Y.DataSource.Function = DSFn;
  95. }, '3.4.0' ,{requires:['datasource-local']});