SchemaLayoutView.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. define([ "require", "backbone", "hbs!tmpl/schema/SchemaTableLayoutView_tmpl", "collection/VSchemaList", "utils/Utils", "utils/CommonViewFunction", "utils/Messages", "utils/Globals", "utils/Enums", "utils/UrlLinks" ], function(require, Backbone, SchemaTableLayoutViewTmpl, VSchemaList, Utils, CommonViewFunction, Messages, Globals, Enums, UrlLinks) {
  2. "use strict";
  3. var SchemaTableLayoutView = Backbone.Marionette.LayoutView.extend({
  4. _viewName: "SchemaTableLayoutView",
  5. template: SchemaTableLayoutViewTmpl,
  6. regions: {
  7. RSchemaTableLayoutView: "#r_schemaTableLayoutView"
  8. },
  9. ui: {
  10. tagClick: '[data-id="tagClick"]',
  11. addTag: "[data-id='addTag']",
  12. addAssignTag: "[data-id='addAssignTag']",
  13. checkDeletedEntity: "[data-id='checkDeletedEntity']"
  14. },
  15. events: function() {
  16. var events = {};
  17. return events["click " + this.ui.addTag] = "checkedValue", events["click " + this.ui.addAssignTag] = "checkedValue",
  18. events["click " + this.ui.tagClick] = function(e) {
  19. if ("i" == e.target.nodeName.toLocaleLowerCase()) this.onClickTagCross(e); else {
  20. var value = e.currentTarget.text;
  21. Utils.setUrl({
  22. url: "#!/tag/tagAttribute/" + value,
  23. mergeBrowserUrl: !1,
  24. trigger: !0
  25. });
  26. }
  27. }, events["click " + this.ui.checkDeletedEntity] = "onCheckDeletedEntity", events;
  28. },
  29. initialize: function(options) {
  30. _.extend(this, _.pick(options, "guid", "classificationDefCollection", "entityDefCollection", "attribute", "fetchCollection", "enumDefCollection")),
  31. this.schemaCollection = new VSchemaList([], {}), this.commonTableOptions = {
  32. collection: this.schemaCollection,
  33. includeFilter: !1,
  34. includePagination: !0,
  35. includePageSize: !0,
  36. includeGotoPage: !0,
  37. includeFooterRecords: !0,
  38. includeOrderAbleColumns: !1,
  39. includeAtlasTableSorting: !0,
  40. gridOpts: {
  41. className: "table table-hover backgrid table-quickMenu",
  42. emptyText: "没有找到记录!"
  43. },
  44. filterOpts: {},
  45. paginatorOpts: {}
  46. }, this.bindEvents(), this.bradCrumbList = [];
  47. },
  48. bindEvents: function() {
  49. var that = this;
  50. this.listenTo(this.schemaCollection, "backgrid:selected", function(model, checked) {
  51. this.arr = [], checked === !0 ? model.set("isEnable", !0) : model.set("isEnable", !1),
  52. this.schemaCollection.find(function(item) {
  53. var obj = item.toJSON();
  54. item.get("isEnable") && that.arr.push({
  55. id: obj.guid,
  56. model: obj
  57. });
  58. }), this.arr.length > 0 ? this.$(".multiSelectTag").show() : this.$(".multiSelectTag").hide();
  59. });
  60. },
  61. onRender: function() {
  62. this.generateTableData();
  63. },
  64. generateTableData: function(checkedDelete) {
  65. var that = this;
  66. if (this.activeObj = [], this.deleteObj = [], this.schemaTableAttribute = null,
  67. this.attribute && this.attribute[0]) {
  68. var firstColumn = this.attribute[0], defObj = that.entityDefCollection.fullCollection.find({
  69. name: firstColumn.typeName
  70. });
  71. if (defObj && defObj.get("options") && defObj.get("options").schemaAttributes && firstColumn) try {
  72. var mapObj = JSON.parse(defObj.get("options").schemaAttributes);
  73. that.schemaTableAttribute = _.pick(firstColumn.attributes, mapObj);
  74. } catch (e) {}
  75. }
  76. _.each(this.attribute, function(obj) {
  77. Enums.entityStateReadOnly[obj.status] ? Enums.entityStateReadOnly[obj.status] && that.deleteObj.push(obj) : (that.activeObj.push(obj),
  78. that.schemaCollection.push(obj));
  79. }), 0 === this.schemaCollection.length && this.deleteObj.length && (this.ui.checkDeletedEntity.find("input").prop("checked", !0),
  80. this.schemaCollection.fullCollection.reset(this.deleteObj)), 0 === this.activeObj.length && 0 === this.deleteObj.length && this.ui.checkDeletedEntity.hide(),
  81. this.renderTableLayoutView();
  82. },
  83. showLoader: function() {
  84. this.$(".fontLoader").show(), this.$(".tableOverlay").show();
  85. },
  86. hideLoader: function(argument) {
  87. this.$(".fontLoader").hide(), this.$(".tableOverlay").hide();
  88. },
  89. renderTableLayoutView: function() {
  90. var that = this;
  91. require([ "utils/TableLayout" ], function(TableLayout) {
  92. var columnCollection = Backgrid.Columns.extend({}), columns = new columnCollection(that.getSchemaTableColumns());
  93. that.RSchemaTableLayoutView.show(new TableLayout(_.extend({}, that.commonTableOptions, {
  94. columns: columns
  95. }))), that.$(".multiSelectTag").hide(), Utils.generatePopover({
  96. el: that.$('[data-id="showMoreLess"]'),
  97. contentClass: "popover-tag-term",
  98. viewFixedPopover: !0,
  99. popoverOptions: {
  100. container: null,
  101. content: function() {
  102. return $(this).find(".popup-tag-term").children().clone();
  103. }
  104. }
  105. });
  106. });
  107. },
  108. getSchemaTableColumns: function() {
  109. var that = this;
  110. var col = {
  111. Check: {
  112. name: "selected",
  113. label: "",
  114. cell: "select-row",
  115. headerCell: "select-all"
  116. }
  117. };
  118. if (this.schemaTableAttribute) return _.each(_.keys(this.schemaTableAttribute), function(key) {
  119. "position" !== key && (col[key] = {
  120. label: Utils.toChinese(key),
  121. cell: "html",
  122. editable: !1,
  123. className: "searchTableName",
  124. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  125. fromRaw: function(rawValue, model) {
  126. var value = _.escape(model.get("attributes")[key]);
  127. if ("name" === key && model.get("guid")) {
  128. var nameHtml = '<a href="#!/detailPage/' + model.get("guid") + '">' + value + "</a>";
  129. return model.get("status") && Enums.entityStateReadOnly[model.get("status")] ? (nameHtml += '<button type="button" title="已删除" class="btn btn-action btn-md deleteBtn"><i class="fa fa-trash"></i></button>',
  130. '<div class="readOnly readOnlyLink">' + nameHtml + "</div>") : nameHtml;
  131. }
  132. return value;
  133. }
  134. })
  135. });
  136. }), col.tag = {
  137. label: "分类",
  138. cell: "Html",
  139. editable: !1,
  140. sortable: !1,
  141. className: "searchTag",
  142. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  143. fromRaw: function(rawValue, model) {
  144. var obj = model.toJSON();
  145. return obj.status && Enums.entityStateReadOnly[obj.status] ? '<div class="readOnly">' + CommonViewFunction.tagForTable(obj) : CommonViewFunction.tagForTable(obj);
  146. }
  147. })
  148. }, this.schemaCollection.constructor.getTableCols(col, this.schemaCollection);
  149. },
  150. checkedValue: function(e) {
  151. e && e.stopPropagation();
  152. var guid = "", that = this, isTagMultiSelect = $(e.currentTarget).hasClass("multiSelectTag");
  153. isTagMultiSelect && this.arr && this.arr.length ? that.addTagModalView(guid, this.arr) : (guid = that.$(e.currentTarget).data("guid"),
  154. that.addTagModalView(guid));
  155. },
  156. addTagModalView: function(guid, multiple) {
  157. var that = this, tagList = that.schemaCollection.find({
  158. guid: guid
  159. });
  160. require([ "views/tag/AddTagModalView" ], function(AddTagModalView) {
  161. new AddTagModalView({
  162. guid: guid,
  163. multiple: multiple,
  164. tagList: _.map(tagList ? tagList.get("classifications") : [], function(obj) {
  165. return obj.typeName;
  166. }),
  167. callback: function() {
  168. that.fetchCollection(), that.arr = [];
  169. },
  170. hideLoader: that.hideLoader.bind(that),
  171. showLoader: that.showLoader.bind(that),
  172. collection: that.classificationDefCollection,
  173. enumDefCollection: that.enumDefCollection
  174. });
  175. });
  176. },
  177. onClickTagCross: function(e) {
  178. var that = this, tagName = $(e.target).data("name"), guid = $(e.target).data("guid"), assetName = $(e.target).data("assetname");
  179. CommonViewFunction.deleteTag({
  180. tagName: tagName,
  181. guid: guid,
  182. msg: "<div class='ellipsis-with-margin'>确认删除<b>" + _.escape(tagName) + "</b> 与 <b>" + _.escape(assetName) + "的关联?</b></div>",
  183. titleMessage: Messages.removeTag,
  184. okText: "移除",
  185. showLoader: that.showLoader.bind(that),
  186. hideLoader: that.hideLoader.bind(that),
  187. callback: function() {
  188. that.fetchCollection();
  189. }
  190. });
  191. },
  192. onCheckDeletedEntity: function(e) {
  193. e.target.checked ? this.deleteObj.length && this.schemaCollection.fullCollection.reset(this.activeObj.concat(this.deleteObj)) : this.schemaCollection.fullCollection.reset(this.activeObj);
  194. },
  195. });
  196. return SchemaTableLayoutView;
  197. });