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", "searchVent")),
  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: "No records found!"
  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 col = {
  110. Check: {
  111. name: "selected",
  112. label: "",
  113. cell: "select-row",
  114. headerCell: "select-all"
  115. }
  116. };
  117. if (this.schemaTableAttribute) return _.each(_.keys(this.schemaTableAttribute), function(key) {
  118. "position" !== key && (col[key] = {
  119. label: key.capitalize(),
  120. cell: "html",
  121. editable: !1,
  122. className: "searchTableName",
  123. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  124. fromRaw: function(rawValue, model) {
  125. var value = _.escape(model.get("attributes")[key]);
  126. if ("name" === key && model.get("guid")) {
  127. var nameHtml = '<a href="#!/detailPage/' + model.get("guid") + '">' + value + "</a>";
  128. return model.get("status") && Enums.entityStateReadOnly[model.get("status")] ? (nameHtml += '<button type="button" title="Deleted" class="btn btn-action btn-md deleteBtn"><i class="fa fa-trash"></i></button>',
  129. '<div class="readOnly readOnlyLink">' + nameHtml + "</div>") : nameHtml;
  130. }
  131. return value;
  132. }
  133. })
  134. });
  135. }), col.tag = {
  136. label: "Classifications",
  137. cell: "Html",
  138. editable: !1,
  139. sortable: !1,
  140. className: "searchTag",
  141. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  142. fromRaw: function(rawValue, model) {
  143. var obj = model.toJSON();
  144. return obj.status && Enums.entityStateReadOnly[obj.status] ? '<div class="readOnly">' + CommonViewFunction.tagForTable(obj) : CommonViewFunction.tagForTable(obj);
  145. }
  146. })
  147. }, this.schemaCollection.constructor.getTableCols(col, this.schemaCollection);
  148. },
  149. checkedValue: function(e) {
  150. e && e.stopPropagation();
  151. var guid = "", that = this, isTagMultiSelect = $(e.currentTarget).hasClass("multiSelectTag");
  152. isTagMultiSelect && this.arr && this.arr.length ? that.addTagModalView(guid, this.arr) : (guid = that.$(e.currentTarget).data("guid"),
  153. that.addTagModalView(guid));
  154. },
  155. addTagModalView: function(guid, multiple) {
  156. var that = this, tagList = that.schemaCollection.find({
  157. guid: guid
  158. });
  159. require([ "views/tag/AddTagModalView" ], function(AddTagModalView) {
  160. new AddTagModalView({
  161. guid: guid,
  162. multiple: multiple,
  163. tagList: _.map(tagList ? tagList.get("classifications") : [], function(obj) {
  164. return obj.typeName;
  165. }),
  166. callback: function() {
  167. that.searchVent && that.searchVent.trigger("Classification:Count:Update"), that.fetchCollection(),
  168. 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'>Remove: <b>" + _.escape(tagName) + "</b> assignment from <b>" + _.escape(assetName) + " ?</b></div>",
  183. titleMessage: Messages.removeTag,
  184. okText: "Remove",
  185. showLoader: that.showLoader.bind(that),
  186. hideLoader: that.hideLoader.bind(that),
  187. callback: function() {
  188. that.searchVent && that.searchVent.trigger("Classification:Count:Update"), 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. });