define([ "require", "backbone", "hbs!tmpl/business_metadata/BusinessMetadataTableLayoutView_tmpl", "utils/Utils", "utils/Messages" ], function(require, Backbone, BusinessMetadataTableLayoutView_tmpl, Utils, Messages) { "use strict"; var BusinessMetadataTableLayoutView = Backbone.Marionette.LayoutView.extend({ _viewName: "BusinessMetadataTableLayoutView", template: BusinessMetadataTableLayoutView_tmpl, regions: { RBusinessMetadataTableLayoutView: "#r_businessMetadataTableLayoutView", RModal: "#r_modal" }, ui: { businessMetadataAttrPage: "[data-id='businessMetadataAttrPage']", businessMetadataAttrPageTitle: "[data-id='businessMetadataAttrPageTitle']", businessMetadataDetailPage: "[data-id='businessMetadataDetailPage']", createBusinessMetadata: "[data-id='createBusinessMetadata']", attributeEdit: "[data-id='attributeEdit']", addAttribute: '[data-id="addAttribute"]', businessMetadataAttrPageOk: '[data-id="businessMetadataAttrPageOk"]', colManager: "[data-id='colManager']", deleteBusinessMetadata: '[data-id="deleteBusinessMetadata"]' }, events: function() { var events = {}, that = this; return events["click " + this.ui.createBusinessMetadata] = "onClickCreateBusinessMetadata", events["click " + this.ui.addAttribute] = "onEditAttr", events["click " + this.ui.attributeEdit] = "onEditAttr", events["click " + this.ui.deleteBusinessMetadata] = function(e) { that.guid = e.target.dataset.guid, that.deleteBusinessMetadataElement(); }, events; }, initialize: function(options) { _.extend(this, _.pick(options, "guid", "entity", "entityName", "attributeDefs", "typeHeaders", "businessMetadataDefCollection", "entityDefCollection", "businessMetadataAttr", "selectedBusinessMetadata")), this.limit = 10, this.newAttr = !1, this.commonTableOptions = { collection: this.businessMetadataDefCollection, includeFilter: !1, includePagination: !0, includeFooterRecords: !0, includePageSize: !0, includeGotoPage: !0, includeAtlasTableSorting: !0, includeTableLoader: !0, includeColumnManager: !0, gridOpts: { className: "table table-hover backgrid table-quickMenu", emptyText: "没有找到记录!" }, columnOpts: { opts: { initialColumnsVisible: null, saveState: !1 }, visibilityControlOpts: { buttonTemplate: _.template("") }, el: this.ui.colManager }, filterOpts: {}, paginatorOpts: {} }, this.guid = null, this.showDetails = !0; }, onRender: function() { this.toggleBusinessMetadataDetailsAttrView(), $.extend(this.businessMetadataDefCollection.queryParams, { count: this.limit }), this.businessMetadataDefCollection.fullCollection.sort({ silent: !0 }), this.renderTableLayoutView(), this.$(".tableOverlay").hide(), this.$(".auditTable").show(), this.businessMetadataDefCollection.comparator = function(model) { return -model.get("timestamp"); }; }, toggleBusinessMetadataDetailsAttrView: function() { var that = this; that.showDetails ? (that.ui.businessMetadataAttrPage.hide(), that.ui.businessMetadataDetailPage.show()) : (that.ui.businessMetadataAttrPage.show(), that.ui.businessMetadataDetailPage.hide()); }, bindEvents: function() {}, loaderStatus: function(isActive) { var that = this; isActive ? (that.$(".businessMetadata-attr-tableOverlay").show(), that.$(".business-metadata-attr-fontLoader").show()) : (that.$(".businessMetadata-attr-tableOverlay").hide(), that.$(".business-metadata-attr-fontLoader").hide()); }, onEditAttr: function(e) { 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({ guid: guid }), attrributes = selectedBusinessMetadata ? selectedBusinessMetadata.get("attributeDefs") : null, attrName = e.currentTarget.dataset.name ? e.currentTarget.dataset.name : null, attrDetails = { name: attrName }; selectedBusinessMetadata && (that.ui.businessMetadataAttrPageOk.text("Save"), that.newAttr = !(!e.currentTarget || "createAttr" !== e.currentTarget.dataset.action), that.guid = guid, _.each(attrributes, function(attrObj) { attrObj.name === attrName && (attrDetails = $.extend(!0, {}, attrObj), attrObj.typeName.includes("array") && (attrDetails.typeName = attrObj.typeName.replace("array<", "").replace(">", ""), attrDetails.multiValued = !0)); }), that.showDetails = !1, that.toggleBusinessMetadataDetailsAttrView(), that.ui.businessMetadataAttrPageOk.attr("data-action", e.currentTarget.dataset.id), require([ "views/business_metadata/CreateBusinessMetadataLayoutView" ], function(CreateBusinessMetadataLayoutView) { that.view = new CreateBusinessMetadataLayoutView({ onEditCallback: function() { that.businessMetadataDefCollection.fullCollection.sort({ silent: !0 }), that.renderTableLayoutView(); }, onUpdateBusinessMetadata: function(fetch) { that.showDetails = !0, that.toggleBusinessMetadataDetailsAttrView(), fetch && (enumDefCollection.fetch({ reset: !0 }), that.entityDefCollection.fetch({ silent: !0 })); }, parent: that.$el, businessMetadataDefCollection: that.businessMetadataDefCollection, enumDefCollection: enumDefCollection, isAttrEdit: isAttrEdit, typeHeaders: typeHeaders, attrDetails: attrDetails, selectedBusinessMetadata: selectedBusinessMetadata, guid: that.guid, isNewAttr: that.newAttr }), isAttrEdit ? that.ui.businessMetadataAttrPageTitle.text("Update Attribute of: " + selectedBusinessMetadata.get("name")) : that.ui.businessMetadataAttrPageTitle.text("Add Business Metadata Attribute for: " + selectedBusinessMetadata.get("name")), that.RModal.show(that.view); })); }, onClickCreateBusinessMetadata: function(e) { var that = this, isNewBusinessMetadata = !0; that.showDetails = !1, that.ui.businessMetadataAttrPageOk.text("Create"), that.ui.businessMetadataAttrPageOk.attr("data-action", "createBusinessMetadata"), that.ui.businessMetadataAttrPageTitle.text("创建业务元数据"), that.toggleBusinessMetadataDetailsAttrView(), require([ "views/business_metadata/CreateBusinessMetadataLayoutView" ], function(CreateBusinessMetadataLayoutView) { that.view = new CreateBusinessMetadataLayoutView({ onUpdateBusinessMetadata: function(fetch) { that.showDetails = !0, that.toggleBusinessMetadataDetailsAttrView(), fetch && (enumDefCollection.fetch({ reset: !0 }), that.entityDefCollection.fetch({ silent: !0 })); }, businessMetadataDefCollection: that.businessMetadataDefCollection, enumDefCollection: enumDefCollection, typeHeaders: typeHeaders, isNewBusinessMetadata: isNewBusinessMetadata }), that.RModal.show(that.view); }); }, renderTableLayoutView: function() { var that = this; require([ "utils/TableLayout" ], function(TableLayout) { var cols = new Backgrid.Columns(that.getBusinessMetadataTableColumns()); that.RBusinessMetadataTableLayoutView.show(new TableLayout(_.extend({}, that.commonTableOptions, { columns: cols }))), that.businessMetadataDefCollection.models.length < that.limit || that.RBusinessMetadataTableLayoutView.$el.find("table tr").last().hide(); }); }, getBusinessMetadataTableColumns: function() { return this.businessMetadataDefCollection.constructor.getTableCols({ attributeDefs: { label: "", cell: "html", editable: !1, sortable: !1, cell: Backgrid.ExpandableCell, fixWidth: "20", accordion: !1, alwaysVisible: !0, expand: function(el, model) { el.attr("colspan", "8"); var attrTableHeading = ($("table"), $("tbody"), "AttributeTypeSearch WeightEnable MultivaluesMax LengthApplicable Type(s)Action"), attrRow = ""; if (model.attributes && model.attributes.attributeDefs.length) { _.each(model.attributes.attributeDefs, function(attrObj) { var applicableEntityTypes = "", typeName = attrObj.typeName, multiSelect = "", maxString = "NA"; if (attrObj.options && attrObj.options.applicableEntityTypes) { var entityTypes = JSON.parse(attrObj.options.applicableEntityTypes); _.each(entityTypes, function(values) { applicableEntityTypes += '"; }); } typeName.includes("array") && (typeName = _.escape(typeName), multiSelect = "checked"), typeName.includes("string") && attrObj.options && attrObj.options.maxStrLength && (maxString = attrObj.options.maxStrLength), attrRow += " " + _.escape(attrObj.name) + "" + typeName + "" + _.escape(attrObj.searchWeight) + " " + maxString + "" + applicableEntityTypes + "
Edit
"; }); var adminText = '
' + attrTableHeading + attrRow + "
"; $(el).append($("
").html(adminText)); } else { var adminText = '
No attributes to show.
'; $(el).append($("
").html(adminText)); } } }, name: { label: "Name", cell: "html", editable: !1, formatter: _.extend({}, Backgrid.CellFormatter.prototype, { fromRaw: function(rawValue, model) { return '' + model.get("name") + ""; } }) }, description: { label: "Description", cell: "html", editable: !1, formatter: _.extend({}, Backgrid.CellFormatter.prototype, { fromRaw: function(rawValue, model) { return _.escape(model.get("description")); } }) }, createdBy: { label: "创建者", cell: "html", renderable: !1, editable: !1, formatter: _.extend({}, Backgrid.CellFormatter.prototype, { fromRaw: function(rawValue, model) { return model.get("updatedBy"); } }) }, createTime: { label: "创建于", cell: "html", renderable: !1, editable: !1, formatter: _.extend({}, Backgrid.CellFormatter.prototype, { fromRaw: function(rawValue, model) { return Utils.formatDate({ date: model.get("createTime") }); } }) }, updatedBy: { label: "更新者", cell: "html", renderable: !1, editable: !1, formatter: _.extend({}, Backgrid.CellFormatter.prototype, { fromRaw: function(rawValue, model) { return model.get("updatedBy"); } }) }, updateTime: { label: "更新于", cell: "html", renderable: !1, editable: !1, formatter: _.extend({}, Backgrid.CellFormatter.prototype, { fromRaw: function(rawValue, model) { return Utils.formatDate({ date: model.get("updateTime") }); } }) }, tools: { label: "操作", cell: "html", sortable: !1, editable: !1, formatter: _.extend({}, Backgrid.CellFormatter.prototype, { fromRaw: function(rawValue, model) { return ""; } }) } }, this.businessMetadataDefCollection); }, deleteBusinessMetadataElement: function(businessMetadataName) { var that = this, notifyObj = { modal: !0, ok: function(argument) { that.onNotifyDeleteOk(); }, cancel: function(argument) {} }, text = "确定删除该业务元数据?"; notifyObj.text = text, Utils.notifyConfirm(notifyObj); }, onNotifyDeleteOk: function(data) { var that = this, deleteBusinessMetadataData = that.businessMetadataDefCollection.fullCollection.findWhere({ guid: that.guid }); if (that.$(".tableOverlay").show(), deleteBusinessMetadataData) { var businessMetadataName = deleteBusinessMetadataData.get("name"); deleteBusinessMetadataData.deleteBusinessMetadata({ typeName: businessMetadataName, success: function() { Utils.notifySuccess({ content: "业务元数据 " + businessMetadataName + Messages.getAbbreviationMsg(!1, "deleteSuccessMessage") }), that.businessMetadataDefCollection.fullCollection.remove(deleteBusinessMetadataData), that.businessMetadataDefCollection.fullCollection.sort({ silent: !0 }), that.renderTableLayoutView(), that.showDetails = !0, that.toggleBusinessMetadataDetailsAttrView(), that.loaderStatus(!1); }, complete: function() { that.$(".tableOverlay").hide(), that.$(".position-relative .fontLoader").removeClass("show"); } }); } else Utils.notifyError({ content: Messages.defaultErrorMessage }); } }); return BusinessMetadataTableLayoutView; });