FacetDataObject.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: BI Dashboard
  6. *| (C) Copyright IBM Corp. 2017
  7. *|
  8. *| US Government Users Restricted Rights - Use, duplication or disclosure
  9. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *+------------------------------------------------------------------------+
  11. */
  12. define(['underscore', '../lib/@waca/core-client/js/core-client/ui/core/Class'], function (_, BaseClass) {
  13. var FacetClass = BaseClass.extend({
  14. _dataObject: null,
  15. init: function init(object) {
  16. FacetClass.inherited('init', this, arguments);
  17. this._dataObject = object;
  18. Object.defineProperty(this, 'displayValue', {
  19. get: function get() {
  20. if (object === undefined || object === null) {
  21. return null;
  22. } else {
  23. if (this._dataObject.hasOwnProperty('d')) {
  24. return this._dataObject.d;
  25. } else if (this._dataObject.hasOwnProperty('u')) {
  26. return this._dataObject.u;
  27. } else {
  28. return this._dataObject;
  29. }
  30. }
  31. }
  32. });
  33. Object.defineProperty(this, 'useValue', {
  34. get: function get() {
  35. if (object === undefined || object === null) {
  36. return null;
  37. } else {
  38. if (this._dataObject.hasOwnProperty('u')) {
  39. return this._dataObject.u;
  40. } else if (this._dataObject.hasOwnProperty('d')) {
  41. return this._dataObject.d;
  42. } else {
  43. return this._dataObject;
  44. }
  45. }
  46. }
  47. });
  48. Object.defineProperty(this, 'parent', {
  49. get: function get() {
  50. if (object === undefined || object === null) {
  51. return null;
  52. } else {
  53. return this._dataObject.hasOwnProperty('p') ? new FacetClass(object.p) : null;
  54. }
  55. }
  56. });
  57. },
  58. getParent: function getParent() {
  59. return this.parent;
  60. },
  61. toJSONObject: function toJSONObject() {
  62. var parent = this.parent ? {
  63. 'parent': { 'useValue': this.parent.useValue }
  64. } : {};
  65. return _.extend({ 'displayValue': this.displayValue, 'useValue': this.useValue }, parent);
  66. }
  67. });
  68. return FacetClass;
  69. });
  70. //# sourceMappingURL=FacetDataObject.js.map