Source: src/data/model/Base.js

  1. /* Copyright (c) 2015-present The Open Source Geospatial Foundation
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. /**
  17. * @class GeoExt.data.model.Base
  18. */
  19. Ext.define('GeoExt.data.model.Base', {
  20. extend: 'Ext.data.Model',
  21. requires: ['Ext.data.identifier.Uuid'],
  22. identifier: 'uuid',
  23. schema: {
  24. id: 'geoext-schema',
  25. namespace: 'GeoExt.data.model',
  26. },
  27. inheritableStatics: {
  28. /**
  29. * Loads a record from a provided data structure initializing the models
  30. * associations. Simply calling Ext.create will not utilize the models
  31. * configured reader and effectively sidetrack associations configs.
  32. * This static helper method makes sure associations are initialized
  33. * properly and are available with the returned record.
  34. *
  35. * Be aware that the provided data may be modified by the models reader
  36. * initializing associations.
  37. *
  38. * @param {Object} data The data to create the record with.
  39. * @return {GeoExt.data.model.Base|undefined} The created record, or undefined if unsuccessful.
  40. * @memberof GeoExt.data.model.Base
  41. * @static
  42. */
  43. loadRawData: function (data) {
  44. const me = this;
  45. const result = me
  46. .getProxy()
  47. .getReader()
  48. .readRecords(data || {});
  49. const records = result.getRecords();
  50. const success = result.getSuccess();
  51. if (success && records.length) {
  52. return records[0];
  53. }
  54. },
  55. },
  56. });