define([ "require", "backbone", "hbs!tmpl/site/Statistics_tmpl", "hbs!tmpl/site/Statistics_Notification_table_tmpl", "hbs!tmpl/site/entity_tmpl", "modules/Modal", "models/VCommon", "utils/UrlLinks", "collection/VTagList", "utils/CommonViewFunction", "utils/Enums", "moment", "utils/Utils", "moment-timezone" ], function(require, Backbone, StatTmpl, StatsNotiTable, EntityTable, Modal, VCommon, UrlLinks, VTagList, CommonViewFunction, Enums, moment, Utils) { "use strict"; Backbone.Marionette.LayoutView.extend({ template: StatTmpl, regions: { RSaveSearchBasic: "[data-id='r_saveSearchBasic']", RSaveSearchAdvance: "[data-id='r_saveSearchAdvance']" }, ui: {}, events: function() {}, initialize: function(options) { _.extend(this, options); var that = this, modal = new Modal({ title: "统计信息", content: this, okCloses: !0, okText: "Close", showFooter: !0, allowCancel: !1, width: "60%", headerButtons: [ { title: "Refresh Data", btnClass: "fa fa-refresh", onClick: function() { modal.$el.find(".header-button .fa-refresh").tooltip("hide").prop("disabled", !0).addClass("fa-spin"), that.fetchMetricData({ update: !0 }); } } ] }).open(); modal.on("closeModal", function() { modal.trigger("cancel"); }), this.modal = modal; }, bindEvents: function() {}, fetchMetricData: function(options) { that.RSaveSearchBasic.show(new SaveSearchView(_.extend(obj, { isBasic: !0, collection: saveSearchBaiscCollection.fullCollection }))), that.RSaveSearchAdvance.show(new SaveSearchView(_.extend(obj, { isBasic: !1, collection: saveSearchAdvanceCollection.fullCollection }))); }, onRender: function() { this.fetchMetricData(); }, genrateStatusData: function(stateObject) { var stats = {}; return _.each(stateObject, function(val, key) { var keys = key.split(":"), key = keys[0], subKey = keys[1]; stats[key] ? stats[key][subKey] = val : (stats[key] = {}, stats[key][subKey] = val); }), stats; }, renderEntities: function(options) { var that = this, data = options.data, entityData = data.entity, activeEntities = entityData.entityActive || {}, deletedEntities = entityData.entityDeleted || {}, stats = {}, activeEntityCount = 0, deletedEntityCount = 0, createEntityData = function(opt) { var entityData = opt.entityData, type = opt.type; _.each(entityData, function(val, key) { var intVal = _.isUndefined(val) ? 0 : val; "active" == type ? activeEntityCount += intVal : deletedEntityCount += intVal, intVal = _.numberFormatWithComma(intVal), stats[key] ? stats[key][type] = intVal : (stats[key] = {}, stats[key][type] = intVal); }); }; createEntityData({ entityData: activeEntities, type: "active" }), createEntityData({ entityData: deletedEntities, type: "deleted" }), _.isEmpty(stats) || (that.ui.entityCard.html(EntityTable({ data: _.pick(stats, _.keys(stats).sort()) })), that.$('[data-id="activeEntity"]').html(" (" + _.numberFormatWithComma(activeEntityCount) + ")"), that.$('[data-id="deletedEntity"]').html(" (" + _.numberFormatWithComma(deletedEntityCount) + ")"), that.ui.entityHeader.html(" (" + _.numberFormatWithComma(data.general.entityCount) + ")")); }, renderStats: function(options) { var that = this, data = this.genrateStatusData(options.valueObject), generalData = options.dataObject, createTable = function(obj) { var tableBody = "", enums = obj.enums, data = obj.data; return _.each(data, function(value, key, list) { tableBody += "