BusinessMetadataAttrTableLayoutView.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. define([ "require", "backbone", "hbs!tmpl/business_metadata/BusinessMetadataAttrTableLayoutView_tmpl", "collection/VEntityList" ], function(require, Backbone, BusinessMetadataAttrTableLayoutView_tmpl, VEntityList) {
  2. "use strict";
  3. var BusinessMetadataAttrTableLayoutView = Backbone.Marionette.LayoutView.extend({
  4. _viewName: "BusinessMetadataAttrTableLayoutView",
  5. template: BusinessMetadataAttrTableLayoutView_tmpl,
  6. regions: {
  7. RBusinessMetadataAttrTableLayoutView: "#r_businessMetadataAttrTableLayoutView",
  8. RModal: "#r_modal"
  9. },
  10. ui: {
  11. attributeEdit: "[data-id='attributeEdit']",
  12. addAttribute: '[data-id="addAttribute"]',
  13. businessMetadataAttrPage: "[data-id='businessMetadataAttrPage']",
  14. businessMetadataAttrPageTitle: "[data-id='businessMetadataAttrPageTitle']",
  15. businessMetadataDetailPage: "[data-id='businessMetadataDetailPage']"
  16. },
  17. events: function() {
  18. var events = {};
  19. return events["click " + this.ui.attributeEdit] = "onEditAttr", events["click " + this.ui.addAttribute] = "onEditAttr",
  20. events;
  21. },
  22. initialize: function(options) {
  23. _.extend(this, _.pick(options, "guid", "model", "typeHeaders", "businessMetadataDefCollection", "entityDefCollection")),
  24. this.businessMetadataAttr = new VEntityList(this.model.get("attributeDefs") || []),
  25. this.commonTableOptions = {
  26. collection: this.businessMetadataAttr,
  27. includeFilter: !1,
  28. includePagination: !1,
  29. includePageSize: !1,
  30. includeAtlasTableSorting: !0,
  31. includeFooterRecords: !1,
  32. gridOpts: {
  33. className: "table table-hover backgrid table-quickMenu",
  34. emptyText: "No records found!"
  35. },
  36. filterOpts: {},
  37. paginatorOpts: {}
  38. }, this.showDetails = !0;
  39. },
  40. onRender: function() {
  41. this.renderTableLayoutView(), this.toggleBusinessMetadataDetailsAttrView();
  42. },
  43. bindEvents: function() {},
  44. toggleBusinessMetadataDetailsAttrView: function() {
  45. var that = this;
  46. that.showDetails ? (that.ui.businessMetadataAttrPage.hide(), that.ui.businessMetadataDetailPage.show()) : (that.ui.businessMetadataAttrPage.show(),
  47. that.ui.businessMetadataDetailPage.hide());
  48. },
  49. onEditAttr: function(e) {
  50. var that = this, isAttrEdit = !1, selectedBusinessMetadata = that.model, attrributes = selectedBusinessMetadata ? selectedBusinessMetadata.get("attributeDefs") : null, attrName = e.target.dataset.name ? e.target.dataset.name : null, attrDetails = {
  51. name: attrName
  52. };
  53. "attributeEdit" == e.target.dataset.action && (isAttrEdit = !0), selectedBusinessMetadata && (that.newAttr = !isAttrEdit,
  54. _.each(attrributes, function(attrObj) {
  55. attrObj.name === attrName && (attrDetails = $.extend(!0, {}, attrObj), attrObj.typeName.includes("array") && (attrDetails.typeName = attrObj.typeName.replace("array<", "").replace(">", ""),
  56. attrDetails.multiValued = !0));
  57. }), this.showDetails = !1, that.toggleBusinessMetadataDetailsAttrView(), require([ "views/business_metadata/CreateBusinessMetadataLayoutView" ], function(CreateBusinessMetadataLayoutView) {
  58. that.view = new CreateBusinessMetadataLayoutView({
  59. onEditCallback: function() {
  60. enumDefCollection.fetch({
  61. reset: !0
  62. }), that.businessMetadataAttr.reset(that.model.get("attributeDefs"));
  63. },
  64. onUpdateBusinessMetadata: function(fetch) {
  65. that.showDetails = !0, that.toggleBusinessMetadataDetailsAttrView(), fetch && that.entityDefCollection.fetch({
  66. silent: !0
  67. });
  68. },
  69. parent: that.$el,
  70. businessMetadataDefCollection: that.businessMetadataDefCollection,
  71. enumDefCollection: enumDefCollection,
  72. isAttrEdit: isAttrEdit,
  73. attrDetails: attrDetails,
  74. typeHeaders: typeHeaders,
  75. selectedBusinessMetadata: that.model,
  76. guid: that.guid,
  77. isNewAttr: that.newAttr
  78. }), isAttrEdit ? that.ui.businessMetadataAttrPageTitle.text("Update Attribute of: " + selectedBusinessMetadata.get("name")) : that.ui.businessMetadataAttrPageTitle.text("Add Business Metadata Attribute for: " + selectedBusinessMetadata.get("name")),
  79. that.RModal.show(that.view);
  80. }));
  81. },
  82. renderTableLayoutView: function() {
  83. var that = this;
  84. require([ "utils/TableLayout" ], function(TableLayout) {
  85. var cols = new Backgrid.Columns(that.getBusinessMetadataTableColumns());
  86. that.RBusinessMetadataAttrTableLayoutView.show(new TableLayout(_.extend({}, that.commonTableOptions, {
  87. columns: cols
  88. })));
  89. });
  90. },
  91. getBusinessMetadataTableColumns: function() {
  92. return this.businessMetadataAttr.constructor.getTableCols({
  93. name: {
  94. label: "Attribute Name",
  95. cell: "html",
  96. editable: !1,
  97. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  98. fromRaw: function(rawValue, model) {
  99. return _.escape(model.get("name"));
  100. }
  101. })
  102. },
  103. typeName: {
  104. label: "Type Name",
  105. cell: "html",
  106. editable: !1,
  107. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  108. fromRaw: function(rawValue, model) {
  109. return _.escape(model.get("typeName"));
  110. }
  111. })
  112. },
  113. searchWeight: {
  114. label: "Search Weight",
  115. cell: "String",
  116. editable: !1
  117. },
  118. enableMultipleValue: {
  119. label: "Enable Multivalues",
  120. cell: "html",
  121. editable: !1,
  122. sortable: !1,
  123. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  124. fromRaw: function(rawValue, model) {
  125. var enableMultipleValue = "";
  126. return model.get("typeName").indexOf("array<") > -1 && (enableMultipleValue = "checked"),
  127. '<input type="checkbox" class="form-check-input multi-value-select" data-id="multiValueSelectStatus" ' + enableMultipleValue + ' disabled="disabled">';
  128. }
  129. })
  130. },
  131. maxStrLength: {
  132. label: "Max Length",
  133. cell: "html",
  134. editable: !1,
  135. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  136. fromRaw: function(rawValue, model) {
  137. var maxString = "NA";
  138. return model.get("typeName").indexOf("string") > -1 && (maxString = model.get("options").maxStrLength || maxString),
  139. maxString;
  140. }
  141. })
  142. },
  143. applicableEntityTypes: {
  144. label: "Entity Type(s)",
  145. cell: "html",
  146. editable: !1,
  147. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  148. fromRaw: function(rawValue, model) {
  149. var options = model.get("options");
  150. if (options && options.applicableEntityTypes) {
  151. var applicableEntityTypes = "", attrEntityTypes = JSON.parse(options.applicableEntityTypes);
  152. return _.each(attrEntityTypes, function(values) {
  153. applicableEntityTypes += '<label class="btn btn-action btn-xs btn-blue no-pointer">' + values + "</label>";
  154. }), applicableEntityTypes;
  155. }
  156. }
  157. })
  158. },
  159. tool: {
  160. label: "Action",
  161. cell: "html",
  162. editable: !1,
  163. sortable: !1,
  164. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  165. fromRaw: function(rawValue, model) {
  166. return '<div class="btn btn-action btn-sm" data-id="attributeEdit" data-action="attributeEdit" data-name="' + model.get("name") + '">Edit</div>';
  167. }
  168. })
  169. }
  170. }, this.businessMetadataAttr);
  171. }
  172. });
  173. return BusinessMetadataAttrTableLayoutView;
  174. });