Ressource.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. var Ressource = (function () {
  2. function Ressource(obj) {
  3. this.id = obj.id;
  4. this.title = obj.title || obj.id;
  5. if (obj.children) {
  6. this.children = obj.children.map(Ressource.toRessource);
  7. }
  8. else {
  9. this.children = [];
  10. }
  11. this.collapseChildren = (obj === null || obj === void 0 ? void 0 : obj.collapseChildren) === undefined ? false : obj.collapseChildren;
  12. this.parent = obj.parent ? Ressource.toRessource(obj.parent) : undefined;
  13. this.height = obj.height;
  14. this.eventEditable = (obj === null || obj === void 0 ? void 0 : obj.eventEditable) === undefined ? true : obj.eventEditable;
  15. this.eventRessourceEditable = (obj === null || obj === void 0 ? void 0 : obj.eventRessourceEditable) === undefined ? true : obj.eventRessourceEditable;
  16. this.eventBgColor = obj.eventBgColor;
  17. this.selected = false;
  18. }
  19. Object.defineProperty(Ressource.prototype, "parentId", {
  20. get: function () {
  21. var _a;
  22. return ((_a = this.parent) === null || _a === void 0 ? void 0 : _a.id) || "";
  23. },
  24. enumerable: false,
  25. configurable: true
  26. });
  27. Object.defineProperty(Ressource.prototype, "depth", {
  28. get: function () {
  29. return this.parent ? this.parent.depth + 1 : 0;
  30. },
  31. enumerable: false,
  32. configurable: true
  33. });
  34. Object.defineProperty(Ressource.prototype, "show", {
  35. get: function () {
  36. return this.parent === undefined ? true : (this.parent.show && !this.parent.collapseChildren);
  37. },
  38. enumerable: false,
  39. configurable: true
  40. });
  41. Ressource.prototype.childOf = function (potentialParent) {
  42. return this.parent === undefined ? false : (this.parent.id === potentialParent.id || this.parent.childOf(potentialParent));
  43. };
  44. Ressource.prototype.toPlainObject = function (parent) {
  45. var _this = this;
  46. return {
  47. id: this.id,
  48. title: this.title,
  49. children: this.children.map(function (o) { return o.toPlainObject(_this); }),
  50. parent: parent
  51. };
  52. };
  53. Ressource.toRessource = function (obj) {
  54. if (obj instanceof Ressource) {
  55. return obj;
  56. }
  57. else {
  58. return new Ressource(obj);
  59. }
  60. };
  61. return Ressource;
  62. }());
  63. export { Ressource };
  64. export default Ressource;
  65. //# sourceMappingURL=Ressource.js.map