GlossaryTreeLayoutView.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. define([ "require", "hbs!tmpl/search/tree/GlossaryTreeLayoutView_tmpl", "utils/Utils", "utils/Messages", "utils/Globals", "utils/UrlLinks", "utils/CommonViewFunction", "collection/VSearchList", "collection/VGlossaryList", "jstree" ], function(require, GlossaryTreeLayoutView_tmpl, Utils, Messages, Globals, UrlLinks, CommonViewFunction, VSearchList, VGlossaryList) {
  2. "use strict";
  3. var GlossaryTreeLayoutView = Marionette.LayoutView.extend({
  4. template: GlossaryTreeLayoutView_tmpl,
  5. regions: {},
  6. ui: {
  7. refreshTree: '[data-id="refreshTree"]',
  8. termSearchTree: '[data-id="termSearchTree"]',
  9. createGlossary: '[data-id="createGlossary"]',
  10. showGlossaryType: '[data-id="showGlossaryType"]',
  11. importGlossary: "[data-id='importGlossary']",
  12. downloadTemplate: "[data-id='downloadTemplate']",
  13. glossaryTreeLoader: ".glossary-tree-loader"
  14. },
  15. templateHelpers: function() {
  16. return {
  17. apiBaseUrl: UrlLinks.apiBaseUrl,
  18. importTmplUrl: UrlLinks.glossaryImportTempUrl()
  19. };
  20. },
  21. events: function() {
  22. var events = {}, that = this;
  23. return events["click " + this.ui.refreshTree] = function(e) {
  24. that.changeLoaderState(!0), that.ui.refreshTree.attr("disabled", !0).tooltip("hide");
  25. var type = $(e.currentTarget).data("type");
  26. e.stopPropagation(), that.refresh({
  27. type: type
  28. });
  29. }, events["click " + this.ui.createGlossary] = function(e) {
  30. var that = this;
  31. e.stopPropagation(), CommonViewFunction.createEditGlossaryCategoryTerm({
  32. isGlossaryView: !0,
  33. collection: that.glossaryCollection,
  34. callback: function(rModel) {
  35. that.glossaryCollection.fullCollection.add(rModel);
  36. },
  37. onModalClose: function() {}
  38. });
  39. }, events["click " + this.ui.showGlossaryType] = function(e) {
  40. e.stopPropagation(), this.isTermView = !this.isTermView, this.glossarySwitchBtnUpdate();
  41. }, events["click " + this.ui.importGlossary] = function(e) {
  42. e.stopPropagation();
  43. var $target = $(e.target);
  44. 0 == $target.parents(".disable-list-option").length && 0 == $target.hasClass("disable-list-option") && that.onClickImportGlossary();
  45. }, events["click " + this.ui.downloadTemplate] = function(e) {
  46. e.stopPropagation();
  47. }, events;
  48. },
  49. bindEvents: function() {
  50. var that = this;
  51. this.listenTo(this.glossaryCollection.fullCollection, "reset add change", function(skip) {
  52. this.ui.termSearchTree.jstree(!0) ? (that.isGlossaryTree = !0, this.ui.termSearchTree.jstree(!0).refresh()) : this.renderGlossaryTree(),
  53. that.changeLoaderState(), that.ui.refreshTree.attr("disabled", !1);
  54. }, this), this.options.categoryEvent && this.options.categoryEvent.on("Success:TermRename", function(options) {
  55. that.refresh();
  56. }), $("body").on("click", ".termPopoverOptions li, .categoryPopoverOptions li", function(e) {
  57. that.$(".termPopover,.categoryPopover").popover("hide"), that[$(this).find("a").data("fn")](e);
  58. });
  59. },
  60. glossarySwitchBtnUpdate: function() {
  61. var tooltipTitle = this.isTermView ? "Show Category" : "Show Term";
  62. this.ui.showGlossaryType.attr({
  63. "data-original-title": tooltipTitle,
  64. title: tooltipTitle
  65. }), this.ui.showGlossaryType.tooltip("hide"), this.ui.showGlossaryType.find("i").toggleClass("switch-button"),
  66. this.isTermView ? (this.ui.importGlossary.removeClass("disable-list-option").find("a").attr("href", "javascript:void(0)"),
  67. this.ui.downloadTemplate.removeClass("disable-list-option").find("a").attr("href", UrlLinks.glossaryImportTempUrl())) : (this.ui.importGlossary.addClass("disable-list-option").find("a").removeAttr("href"),
  68. this.ui.downloadTemplate.addClass("disable-list-option").find("a").removeAttr("href")),
  69. this.ui.termSearchTree.jstree(!0).refresh();
  70. },
  71. initialize: function(options) {
  72. this.options = options, _.extend(this, _.pick(options, "typeHeaders", "searchVent", "entityDefCollection", "enumDefCollection", "classificationDefCollection", "searchTableColumns", "searchTableFilters", "metricCollection", "query", "categoryEvent")),
  73. this.glossaryTermId = this.glossaryId = null, this.glossaryCollection = new VGlossaryList([], {
  74. comparator: function(item) {
  75. return item.get("name");
  76. }
  77. }), this.getViewType(), this.bindEvents(), this.isGlossaryTree = this.isGlossryTreeview();
  78. },
  79. isGlossryTreeview: function() {
  80. var queryParams = Utils.getUrlState.getQueryParams();
  81. if (queryParams && ("term" === queryParams.gType || "category" === queryParams.gType)) return !0;
  82. },
  83. onRender: function() {
  84. this.changeLoaderState(!0), this.fetchGlossary();
  85. },
  86. changeLoaderState: function(showLoader) {
  87. showLoader ? (this.ui.termSearchTree.hide(), this.ui.glossaryTreeLoader.show()) : (this.ui.termSearchTree.show(),
  88. this.ui.glossaryTreeLoader.hide());
  89. },
  90. onBeforeDestroy: function() {
  91. this.options.categoryEvent.off("Success:TermRename");
  92. },
  93. getViewType: function() {
  94. Utils.getUrlState.isGlossaryTab() ? this.isTermView = !this.options.value.viewType || "term" == this.options.value.viewType : this.isTermView = !0;
  95. },
  96. manualRender: function(options) {
  97. if (_.extend(this.options, options), void 0 === this.options.value && (this.options.value = {}),
  98. this.options.value.term || "category" == this.options.value.gType) {
  99. if (this.options.value.term) {
  100. var glossaryName = this.options.value.term.split("@")[1], termName = this.options.value.term.split("@")[0], dataFound = this.glossaryCollection.fullCollection.find(function(obj) {
  101. return obj.get("name") === glossaryName;
  102. });
  103. if (dataFound) {
  104. var terms = dataFound.get("terms"), terModel = _.find(terms, function(model) {
  105. return model.displayText === termName;
  106. });
  107. terModel && (this.glossaryTermId && this.glossaryTermId !== terModel.termGuid || null === this.glossaryTermId) && (this.glossaryTermId && this.ui.termSearchTree.jstree(!0).deselect_node(this.glossaryTermId),
  108. this.ui.termSearchTree.jstree(!0).deselect_all(), this.glossaryTermId = terModel.termGuid,
  109. this.fromManualRender = !0, this.ui.termSearchTree.jstree(!0).select_node(terModel.termGuid));
  110. }
  111. }
  112. } else this.ui.termSearchTree.jstree(!0).deselect_all(), this.glossaryTermId = null;
  113. },
  114. fetchGlossary: function() {
  115. this.glossaryCollection.fetch({
  116. reset: !0
  117. });
  118. },
  119. renderGlossaryTree: function() {
  120. this.generateSearchTree({
  121. $el: this.ui.termSearchTree
  122. }), this.createTermAction();
  123. },
  124. onNodeSelect: function(options, showCategory) {
  125. var nodeType = options.node.original.type;
  126. if (this.isGlossaryTree && ("GlossaryTerm" === nodeType || "GlossaryCategory" === nodeType)) return void (this.isGlossaryTree = !1);
  127. var name, selectedNodeId, that = this, glossaryType = options.node.original.gType;
  128. if ("category" == glossaryType) selectedNodeId = options.node.id, that.glossaryTermId != selectedNodeId ? (that.glossaryTermId = selectedNodeId,
  129. that.onViewEdit()) : (that.glossaryTermId = null, that.showDefaultPage()); else if ("term" == glossaryType) {
  130. options && (name = _.unescape(options.node.original.name), selectedNodeId = options.node.id);
  131. var termValue = null, params = {
  132. searchType: "basic"
  133. };
  134. if (this.options.value && this.options.value.isCF && (this.options.value.isCF = null),
  135. that.glossaryTermId != selectedNodeId) that.glossaryTermId = selectedNodeId, termValue = options ? name + "@" + options.node.original.parent.name : this.options.value.term,
  136. params.term = termValue, params.gtype = "term", params.viewType = "term", params.guid = selectedNodeId; else if (that.glossaryTermId = params.term = null,
  137. that.ui.termSearchTree.jstree(!0).deselect_all(!0), !that.options.value.type && !that.options.value.tag && !that.options.value.query) return void that.showDefaultPage();
  138. that.glossaryId = null;
  139. var searchParam = _.extend({}, that.options.value, params);
  140. this.triggerSearch(searchParam), that.searchVent && that.searchVent.trigger("Success:Category");
  141. } else if (glossaryType = "glossary") if (that.glossaryTermId = null, that.glossaryId != options.node.id) {
  142. that.glossaryId = options.node.id;
  143. var params = {
  144. gId: that.glossaryId,
  145. gType: options.node.original.gType,
  146. viewType: this.isTermView ? "term" : "category"
  147. };
  148. Utils.setUrl({
  149. url: "#!/glossary/" + that.glossaryId,
  150. urlParams: params,
  151. mergeBrowserUrl: !1,
  152. trigger: !1,
  153. updateTabState: !0
  154. });
  155. } else that.glossaryId = null, that.ui.termSearchTree.jstree(!0).deselect_all(!0),
  156. this.showDefaultPage(); else that.glossaryTermId = null, that.glossaryId != options.node.id ? that.glossaryId = options.node.id : (that.glossaryId = null,
  157. that.ui.termSearchTree.jstree(!0).deselect_all(!0));
  158. },
  159. triggerSearch: function(params, url) {
  160. var serachUrl = url ? url : "#!/search/searchResult";
  161. Utils.setUrl({
  162. url: serachUrl,
  163. urlParams: params,
  164. mergeBrowserUrl: !1,
  165. trigger: !0,
  166. updateTabState: !0
  167. });
  168. },
  169. showDefaultPage: function() {
  170. Utils.setUrl({
  171. url: "!/search",
  172. mergeBrowserUrl: !1,
  173. trigger: !0,
  174. updateTabState: !0
  175. });
  176. },
  177. generateCategoryData: function(options) {
  178. return _.map(options.data, function(obj) {
  179. return {
  180. text: _.escape(obj.displayText),
  181. icon: "fa fa-files-o",
  182. guid: obj.categoryGuid,
  183. id: obj.categoryGuid,
  184. glossaryId: options.node.glossaryId,
  185. glossaryName: options.node.glossaryName,
  186. model: obj,
  187. type: "GlossaryCategory",
  188. gType: "category",
  189. children: !0
  190. };
  191. });
  192. },
  193. getCategory: function(options) {
  194. var that = this;
  195. this.glossaryCollection.getCategory({
  196. guid: options.node.guid,
  197. related: !0,
  198. ajaxOptions: {
  199. success: function(data) {
  200. data && data.children ? options.callback(that.generateCategoryData(_.extend({}, {
  201. data: data.children
  202. }, options))) : options.callback([]);
  203. },
  204. cust_error: function() {
  205. options.callback([]);
  206. }
  207. }
  208. });
  209. },
  210. getGlossaryTree: function(options) {
  211. var that = this, queryParams = (options && options.collection || this.glossaryCollection.fullCollection,
  212. Utils.getUrlState.getQueryParams()), glossaryGuid = queryParams ? queryParams.gId : null, gType = queryParams ? queryParams.gType : "term";
  213. return this.glossaryCollection.fullCollection.map(function(model, i) {
  214. var obj = model.toJSON(), parent = {
  215. text: _.escape(obj.name),
  216. name: _.escape(obj.name),
  217. icon: "fa fa-folder-o",
  218. guid: obj.guid,
  219. id: obj.guid,
  220. model: obj,
  221. type: obj.typeName ? obj.typeName : "GLOSSARY",
  222. gType: "glossary",
  223. children: [],
  224. state: {
  225. opened: !0,
  226. selected: model.id === glossaryGuid && "glossary" === gType
  227. }
  228. }, openGlossaryNodesState = function(treeDate) {
  229. 1 == treeDate.length && _.each(treeDate, function(model) {
  230. model.state.opeaned = !0;
  231. });
  232. }, generateNode = function(nodeOptions, model, isTermView, parentNode) {
  233. var nodeStructure = {
  234. text: _.escape(model.displayText),
  235. name: _.escape(model.displayText),
  236. type: nodeOptions.type,
  237. gType: that.isTermView ? "term" : "category",
  238. guid: nodeOptions.guid,
  239. id: nodeOptions.guid,
  240. parent: parentNode ? parentNode : obj,
  241. glossaryName: parentNode ? parentNode.name ? parentNode.name : parentNode.displayText : obj.name,
  242. glossaryId: parentNode ? parentNode.guid ? parentNode.guid : parentNode.categoryGuid : obj.guid,
  243. model: model,
  244. icon: "fa fa-file-o"
  245. };
  246. return nodeStructure;
  247. };
  248. if (!that.isTermView && obj.categories && !that.isTermView) {
  249. var isSelected = !1, categoryList = (obj.guid, []), catrgoryRelation = [];
  250. _.each(obj.categories, function(category) {
  251. that.options.value && (isSelected = !!that.options.value.guid && that.options.value.guid == category.categoryGuid);
  252. var typeName = category.typeName || "GlossaryCategory", guid = category.categoryGuid, categoryObj = {
  253. id: guid,
  254. guid: guid,
  255. text: _.escape(category.displayText),
  256. type: typeName,
  257. gType: "category",
  258. glossaryId: obj.guid,
  259. glossaryName: obj.name,
  260. children: [],
  261. model: category,
  262. icon: "fa fa-files-o"
  263. };
  264. category.parentCategoryGuid && catrgoryRelation.push({
  265. parent: category.parentCategoryGuid,
  266. child: guid
  267. }), categoryList.push(categoryObj);
  268. }), _.each(categoryList, function(category) {
  269. var getRelation = _.find(catrgoryRelation, function(catrgoryObj) {
  270. if (catrgoryObj.child == category.guid) return catrgoryObj;
  271. });
  272. getRelation ? _.map(categoryList, function(catrgoryObj) {
  273. catrgoryObj.guid == getRelation.parent && catrgoryObj.children.push(category);
  274. }) : parent.children.push(category);
  275. });
  276. }
  277. if (that.isTermView && obj.terms) {
  278. var isSelected = !1;
  279. _.each(obj.terms, function(term) {
  280. that.options.value && (isSelected = !!that.options.value.term && that.options.value.term.split("@")[0] == term.displayText);
  281. var parentNodeDetails = {
  282. type: term.typeName || "GlossaryTerm",
  283. guid: term.termGuid
  284. }, parentNodeProperties = {}, getParentNodeDetails = generateNode(parentNodeDetails, term, that.isTermView), termParentNode = _.extend(parentNodeProperties, getParentNodeDetails);
  285. parent.children.push(termParentNode);
  286. });
  287. }
  288. return openGlossaryNodesState(parent), parent;
  289. });
  290. },
  291. createTermAction: function() {
  292. Utils.generatePopover({
  293. el: this.$el,
  294. contentClass: "termPopoverOptions",
  295. popoverOptions: {
  296. selector: ".termPopover",
  297. content: function() {
  298. var type = $(this).data("detail"), liString = "";
  299. return liString = "glossary" == type ? "<li data-type=" + type + " class='listTerm'><i class='fa fa-plus'></i> <a href='javascript:void(0)' data-fn='createSubNode'>Create Term</a></li><li data-type=" + type + " class='listTerm'><i class='fa fa-list-alt'></i><a href='javascript:void(0)' data-fn='onViewEdit'>View/Edit Glossary</a></li><li data-type=" + type + " class='listTerm'><i class='fa fa-trash-o'></i><a href='javascript:void(0)' data-fn='deleteNode'>删除术语表</a></li>" : "<li data-type=" + type + " class='listTerm'><i class='fa fa-list-alt'></i><a href='javascript:void(0)' data-fn='onViewEdit'>View/Edit Term</a></li><li data-type=" + type + " class='listTerm'><i class='fa fa-search'></i><a href='javascript:void(0)' data-fn='searchSelectedTerm'>Search</a></li><li data-type=" + type + " class='listTerm'><i class='fa fa-trash-o'></i><a href='javascript:void(0)' data-fn='deleteNode'>Delete Term</a></li>",
  300. "<ul>" + liString + "</ul>";
  301. }
  302. }
  303. });
  304. },
  305. createCategoryAction: function() {
  306. Utils.generatePopover({
  307. el: this.$(".categoryPopover"),
  308. contentClass: "categoryPopoverOptions",
  309. popoverOptions: {
  310. content: function() {
  311. var type = $(this).data("detail"), liString = "";
  312. return liString = "glossary" == type ? "<li data-type=" + type + " class='listTerm'><i class='fa fa-plus'></i> <a href='javascript:void(0)' data-fn='createSubNode'>Create Category</a></li>" : "<li data-type=" + type + " class='listTerm'><i class='fa fa-list-alt'></i><a href='javascript:void(0)' data-fn='createSubNode'>Create Sub-Category</a></li>",
  313. "<ul>" + liString + "</ul>";
  314. },
  315. viewFixedPopover: !0
  316. }
  317. });
  318. },
  319. createSubNode: function(opt) {
  320. var that = this, selectednode = that.ui.termSearchTree.jstree("get_selected", !0);
  321. "GLOSSARY" != selectednode[0].original.type && "GlossaryCategory" != selectednode[0].original.type || this.isTermView ? CommonViewFunction.createEditGlossaryCategoryTerm({
  322. isTermView: !0,
  323. callback: function() {
  324. that.fetchGlossary(), that.options.categoryEvent.trigger("Success:Term", !0);
  325. },
  326. collection: that.glossaryCollection,
  327. node: selectednode[0].original
  328. }) : CommonViewFunction.createEditGlossaryCategoryTerm({
  329. isCategoryView: !0,
  330. collection: that.glossaryCollection,
  331. callback: function(updateCollection) {
  332. var updatedObj = {
  333. categoryGuid: updateCollection.guid,
  334. displayText: updateCollection.name,
  335. relationGuid: updateCollection.anchor ? updateCollection.anchor.relationGuid : null
  336. }, glossary = that.glossaryCollection.fullCollection.findWhere({
  337. guid: updateCollection.anchor.glossaryGuid
  338. });
  339. if (updateCollection.parentCategory && (updatedObj.parentCategoryGuid = updateCollection.parentCategory.categoryGuid),
  340. glossary) {
  341. var glossaryAttributes = glossary.attributes || null;
  342. glossaryAttributes && (glossaryAttributes.categories ? glossaryAttributes.categories.push(updatedObj) : glossaryAttributes.categories = [ updatedObj ]);
  343. }
  344. that.ui.termSearchTree.jstree(!0).refresh();
  345. },
  346. node: selectednode[0].original
  347. });
  348. },
  349. searchSelectedTerm: function() {
  350. var params = {
  351. searchType: "basic",
  352. dslChecked: !1,
  353. term: this.options.value.term
  354. };
  355. this.triggerSearch(params);
  356. },
  357. deleteNode: function(opt) {
  358. var that = this, messageType = "", selectednode = this.ui.termSearchTree.jstree("get_selected", !0), type = selectednode[0].original.type, guid = selectednode[0].original.guid, gId = selectednode[0].original.parent && selectednode[0].original.parent.guid, options = {
  359. success: function(rModel, response) {
  360. var searchParam = null;
  361. gId || (gId = guid);
  362. var glossary = that.glossaryCollection.fullCollection.get(gId);
  363. "GlossaryTerm" == type && glossary.set("terms", _.reject(glossary.get("terms"), function(obj) {
  364. return obj.termGuid == guid;
  365. }), {
  366. silent: !0
  367. }), Utils.notifySuccess({
  368. content: messageType + Messages.getAbbreviationMsg(!1, "deleteSuccessMessage")
  369. }), that.ui.termSearchTree.jstree(!0).refresh();
  370. var params = {
  371. searchType: "basic",
  372. term: null
  373. };
  374. that.glossaryTermId = null, "category" == that.options.value.gType ? that.showDefaultPage() : (searchParam = _.extend({}, that.options.value, params),
  375. that.triggerSearch(searchParam));
  376. },
  377. complete: function() {
  378. that.notificationModal.hideButtonLoader(), that.notificationModal.remove();
  379. }
  380. }, notifyObj = {
  381. modal: !0,
  382. ok: function(obj) {
  383. that.notificationModal = obj, obj.showButtonLoader(), "Glossary" == type || "GLOSSARY" == type ? that.glossaryCollection.fullCollection.get(guid).destroy(options, {
  384. silent: !0,
  385. reset: !1
  386. }) : "GlossaryCategory" == type ? new that.glossaryCollection.model().deleteCategory(guid, options) : "GlossaryTerm" == type && new that.glossaryCollection.model().deleteTerm(guid, options);
  387. },
  388. okCloses: !1,
  389. cancel: function(argument) {}
  390. };
  391. "Glossary" == type || "GLOSSARY" == type ? messageType = "Glossary" : "GlossaryCategory" == type ? messageType = "Category" : "GlossaryTerm" == type && (messageType = "Term"),
  392. notifyObj.text = "Are you sure you want to delete the " + messageType, Utils.notifyConfirm(notifyObj);
  393. },
  394. onViewEdit: function() {
  395. var that = this, selectednode = this.ui.termSearchTree.jstree("get_selected", !0), type = selectednode[0].original.type, guid = selectednode[0].original.guid, gId = selectednode[0].original.parent && selectednode[0].original.parent.guid, isGlossaryView = "GlossaryTerm" != type && "GlossaryCategory" != type, model = this.glossaryCollection.fullCollection.get(guid);
  396. this.glossaryCollection.fullCollection.get(gId);
  397. if (isGlossaryView) CommonViewFunction.createEditGlossaryCategoryTerm({
  398. model: model,
  399. isGlossaryView: !0,
  400. collection: this.glossaryCollection,
  401. callback: function(sModel) {
  402. var data = sModel.toJSON();
  403. model.set(data, {
  404. silent: !0
  405. }), that.ui.termSearchTree.jstree(!0).refresh();
  406. }
  407. }); else {
  408. var glossaryId = selectednode[0].original.glossaryId, getSelectedParent = null, params = null;
  409. getSelectedParent = selectednode[0].parents.length > 2 ? selectednode[0].parents[selectednode[0].parents.length - 3] : selectednode[0].id,
  410. params = {
  411. gId: glossaryId,
  412. guid: getSelectedParent,
  413. gType: that.isTermView ? "term" : "category",
  414. viewType: that.isTermView ? "term" : "category",
  415. searchType: "basic"
  416. }, "GlossaryTerm" === type && (params.term = selectednode[0].original.name + "@" + selectednode[0].original.parent.name);
  417. var serachUrl = "#!/glossary/" + guid;
  418. this.triggerSearch(params, serachUrl), !this.isTermView && this.options.categoryEvent && that.options.categoryEvent.trigger("Success:Category", !0);
  419. }
  420. },
  421. generateSearchTree: function(options) {
  422. var $el = options && options.$el, that = (options && options.data, options && options.type,
  423. this), createAction = function(options) {
  424. that.isTermView ? that.createTermAction() : that.createCategoryAction();
  425. }, getEntityTreeConfig = function(opt) {
  426. return {
  427. plugins: [ "search", "core", "sort", "conditionalselect", "changed", "wholerow", "node_customize" ],
  428. state: {
  429. opened: !0
  430. },
  431. search: {
  432. show_only_matches: !0,
  433. case_sensitive: !1
  434. },
  435. node_customize: {
  436. default: function(el, node) {
  437. var aTerm = $(el).find(">a.jstree-anchor");
  438. aTerm.append("<span class='tree-tooltip'>" + _.escape(aTerm.text()) + "</span>");
  439. var popoverClass = that.isTermView ? "fa fa-ellipsis-h termPopover " : "fa fa-ellipsis-h categoryPopover";
  440. $(el).append('<div class="tools" data-type=' + node.original.gType + '><i class="' + popoverClass + '"rel="popover" data-detail=' + node.original.gType + "></i></div>");
  441. }
  442. },
  443. core: {
  444. data: function(node, cb) {
  445. "#" === node.id ? cb(that.getGlossaryTree()) : that.getCategory({
  446. node: node.original,
  447. callback: cb
  448. });
  449. },
  450. multiple: !1
  451. }
  452. };
  453. };
  454. $el.jstree(getEntityTreeConfig({
  455. type: ""
  456. })).on("load_node.jstree", function(e, data) {}).on("open_node.jstree", function(e, data) {}).on("select_node.jstree", function(e, data) {
  457. that.fromManualRender !== !0 ? (that.onNodeSelect(data), that.glossaryId === data.node.original.id && (that.glossaryId = null)) : that.fromManualRender = !1,
  458. createAction(_.extend({}, options, data));
  459. }).on("open_node.jstree", function(e, data) {
  460. createAction(_.extend({}, options, data));
  461. }).on("search.jstree", function(nodes, str, res) {
  462. 0 === str.nodes.length ? ($el.jstree(!0).hide_all(), $el.parents(".panel").addClass("hide")) : $el.parents(".panel").removeClass("hide");
  463. }).on("loaded.jstree", function() {
  464. that.options.value && (that.options.value.term && that.selectDefaultNode(), that.isTermView || (that.selectDefaultNode(),
  465. that.options.categoryEvent.trigger("Success:Category", !0))), that.isTermView === !1 && that.glossarySwitchBtnUpdate();
  466. }).on("hover_node.jstree", function(nodes, str, res) {
  467. var aTerm = that.$("#" + str.node.a_attr.id), termOffset = aTerm.find(">.jstree-icon").offset();
  468. that.$(".tree-tooltip").removeClass("show"), setTimeout(function() {
  469. aTerm.hasClass("jstree-hovered") && termOffset.top && termOffset.left && aTerm.find(">span.tree-tooltip").css({
  470. top: "calc(" + termOffset.top + "px - 45px)",
  471. left: "24px"
  472. }).addClass("show");
  473. }, 1200);
  474. }).on("dehover_node.jstree", function(nodes, str, res) {
  475. that.$(".tree-tooltip").removeClass("show");
  476. });
  477. },
  478. selectDefaultNode: function() {
  479. this.ui.termSearchTree.jstree(!0).select_node(this.options.value.guid);
  480. },
  481. refresh: function(options) {
  482. this.glossaryTermId = null, this.fetchGlossary(), this.isGlossaryTree = !0;
  483. },
  484. onClickImportGlossary: function() {
  485. var that = this;
  486. require([ "views/import/ImportLayoutView" ], function(ImportLayoutView) {
  487. new ImportLayoutView({
  488. callback: function() {
  489. that.refresh();
  490. },
  491. isGlossary: !0
  492. });
  493. });
  494. }
  495. });
  496. return GlossaryTreeLayoutView;
  497. });