SideNavLayoutView_old.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. define([ "require", "hbs!tmpl/site/SideNavLayoutView_tmpl", "utils/Utils", "utils/Globals", "utils/UrlLinks" ], function(require, tmpl, Utils, Globals, UrlLinks) {
  2. "use strict";
  3. var SideNavLayoutView = Marionette.LayoutView.extend({
  4. template: tmpl,
  5. regions: {
  6. RTagLayoutView: "#r_tagLayoutView",
  7. RSearchLayoutView: "#r_searchLayoutView",
  8. RGlossaryLayoutView: "#r_glossaryLayoutView"
  9. },
  10. ui: {
  11. tabs: ".tabs li a"
  12. },
  13. templateHelpers: function() {
  14. return {
  15. apiBaseUrl: UrlLinks.apiBaseUrl
  16. };
  17. },
  18. events: function() {
  19. var events = {};
  20. return events["click " + this.ui.tabs] = function(e) {
  21. var urlString = "", elementName = $(e.currentTarget).data(), tabStateUrls = Globals.saveApplicationState.tabState, urlStateObj = Utils.getUrlState, hashUrl = Utils.getUrlState.getQueryUrl().hash;
  22. urlStateObj.isTagTab() ? hashUrl != tabStateUrls.tagUrl && (Globals.saveApplicationState.tabState.tagUrl = hashUrl) : urlStateObj.isSearchTab() && hashUrl != tabStateUrls.searchUrl && (Globals.saveApplicationState.tabState.searchUrl = hashUrl),
  23. "tab-classification" == elementName.name ? urlString = tabStateUrls.tagUrl : "tab-search" == elementName.name ? urlString = tabStateUrls.searchUrl : "tab-glossary" == elementName.name && (urlString = tabStateUrls.glossaryUrl),
  24. Utils.setUrl({
  25. url: urlString,
  26. mergeBrowserUrl: !1,
  27. trigger: !0,
  28. updateTabState: !0
  29. });
  30. }, events;
  31. },
  32. initialize: function(options) {
  33. this.options = options;
  34. },
  35. onRender: function() {
  36. this.renderTagLayoutView(), this.renderSearchLayoutView(), this.renderGlossaryLayoutView(),
  37. this.selectTab();
  38. },
  39. renderTagLayoutView: function() {
  40. var that = this;
  41. require([ "views/tag/TagLayoutView" ], function(TagLayoutView) {
  42. that.RTagLayoutView.show(new TagLayoutView(_.extend(that.options, {
  43. collection: that.options.classificationDefCollection
  44. })));
  45. });
  46. },
  47. renderSearchLayoutView: function() {
  48. var that = this;
  49. require([ "views/search/SearchLayoutView" ], function(SearchLayoutView) {
  50. that.RSearchLayoutView.show(new SearchLayoutView(that.options));
  51. });
  52. },
  53. renderGlossaryLayoutView: function() {
  54. var that = this;
  55. require([ "views/glossary/GlossaryLayoutView" ], function(GlossaryLayoutView) {
  56. that.RGlossaryLayoutView.show(new GlossaryLayoutView(that.options));
  57. });
  58. },
  59. selectTab: function() {
  60. var that = this, activeTab = function(options) {
  61. var view = options.view;
  62. that.$(".tabs").find('li a[aria-controls="tab-' + view + '"]').parents("li").addClass("active").siblings().removeClass("active"),
  63. that.$(".tab-content").find("div#tab-" + view).addClass("active").siblings().removeClass("active");
  64. };
  65. if (Utils.getUrlState.isSearchTab() || Utils.getUrlState.isInitial()) activeTab({
  66. view: "search"
  67. }); else if (Utils.getUrlState.isTagTab()) activeTab({
  68. view: "classification"
  69. }); else if (Utils.getUrlState.isGlossaryTab()) activeTab({
  70. view: "glossary"
  71. }); else if (Utils.getUrlState.isDetailPage()) {
  72. var queryParams = Utils.getUrlState.getQueryParams(), view = "search";
  73. queryParams && queryParams.from && ("classification" == queryParams.from ? view = "tag" : "glossary" == queryParams.from && (view = "glossary")),
  74. activeTab({
  75. view: view
  76. });
  77. }
  78. }
  79. });
  80. return SideNavLayoutView;
  81. });