AuditTableLayoutView.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. define([ "require", "backbone", "hbs!tmpl/audit/AuditTableLayoutView_tmpl", "collection/VEntityList", "utils/Utils", "utils/Enums", "utils/UrlLinks" ], function(require, Backbone, AuditTableLayoutView_tmpl, VEntityList, Utils, Enums, UrlLinks) {
  2. "use strict";
  3. var AuditTableLayoutView = Backbone.Marionette.LayoutView.extend({
  4. _viewName: "AuditTableLayoutView",
  5. template: AuditTableLayoutView_tmpl,
  6. regions: {
  7. RAuditTableLayoutView: "#r_auditTableLayoutView"
  8. },
  9. ui: {},
  10. events: function() {
  11. var events = {};
  12. return events;
  13. },
  14. initialize: function(options) {
  15. _.extend(this, _.pick(options, "guid", "entity", "entityName", "attributeDefs")),
  16. this.entityCollection = new VEntityList(), this.limit = 25, this.offset = 0, this.entityCollection.url = UrlLinks.entityCollectionaudit(this.guid),
  17. this.entityCollection.modelAttrName = "events", this.entityModel = new this.entityCollection.model(),
  18. this.pervOld = [], this.commonTableOptions = {
  19. collection: this.entityCollection,
  20. includeFilter: !1,
  21. includePagination: !1,
  22. includeAtlasPagination: !0,
  23. includeAtlasPageSize: !0,
  24. includeTableLoader: !0,
  25. includeAtlasTableSorting: !1,
  26. showDefaultTableSorted: !0,
  27. columnSorting: !1,
  28. includeFooterRecords: !1,
  29. gridOpts: {
  30. className: "table table-hover backgrid table-quickMenu",
  31. emptyText: "没有找到记录!"
  32. },
  33. sortOpts: {
  34. sortColumn: "timestamp",
  35. sortDirection: "descending"
  36. },
  37. isApiSorting: !0,
  38. atlasPaginationOpts: this.getPaginationOptions(),
  39. filterOpts: {},
  40. paginatorOpts: {}
  41. }, this.currPage = 1, this.fromSort = !1;
  42. },
  43. onRender: function() {
  44. $.extend(this.entityCollection.queryParams, {
  45. offset: this.offset,
  46. count: this.limit,
  47. sortKey: null,
  48. order: "sortOrder",
  49. sortBy: "timestamp",
  50. sortOrder: "desc"
  51. }), this.fetchAuditCollection(), this.renderTableLayoutView();
  52. },
  53. fetchAuditCollection: function() {
  54. this.commonTableOptions.atlasPaginationOpts = this.getPaginationOptions(), this.fetchCollection();
  55. },
  56. bindEvents: function() {},
  57. getPaginationOptions: function() {
  58. return {
  59. count: this.getPageCount(),
  60. offset: this.entityCollection.queryParams.offset || this.offset,
  61. fetchCollection: this.fetchCollection.bind(this)
  62. };
  63. },
  64. getPageCount: function() {
  65. return this.entityCollection.queryParams.limit || this.entityCollection.queryParams.count || this.limit;
  66. },
  67. fetchCollection: function(options) {
  68. var that = this;
  69. this.$(".fontLoader").show(), this.$(".tableOverlay").show(), this.entityCollection.queryParams.count = this.getPageCount(),
  70. this.entityCollection.queryParams = _.omit(this.entityCollection.queryParams, "limit"),
  71. this.entityCollection.fetch({
  72. success: function(dataOrCollection, response) {
  73. that.entityCollection.state.pageSize = that.getPageCount(), that.entityCollection.reset(response, $.extend(options));
  74. },
  75. complete: function() {
  76. that.$(".fontLoader").hide(), that.$(".tableOverlay").hide(), that.$(".auditTable").show(),
  77. that.fromSort && (that.fromSort = !that.fromSort);
  78. },
  79. silent: !0
  80. });
  81. },
  82. renderTableLayoutView: function() {
  83. var that = this;
  84. require([ "utils/TableLayout" ], function(TableLayout) {
  85. var cols = new Backgrid.Columns(that.getAuditTableColumns());
  86. that.RAuditTableLayoutView.show(new TableLayout(_.extend({}, that.commonTableOptions, {
  87. columns: cols
  88. })));
  89. });
  90. },
  91. backgridHeaderClickHandel: function() {
  92. var that = this;
  93. return Backgrid.HeaderCell.extend({
  94. onClick: function(e) {
  95. e.preventDefault();
  96. var column = this.column, direction = "ascending", columnName = column.get("name").toLocaleLowerCase();
  97. "ascending" === column.get("direction") && (direction = "descending"), column.set("direction", direction);
  98. var options = {
  99. sortBy: columnName,
  100. sortOrder: "ascending" === direction ? "asc" : "desc",
  101. offset: that.entityCollection.queryParams.offset || that.offset,
  102. count: that.getPageCount()
  103. };
  104. that.commonTableOptions.sortOpts = {
  105. sortColumn: columnName,
  106. sortDirection: "ascending" === direction ? "ascending" : "descending"
  107. }, $.extend(that.entityCollection.queryParams, options), that.fromSort = !0, that.fetchAuditCollection();
  108. }
  109. });
  110. },
  111. getAuditTableColumns: function() {
  112. var that = this;
  113. return this.entityCollection.constructor.getTableCols({
  114. tool: {
  115. label: "",
  116. cell: "html",
  117. editable: !1,
  118. sortable: !1,
  119. fixWidth: "20",
  120. cell: Backgrid.ExpandableCell,
  121. accordion: !1,
  122. expand: function(el, model) {
  123. el.attr("colspan", "4"), require([ "views/audit/CreateAuditTableLayoutView" ], function(CreateAuditTableLayoutView) {
  124. that.action = model.get("action");
  125. var eventModel = that.entityCollection.fullCollection.findWhere({
  126. eventKey: model.get("eventKey")
  127. }).toJSON(), collectionModel = new that.entityCollection.model(eventModel), view = new CreateAuditTableLayoutView({
  128. guid: that.guid,
  129. entityModel: collectionModel,
  130. action: that.action,
  131. entity: that.entity,
  132. entityName: that.entityName,
  133. attributeDefs: that.attributeDefs
  134. });
  135. view.render(), $(el).append($("<div>").html(view.$el));
  136. });
  137. }
  138. },
  139. user: {
  140. label: "用户",
  141. cell: "html",
  142. editable: !1,
  143. headerCell: that.backgridHeaderClickHandel()
  144. },
  145. timestamp: {
  146. label: "时间戳",
  147. cell: "html",
  148. editable: !1,
  149. headerCell: that.backgridHeaderClickHandel(),
  150. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  151. fromRaw: function(rawValue, model) {
  152. return Utils.formatDate({
  153. date: rawValue
  154. });
  155. }
  156. })
  157. },
  158. action: {
  159. label: "操作",
  160. cell: "html",
  161. editable: !1,
  162. headerCell: that.backgridHeaderClickHandel(),
  163. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  164. fromRaw: function(rawValue, model) {
  165. return Enums.auditAction[rawValue] ? Enums.auditAction[rawValue] : rawValue;
  166. }
  167. })
  168. }
  169. }, this.entityCollection);
  170. }
  171. });
  172. return AuditTableLayoutView;
  173. });