123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- 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("<button class='btn btn-action btn-sm pull-right'>Columns <i class='fa fa-caret-down'></i></button>")
- },
- 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"), "<thead><td style='display:table-cell'><b>属性</b></td><td style='display:table-cell'><b>类型</b></td><td style='display:table-cell'><b>搜索权重</b></td><td style='display:table-cell'><b>启用多值</b></td><td style='display:table-cell'><b>最大长度</b></td><td style='display:table-cell'><b>适用类型</b></td><td style='display:table-cell'><b>操作</b></td></thead>"), 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 += '<label class="btn btn-action btn-sm btn-blue no-pointer">' + values + "</label>";
- });
- }
- typeName.includes("array") && (typeName = _.escape(typeName), multiSelect = "checked"),
- typeName.includes("string") && attrObj.options && attrObj.options.maxStrLength && (maxString = attrObj.options.maxStrLength),
- 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> ";
- });
- var adminText = '<div class="row"><div class="col-sm-12 attr-details"><table style="padding: 50px;">' + attrTableHeading + attrRow + "</table></div></div>";
- $(el).append($("<div>").html(adminText));
- } else {
- var adminText = '<div class="row"><div class="col-sm-12 attr-details"><h5 class="text-center"> No attributes to show.</h5></div></div>';
- $(el).append($("<div>").html(adminText));
- }
- }
- },
- name: {
- label: "Name",
- cell: "html",
- editable: !1,
- formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
- fromRaw: function(rawValue, model) {
- return '<a title= "' + model.get("name") + '" href ="#!/administrator/businessMetadata/' + model.get("guid") + '?from=bm">' + model.get("name") + "</a>";
- }
- })
- },
- 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 "<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>";
- }
- })
- }
- }, 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;
- });
|