GlossaryDetailLayoutView.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. define([ "require", "backbone", "hbs!tmpl/glossary/GlossaryDetailLayoutView_tmpl", "utils/Utils", "utils/Messages", "utils/Globals", "utils/CommonViewFunction", "collection/VGlossaryList" ], function(require, Backbone, GlossaryDetailLayoutViewTmpl, Utils, Messages, Globals, CommonViewFunction, VGlossaryList) {
  2. "use strict";
  3. var GlossaryDetailLayoutView = Backbone.Marionette.LayoutView.extend({
  4. _viewName: "GlossaryDetailLayoutView",
  5. template: GlossaryDetailLayoutViewTmpl,
  6. regions: {
  7. RSearchResultLayoutView: "#r_searchResultLayoutView",
  8. RTagTableLayoutView: "#r_tagTableLayoutView",
  9. RRelationLayoutView: "#r_relationLayoutView"
  10. },
  11. templateHelpers: function() {
  12. return {
  13. isTermView: this.isTermView,
  14. isCategoryView: this.isCategoryView
  15. };
  16. },
  17. ui: {
  18. details: "[data-id='details']",
  19. editButton: "[data-id='editButton']",
  20. title: "[data-id='title']",
  21. shortDescription: "[data-id='shortDescription']",
  22. longDescription: "[data-id='longDescription']",
  23. categoryList: "[data-id='categoryList']",
  24. removeCategory: "[data-id='removeCategory']",
  25. categoryClick: "[data-id='categoryClick']",
  26. addCategory: "[data-id='addCategory']",
  27. termList: "[data-id='termList']",
  28. removeTerm: "[data-id='removeTerm']",
  29. termClick: "[data-id='termClick']",
  30. addTerm: "[data-id='addTerm']",
  31. tagList: "[data-id='tagListTerm']",
  32. removeTag: '[data-id="removeTagTerm"]',
  33. tagClick: '[data-id="tagClickTerm"]',
  34. addTag: '[data-id="addTagTerm"]',
  35. backButton: '[data-id="backButton"]'
  36. },
  37. events: function() {
  38. var events = {};
  39. return events["click " + this.ui.categoryClick] = function(e) {
  40. if ("i" == e.target.nodeName.toLocaleLowerCase()) this.onClickRemoveAssociationBtn(e); else {
  41. var guid = $(e.currentTarget).data("guid"), gId = this.data.anchor && this.data.anchor.glossaryGuid, categoryObj = _.find(this.data.categories, {
  42. categoryGuid: guid
  43. });
  44. this.glossary.selectedItem = {
  45. type: "GlossaryCategory",
  46. guid: guid,
  47. model: categoryObj
  48. }, Utils.setUrl({
  49. url: "#!/glossary/" + guid,
  50. mergeBrowserUrl: !1,
  51. urlParams: {
  52. gType: "category",
  53. viewType: "category",
  54. fromView: "glossary",
  55. gId: gId
  56. },
  57. trigger: !0,
  58. updateTabState: !0
  59. });
  60. }
  61. }, events["click " + this.ui.termClick] = function(e) {
  62. if ("i" == e.target.nodeName.toLocaleLowerCase()) this.onClickRemoveAssociationBtn(e); else {
  63. var guid = $(e.currentTarget).data("guid"), gId = this.data.anchor && this.data.anchor.glossaryGuid, termObj = _.find(this.data.terms, {
  64. termGuid: guid
  65. });
  66. this.glossary.selectedItem = {
  67. type: "GlossaryTerm",
  68. guid: guid,
  69. model: termObj
  70. }, Utils.setUrl({
  71. url: "#!/glossary/" + guid,
  72. mergeBrowserUrl: !1,
  73. urlParams: {
  74. gType: "term",
  75. viewType: "term",
  76. fromView: "glossary",
  77. gId: gId
  78. },
  79. trigger: !0,
  80. updateTabState: !0
  81. });
  82. }
  83. }, events["click " + this.ui.tagClick] = function(e) {
  84. "i" == e.target.nodeName.toLocaleLowerCase() ? this.onClickTagCross(e) : Utils.setUrl({
  85. url: "#!/tag/tagAttribute/" + e.currentTarget.textContent,
  86. mergeBrowserUrl: !1,
  87. trigger: !0
  88. });
  89. }, events["click " + this.ui.editButton] = function(e) {
  90. var that = this, model = this.glossaryCollection.fullCollection.get(this.guid);
  91. this.isGlossaryView ? CommonViewFunction.createEditGlossaryCategoryTerm({
  92. model: model,
  93. isGlossaryView: this.isGlossaryView,
  94. collection: this.glossaryCollection,
  95. callback: function(sModel) {
  96. var data = sModel.toJSON();
  97. model.set(data, {
  98. silent: !0
  99. }), that.data = data, that.renderDetails(that.data), that.glossaryCollection.trigger("update:details", {
  100. isGlossaryUpdate: !0
  101. });
  102. }
  103. }) : CommonViewFunction.createEditGlossaryCategoryTerm({
  104. isTermView: this.isTermView,
  105. isCategoryView: this.isCategoryView,
  106. model: this.data,
  107. collection: this.glossaryCollection,
  108. callback: function(data) {
  109. if (data.name != that.data.name) {
  110. var glossary = that.glossaryCollection.fullCollection.get(data.anchor.glossaryGuid);
  111. that.isTermView ? _.find(glossary.get("terms"), function(obj) {
  112. obj.termGuid == data.guid && (obj.displayText = data.name);
  113. }) : data.parentCategory || _.find(glossary.get("categories"), function(obj) {
  114. obj.categoryGuid == data.guid && (obj.displayText = data.name);
  115. }), that.options.categoryEvent.trigger("Success:TermRename", !0);
  116. }
  117. that.data = data, that.renderDetails(that.data);
  118. }
  119. });
  120. }, events["click " + this.ui.backButton] = function() {
  121. Utils.backButtonClick();
  122. }, events["click " + this.ui.addTerm] = "onClickAddTermBtn", events["click " + this.ui.addCategory] = "onClickAddTermBtn",
  123. events["click " + this.ui.addTag] = "onClickAddTagBtn", events;
  124. },
  125. initialize: function(options) {
  126. _.extend(this, _.pick(options, "guid", "glossaryCollection", "glossary", "collection", "typeHeaders", "value", "entityDefCollection", "enumDefCollection", "classificationDefCollection", "searchVent", "categoryEvent")),
  127. this.value && this.value.gType && ("category" == this.value.gType ? this.isCategoryView = !0 : "term" == this.value.gType ? this.isTermView = !0 : this.isGlossaryView = !0),
  128. this.selectedTermAttribute = null;
  129. },
  130. onRender: function() {
  131. this.glossaryCollection.fetch({
  132. reset: !0,
  133. silent: !0
  134. }), this.$(".fontLoader-relative").show(), this.getData(), this.bindEvents();
  135. },
  136. bindEvents: function() {
  137. var that = this;
  138. that.options.categoryEvent && that.options.categoryEvent.on("Success:Term", function(options) {
  139. that.glossaryCollection.fetch({
  140. reset: !0,
  141. silent: !0
  142. });
  143. });
  144. },
  145. onBeforeDestroy: function() {
  146. this.options.categoryEvent.off("Success:Term");
  147. },
  148. getData: function() {
  149. if (this.isGlossaryView) this.glossaryCollection.fullCollection.length ? (this.data = this.glossaryCollection.fullCollection.get(this.guid).toJSON(),
  150. this.glossaryCollection.trigger("data:updated", $.extend(!0, {}, this.data)), this.renderDetails(this.data)) : this.listenTo(this.glossaryCollection.fullCollection, "reset ", function(skip) {
  151. var foundGlossary = this.glossaryCollection.fullCollection.get(this.guid);
  152. this.data = foundGlossary ? foundGlossary.toJSON() : null, this.glossaryCollection.trigger("data:updated", $.extend(!0, {}, this.data)),
  153. null == this.data && (this.glossary.selectedItem = {}, Utils.setUrl({
  154. url: "#!/glossary",
  155. mergeBrowserUrl: !1,
  156. urlParams: null,
  157. trigger: !0,
  158. updateTabState: !0
  159. })), this.renderDetails(this.data);
  160. }, this); else {
  161. Utils.showTitleLoader(this.$(".page-title .fontLoader"), this.ui.details);
  162. var getApiFunctionKey = "getCategory", that = this;
  163. this.isTermView && (getApiFunctionKey = "getTerm"), this.glossaryCollection[getApiFunctionKey]({
  164. guid: this.guid,
  165. ajaxOptions: {
  166. success: function(data) {
  167. if (!that.isDestroyed) {
  168. if (that.data = data, that.isTermView) {
  169. var tags = {
  170. self: [],
  171. propagated: [],
  172. propagatedMap: {},
  173. combineMap: {}
  174. };
  175. if (that.data) {
  176. var tagObject = that.data.classifications;
  177. _.each(tagObject, function(val) {
  178. var typeName = val.typeName;
  179. val.entityGuid === that.guid ? tags.self.push(val) : (tags.propagated.push(val),
  180. tags.propagatedMap[typeName] ? tags.propagatedMap[typeName].count += tags.propagatedMap[typeName].count : (tags.propagatedMap[typeName] = val,
  181. tags.propagatedMap[typeName].count = 1)), void 0 === tags.combineMap[typeName] && (tags.combineMap[typeName] = val);
  182. }), tags.self = _.sortBy(tags.self, "typeName"), tags.propagated = _.sortBy(tags.propagated, "typeName");
  183. }
  184. var obj = {
  185. guid: that.guid,
  186. entityDefCollection: that.entityDefCollection,
  187. typeHeaders: that.typeHeaders,
  188. tagCollection: that.collection,
  189. enumDefCollection: that.enumDefCollection,
  190. classificationDefCollection: that.classificationDefCollection,
  191. glossaryCollection: that.glossaryCollection,
  192. searchVent: that.searchVent,
  193. tags: tags,
  194. getSelectedTermAttribute: function() {
  195. return that.selectedTermAttribute;
  196. },
  197. setSelectedTermAttribute: function(val) {
  198. that.selectedTermAttribute = val;
  199. }
  200. };
  201. that.renderSearchResultLayoutView(obj), that.renderTagTableLayoutView(obj), that.renderRelationLayoutView(obj);
  202. }
  203. that.glossaryCollection.trigger("data:updated", $.extend(!0, {}, data)), that.glossary.selectedItem.model = data,
  204. that.glossary.selectedItem.guid = data.guid, that.renderDetails(data);
  205. }
  206. },
  207. cust_error: function() {}
  208. }
  209. });
  210. }
  211. },
  212. renderDetails: function(data) {
  213. Utils.hideTitleLoader(this.$(".fontLoader"), this.ui.details), data ? (this.ui.title.text(data.name || data.displayText || data.qualifiedName),
  214. this.ui.shortDescription.text(data.shortDescription ? data.shortDescription : ""),
  215. this.ui.longDescription.text(data.longDescription ? data.longDescription : ""),
  216. this.generateCategories(data.categories), this.generateTerm(data.terms), this.generateTag(data.classifications)) : this.ui.title.text("No Data found");
  217. },
  218. generateCategories: function(data) {
  219. var categories = "";
  220. _.each(data, function(val) {
  221. var name = _.escape(val.displayText);
  222. categories += '<span data-guid="' + val.categoryGuid + '" class="btn btn-action btn-sm btn-icon btn-blue" data-id="categoryClick"><span>' + name + '</span><i class="fa fa-close" data-id="removeCategory" data-type="category" title="Remove Category"></i></span>';
  223. }), this.ui.categoryList.find("span.btn").remove(), this.ui.categoryList.prepend(categories);
  224. },
  225. generateTerm: function(data) {
  226. var terms = "";
  227. _.each(data, function(val) {
  228. var name = _.escape(val.displayText);
  229. terms += '<span data-guid="' + val.termGuid + '" class="btn btn-action btn-sm btn-icon btn-blue" data-id="termClick"><span>' + name + '</span><i class="fa fa-close" data-id="removeTerm" data-type="term" title="Remove Term"></i></span>';
  230. }), this.ui.termList.find("span.btn").remove(), this.ui.termList.prepend(terms);
  231. },
  232. generateTag: function(tagObject) {
  233. var tagData = "";
  234. _.each(tagObject, function(val) {
  235. tagData += '<span class="btn btn-action btn-sm btn-icon btn-blue" data-id="tagClickTerm"><span>' + val.typeName + '</span><i class="fa fa-close" data-id="removeTagTerm" data-type="tag" title="Remove Classification"></i></span>';
  236. }), this.ui.tagList.find("span.btn").remove(), this.ui.tagList.prepend(tagData);
  237. },
  238. getCategoryTermCount: function(collection, matchString) {
  239. var terms = 0;
  240. return _.each(collection, function(model) {
  241. model.get(matchString) && (terms += model.get(matchString).length);
  242. }), terms;
  243. },
  244. onClickAddTermBtn: function(e) {
  245. var that = this, glossary = this.glossaryCollection;
  246. if (this.value && this.value.gId) {
  247. var foundModel = this.glossaryCollection.find({
  248. guid: this.value.gId
  249. });
  250. foundModel && (glossary = new VGlossaryList([ foundModel.toJSON() ], {
  251. comparator: function(item) {
  252. return item.get("name");
  253. }
  254. }));
  255. }
  256. var obj = {
  257. callback: function() {
  258. that.getData();
  259. },
  260. glossaryCollection: glossary
  261. }, emptyListMessage = this.isCategoryView ? "没有与此类别关联的可用术语" : "没有与此术语关联的可用类别";
  262. obj = this.isCategoryView ? _.extend(obj, {
  263. categoryData: this.data,
  264. associatedTerms: this.data && this.data.terms && this.data.terms.length > 0 ? this.data.terms : [],
  265. isCategoryView: this.isCategoryView
  266. }) : _.extend(obj, {
  267. termData: this.data,
  268. isTermView: this.isTermView
  269. }), this.getCategoryTermCount(glossary.fullCollection.models, this.isCategoryView ? "terms" : "categories") ? this.AssignTermLayoutViewModal(obj) : Utils.notifyInfo({
  270. content: emptyListMessage
  271. });
  272. },
  273. AssignTermLayoutViewModal: function(termCategoryObj) {
  274. var that = this;
  275. require([ "views/glossary/AssignTermLayoutView" ], function(AssignTermLayoutView) {
  276. var view = new AssignTermLayoutView(termCategoryObj);
  277. view.modal.on("ok", function() {
  278. that.hideLoader();
  279. });
  280. });
  281. },
  282. onClickAddTagBtn: function(e) {
  283. var that = this;
  284. require([ "views/tag/AddTagModalView" ], function(AddTagModalView) {
  285. var tagList = [];
  286. _.map(that.data.classifications, function(obj) {
  287. obj.entityGuid === that.guid && tagList.push(obj.typeName);
  288. });
  289. new AddTagModalView({
  290. guid: that.guid,
  291. tagList: tagList,
  292. callback: function() {
  293. that.searchVent && that.searchVent.trigger("Classification:Count:Update"), that.getData();
  294. },
  295. showLoader: that.showLoader.bind(that),
  296. hideLoader: that.hideLoader.bind(that),
  297. collection: that.classificationDefCollection,
  298. enumDefCollection: that.enumDefCollection
  299. });
  300. });
  301. },
  302. onClickTagCross: function(e) {
  303. var that = this, tagName = $(e.currentTarget).text(), termName = this.data.name;
  304. CommonViewFunction.deleteTag(_.extend({}, {
  305. msg: "<div class='ellipsis-with-margin'>Remove: <b>" + _.escape(tagName) + "</b> assignment from <b>" + _.escape(termName) + "?</b></div>",
  306. titleMessage: Messages.removeTag,
  307. okText: "Remove",
  308. showLoader: that.showLoader.bind(that),
  309. hideLoader: that.hideLoader.bind(that),
  310. tagName: tagName,
  311. guid: that.guid,
  312. callback: function() {
  313. that.searchVent && that.searchVent.trigger("Classification:Count:Update"), that.getData();
  314. }
  315. }));
  316. },
  317. onClickRemoveAssociationBtn: function(e) {
  318. var $el = $(e.currentTarget), guid = $el.data("guid"), name = $el.text(), that = this;
  319. CommonViewFunction.removeCategoryTermAssociation({
  320. selectedGuid: guid,
  321. model: that.data,
  322. collection: that.glossaryCollection,
  323. msg: "<div class='ellipsis-with-margin'>Remove: <b>" + _.escape(name) + "</b> assignment from <b>" + _.escape(that.data.name) + "?</b></div>",
  324. titleMessage: Messages.glossary[that.isTermView ? "removeCategoryfromTerm" : "removeTermfromCategory"],
  325. isCategoryView: that.isCategoryView,
  326. isTermView: that.isTermView,
  327. buttonText: "Remove",
  328. showLoader: that.hideLoader.bind(that),
  329. hideLoader: that.hideLoader.bind(that),
  330. callback: function() {
  331. that.getData();
  332. }
  333. });
  334. },
  335. showLoader: function() {
  336. Utils.showTitleLoader(this.$(".page-title .fontLoader"), this.ui.details);
  337. },
  338. hideLoader: function() {
  339. Utils.hideTitleLoader(this.$(".page-title .fontLoader"), this.ui.details);
  340. },
  341. renderTagTableLayoutView: function(options) {
  342. var that = this;
  343. require([ "views/tag/TagDetailTableLayoutView" ], function(TagDetailTableLayoutView) {
  344. that.RTagTableLayoutView && that.RTagTableLayoutView.show(new TagDetailTableLayoutView(_.extend({}, options, {
  345. entityName: _.escape(that.ui.title.text()),
  346. fetchCollection: that.getData.bind(that),
  347. entity: that.data
  348. })));
  349. });
  350. },
  351. renderSearchResultLayoutView: function(options) {
  352. var that = this;
  353. require([ "views/search/SearchResultLayoutView" ], function(SearchResultLayoutView) {
  354. that.RSearchResultLayoutView && that.RSearchResultLayoutView.show(new SearchResultLayoutView(_.extend({}, options, {
  355. value: {
  356. searchType: "basic",
  357. term: that.data.qualifiedName
  358. },
  359. fromView: "glossary"
  360. })));
  361. });
  362. },
  363. renderRelationLayoutView: function(options) {
  364. var that = this;
  365. require([ "views/glossary/TermRelationAttributeLayoutView" ], function(TermRelationAttributeLayoutView) {
  366. that.RRelationLayoutView && that.RRelationLayoutView.show(new TermRelationAttributeLayoutView(_.extend({}, options, {
  367. entityName: that.ui.title.text(),
  368. fetchCollection: that.getData.bind(that),
  369. data: that.data
  370. })));
  371. });
  372. }
  373. });
  374. return GlossaryDetailLayoutView;
  375. });