API Docs for: 3.17.2
Show:

File: datasource/js/datasource-textschema.js

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