GlossaryLayoutView.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. define([ "require", "backbone", "hbs!tmpl/glossary/GlossaryLayoutView_tmpl", "utils/Utils", "utils/Messages", "utils/Globals", "utils/UrlLinks", "utils/CommonViewFunction", "jstree" ], function(require, Backbone, GlossaryLayoutViewTmpl, Utils, Messages, Globals, UrlLinks, CommonViewFunction) {
  2. "use strict";
  3. var GlossaryLayoutView = Backbone.Marionette.LayoutView.extend({
  4. _viewName: "GlossaryLayoutView",
  5. template: GlossaryLayoutViewTmpl,
  6. regions: {},
  7. templateHelpers: function() {
  8. return {
  9. isAssignView: this.isAssignView,
  10. importTmplUrl: UrlLinks.glossaryImportTempUrl(),
  11. isAssignAttributeRelationView: this.isAssignAttributeRelationView
  12. };
  13. },
  14. ui: {
  15. createGlossary: "[data-id='createGlossary']",
  16. refreshGlossary: "[data-id='refreshGlossary']",
  17. searchTerm: "[data-id='searchTerm']",
  18. searchCategory: "[data-id='searchCategory']",
  19. glossaryView: 'input[name="glossaryView"]',
  20. termTree: "[data-id='termTree']",
  21. categoryTree: "[data-id='categoryTree']",
  22. importGlossary: "[data-id='importGlossary']",
  23. glossaryTreeLoader: "[data-id='glossaryTreeLoader']",
  24. glossaryTreeView: "[data-id='glossaryTreeView']"
  25. },
  26. events: function() {
  27. var events = {};
  28. return events["change " + this.ui.glossaryView] = "glossaryViewToggle", events["click " + this.ui.createGlossary] = function(e) {
  29. var that = this;
  30. e && $(e.currentTarget).attr("disabled", "true"), CommonViewFunction.createEditGlossaryCategoryTerm({
  31. isGlossaryView: !0,
  32. collection: this.glossaryCollection,
  33. callback: function() {
  34. that.ui.createGlossary.removeAttr("disabled"), that.getGlossary();
  35. },
  36. onModalClose: function() {
  37. that.ui.createGlossary.removeAttr("disabled");
  38. }
  39. });
  40. }, events["click " + this.ui.refreshGlossary] = function() {
  41. this.ui.refreshGlossary.attr("disabled", !0), this.getGlossary();
  42. }, events["click " + this.ui.importGlossary] = "onClickImportGlossary", events["keyup " + this.ui.searchTerm] = function() {
  43. this.ui.termTree.jstree("search", _.escape(this.ui.searchTerm.val()));
  44. }, events["keyup " + this.ui.searchCategory] = function() {
  45. this.ui.categoryTree.jstree("search", this.ui.searchCategory.val());
  46. }, events;
  47. },
  48. initialize: function(options) {
  49. _.extend(this, _.pick(options, "associatedTerms", "guid", "value", "glossaryCollection", "glossary", "isAssignTermView", "isAssignCategoryView", "isAssignEntityView", "isAssignAttributeRelationView", "importVent")),
  50. this.viewType = "term", this.isAssignView = this.isAssignTermView || this.isAssignCategoryView || this.isAssignEntityView || this.isAssignAttributeRelationView,
  51. this.bindEvents(), this.query = {
  52. term: {},
  53. category: {}
  54. }, Utils.getUrlState.isGlossaryTab() && this.value && this.value.viewType && (this.viewType = this.value.viewType,
  55. this.query[this.viewType] = _.extend({}, this.value, {
  56. guid: this.guid
  57. }));
  58. },
  59. bindEvents: function() {
  60. var that = this;
  61. this.listenTo(this.glossaryCollection.fullCollection, "reset add change", function(skip) {
  62. this.generateTree(), this.setValues(), this.changeLoaderState(!1), this.ui.refreshGlossary.attr("disabled", !1);
  63. }, this), this.listenTo(this.glossaryCollection, "update:details", function(options) {
  64. var isGlossaryUpdate = options.isGlossaryUpdate;
  65. if (isGlossaryUpdate) this.ui.termTree.jstree(!0).refresh && this.ui.termTree.jstree(!0).refresh(),
  66. this.ui.categoryTree.jstree(!0).refresh && this.ui.categoryTree.jstree(!0).refresh(); else {
  67. var $tree = this.ui["term" == this.viewType ? "termTree" : "categoryTree"];
  68. $tree.jstree(!0).refresh && ($tree.jstree(!0).refresh(), this.setValues({
  69. trigger: !1
  70. }));
  71. }
  72. this.changeLoaderState(!1);
  73. }, this), this.isAssignView || $("body").on("click", ".termPopoverOptions li, .categoryPopoverOptions li", function(e) {
  74. that.$(".termPopover,.categoryPopover").popover("hide"), that[$(this).find("a").data("fn")](e);
  75. }), this.importVent && this.importVent.on("Import:Glossary:Update", function(options) {
  76. that.getGlossary();
  77. });
  78. },
  79. onRender: function() {
  80. this.changeLoaderState(!0), this.isAssignCategoryView && (this.$(".category-view").show(),
  81. this.$(".term-view").hide()), this.isAssignView && this.glossaryCollection.fullCollection.length ? (this.generateTree(),
  82. this.disableNodesList = this.getDisableNodes()) : this.getGlossary();
  83. },
  84. changeLoaderState: function(showLoader) {
  85. showLoader ? (this.ui.glossaryTreeLoader.show(), this.ui.glossaryTreeView.hide()) : (this.ui.glossaryTreeLoader.hide(),
  86. this.ui.glossaryTreeView.show());
  87. },
  88. setValues: function(options) {
  89. "category" == this.viewType ? this.ui.glossaryView.prop("checked") || this.ui.glossaryView.prop("checked", !0).trigger("change", options) : this.ui.glossaryView.prop("checked") && this.ui.glossaryView.prop("checked", !1).trigger("change", options);
  90. },
  91. glossaryViewToggle: function(e, options) {
  92. var that = this;
  93. e.currentTarget.checked ? (this.$(".category-view").show(), this.$(".term-view").hide(),
  94. this.viewType = "category", this.$(".dropdown-toggle").attr("disabled", "disabled")) : (this.$(".term-view").show(),
  95. this.$(".category-view").hide(), this.viewType = "term", this.$(".dropdown-toggle").removeAttr("disabled"));
  96. var setDefaultSelector = function() {
  97. if (that.value) {
  98. var model = null;
  99. model = that.value.gId ? that.glossaryCollection.fullCollection.get(that.value.gId) : that.glossaryCollection.fullCollection.first(),
  100. model = model.toJSON ? model.toJSON() : model, that.glossary.selectedItem = {
  101. type: "Glossary",
  102. guid: model.guid,
  103. id: model.guid,
  104. model: model,
  105. text: model.name,
  106. gType: "glossary"
  107. };
  108. }
  109. };
  110. if (Utils.getUrlState.isGlossaryTab()) {
  111. var obj = this.query[this.viewType], $tree = this.ui["term" == this.viewType ? "termTree" : "categoryTree"];
  112. if (obj.gId = that.value.gId, obj.guid) {
  113. var node = $tree.jstree(!0).get_node(obj.guid);
  114. node && (this.glossary.selectedItem = node.original, $tree.jstree("activate_node", obj.guid));
  115. } else that.glossaryCollection.fullCollection.length && (setDefaultSelector(), $tree.jstree("activate_node", that.glossary.selectedItem.guid));
  116. this.query[this.viewType] = _.extend(obj, _.pick(this.glossary.selectedItem, "model", "guid", "gType", "type"), {
  117. viewType: this.viewType,
  118. isNodeNotFoundAtLoad: this.query[this.viewType].isNodeNotFoundAtLoad
  119. });
  120. var url = _.isEmpty(this.glossary.selectedItem) ? "#!/glossary" : "#!/glossary/" + this.glossary.selectedItem.guid;
  121. Utils.setUrl({
  122. url: url,
  123. urlParams: _.extend({}, _.omit(obj, "guid", "model", "type", "isNodeNotFoundAtLoad")),
  124. mergeBrowserUrl: !1,
  125. trigger: !(options && !_.isUndefined(options.trigger)) || options.trigger,
  126. updateTabState: !0
  127. });
  128. }
  129. },
  130. getGlossary: function() {
  131. this.changeLoaderState(!0), this.glossaryCollection.fetch({
  132. reset: !0
  133. });
  134. },
  135. generateCategoryData: function(options) {
  136. return _.map(options.data, function(obj) {
  137. return {
  138. text: _.escape(obj.displayText),
  139. icon: "fa fa-files-o",
  140. guid: obj.categoryGuid,
  141. id: obj.categoryGuid,
  142. glossaryId: options.node.glossaryId,
  143. glossaryName: options.node.glossaryName,
  144. model: obj,
  145. type: "GlossaryCategory",
  146. gType: "category",
  147. children: !0
  148. };
  149. });
  150. },
  151. getCategory: function(options) {
  152. var that = this;
  153. this.glossaryCollection.getCategory({
  154. guid: options.node.guid,
  155. related: !0,
  156. ajaxOptions: {
  157. success: function(data) {
  158. data && data.children ? options.callback(that.generateCategoryData(_.extend({}, {
  159. data: data.children
  160. }, options))) : options.callback([]);
  161. },
  162. cust_error: function() {
  163. options.callback([]);
  164. }
  165. }
  166. });
  167. },
  168. generateData: function(opt) {
  169. var that = this, associatedTerms = (that.guid, that.associatedTerms), type = opt.type;
  170. opt.type == this.viewType && (this.query[opt.type].isNodeNotFoundAtLoad = !0);
  171. var getSelectedState = function(options) {
  172. var objGuid = options.objGuid, node = options.node, index = options.index;
  173. if (that.isAssignView) return {
  174. opened: !0
  175. };
  176. if (that.guid) {
  177. if (that.guid == objGuid) return that.query[that.viewType].isNodeNotFoundAtLoad = !1,
  178. that.glossary.selectedItem = node, that.query[that.viewType].model = node.model,
  179. that.query[that.viewType].type = node.type, {
  180. opened: !0,
  181. selected: !0
  182. };
  183. } else {
  184. that.query[that.viewType].isNodeNotFoundAtLoad = !1;
  185. var selectedItem = {
  186. type: "Glossary",
  187. gType: "glossary",
  188. model: that.glossaryCollection.fullCollection.first().toJSON()
  189. };
  190. if (selectedItem.text = selectedItem.model.name, selectedItem.guid = selectedItem.model.guid,
  191. 0 == index && selectedItem.guid == objGuid) return that.glossary.selectedItem = selectedItem,
  192. that.query[that.viewType].model = selectedItem.model, that.query[that.viewType].type = selectedItem.type,
  193. {
  194. opened: !0,
  195. selected: !0
  196. };
  197. }
  198. };
  199. return this.glossaryCollection.fullCollection.map(function(model, i) {
  200. var obj = model.toJSON(), parent = {
  201. text: _.escape(obj.name),
  202. icon: "fa fa-folder-o",
  203. guid: obj.guid,
  204. id: obj.guid,
  205. model: obj,
  206. type: obj.typeName ? obj.typeName : "Glossary",
  207. gType: "glossary",
  208. children: []
  209. };
  210. if (parent.state = getSelectedState({
  211. index: i,
  212. node: parent,
  213. objGuid: obj.guid
  214. }), "category" == type && obj.categories) {
  215. var isSelected = !1, categoryList = (obj.guid, []), catrgoryRelation = [];
  216. _.each(obj.categories, function(category) {
  217. that.options.value && (isSelected = !!that.options.value.guid && that.options.value.guid == category.categoryGuid);
  218. var typeName = category.typeName || "GlossaryCategory", guid = category.categoryGuid, categoryObj = {
  219. id: guid,
  220. guid: guid,
  221. text: _.escape(category.displayText),
  222. type: typeName,
  223. gType: "category",
  224. glossaryId: obj.guid,
  225. glossaryName: obj.name,
  226. children: [],
  227. model: category,
  228. icon: "fa fa-files-o"
  229. };
  230. categoryObj.state = getSelectedState({
  231. index: i,
  232. node: categoryObj,
  233. objGuid: guid
  234. }), category.parentCategoryGuid && catrgoryRelation.push({
  235. parent: category.parentCategoryGuid,
  236. child: guid
  237. }), categoryList.push(categoryObj);
  238. }), _.each(categoryList, function(category) {
  239. var getRelation = _.find(catrgoryRelation, function(catrgoryObj) {
  240. if (catrgoryObj.child == category.guid) return catrgoryObj;
  241. });
  242. getRelation ? _.map(categoryList, function(catrgoryObj) {
  243. catrgoryObj.guid == getRelation.parent && catrgoryObj.children.push(category);
  244. }) : parent.children.push(category);
  245. });
  246. }
  247. return "term" == type && obj.terms && _.each(obj.terms, function(term) {
  248. if (associatedTerms) {
  249. var associatedTermFound = _.find(associatedTerms, function(obj, index) {
  250. if ((obj.termGuid ? obj.termGuid : obj.guid) == term.termGuid) return obj;
  251. });
  252. if (associatedTermFound) return;
  253. }
  254. var typeName = term.typeName || "GlossaryTerm", guid = term.termGuid, termObj = {
  255. text: _.escape(term.displayText),
  256. type: typeName,
  257. gType: "term",
  258. guid: guid,
  259. id: guid,
  260. parent: obj,
  261. glossaryName: obj.name,
  262. glossaryId: obj.guid,
  263. model: term,
  264. icon: "fa fa-file-o"
  265. };
  266. termObj.state = getSelectedState({
  267. index: i,
  268. node: termObj,
  269. objGuid: guid
  270. }), parent.children.push(termObj);
  271. }), parent;
  272. });
  273. },
  274. manualRender: function(options) {
  275. if (_.extend(this, _.omit(options, "isTrigger")), this.value && this.value.viewType && (this.viewType = this.value.viewType),
  276. this.guid && this.value && (this.value.fromView && this.value.fromView || this.value.updateView)) {
  277. var $tree = this.ui["term" == this.viewType ? "termTree" : "categoryTree"], node = $tree.jstree(!0).get_node(this.guid);
  278. node && ($tree.jstree("activate_node", this.guid, {
  279. skipTrigger: !0
  280. }), delete this.value.fromView, delete this.value.updateView, this.glossary.selectedItem = node.original,
  281. this.query[this.viewType] = _.extend({}, _.pick(this.glossary.selectedItem, "model", "guid", "gType", "type"), {
  282. viewType: this.viewType
  283. }), Utils.setUrl({
  284. url: "#!/glossary/" + this.guid,
  285. urlParams: this.value,
  286. mergeBrowserUrl: !1,
  287. trigger: !1,
  288. updateTabState: !0
  289. }), this.glossaryCollection.trigger("update:details", {
  290. isGlossaryUpdate: "glossary" == this.value.gType
  291. }));
  292. } else this.setValues();
  293. options.isTrigger && this.triggerUrl();
  294. },
  295. getDisableNodes: function() {
  296. var disableNodesSelection = [];
  297. if (this.options && this.options.isAssignAttributeRelationView) {
  298. var disableTerms = this.options.termData && this.options.selectedTermAttribute ? this.options.termData[this.options.selectedTermAttribute] : null;
  299. disableNodesSelection = _.map(disableTerms, function(obj) {
  300. return obj.termGuid;
  301. }), disableNodesSelection.push(this.options.termData.guid);
  302. }
  303. return disableNodesSelection;
  304. },
  305. generateTree: function() {
  306. var $termTree = this.ui.termTree, $categoryTree = this.ui.categoryTree, that = this, getTreeConfig = (that.guid,
  307. function(options) {
  308. return {
  309. plugins: [ "search", "themes", "core", "wholerow", "sort", "conditionalselect" ],
  310. conditionalselect: function(node) {
  311. var obj = node && node.original && node.original.type;
  312. if (obj) {
  313. if (that.isAssignView) {
  314. var isDisableNode = !1;
  315. return that.disableNodesList && (isDisableNode = that.disableNodesList.indexOf(node.original.guid) > -1),
  316. "Glossary" != obj && !isDisableNode;
  317. }
  318. return "NoAction" != obj;
  319. }
  320. },
  321. search: {
  322. show_only_matches: !0
  323. },
  324. core: {
  325. data: function(node, cb) {
  326. "#" === node.id ? cb(that.generateData(options)) : that.getCategory({
  327. node: node.original,
  328. callback: cb
  329. });
  330. },
  331. themes: {
  332. name: that.isAssignView ? "default" : "default-dark",
  333. dots: !0
  334. }
  335. }
  336. };
  337. }), treeLoaded = function(options) {
  338. if (1 == that.query[options.type].isNodeNotFoundAtLoad) {
  339. var id = that.glossary.selectedItem.guid;
  340. id && options.$el.jstree("activate_node", id);
  341. }
  342. that.changeLoaderState(!1);
  343. }, createAction = function(options) {
  344. var $el = options.el, type = options.type, popoverClassName = "term" == type ? "termPopover" : "categoryPopover";
  345. if (!that.isAssignView) {
  346. var wholerowEl = $el.find("li[role='treeitem'] > .jstree-wholerow:not(:has(>div.tools))");
  347. wholerowEl.append('<div class="tools"><i class="fa fa-ellipsis-h ' + popoverClassName + '"></i></div>'),
  348. "term" == type ? that.createTermAction() : "category" == type && that.createCategoryAction();
  349. }
  350. }, initializeTree = function(options) {
  351. var $el = options.el, type = options.type;
  352. $el.jstree(getTreeConfig({
  353. type: type
  354. })).on("load_node.jstree", function(e, data) {
  355. createAction(_.extend({}, options, data));
  356. }).on("open_node.jstree", function(e, data) {
  357. createAction(_.extend({}, options, data));
  358. }).on("select_node.jstree", function(e, data) {
  359. if (that.isAssignView) that.glossary.selectedItem = data.node.original, that.glossaryCollection.trigger("node_selected"); else {
  360. var popoverClassName = "term" == type ? ".termPopover" : ".categoryPopover", currentClickedPopoverEl = "";
  361. if (data.event && (currentClickedPopoverEl = $(data.event.currentTarget).parent().hasClass("jstree-leaf") ? $(data.event.currentTarget).parent().find(popoverClassName) : $(data.event.currentTarget).parent().find(">div " + popoverClassName),
  362. $(popoverClassName).not(currentClickedPopoverEl).popover("hide")), 1 == that.query[type].isNodeNotFoundAtLoad) that.query[type].isNodeNotFoundAtLoad = !1; else if (type == that.viewType) {
  363. if (data && data.event && data.event.skipTrigger) return;
  364. that.glossary.selectedItem.guid !== data.node.original.guid && (that.glossary.selectedItem = data.node.original,
  365. that.triggerUrl());
  366. }
  367. }
  368. }).on("search.jstree", function(e, data) {
  369. createAction(_.extend({}, options, data));
  370. }).on("clear_search.jstree", function(e, data) {
  371. createAction(_.extend({}, options, data));
  372. }).bind("loaded.jstree", function(e, data) {
  373. treeLoaded({
  374. $el: $el,
  375. type: type
  376. });
  377. });
  378. }, initializeTermTree = function() {
  379. $termTree.data("jstree") ? ($(".termPopover").popover("destroy"), $termTree.jstree(!0).refresh()) : initializeTree({
  380. el: $termTree,
  381. type: "term"
  382. });
  383. }, initializeCategoryTree = function() {
  384. $categoryTree.data("jstree") ? ($(".categoryPopover").popover("destroy"), $categoryTree.jstree(!0).refresh()) : initializeTree({
  385. el: $categoryTree,
  386. type: "category"
  387. });
  388. };
  389. this.isAssignView ? this.isAssignTermView || this.isAssignEntityView || this.isAssignAttributeRelationView ? initializeTermTree() : this.isAssignCategoryView && initializeCategoryTree() : (initializeTermTree(),
  390. initializeCategoryTree()), Utils.getUrlState.isGlossaryTab() && this.triggerUrl(),
  391. this.glossaryCollection.trigger("render:done");
  392. },
  393. createTermAction: function() {
  394. var that = this;
  395. Utils.generatePopover({
  396. el: this.$(".termPopover"),
  397. contentClass: "termPopoverOptions",
  398. popoverOptions: {
  399. content: function() {
  400. var node = that.query[that.viewType], liString = "";
  401. return liString = "Glossary" == node.type ? "<li data-type=" + node.type + " class='listTerm'><i class='fa fa-plus'></i> <a href='javascript:void(0)' data-fn='createSubNode'>创建术语</a></li><li data-type=" + node.type + " class='listTerm'><i class='fa fa-trash-o'></i><a href='javascript:void(0)' data-fn='deleteNode'>删除术语表</a></li>" : "<li data-type=" + node.type + " class='listTerm'><i class='fa fa-trash-o'></i><a href='javascript:void(0)' data-fn='deleteNode'>删除术语</a></li>",
  402. "<ul>" + liString + "</ul>";
  403. }
  404. }
  405. });
  406. },
  407. createCategoryAction: function() {
  408. var that = this;
  409. Utils.generatePopover({
  410. el: this.$(".categoryPopover"),
  411. contentClass: "categoryPopoverOptions",
  412. popoverOptions: {
  413. content: function() {
  414. var node = that.query[that.viewType], liString = "";
  415. return liString = "Glossary" == node.type ? "<li data-type=" + node.type + " class='listTerm'><i class='fa fa-plus'></i> <a href='javascript:void(0)' data-fn='createSubNode'>创建类别</a></li><li data-type=" + node.type + " class='listTerm'><i class='fa fa-trash-o'></i><a href='javascript:void(0)' data-fn='deleteNode'>删除术语表</a></li>" : "<li data-type=" + node.type + " class='listTerm'><i class='fa fa-plus'></i> <a href='javascript:void(0)' data-fn='createSubNode'>Create Sub-Category</a></li><li data-type=" + node.type + " class='listTerm'><i class='fa fa-trash-o'></i><a href='javascript:void(0)' data-fn='deleteNode'>Delete Category</a></li>",
  416. "<ul>" + liString + "</ul>";
  417. }
  418. }
  419. });
  420. },
  421. createSubNode: function(opt) {
  422. var that = this, type = this.glossary.selectedItem.type;
  423. "Glossary" != type && "GlossaryCategory" != type || "category" != this.viewType ? CommonViewFunction.createEditGlossaryCategoryTerm({
  424. isTermView: !0,
  425. callback: function() {
  426. that.getGlossary();
  427. },
  428. collection: that.glossaryCollection,
  429. node: this.glossary.selectedItem
  430. }) : CommonViewFunction.createEditGlossaryCategoryTerm({
  431. isCategoryView: !0,
  432. collection: that.glossaryCollection,
  433. callback: function(updateCollection) {
  434. var updatedObj = {
  435. categoryGuid: updateCollection.guid,
  436. displayText: updateCollection.name,
  437. relationGuid: updateCollection.anchor ? updateCollection.anchor.relationGuid : null
  438. }, glossary = that.glossaryCollection.fullCollection.findWhere({
  439. guid: updateCollection.anchor.glossaryGuid
  440. });
  441. if (updateCollection.parentCategory && (updatedObj.parentCategoryGuid = updateCollection.parentCategory.categoryGuid),
  442. glossary) {
  443. var glossaryAttributes = glossary.attributes || null;
  444. glossaryAttributes && (glossaryAttributes.categories ? glossaryAttributes.categories.push(updatedObj) : glossaryAttributes.categories = [ updatedObj ]);
  445. }
  446. that.ui.categoryTree.jstree(!0).refresh();
  447. },
  448. node: this.glossary.selectedItem
  449. });
  450. },
  451. deleteNode: function(opt) {
  452. var that = this, messageType = "", type = this.glossary.selectedItem.type, guid = this.glossary.selectedItem.guid, gId = this.glossary.selectedItem.glossaryId, options = {
  453. success: function(rModel, response) {
  454. gId || (gId = guid);
  455. var glossary = that.glossaryCollection.fullCollection.get(gId);
  456. that.value && ("term" == that.value.gType ? glossary.set("terms", _.reject(glossary.get("terms"), function(obj) {
  457. return obj.termGuid == guid;
  458. }), {
  459. silent: !0
  460. }) : "category" == that.value.gType ? glossary.set("categories", _.reject(glossary.get("categories"), function(obj) {
  461. return obj.categoryGuid == guid || obj.parentCategoryGuid == guid;
  462. }), {
  463. silent: !0
  464. }) : (glossary = that.glossaryCollection.fullCollection.first(), gId = glossary ? glossary.get("guid") : null)),
  465. Utils.notifySuccess({
  466. content: messageType + Messages.getAbbreviationMsg(!1, "deleteSuccessMessage")
  467. });
  468. var url = gId ? "#!/glossary/" + gId : "#!/glossary";
  469. null == gId && (that.glossary.selectedItem = {}, that.value = null, that.query = {
  470. term: {},
  471. category: {}
  472. }, that.ui.categoryTree.jstree(!0).refresh(), that.ui.termTree.jstree(!0).refresh()),
  473. Utils.setUrl({
  474. url: url,
  475. mergeBrowserUrl: !1,
  476. trigger: !0,
  477. urlParams: gId ? _.extend({}, that.value, {
  478. gType: "glossary",
  479. updateView: !0,
  480. gId: null
  481. }) : null,
  482. updateTabState: !0
  483. });
  484. },
  485. complete: function() {
  486. that.notificationModal.hideButtonLoader(), that.notificationModal.remove();
  487. }
  488. }, notifyObj = {
  489. modal: !0,
  490. ok: function(obj) {
  491. that.notificationModal = obj, obj.showButtonLoader(), "Glossary" == type ? that.glossaryCollection.fullCollection.get(guid).destroy(options, {
  492. silent: !0,
  493. reset: !1
  494. }) : "GlossaryCategory" == type ? new that.glossaryCollection.model().deleteCategory(guid, options) : "GlossaryTerm" == type && new that.glossaryCollection.model().deleteTerm(guid, options);
  495. },
  496. okCloses: !1,
  497. cancel: function(argument) {}
  498. };
  499. "Glossary" == type ? messageType = "Glossary" : "GlossaryCategory" == type ? messageType = "Category" : "GlossaryTerm" == type && (messageType = "Term"),
  500. notifyObj.text = "Are you sure you want to delete the " + messageType, Utils.notifyConfirm(notifyObj);
  501. },
  502. triggerUrl: function(options) {
  503. if (!this.isAssignView) {
  504. var selectedItem = this.glossary.selectedItem;
  505. if (this.glossaryCollection.length && (_.isEmpty(selectedItem) || this.query[this.viewType].isNodeNotFoundAtLoad)) {
  506. var model = selectedItem.model;
  507. model && !_.isUndefined(model.parentCategory || model.parentCategoryGuid) && (selectedItem = {
  508. model: this.glossaryCollection.first().toJSON()
  509. }, selectedItem.guid = selectedItem.model.guid, selectedItem.type = "Glossary",
  510. selectedItem.gType = "glossary", selectedItem.text = model.name, this.glossary.selectedItem = selectedItem,
  511. this.query[this.viewType].model = selectedItem.model, this.query[this.viewType].gType = "glossary",
  512. this.query[this.viewType].type = "Glossary", delete this.query[this.viewType].gId);
  513. }
  514. if (!_.isEmpty(selectedItem) && (Utils.getUrlState.isGlossaryTab() || Utils.getUrlState.isDetailPage())) {
  515. var obj = {};
  516. selectedItem.glossaryId ? obj.gId = selectedItem.glossaryId : "Glossary" == selectedItem.type && (obj.gId = selectedItem.guid),
  517. this.query[this.viewType] = _.extend(obj, _.omit(this.value, "gId"), _.pick(this.glossary.selectedItem, "model", "type", "gType", "guid"), {
  518. viewType: this.viewType,
  519. isNodeNotFoundAtLoad: this.query[this.viewType].isNodeNotFoundAtLoad
  520. }), "GlossaryTerm" === selectedItem.type ? obj.term = selectedItem.text + "@" + selectedItem.glossaryName : delete obj.term,
  521. Utils.setUrl({
  522. url: "#!/glossary/" + obj.guid,
  523. mergeBrowserUrl: !1,
  524. trigger: !0,
  525. urlParams: _.omit(obj, "model", "type", "isNodeNotFoundAtLoad"),
  526. updateTabState: !0
  527. });
  528. }
  529. }
  530. },
  531. onClickImportGlossary: function() {
  532. var that = this;
  533. require([ "views/import/ImportLayoutView" ], function(ImportLayoutView) {
  534. new ImportLayoutView({
  535. callback: function() {
  536. that.getGlossary();
  537. },
  538. isGlossary: !0
  539. });
  540. });
  541. }
  542. });
  543. return GlossaryLayoutView;
  544. });