GlossaryDetailLayoutView.js 20 KB

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