Dashboard sipadu mbip
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

datasource-arrayschema.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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-arrayschema', function(Y) {
  9. /**
  10. * Extends DataSource with schema-parsing on array data.
  11. *
  12. * @module datasource
  13. * @submodule datasource-arrayschema
  14. */
  15. /**
  16. * Adds schema-parsing to the DataSource Utility.
  17. * @class DataSourceArraySchema
  18. * @extends Plugin.Base
  19. */
  20. var DataSourceArraySchema = function() {
  21. DataSourceArraySchema.superclass.constructor.apply(this, arguments);
  22. };
  23. Y.mix(DataSourceArraySchema, {
  24. /**
  25. * The namespace for the plugin. This will be the property on the host which
  26. * references the plugin instance.
  27. *
  28. * @property NS
  29. * @type String
  30. * @static
  31. * @final
  32. * @value "schema"
  33. */
  34. NS: "schema",
  35. /**
  36. * Class name.
  37. *
  38. * @property NAME
  39. * @type String
  40. * @static
  41. * @final
  42. * @value "dataSourceArraySchema"
  43. */
  44. NAME: "dataSourceArraySchema",
  45. /////////////////////////////////////////////////////////////////////////////
  46. //
  47. // DataSourceArraySchema Attributes
  48. //
  49. /////////////////////////////////////////////////////////////////////////////
  50. ATTRS: {
  51. schema: {
  52. //value: {}
  53. }
  54. }
  55. });
  56. Y.extend(DataSourceArraySchema, Y.Plugin.Base, {
  57. /**
  58. * Internal init() handler.
  59. *
  60. * @method initializer
  61. * @param config {Object} Config object.
  62. * @private
  63. */
  64. initializer: function(config) {
  65. this.doBefore("_defDataFn", this._beforeDefDataFn);
  66. },
  67. /**
  68. * Parses raw data into a normalized response.
  69. *
  70. * @method _beforeDefDataFn
  71. * @param tId {Number} Unique transaction ID.
  72. * @param request {Object} The request.
  73. * @param callback {Object} The callback object with the following properties:
  74. * <dl>
  75. * <dt>success (Function)</dt> <dd>Success handler.</dd>
  76. * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
  77. * </dl>
  78. * @param data {Object} Raw data.
  79. * @protected
  80. */
  81. _beforeDefDataFn: function(e) {
  82. var data = (Y.DataSource.IO && (this.get("host") instanceof Y.DataSource.IO) && Y.Lang.isString(e.data.responseText)) ? e.data.responseText : e.data,
  83. response = Y.DataSchema.Array.apply.call(this, this.get("schema"), data),
  84. payload = e.details[0];
  85. // Default
  86. if (!response) {
  87. response = {
  88. meta: {},
  89. results: data
  90. };
  91. }
  92. payload.response = response;
  93. this.get("host").fire("response", payload);
  94. return new Y.Do.Halt("DataSourceArraySchema plugin halted _defDataFn");
  95. }
  96. });
  97. Y.namespace('Plugin').DataSourceArraySchema = DataSourceArraySchema;
  98. }, '3.4.0' ,{requires:['datasource-local', 'plugin', 'dataschema-array']});