ClassificationTreeLayoutView.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. define([ "require", "hbs!tmpl/search/tree/ClassificationTreeLayoutView_tmpl", "utils/Utils", "utils/Messages", "utils/Globals", "utils/UrlLinks", "utils/CommonViewFunction", "collection/VSearchList", "collection/VGlossaryList", "utils/Enums", "collection/VTagList", "jstree" ], function(require, ClassificationTreeLayoutViewTmpl, Utils, Messages, Globals, UrlLinks, CommonViewFunction, VSearchList, VGlossaryList, Enums, VTagList) {
  2. "use strict";
  3. var ClassificationTreeLayoutView = Marionette.LayoutView.extend({
  4. template: ClassificationTreeLayoutViewTmpl,
  5. regions: {},
  6. ui: {
  7. refreshTree: '[data-id="refreshTree"]',
  8. groupOrFlatTree: '[data-id="groupOrFlatTreeView"]',
  9. classificationSearchTree: '[data-id="classificationSearchTree"]',
  10. showEmptyClassifications: '[data-id="showEmptyClassifications"]',
  11. createTag: '[data-id="createTag"]',
  12. wildCardClick: '[data-id="wildCardClick"]',
  13. wildCardSearch: '[data-id="wildCardSearch"]',
  14. wildCardValue: '[data-id="wildCardValue"]',
  15. wildCardContainer: '[data-id="wildCardContainer"]',
  16. clearWildCard: '[data-id="clearWildCard"]',
  17. classificationTreeLoader: '[data-id="classificationTreeLoader"]'
  18. },
  19. templateHelpers: function() {
  20. return {
  21. apiBaseUrl: UrlLinks.apiBaseUrl
  22. };
  23. },
  24. events: function() {
  25. var events = {}, that = this;
  26. return events["click " + this.ui.refreshTree] = function(e) {
  27. that.changeLoaderState(!0), that.ui.refreshTree.attr("disabled", !0).tooltip("hide");
  28. var type = $(e.currentTarget).data("type");
  29. e.stopPropagation(), that.refresh({
  30. type: type
  31. });
  32. }, events["click " + this.ui.createTag] = function(e) {
  33. e.stopPropagation(), that.onClickCreateTag();
  34. }, events["click " + this.ui.showEmptyClassifications] = function(e) {
  35. e.stopPropagation(), this.isEmptyClassification = !this.isEmptyClassification, this.classificationSwitchBtnUpdate();
  36. }, events["click " + this.ui.groupOrFlatTree] = function(e) {
  37. var type = $(e.currentTarget).data("type");
  38. e.stopPropagation(), this.isGroupView = !this.isGroupView, this.ui.groupOrFlatTree.tooltip("hide"),
  39. this.ui.groupOrFlatTree.find("i").toggleClass("fa-sitemap fa-list-ul"), this.ui.groupOrFlatTree.find("span").html(this.isGroupView ? "Show flat tree" : "Show group tree"),
  40. that.ui[type + "SearchTree"].jstree(!0).destroy(), that.renderClassificationTree();
  41. }, events["click " + this.ui.wildCardClick] = function(e) {
  42. e.stopPropagation();
  43. }, events["click " + this.ui.wildCardSearch] = function(e) {
  44. e.stopPropagation();
  45. var tagValue = this.ui.wildCardValue.val();
  46. tagValue.indexOf("*") != -1 && that.findSearchResult(tagValue);
  47. }, events["click " + this.ui.wildCardValue] = function(e) {
  48. e.stopPropagation();
  49. }, events["click " + this.ui.clearWildCard] = function(e) {
  50. e.stopPropagation(), that.ui.wildCardValue.val(""), that.ui.clearWildCard.addClass("hide-icon");
  51. }, events["click " + this.ui.wildCardContainer] = function(e) {
  52. e.stopPropagation();
  53. }, events["keydown " + this.ui.wildCardValue] = function(e) {
  54. e.stopPropagation();
  55. var code = e.which;
  56. if (this.ui.wildCardValue.val().length > 0 ? this.ui.clearWildCard.removeClass("hide-icon") : this.ui.clearWildCard.addClass("hide-icon"),
  57. 13 == code) {
  58. e.preventDefault();
  59. var tagValue = this.ui.wildCardValue.val();
  60. tagValue.indexOf("*") != -1 && that.findSearchResult(tagValue);
  61. }
  62. }, events["keyup " + this.ui.wildCardValue] = function(e) {
  63. e.stopPropagation(), e.preventDefault();
  64. }, events;
  65. },
  66. initialize: function(options) {
  67. this.options = options, _.extend(this, _.pick(options, "typeHeaders", "searchVent", "entityDefCollection", "enumDefCollection", "classificationDefCollection", "searchTableColumns", "searchTableFilters", "metricCollection")),
  68. this.bindEvents(), this.entityCountObj = _.first(this.metricCollection.toJSON()),
  69. this.isEmptyClassification = !1, this.entityTreeData = {}, this.tagId = null, this.isGroupView = !0;
  70. },
  71. onRender: function() {
  72. this.changeLoaderState(!0), this.checkTagOnRefresh(), this.createClassificationAction(),
  73. this.ui.clearWildCard.addClass("hide-icon"), this.changeLoaderState(!1);
  74. },
  75. checkTagOnRefresh: function() {
  76. var that = this, tagName = this.options && this.options.value ? this.options.value.tag : null, presentTag = this.classificationDefCollection.fullCollection.findWhere({
  77. name: tagName
  78. }), tag = new VTagList();
  79. !presentTag && tagName ? (tag.url = UrlLinks.classificationDefApiUrl(tagName), tag.fetch({
  80. success: function(dataOrCollection, tagDetails) {
  81. that.classificationDefCollection.fullCollection.add(tagDetails);
  82. },
  83. cust_error: function(model, response) {
  84. that.renderClassificationTree();
  85. }
  86. })) : this.renderClassificationTree();
  87. },
  88. changeLoaderState: function(showLoader) {
  89. showLoader ? (this.ui.classificationSearchTree.hide(), this.ui.classificationTreeLoader.show()) : (this.ui.classificationSearchTree.show(),
  90. this.ui.classificationTreeLoader.hide());
  91. },
  92. bindEvents: function() {
  93. var that = this;
  94. this.listenTo(this.classificationDefCollection.fullCollection, "reset add", function(model) {
  95. that.classificationTreeUpdate = !0, that.classificationTreeRefresh();
  96. }, this), this.listenTo(this.classificationDefCollection.fullCollection, "remove", function(model) {
  97. that.classificationTreeUpdate = !1, that.classificationTreeRefresh();
  98. }, this), $("body").on("click", ".classificationPopoverOptions li", function(e) {
  99. that.$(".classificationPopover").popover("hide"), that[$(this).find("a").data("fn") + "Classification"](e);
  100. }), this.searchVent.on("Classification:Count:Update", function(options) {
  101. that.changeLoaderState(!0);
  102. var opt = options || {};
  103. opt && !opt.metricData ? that.metricCollection.fetch({
  104. complete: function() {
  105. that.entityCountObj = _.first(that.metricCollection.toJSON()), that.classificationTreeUpdate = !0,
  106. that.ui.classificationSearchTree.jstree(!0).refresh(), that.changeLoaderState(!1);
  107. }
  108. }) : (that.entityCountObj = opt.metricData, that.ui.classificationSearchTree.jstree(!0).refresh(),
  109. that.changeLoaderState(!1));
  110. });
  111. },
  112. classificationTreeRefresh: function() {
  113. this.ui.classificationSearchTree.jstree(!0) ? this.ui.classificationSearchTree.jstree(!0).refresh() : this.renderClassificationTree();
  114. },
  115. findSearchResult: function(tagValue) {
  116. if (!tagValue) return void Utils.notifyInfo({
  117. content: "Search should not be empty!"
  118. });
  119. var params = {
  120. searchType: "basic",
  121. dslChecked: !1
  122. };
  123. this.options.value && (params.tag = tagValue);
  124. var searchParam = _.extend({}, this.options.value, params);
  125. this.triggerSearch(searchParam);
  126. },
  127. onSearchClassificationNode: function(showEmptyTag) {
  128. this.isEmptyClassification = showEmptyTag, this.classificationSwitchBtnUpdate();
  129. },
  130. classificationSwitchBtnUpdate: function() {
  131. this.ui.showEmptyClassifications.attr("data-original-title", (this.isEmptyClassification ? "Show" : "Hide") + " unused classification"),
  132. this.ui.showEmptyClassifications.tooltip("hide"), this.ui.showEmptyClassifications.find("i").toggleClass("fa-toggle-on fa-toggle-off"),
  133. this.ui.showEmptyClassifications.find("span").html((this.isEmptyClassification ? "Show" : "Hide") + " unused classification"),
  134. this.ui.classificationSearchTree.jstree(!0).refresh();
  135. },
  136. createClassificationAction: function() {
  137. Utils.generatePopover({
  138. el: this.$el,
  139. contentClass: "classificationPopoverOptions",
  140. popoverOptions: {
  141. selector: ".classificationPopover",
  142. content: function() {
  143. var name = this.dataset.name || null, searchString = "<li><i class='fa fa-search'></i><a href='javascript:void(0)' data-fn='onSelectedSearch'>Search</a></li>";
  144. if (name && Enums.addOnClassification.includes(name)) return "<ul>" + searchString + "</ul>";
  145. var liString = " <li><i class='fa fa-plus'></i><a href='javascript:void(0)' data-fn='onClickCreateTag'>Create Sub-classification</a></li><li><i class='fa fa-list-alt'></i><a href='javascript:void(0)' data-fn='onViewEdit'>View/Edit</a></li><li><i class='fa fa-trash-o'></i><a href='javascript:void(0)' data-fn='onDelete'>Delete</a></li>";
  146. return "<ul>" + liString + searchString + "</ul>";
  147. }
  148. }
  149. });
  150. },
  151. renderClassificationTree: function() {
  152. this.generateSearchTree({
  153. $el: this.ui.classificationSearchTree
  154. });
  155. },
  156. manualRender: function(options) {
  157. var that = this;
  158. if (_.extend(this.options, options), void 0 === this.options.value && (this.options.value = {}),
  159. this.options.value.tag) {
  160. if ("_ALL_CLASSIFICATION_TYPES" === that.options.value.tag && "_ALL_CLASSIFICATION_TYPES" !== this.tagId || "_NOT_CLASSIFIED" === that.options.value.tag && "_NOT_CLASSIFIED" !== this.tagId || "_CLASSIFIED" === that.options.value.tag && "_CLASSIFIED" !== this.tagId) this.fromManualRender = !0,
  161. this.tagId && this.ui.classificationSearchTree.jstree(!0).deselect_node(this.tagId),
  162. this.tagId = Globals[that.options.value.tag].guid, this.ui.classificationSearchTree.jstree(!0).select_node(this.tagId); else if ("_ALL_CLASSIFICATION_TYPES" !== this.tagId && that.options.value.tag !== this.tagId || "_NOT_CLASSIFIED" !== this.tagId && that.options.value.tag !== this.tagId || "_CLASSIFIED" !== this.tagId && that.options.value.tag !== this.tagId) {
  163. that.options.value.tag.indexOf("*") != -1 && (that.ui.classificationSearchTree.jstree(!0).deselect_all(),
  164. that.ui.wildCardValue.val(that.options.value.tag));
  165. var dataFound = this.classificationDefCollection.fullCollection.find(function(obj) {
  166. return obj.get("name") === that.options.value.tag;
  167. });
  168. dataFound && (this.tagId && this.tagId !== dataFound.get("guid") || null === this.tagId) && (this.tagId && this.ui.classificationSearchTree.jstree(!0).deselect_node(this.tagId),
  169. this.fromManualRender = !0, this.tagId = dataFound.get("guid"), this.ui.classificationSearchTree.jstree(!0).select_node(dataFound.get("guid")));
  170. }
  171. } else this.ui.classificationSearchTree.jstree(!0).deselect_all(), this.tagId = null;
  172. },
  173. onNodeSelect: function(options) {
  174. if (this.classificationTreeUpdate) return void (this.classificationTreeUpdate = !1);
  175. var name, selectedNodeId, that = this;
  176. that.ui.wildCardValue.val(""), options ? (name = options.node.original.name, selectedNodeId = options.node.id) : name = this.options.value.type || this.options.value.tag;
  177. var tagValue = null, params = {
  178. searchType: "basic",
  179. dslChecked: !1
  180. };
  181. if (this.options.value && (this.options.value.tag && (params.tag = this.options.value.tag),
  182. this.options.value.isCF && (this.options.value.isCF = null), this.options.value.tagFilters && (params.tagFilters = null)),
  183. that.tagId != selectedNodeId) that.tagId = selectedNodeId, tagValue = name, params.tag = tagValue; else if (that.options.value.tag = that.tagId = params.tag = null,
  184. that.ui.classificationSearchTree.jstree(!0).deselect_all(!0), !(that.options.value.type || that.options.value.tag || that.options.value.term || that.options.value.query)) {
  185. var defaultUrl = "#!/search";
  186. return void that.onClassificationUpdate(defaultUrl);
  187. }
  188. var searchParam = _.extend({}, this.options.value, params);
  189. this.triggerSearch(searchParam);
  190. },
  191. triggerSearch: function(params, url) {
  192. var serachUrl = url ? url : "#!/search/searchResult";
  193. Utils.setUrl({
  194. url: serachUrl,
  195. urlParams: params,
  196. mergeBrowserUrl: !1,
  197. trigger: !0,
  198. updateTabState: !0
  199. });
  200. },
  201. onClassificationUpdate: function(url) {
  202. Utils.setUrl({
  203. url: url,
  204. mergeBrowserUrl: !1,
  205. trigger: !0,
  206. updateTabState: !0
  207. });
  208. },
  209. refresh: function(options) {
  210. var that = this, apiCount = 2, renderTree = function() {
  211. 0 === apiCount && (that.classificationDefCollection.fullCollection.comparator = function(model) {
  212. return model.get("name").toLowerCase();
  213. }, that.classificationDefCollection.fullCollection.sort({
  214. silent: !0
  215. }), that.classificationTreeUpdate = !0, that.ui.classificationSearchTree.jstree(!0).refresh(),
  216. that.changeLoaderState(!1), that.ui.refreshTree.attr("disabled", !1));
  217. };
  218. this.classificationDefCollection.fetch({
  219. silent: !0,
  220. complete: function() {
  221. --apiCount, renderTree();
  222. }
  223. }), this.metricCollection.fetch({
  224. complete: function() {
  225. --apiCount, that.entityCountObj = _.first(that.metricCollection.toJSON()), renderTree();
  226. }
  227. });
  228. },
  229. getClassificationTree: function(options) {
  230. var that = this, collection = options && options.collection || this.classificationDefCollection.fullCollection, listOfParents = [], listWithEmptyParents = [], listWithEmptyParentsFlatView = [], flatViewList = [], isSelectedChild = !1, generateNode = function(nodeOptions, options, isChild) {
  231. var nodeStructure = {
  232. text: _.escape(nodeOptions.name),
  233. name: _.escape(nodeOptions.name),
  234. children: that.isGroupView ? getChildren({
  235. children: isChild ? nodeOptions.model.subTypes : nodeOptions.model.get("subTypes"),
  236. parent: isChild ? options.parentName : nodeOptions.name
  237. }) : null,
  238. type: isChild ? nodeOptions.children.get("category") : nodeOptions.model.get("category"),
  239. id: isChild ? nodeOptions.children.get("guid") : nodeOptions.model.get("guid"),
  240. icon: "fa fa-tag",
  241. gType: "Classification"
  242. };
  243. return nodeStructure;
  244. }, getChildren = function(options) {
  245. var children = options.children, data = [], dataWithoutEmptyTag = [];
  246. children && children.length && _.each(children, function(name) {
  247. var child = collection.find({
  248. name: name
  249. }), tagEntityCount = that.entityCountObj ? that.entityCountObj.tag.tagEntities[name] : null, tagname = tagEntityCount ? name + " (" + _.numberFormatWithComma(tagEntityCount) + ")" : name;
  250. if (that.options.value && (isSelectedChild = !!that.options.value.tag && that.options.value.tag == name,
  251. that.tagId || (that.tagId = isSelectedChild ? child.get("guid") : null)), child) {
  252. var modelJSON = child.toJSON(), nodeDetails = {
  253. name: _.escape(name),
  254. model: modelJSON,
  255. children: child,
  256. isSelectedChild: isSelectedChild
  257. }, nodeProperties = {
  258. parent: options.parentName,
  259. text: _.escape(tagname),
  260. guid: child.get("guid"),
  261. model: child,
  262. state: {
  263. selected: isSelectedChild,
  264. opened: !0
  265. }
  266. }, isChild = !0, getNodeDetails = generateNode(nodeDetails, options, isChild), classificationNode = _.extend(getNodeDetails, nodeProperties);
  267. if (data.push(classificationNode), that.isEmptyClassification) {
  268. var isTagEntityCount = _.isNaN(tagEntityCount) ? 0 : tagEntityCount;
  269. isTagEntityCount && dataWithoutEmptyTag.push(classificationNode);
  270. }
  271. }
  272. });
  273. var tagData = that.isEmptyClassification ? dataWithoutEmptyTag : data;
  274. return tagData;
  275. };
  276. collection.each(function(model) {
  277. var modelJSON = model.toJSON(), name = modelJSON.name, tagEntityCount = that.entityCountObj ? that.entityCountObj.tag.tagEntities[name] : null, tagname = tagEntityCount ? name + " (" + _.numberFormatWithComma(tagEntityCount) + ")" : name, isSelected = !1;
  278. that.options.value && (isSelected = !!that.options.value.tag && that.options.value.tag == name,
  279. that.tagId || (that.tagId = isSelected ? model.get("guid") : null));
  280. var getParentNodeDetails, classificationParentNode, getParentFlatView, classificationParentFlatView, parentNodeDetails = {
  281. name: _.escape(name),
  282. model: model,
  283. isSelectedChild: isSelectedChild
  284. }, parentNodeProperties = {
  285. text: _.escape(tagname),
  286. state: {
  287. disabled: 0 == tagEntityCount,
  288. selected: isSelected,
  289. opened: !0
  290. }
  291. }, isChild = !1;
  292. if (0 == modelJSON.superTypes.length && (getParentNodeDetails = generateNode(parentNodeDetails, model, isChild),
  293. classificationParentNode = _.extend(getParentNodeDetails, parentNodeProperties),
  294. listOfParents.push(classificationParentNode)), getParentFlatView = generateNode(parentNodeDetails, model),
  295. classificationParentFlatView = _.extend(getParentFlatView, parentNodeProperties),
  296. flatViewList.push(classificationParentFlatView), that.isEmptyClassification) {
  297. var isTagEntityCount = _.isNaN(tagEntityCount) ? 0 : tagEntityCount;
  298. isTagEntityCount && (0 == modelJSON.superTypes.length && listWithEmptyParents.push(classificationParentNode),
  299. listWithEmptyParentsFlatView.push(classificationParentFlatView));
  300. }
  301. });
  302. var classificationTreeData = that.isEmptyClassification ? listWithEmptyParents : listOfParents, flatViewClassificaton = that.isEmptyClassification ? listWithEmptyParentsFlatView : flatViewList, classificationData = that.isGroupView ? that.pushRootClassificationToJstree.call(that, classificationTreeData) : that.pushRootClassificationToJstree.call(that, flatViewClassificaton);
  303. return classificationData;
  304. },
  305. pushRootClassificationToJstree: function(data) {
  306. var that = this;
  307. return _.each(Enums.addOnClassification, function(addOnClassification) {
  308. var rootClassification = Globals[addOnClassification], isSelected = !(!that.options.value || !that.options.value.tag) && that.options.value.tag == rootClassification.name, rootClassificationNode = {
  309. text: _.escape(rootClassification.name),
  310. name: rootClassification.name,
  311. type: rootClassification.category,
  312. gType: "Classification",
  313. guid: rootClassification.guid,
  314. id: rootClassification.guid,
  315. model: rootClassification,
  316. children: [],
  317. icon: "fa fa-tag",
  318. state: {
  319. selected: isSelected
  320. }
  321. };
  322. data.push(rootClassificationNode);
  323. }), data;
  324. },
  325. generateSearchTree: function(options) {
  326. var $el = options && options.$el, that = (options && options.type, this), getEntityTreeConfig = function(opt) {
  327. return {
  328. plugins: [ "search", "core", "sort", "conditionalselect", "changed", "wholerow", "node_customize" ],
  329. conditionalselect: function(node) {
  330. var type = node.original.type;
  331. return "ENTITY" != type && "GLOSSARY" != type || !node.children.length && "GLOSSARY" != type;
  332. },
  333. state: {
  334. opened: !0
  335. },
  336. search: {
  337. show_only_matches: !0,
  338. case_sensitive: !1
  339. },
  340. node_customize: {
  341. default: function(el) {
  342. var aTag = $(el).find(">a.jstree-anchor"), nameText = aTag.text();
  343. aTag.append("<span class='tree-tooltip'>" + nameText + "</span>"), $(el).append('<div class="tools"><i class="fa fa-ellipsis-h classificationPopover" rel="popover" data-name=' + nameText + "></i></div>");
  344. }
  345. },
  346. core: {
  347. multiple: !1,
  348. data: function(node, cb) {
  349. "#" === node.id && cb(that.getClassificationTree());
  350. }
  351. }
  352. };
  353. };
  354. $el.jstree(getEntityTreeConfig({
  355. type: ""
  356. })).on("open_node.jstree", function(e, data) {
  357. that.isTreeOpen = !0;
  358. }).on("select_node.jstree", function(e, data) {
  359. that.fromManualRender !== !0 ? that.onNodeSelect(data) : that.fromManualRender = !1;
  360. }).on("search.jstree", function(nodes, str, res) {
  361. 0 === str.nodes.length ? ($el.jstree(!0).hide_all(), $el.parents(".panel").addClass("hide")) : $el.parents(".panel").removeClass("hide");
  362. }).on("hover_node.jstree", function(nodes, str, res) {
  363. var aTag = that.$("#" + str.node.a_attr.id), tagOffset = aTag.find(">.jstree-icon").offset();
  364. that.$(".tree-tooltip").removeClass("show"), setTimeout(function() {
  365. aTag.hasClass("jstree-hovered") && tagOffset.top && tagOffset.left && aTag.find(">span.tree-tooltip").css({
  366. top: "calc(" + tagOffset.top + "px - 45px)",
  367. left: "24px"
  368. }).addClass("show");
  369. }, 1200);
  370. }).on("dehover_node.jstree", function(nodes, str, res) {
  371. that.$(".tree-tooltip").removeClass("show");
  372. });
  373. },
  374. onClickCreateTag: function(tagName) {
  375. var that = this;
  376. require([ "views/tag/CreateTagLayoutView", "modules/Modal" ], function(CreateTagLayoutView, Modal) {
  377. var view = new CreateTagLayoutView({
  378. tagCollection: that.options.classificationDefCollection,
  379. enumDefCollection: enumDefCollection,
  380. selectedTag: tagName
  381. }), modal = new Modal({
  382. title: "Create a new classification",
  383. content: view,
  384. cancelText: "Cancel",
  385. okCloses: !1,
  386. okText: "Create",
  387. allowCancel: !0
  388. }).open();
  389. modal.$el.find("button.ok").attr("disabled", "true"), view.ui.tagName.on("keyup input", function(e) {
  390. view.ui.description.val($(this).val().replace(/\s+/g, " "));
  391. }), view.ui.description.on("input keydown", function(e) {
  392. $(this).val($(this).val().replace(/\s+/g, " "));
  393. }), modal.on("shownModal", function() {
  394. view.ui.parentTag.select2({
  395. multiple: !0,
  396. placeholder: "Search Classification",
  397. allowClear: !0
  398. });
  399. }), modal.on("ok", function() {
  400. modal.$el.find("button.ok").showButtonLoader(), that.onCreateTagButton(view, modal);
  401. }), modal.on("closeModal", function() {
  402. modal.trigger("cancel");
  403. });
  404. });
  405. },
  406. onCreateTagButton: function(ref, modal) {
  407. var that = this, validate = !0;
  408. if (modal.$el.find(".attributeInput").length > 0 && modal.$el.find(".attributeInput").each(function() {
  409. "" === $(this).val() && ($(this).css("borderColor", "red"), validate = !1);
  410. }), modal.$el.find(".attributeInput").keyup(function() {
  411. $(this).css("borderColor", "#e8e9ee"), modal.$el.find("button.ok").removeAttr("disabled");
  412. }), !validate) return Utils.notifyInfo({
  413. content: "Please fill the attributes or delete the input box"
  414. }), void modal.$el.find("button.ok").hideButtonLoader();
  415. var name = ref.ui.tagName.val(), description = ref.ui.description.val(), superTypes = [], parentTagVal = ref.ui.parentTag.val();
  416. parentTagVal && parentTagVal.length && (superTypes = parentTagVal);
  417. var attributeObj = ref.collection.toJSON();
  418. if (1 === ref.collection.length && "" === ref.collection.first().get("name") && (attributeObj = []),
  419. attributeObj.length) {
  420. var superTypesAttributes = [];
  421. _.each(superTypes, function(name) {
  422. var parentTags = that.options.classificationDefCollection.fullCollection.findWhere({
  423. name: name
  424. });
  425. superTypesAttributes = superTypesAttributes.concat(parentTags.get("attributeDefs"));
  426. });
  427. var duplicateAttributeList = [];
  428. _.each(attributeObj, function(obj) {
  429. var duplicateCheck = _.find(superTypesAttributes, function(activeTagObj) {
  430. return activeTagObj.name.toLowerCase() === obj.name.toLowerCase();
  431. });
  432. duplicateCheck && duplicateAttributeList.push(_.escape(obj.name));
  433. });
  434. var notifyObj = {
  435. modal: !0,
  436. confirm: {
  437. confirm: !0,
  438. buttons: [ {
  439. text: "Ok",
  440. addClass: "btn-atlas btn-md",
  441. click: function(notice) {
  442. notice.remove();
  443. }
  444. }, null ]
  445. }
  446. };
  447. if (duplicateAttributeList.length) {
  448. if (duplicateAttributeList.length < 2) var text = "Attribute <b>" + duplicateAttributeList.join(",") + "</b> is duplicate !"; else if (attributeObj.length > duplicateAttributeList.length) var text = "Attributes: <b>" + duplicateAttributeList.join(",") + "</b> are duplicate !"; else var text = "All attributes are duplicate !";
  449. return notifyObj.text = text, Utils.notifyConfirm(notifyObj), modal.$el.find("button.ok").hideButtonLoader(),
  450. !1;
  451. }
  452. }
  453. this.json = {
  454. classificationDefs: [ {
  455. name: name.trim(),
  456. description: description.trim(),
  457. superTypes: superTypes.length ? superTypes : [],
  458. attributeDefs: attributeObj
  459. } ],
  460. entityDefs: [],
  461. enumDefs: [],
  462. structDefs: []
  463. }, new this.options.classificationDefCollection.model().set(this.json).save(null, {
  464. success: function(model, response) {
  465. var classificationDefs = model.get("classificationDefs");
  466. that.createTag = !0, classificationDefs[0] && _.each(classificationDefs[0].superTypes, function(superType) {
  467. var superTypeModel = that.options.classificationDefCollection.fullCollection.find({
  468. name: superType
  469. }), subTypes = [];
  470. superTypeModel && (subTypes = superTypeModel.get("subTypes"), subTypes.push(classificationDefs[0].name),
  471. superTypeModel.set({
  472. subTypes: _.uniq(subTypes)
  473. }));
  474. }), that.options.classificationDefCollection.fullCollection.add(classificationDefs),
  475. Utils.notifySuccess({
  476. content: "Classification " + name + Messages.getAbbreviationMsg(!1, "addSuccessMessage")
  477. }), modal.trigger("cancel"), modal.$el.find("button.ok").showButtonLoader(), that.typeHeaders.fetch({
  478. reset: !0
  479. });
  480. },
  481. complete: function() {
  482. modal.$el.find("button.ok").hideButtonLoader();
  483. }
  484. });
  485. },
  486. onClickCreateTagClassification: function(e) {
  487. var selectedNode = this.ui.classificationSearchTree.jstree("get_selected", !0);
  488. selectedNode && selectedNode[0] && this.onClickCreateTag(selectedNode[0].original.name);
  489. },
  490. onViewEditClassification: function() {
  491. var selectedNode = this.ui.classificationSearchTree.jstree("get_selected", !0);
  492. if (selectedNode && selectedNode[0]) {
  493. var url = "#!/tag/tagAttribute/" + selectedNode[0].original.name + "?tag=" + selectedNode[0].original.name;
  494. this.onClassificationUpdate(url);
  495. }
  496. },
  497. onDeleteClassification: function() {
  498. var that = this, notifyObj = {
  499. modal: !0,
  500. ok: function(obj) {
  501. that.notificationModal = obj, obj.showButtonLoader(), that.onNotifyOk();
  502. },
  503. okCloses: !1,
  504. cancel: function(argument) {}
  505. }, text = "Are you sure you want to delete the classification";
  506. notifyObj.text = text, Utils.notifyConfirm(notifyObj);
  507. },
  508. onSelectedSearchClassification: function() {
  509. var params = {
  510. searchType: "basic",
  511. dslChecked: !1,
  512. tag: this.options.value.tag
  513. };
  514. this.triggerSearch(params);
  515. },
  516. onNotifyOk: function(data) {
  517. var that = this;
  518. if (this.tagId) {
  519. var deleteTagData = this.classificationDefCollection.fullCollection.findWhere({
  520. guid: this.tagId
  521. });
  522. if (deleteTagData) {
  523. var tagName = deleteTagData.get("name"), superTypeOfDeleteTag = deleteTagData.get("superTypes"), superTypeObj = superTypeOfDeleteTag ? this.classificationDefCollection.fullCollection.findWhere({
  524. name: superTypeOfDeleteTag[0]
  525. }) : null;
  526. deleteTagData.deleteTag({
  527. typeName: tagName,
  528. success: function() {
  529. if (Utils.notifySuccess({
  530. content: "Classification " + tagName + Messages.getAbbreviationMsg(!1, "deleteSuccessMessage")
  531. }), superTypeObj) {
  532. var parentSubTypeUpdate = _.reject(superTypeObj.get("subTypes"), function(subtype) {
  533. return subtype === tagName;
  534. });
  535. superTypeObj.set("subTypes", parentSubTypeUpdate);
  536. }
  537. var searchUrl = Globals.saveApplicationState.tabState.searchUrl, urlObj = Utils.getUrlState.getQueryParams(searchUrl);
  538. that.classificationDefCollection.fullCollection.remove(deleteTagData), that.ui.classificationSearchTree.jstree(!0).refresh(),
  539. delete urlObj.tag;
  540. var url = urlObj.type || urlObj.term || urlObj.query ? "#!/search/searchResult" : "#!/search";
  541. that.triggerSearch(urlObj, url);
  542. },
  543. complete: function() {
  544. that.notificationModal.hideButtonLoader(), that.notificationModal.remove();
  545. }
  546. });
  547. } else Utils.notifyError({
  548. content: Messages.defaultErrorMessage
  549. });
  550. }
  551. }
  552. });
  553. return ClassificationTreeLayoutView;
  554. });