Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

132 rindas
2.1 KiB

  1. define([
  2. ], function (
  3. ) {
  4. return {
  5. type: 'syncer',
  6. o: {
  7. components: []
  8. },
  9. oSelf: {
  10. components: []
  11. },
  12. reset: function () {
  13. this.o = {
  14. components: []
  15. };
  16. this.oSelf = {
  17. components: []
  18. };
  19. },
  20. get: function (self) {
  21. var o = this.o;
  22. if (self)
  23. o = this.oSelf;
  24. var keys = Object.keys(o);
  25. if (o.components.length == 0) {
  26. if (keys.length == 1)
  27. return null;
  28. else
  29. delete o.components;
  30. }
  31. o.id = this.obj.id;
  32. return o;
  33. },
  34. set: function (self, cpnType, property, value) {
  35. var o = this.o;
  36. if (self)
  37. o = this.oSelf;
  38. if (cpnType) {
  39. var cpn = o.components.find(c => (c.type == cpnType))
  40. if (!cpn) {
  41. cpn = {
  42. type: cpnType
  43. };
  44. o.components.push(cpn);
  45. }
  46. cpn[property] = value;
  47. } else {
  48. o[property] = value;
  49. }
  50. },
  51. setObject: function (self, cpnType, object, property, value) {
  52. var o = this.o;
  53. if (self)
  54. o = this.oSelf;
  55. var cpn = o.components.find(c => (c.type == cpnType))
  56. if (!cpn) {
  57. cpn = {
  58. type: cpnType
  59. };
  60. o.components.push(cpn);
  61. }
  62. var obj = cpn[object];
  63. if (!obj) {
  64. obj = {};
  65. cpn[object] = obj;
  66. }
  67. obj[property] = value;
  68. },
  69. setArray: function (self, cpnType, property, value, noDuplicate) {
  70. var o = this.o;
  71. if (self)
  72. o = this.oSelf;
  73. var cpn = o.components.find(c => (c.type == cpnType))
  74. if (!cpn) {
  75. cpn = {
  76. type: cpnType
  77. };
  78. o.components.push(cpn);
  79. }
  80. if (cpn[property] == null)
  81. cpn[property] = [];
  82. if ((noDuplicate) && (cpn[property].find(f => (f == value))))
  83. return;
  84. cpn[property].push(value);
  85. },
  86. setSelfArray: function (self, property, value) {
  87. var o = this.o;
  88. if (self)
  89. o = this.oSelf;
  90. if (o[property] == null)
  91. o[property] = [];
  92. o[property].push(value);
  93. },
  94. delete: function (self, cpnType, property) {
  95. var o = this.o;
  96. if (self)
  97. o = this.oSelf;
  98. if (cpnType) {
  99. var cpn = o.components.find(c => (c.type == cpnType))
  100. if (!cpn)
  101. return;
  102. delete cpn[property];
  103. } else {
  104. delete o[property];
  105. }
  106. }
  107. };
  108. });