BusinessMetadataTableLayoutView.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. define([ "require", "backbone", "hbs!tmpl/business_metadata/BusinessMetadataTableLayoutView_tmpl", "utils/Utils", "utils/Messages" ], function(require, Backbone, BusinessMetadataTableLayoutView_tmpl, Utils, Messages) {
  2. "use strict";
  3. var BusinessMetadataTableLayoutView = Backbone.Marionette.LayoutView.extend({
  4. _viewName: "BusinessMetadataTableLayoutView",
  5. template: BusinessMetadataTableLayoutView_tmpl,
  6. regions: {
  7. RBusinessMetadataTableLayoutView: "#r_businessMetadataTableLayoutView",
  8. RModal: "#r_modal"
  9. },
  10. ui: {
  11. businessMetadataAttrPage: "[data-id='businessMetadataAttrPage']",
  12. businessMetadataAttrPageTitle: "[data-id='businessMetadataAttrPageTitle']",
  13. businessMetadataDetailPage: "[data-id='businessMetadataDetailPage']",
  14. createBusinessMetadata: "[data-id='createBusinessMetadata']",
  15. attributeEdit: "[data-id='attributeEdit']",
  16. addAttribute: '[data-id="addAttribute"]',
  17. businessMetadataAttrPageOk: '[data-id="businessMetadataAttrPageOk"]',
  18. colManager: "[data-id='colManager']",
  19. deleteBusinessMetadata: '[data-id="deleteBusinessMetadata"]'
  20. },
  21. events: function() {
  22. var events = {}, that = this;
  23. return events["click " + this.ui.createBusinessMetadata] = "onClickCreateBusinessMetadata",
  24. events["click " + this.ui.addAttribute] = "onEditAttr", events["click " + this.ui.attributeEdit] = "onEditAttr",
  25. events["click " + this.ui.deleteBusinessMetadata] = function(e) {
  26. that.guid = e.target.dataset.guid, that.deleteBusinessMetadataElement();
  27. }, events;
  28. },
  29. initialize: function(options) {
  30. _.extend(this, _.pick(options, "guid", "entity", "entityName", "attributeDefs", "typeHeaders", "businessMetadataDefCollection", "entityDefCollection", "businessMetadataAttr", "selectedBusinessMetadata")),
  31. this.limit = 10, this.newAttr = !1, this.commonTableOptions = {
  32. collection: this.businessMetadataDefCollection,
  33. includeFilter: !1,
  34. includePagination: !0,
  35. includeFooterRecords: !0,
  36. includePageSize: !0,
  37. includeGotoPage: !0,
  38. includeAtlasTableSorting: !0,
  39. includeTableLoader: !0,
  40. includeColumnManager: !0,
  41. gridOpts: {
  42. className: "table table-hover backgrid table-quickMenu",
  43. emptyText: "No records found!"
  44. },
  45. columnOpts: {
  46. opts: {
  47. initialColumnsVisible: null,
  48. saveState: !1
  49. },
  50. visibilityControlOpts: {
  51. buttonTemplate: _.template("<button class='btn btn-action btn-sm pull-right'>Columns&nbsp<i class='fa fa-caret-down'></i></button>")
  52. },
  53. el: this.ui.colManager
  54. },
  55. filterOpts: {},
  56. paginatorOpts: {}
  57. }, this.guid = null, this.showDetails = !0;
  58. },
  59. onRender: function() {
  60. this.toggleBusinessMetadataDetailsAttrView(), $.extend(this.businessMetadataDefCollection.queryParams, {
  61. count: this.limit
  62. }), this.businessMetadataDefCollection.fullCollection.sort({
  63. silent: !0
  64. }), this.renderTableLayoutView(), this.$(".tableOverlay").hide(), this.$(".auditTable").show(),
  65. this.businessMetadataDefCollection.comparator = function(model) {
  66. return -model.get("timestamp");
  67. };
  68. },
  69. toggleBusinessMetadataDetailsAttrView: function() {
  70. var that = this;
  71. that.showDetails ? (that.ui.businessMetadataAttrPage.hide(), that.ui.businessMetadataDetailPage.show()) : (that.ui.businessMetadataAttrPage.show(),
  72. that.ui.businessMetadataDetailPage.hide());
  73. },
  74. bindEvents: function() {},
  75. loaderStatus: function(isActive) {
  76. var that = this;
  77. isActive ? (that.$(".businessMetadata-attr-tableOverlay").show(), that.$(".business-metadata-attr-fontLoader").show()) : (that.$(".businessMetadata-attr-tableOverlay").hide(),
  78. that.$(".business-metadata-attr-fontLoader").hide());
  79. },
  80. onEditAttr: function(e) {
  81. var that = this, isAttrEdit = !(!e.currentTarget.dataset || "attributeEdit" !== e.currentTarget.dataset.id), guid = e.currentTarget.dataset && e.currentTarget.dataset.guid ? e.currentTarget.dataset.guid : null, selectedBusinessMetadata = that.businessMetadataDefCollection.fullCollection.findWhere({
  82. guid: guid
  83. }), attrributes = selectedBusinessMetadata ? selectedBusinessMetadata.get("attributeDefs") : null, attrName = e.currentTarget.dataset.name ? e.currentTarget.dataset.name : null, attrDetails = {
  84. name: attrName
  85. };
  86. selectedBusinessMetadata && (that.ui.businessMetadataAttrPageOk.text("Save"), that.newAttr = !(!e.currentTarget || "createAttr" !== e.currentTarget.dataset.action),
  87. that.guid = guid, _.each(attrributes, function(attrObj) {
  88. attrObj.name === attrName && (attrDetails = $.extend(!0, {}, attrObj), attrObj.typeName.includes("array") && (attrDetails.typeName = attrObj.typeName.replace("array<", "").replace(">", ""),
  89. attrDetails.multiValued = !0));
  90. }), that.showDetails = !1, that.toggleBusinessMetadataDetailsAttrView(), that.ui.businessMetadataAttrPageOk.attr("data-action", e.currentTarget.dataset.id),
  91. require([ "views/business_metadata/CreateBusinessMetadataLayoutView" ], function(CreateBusinessMetadataLayoutView) {
  92. that.view = new CreateBusinessMetadataLayoutView({
  93. onEditCallback: function() {
  94. that.businessMetadataDefCollection.fullCollection.sort({
  95. silent: !0
  96. }), that.renderTableLayoutView();
  97. },
  98. onUpdateBusinessMetadata: function(fetch) {
  99. that.showDetails = !0, that.toggleBusinessMetadataDetailsAttrView(), fetch && (enumDefCollection.fetch({
  100. reset: !0
  101. }), that.entityDefCollection.fetch({
  102. silent: !0
  103. }));
  104. },
  105. parent: that.$el,
  106. businessMetadataDefCollection: that.businessMetadataDefCollection,
  107. enumDefCollection: enumDefCollection,
  108. isAttrEdit: isAttrEdit,
  109. typeHeaders: typeHeaders,
  110. attrDetails: attrDetails,
  111. selectedBusinessMetadata: selectedBusinessMetadata,
  112. guid: that.guid,
  113. isNewAttr: that.newAttr
  114. }), isAttrEdit ? that.ui.businessMetadataAttrPageTitle.text("Update Attribute of: " + selectedBusinessMetadata.get("name")) : that.ui.businessMetadataAttrPageTitle.text("Add Business Metadata Attribute for: " + selectedBusinessMetadata.get("name")),
  115. that.RModal.show(that.view);
  116. }));
  117. },
  118. onClickCreateBusinessMetadata: function(e) {
  119. var that = this, isNewBusinessMetadata = !0;
  120. that.showDetails = !1, that.ui.businessMetadataAttrPageOk.text("Create"), that.ui.businessMetadataAttrPageOk.attr("data-action", "createBusinessMetadata"),
  121. that.ui.businessMetadataAttrPageTitle.text("Create Business Metadata"), that.toggleBusinessMetadataDetailsAttrView(),
  122. require([ "views/business_metadata/CreateBusinessMetadataLayoutView" ], function(CreateBusinessMetadataLayoutView) {
  123. that.view = new CreateBusinessMetadataLayoutView({
  124. onUpdateBusinessMetadata: function(fetch) {
  125. that.showDetails = !0, that.toggleBusinessMetadataDetailsAttrView(), fetch && (enumDefCollection.fetch({
  126. reset: !0
  127. }), that.entityDefCollection.fetch({
  128. silent: !0
  129. }));
  130. },
  131. businessMetadataDefCollection: that.businessMetadataDefCollection,
  132. enumDefCollection: enumDefCollection,
  133. typeHeaders: typeHeaders,
  134. isNewBusinessMetadata: isNewBusinessMetadata
  135. }), that.RModal.show(that.view);
  136. });
  137. },
  138. renderTableLayoutView: function() {
  139. var that = this;
  140. require([ "utils/TableLayout" ], function(TableLayout) {
  141. var cols = new Backgrid.Columns(that.getBusinessMetadataTableColumns());
  142. that.RBusinessMetadataTableLayoutView.show(new TableLayout(_.extend({}, that.commonTableOptions, {
  143. columns: cols
  144. }))), that.businessMetadataDefCollection.models.length < that.limit || that.RBusinessMetadataTableLayoutView.$el.find("table tr").last().hide();
  145. });
  146. },
  147. getBusinessMetadataTableColumns: function() {
  148. return this.businessMetadataDefCollection.constructor.getTableCols({
  149. attributeDefs: {
  150. label: "",
  151. cell: "html",
  152. editable: !1,
  153. sortable: !1,
  154. cell: Backgrid.ExpandableCell,
  155. fixWidth: "20",
  156. accordion: !1,
  157. alwaysVisible: !0,
  158. expand: function(el, model) {
  159. el.attr("colspan", "8");
  160. var attrTableHeading = ($("table"), $("tbody"), "<thead><td style='display:table-cell'><b>Attribute</b></td><td style='display:table-cell'><b>Type</b></td><td style='display:table-cell'><b>Search Weight</b></td><td style='display:table-cell'><b>Enable Multivalues</b></td><td style='display:table-cell'><b>Max Length</b></td><td style='display:table-cell'><b>Applicable Type(s)</b></td><td style='display:table-cell'><b>Action</b></td></thead>"), attrRow = "";
  161. if (model.attributes && model.attributes.attributeDefs.length) {
  162. _.each(model.attributes.attributeDefs, function(attrObj) {
  163. var applicableEntityTypes = "", typeName = attrObj.typeName, multiSelect = "", maxString = "NA";
  164. if (attrObj.options && attrObj.options.applicableEntityTypes) {
  165. var entityTypes = JSON.parse(attrObj.options.applicableEntityTypes);
  166. _.each(entityTypes, function(values) {
  167. applicableEntityTypes += '<label class="btn btn-action btn-sm btn-blue no-pointer">' + values + "</label>";
  168. });
  169. }
  170. typeName.includes("array") && (typeName = _.escape(typeName), multiSelect = "checked"),
  171. typeName.includes("string") && attrObj.options && attrObj.options.maxStrLength && (maxString = attrObj.options.maxStrLength),
  172. attrRow += "<tr> <td style='display:table-cell'>" + _.escape(attrObj.name) + "</td><td style='display:table-cell'>" + typeName + "</td><td style='display:table-cell'>" + _.escape(attrObj.searchWeight) + "</td><td style='display:table-cell'><input type='checkbox' class='form-check-input multi-value-select' " + multiSelect + " disabled='disabled'> </td><td style='display:table-cell'>" + maxString + "</td><td style='display:table-cell'>" + applicableEntityTypes + "</td><td style='display:table-cell'> <div class='btn btn-action btn-sm' style='margin-left:0px;' data-id='attributeEdit' data-guid='" + model.get("guid") + "' data-name ='" + _.escape(attrObj.name) + "' data-action='attributeEdit' >Edit</div> </td></tr> ";
  173. });
  174. var adminText = '<div class="row"><div class="col-sm-12 attr-details"><table style="padding: 50px;">' + attrTableHeading + attrRow + "</table></div></div>";
  175. $(el).append($("<div>").html(adminText));
  176. } else {
  177. var adminText = '<div class="row"><div class="col-sm-12 attr-details"><h5 class="text-center"> No attributes to show.</h5></div></div>';
  178. $(el).append($("<div>").html(adminText));
  179. }
  180. }
  181. },
  182. name: {
  183. label: "Name",
  184. cell: "html",
  185. editable: !1,
  186. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  187. fromRaw: function(rawValue, model) {
  188. return '<a title= "' + model.get("name") + '" href ="#!/administrator/businessMetadata/' + model.get("guid") + '?from=bm">' + model.get("name") + "</a>";
  189. }
  190. })
  191. },
  192. description: {
  193. label: "Description",
  194. cell: "html",
  195. editable: !1,
  196. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  197. fromRaw: function(rawValue, model) {
  198. return _.escape(model.get("description"));
  199. }
  200. })
  201. },
  202. createdBy: {
  203. label: "Created by",
  204. cell: "html",
  205. renderable: !1,
  206. editable: !1,
  207. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  208. fromRaw: function(rawValue, model) {
  209. return model.get("updatedBy");
  210. }
  211. })
  212. },
  213. createTime: {
  214. label: "Created on",
  215. cell: "html",
  216. renderable: !1,
  217. editable: !1,
  218. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  219. fromRaw: function(rawValue, model) {
  220. return Utils.formatDate({
  221. date: model.get("createTime")
  222. });
  223. }
  224. })
  225. },
  226. updatedBy: {
  227. label: "Updated by",
  228. cell: "html",
  229. renderable: !1,
  230. editable: !1,
  231. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  232. fromRaw: function(rawValue, model) {
  233. return model.get("updatedBy");
  234. }
  235. })
  236. },
  237. updateTime: {
  238. label: "Updated on",
  239. cell: "html",
  240. renderable: !1,
  241. editable: !1,
  242. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  243. fromRaw: function(rawValue, model) {
  244. return Utils.formatDate({
  245. date: model.get("updateTime")
  246. });
  247. }
  248. })
  249. },
  250. tools: {
  251. label: "Action",
  252. cell: "html",
  253. sortable: !1,
  254. editable: !1,
  255. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  256. fromRaw: function(rawValue, model) {
  257. return "<button type='button' data-id='addAttribute' data-guid='" + model.get("guid") + "' class='btn btn-action btn-sm' style='margin-bottom: 10px;' data-action='createAttr' data-original-title='Add Business Metadata attribute'><i class='fa fa-plus'></i> Attributes</button>";
  258. }
  259. })
  260. }
  261. }, this.businessMetadataDefCollection);
  262. },
  263. deleteBusinessMetadataElement: function(businessMetadataName) {
  264. var that = this, notifyObj = {
  265. modal: !0,
  266. ok: function(argument) {
  267. that.onNotifyDeleteOk();
  268. },
  269. cancel: function(argument) {}
  270. }, text = "Are you sure you want to delete the business metadata";
  271. notifyObj.text = text, Utils.notifyConfirm(notifyObj);
  272. },
  273. onNotifyDeleteOk: function(data) {
  274. var that = this, deleteBusinessMetadataData = that.businessMetadataDefCollection.fullCollection.findWhere({
  275. guid: that.guid
  276. });
  277. if (that.$(".tableOverlay").show(), deleteBusinessMetadataData) {
  278. var businessMetadataName = deleteBusinessMetadataData.get("name");
  279. deleteBusinessMetadataData.deleteBusinessMetadata({
  280. typeName: businessMetadataName,
  281. success: function() {
  282. Utils.notifySuccess({
  283. content: "业务元数据 " + businessMetadataName + Messages.getAbbreviationMsg(!1, "deleteSuccessMessage")
  284. }), that.businessMetadataDefCollection.fullCollection.remove(deleteBusinessMetadataData),
  285. that.businessMetadataDefCollection.fullCollection.sort({
  286. silent: !0
  287. }), that.renderTableLayoutView(), that.showDetails = !0, that.toggleBusinessMetadataDetailsAttrView(),
  288. that.loaderStatus(!1);
  289. },
  290. complete: function() {
  291. that.$(".tableOverlay").hide(), that.$(".position-relative .fontLoader").removeClass("show");
  292. }
  293. });
  294. } else Utils.notifyError({
  295. content: Messages.defaultErrorMessage
  296. });
  297. }
  298. });
  299. return BusinessMetadataTableLayoutView;
  300. });