define([ "require", "backbone", "hbs!tmpl/audit/AdminAuditTableLayoutView_tmpl", "collection/VEntityList", "utils/Utils", "utils/UrlLinks", "utils/CommonViewFunction", "utils/Enums", "moment" ], function(require, Backbone, AdminAuditTableLayoutView_tmpl, VEntityList, Utils, UrlLinks, CommonViewFunction, Enums, moment) { "use strict"; var AdminAuditTableLayoutView = Backbone.Marionette.LayoutView.extend({ _viewName: "AdminAuditTableLayoutView", template: AdminAuditTableLayoutView_tmpl, regions: { RAuditTableLayoutView: "#r_adminAuditTableLayoutView", RQueryBuilderAdmin: "#r_attributeQueryBuilderAdmin" }, ui: { adminPurgedEntityClick: "[data-id='adminPurgedEntity']", adminAuditEntityDetails: "[data-id='adminAuditEntityDetails']", attrFilter: "[data-id='adminAttrFilter']", adminRegion: "[data-id='adminRegion']", attrApply: "[data-id='attrApply']", showDefault: "[data-id='showDefault']", attrClose: "[data-id='attrClose']" }, events: function() { var events = {}, that = this; return events["click " + this.ui.adminPurgedEntityClick] = "onClickAdminPurgedEntity", events["click " + this.ui.adminAuditEntityDetails] = "showAdminAuditEntity", events["click " + this.ui.attrFilter] = function(e) { this.ui.attrFilter.find(".fa-angle-right").toggleClass("fa-angle-down"), this.$(".attributeResultContainer").addClass("overlay"), this.$(".attribute-filter-container, .attr-filter-overlay").toggleClass("hide"), this.onClickAttrFilter(); }, events["click " + this.ui.attrClose] = function(e) { that.closeAttributeModel(); }, events["click " + this.ui.attrApply] = function(e) { that.okAttrFilterButton(e); }, events; }, initialize: function(options) { _.extend(this, _.pick(options, "searchTableFilters", "entityDefCollection", "enumDefCollection")), this.entityCollection = new VEntityList(), this.limit = 25, this.offset = 0, this.entityCollection.url = UrlLinks.adminApiUrl(), this.entityCollection.modelAttrName = "events", this.commonTableOptions = { collection: this.entityCollection, includePagination: !1, includeAtlasPagination: !0, includeFooterRecords: !1, includeColumnManager: !0, includeOrderAbleColumns: !1, includeSizeAbleColumns: !1, includeTableLoader: !0, includeAtlasPageSize: !0, includeAtlasTableSorting: !0, columnOpts: { opts: { initialColumnsVisible: null, saveState: !1 }, visibilityControlOpts: { buttonTemplate: _.template("") }, el: this.ui.colManager }, atlasPaginationOpts: { limit: this.limit, offset: this.offset, fetchCollection: this.getAdminCollection.bind(this) }, gridOpts: { emptyText: "没有找到记录!", className: "table table-hover backgrid table-quickMenu colSort" }, filterOpts: {}, paginatorOpts: {} }, this.isFilters = null, this.adminAuditEntityData = {}; }, onRender: function() { this.ui.adminRegion.hide(), this.getAdminCollection(), this.entityCollection.comparator = function(model) { return -model.get("timestamp"); }, this.renderTableLayoutView(); }, onShow: function() { this.$(".fontLoader").show(), this.$(".tableOverlay").show(); }, bindEvents: function() {}, closeAttributeModel: function() { var that = this; that.$(".attributeResultContainer").removeClass("overlay"), that.ui.attrFilter.find(".fa-angle-right").toggleClass("fa-angle-down"), that.$(".attribute-filter-container, .attr-filter-overlay").toggleClass("hide"); }, onClickAttrFilter: function() { var that = this; this.ui.adminRegion.show(), require([ "views/search/QueryBuilderView" ], function(QueryBuilderView) { that.RQueryBuilderAdmin.show(new QueryBuilderView({ adminAttrFilters: !0, searchTableFilters: that.searchTableFilters, entityDefCollection: that.entityDefCollection, enumDefCollection: that.enumDefCollection })); }); }, okAttrFilterButton: function(options) { var that = this, isFilterValidate = !0, queryBuilderRef = that.RQueryBuilderAdmin.currentView.ui.builder; if (queryBuilderRef.data("queryBuilder")) { var queryBuilder = queryBuilderRef.queryBuilder("getRules"); queryBuilder ? (that.ruleUrl = that.searchTableFilters.adminAttrFilters = CommonViewFunction.attributeFilter.generateUrl({ value: queryBuilder, formatedDateToLong: !0 }), that.isFilters = queryBuilder.rules.length ? queryBuilder.rules : null) : isFilterValidate = !1; } isFilterValidate && (that.closeAttributeModel(), that.defaultPagination(), that.getAdminCollection()); }, getAdminCollection: function(option) { var that = this, auditFilters = CommonViewFunction.attributeFilter.generateAPIObj(that.ruleUrl); $.extend(that.entityCollection.queryParams, { auditFilters: that.isFilters ? auditFilters : null, limit: that.entityCollection.queryParams.limit || that.limit, offset: that.entityCollection.queryParams.offset || that.offset, sortBy: "startTime", sortOrder: "DESCENDING" }); var apiObj = { sort: !1, data: _.pick(that.entityCollection.queryParams, "auditFilters", "limit", "offset", "sortBy", "sortOrder"), success: function(dataOrCollection, response) { that.entityCollection.state.pageSize = that.entityCollection.queryParams.limit || 25, that.entityCollection.fullCollection.reset(dataOrCollection, option); }, complete: function() { that.$(".fontLoader").hide(), that.$(".tableOverlay").hide(), that.$(".auditTable").show(); }, reset: !0 }; this.entityCollection.getAdminData(apiObj); }, renderTableLayoutView: function() { var that = this; this.ui.showDefault.hide(), require([ "utils/TableLayout" ], function(TableLayout) { var cols = new Backgrid.Columns(that.getAuditTableColumns()); that.RAuditTableLayoutView.show(new TableLayout(_.extend({}, that.commonTableOptions, { columns: cols }))); }); }, createTableWithValues: function(tableDetails, isAdminAudit) { var attrTable = CommonViewFunction.propertyTable({ scope: this, getValue: function(val, key) { return key && key.toLowerCase().indexOf("time") > 0 ? Utils.formatDate({ date: val }) : val; }, valueObject: tableDetails, guidHyperLink: !isAdminAudit }); return attrTable; }, getAuditTableColumns: function() { var that = this; return this.entityCollection.constructor.getTableCols({ result: { label: "", cell: "html", editable: !1, sortable: !1, cell: Backgrid.ExpandableCell, fixWidth: "20", accordion: !1, alwaysVisible: !0, renderable: !0, isExpandVisible: function(el, model) { return !Enums.serverAudits[model.get("operation")]; }, expand: function(el, model) { var operation = model.get("operation"), results = model.get("result") || null, adminText = "No records found", adminTypDetails = null, auditData = { operation: operation, model: model, results: results, adminText: adminText, adminTypDetails: adminTypDetails }; if (el.attr("colspan", "8"), results) { adminText = "PURGE" == operation ? that.displayPurgeAndImportAudits(auditData) : "EXPORT" == operation || "IMPORT" == operation ? that.displayExportAudits(auditData) : that.displayCreateUpdateAudits(auditData); } $(el).append($("