/Src/Bowerbird.Website/js/bowerbird/views/projectDetailsView.js

https://github.com/Bowerbird/bowerbird-web · JavaScript · 296 lines · 220 code · 67 blank · 9 comment · 24 complexity · fb7f8c60fc9a94dcea60f088a0d1bb81 MD5 · raw file

  1. /// <reference path="../../libs/log.js" />
  2. /// <reference path="../../libs/require/require.js" />
  3. /// <reference path="../../libs/jquery/jquery-1.7.2.js" />
  4. /// <reference path="../../libs/underscore/underscore.js" />
  5. /// <reference path="../../libs/backbone/backbone.js" />
  6. /// <reference path="../../libs/backbone.marionette/backbone.marionette.js" />
  7. // ProjectDetailsView
  8. // ------------------
  9. define(['jquery', 'underscore', 'backbone', 'app', 'views/activitylistview', 'views/sightinglistview', 'views/postlistview', 'views/userlistview', 'views/projectaboutview',
  10. 'views/sightingsearchpanelview', 'views/postsearchpanelview', 'views/usersearchpanelview'],
  11. function ($, _, Backbone, app, ActivityListView, SightingListView, PostListView, UserListView, ProjectAboutView, SightingSearchPanelView, PostSearchPanelView, UserSearchPanelView) {
  12. var ProjectDetailsView = Backbone.Marionette.Layout.extend({
  13. viewType: 'detail',
  14. className: 'project double',
  15. template: 'Project',
  16. regions: {
  17. summary: '.summary',
  18. search: '.search',
  19. list: '.list'
  20. },
  21. events: {
  22. 'click .activities-tab-button': 'showActivityTabSelection',
  23. 'click .sightings-tab-button': 'showSightingsTabSelection',
  24. 'click .posts-tab-button': 'showPostsTabSelection',
  25. 'click .members-tab-button': 'showMembersTabSelection',
  26. 'click .about-tab-button': 'showAboutTabSelection'
  27. },
  28. activeTab: '',
  29. initialize: function () {
  30. _.bindAll(this, 'toggleSearchPanel');
  31. },
  32. serializeData: function () {
  33. return {
  34. Model: {
  35. Project: this.model.toJSON(),
  36. //IsMember: _.any(app.authenticatedUser.memberships, function (membership) { return membership.GroupId === this.model.id; }, this),
  37. UserCountDescription: this.model.get('UserCount') === 1 ? 'Member' : 'Members',
  38. SightingCountDescription: this.model.get('SightingCount') === 1 ? 'Sighting' : 'Sightings',
  39. PostCountDescription: this.model.get('PostCount') === 1 ? 'Post' : 'Posts'
  40. }
  41. };
  42. },
  43. onShow: function () {
  44. this._showDetails();
  45. },
  46. showBootstrappedDetails: function () {
  47. this.initializeRegions();
  48. this._showDetails();
  49. },
  50. _showDetails: function () {
  51. },
  52. showActivityTabSelection: function (e) {
  53. e.preventDefault();
  54. this.showTabSelection('activities', $(e.currentTarget).attr('href'));
  55. },
  56. showSightingsTabSelection: function (e) {
  57. e.preventDefault();
  58. this.showTabSelection('sightings', $(e.currentTarget).attr('href'));
  59. },
  60. showPostsTabSelection: function (e) {
  61. e.preventDefault();
  62. this.showTabSelection('posts', $(e.currentTarget).attr('href'));
  63. },
  64. showMembersTabSelection: function (e) {
  65. e.preventDefault();
  66. this.showTabSelection('members', $(e.currentTarget).attr('href'));
  67. },
  68. showAboutTabSelection: function (e) {
  69. e.preventDefault();
  70. this.showTabSelection('about', $(e.currentTarget).attr('href'));
  71. },
  72. showTabSelection: function (tab, url) {
  73. if (this.activeTab === tab) {
  74. return;
  75. }
  76. this.switchTabHighlight(tab);
  77. this.list.currentView.showLoading();
  78. Backbone.history.navigate(url, { trigger: true });
  79. },
  80. showActivity: function (activityCollection) {
  81. this.switchTabHighlight('activities');
  82. var options = {
  83. model: this.model,
  84. collection: activityCollection
  85. };
  86. if (app.isPrerenderingView('projects')) {
  87. options['el'] = '.list > div';
  88. }
  89. var activityListView = new ActivityListView(options);
  90. if (app.isPrerenderingView('projects')) {
  91. this.list.attachView(activityListView);
  92. activityListView.showBootstrappedDetails();
  93. } else {
  94. this.list.show(activityListView);
  95. }
  96. },
  97. showSightings: function (sightingCollection, categorySelectList, fieldSelectList) {
  98. this.switchTabHighlight('sightings');
  99. var options = {
  100. model: this.model,
  101. collection: sightingCollection
  102. };
  103. var searchOptions = {
  104. sightingCollection: sightingCollection,
  105. categorySelectList: categorySelectList,
  106. fieldSelectList: fieldSelectList
  107. };
  108. if (app.isPrerenderingView('projects')) {
  109. options['el'] = '.list > div';
  110. searchOptions['el'] = '.search > div';
  111. }
  112. var sightingListView = new SightingListView(options);
  113. var sightingSearchPanelView = new SightingSearchPanelView(searchOptions);
  114. if (app.isPrerenderingView('projects')) {
  115. this.list.attachView(sightingListView);
  116. sightingListView.showBootstrappedDetails();
  117. this.search.attachView(sightingSearchPanelView);
  118. sightingSearchPanelView.showBootstrappedDetails();
  119. } else {
  120. this.list.show(sightingListView);
  121. this.search.show(sightingSearchPanelView);
  122. }
  123. sightingListView.on('toggle-search', this.toggleSearchPanel);
  124. if (sightingCollection.hasSearchCriteria()) {
  125. this.$el.find('.search-bar').slideDown();
  126. }
  127. },
  128. showPosts: function (postCollection, fieldSelectList) {
  129. this.switchTabHighlight('posts');
  130. var options = {
  131. model: this.model,
  132. collection: postCollection
  133. };
  134. var searchOptions = {
  135. postCollection: postCollection,
  136. fieldSelectList: fieldSelectList
  137. };
  138. if (app.isPrerenderingView('projects')) {
  139. options['el'] = '.list > div';
  140. searchOptions['el'] = '.search > div';
  141. }
  142. var postListView = new PostListView(options);
  143. var postSearchPanelView = new PostSearchPanelView(searchOptions);
  144. if (app.isPrerenderingView('projects')) {
  145. this.list.attachView(postListView);
  146. postListView.showBootstrappedDetails();
  147. this.search.attachView(postSearchPanelView);
  148. postSearchPanelView.showBootstrappedDetails();
  149. } else {
  150. this.list.show(postListView);
  151. this.search.show(postSearchPanelView);
  152. }
  153. postListView.on('toggle-search', this.toggleSearchPanel);
  154. if (postCollection.hasSearchCriteria()) {
  155. this.$el.find('.search-bar').slideDown();
  156. }
  157. },
  158. showMembers: function (userCollection, fieldSelectList) {
  159. this.switchTabHighlight('members');
  160. var options = {
  161. model: this.model,
  162. collection: userCollection
  163. };
  164. var searchOptions = {
  165. userCollection: userCollection,
  166. fieldSelectList: fieldSelectList
  167. };
  168. if (app.isPrerenderingView('projects')) {
  169. options['el'] = '.list > div';
  170. searchOptions['el'] = '.search > div';
  171. }
  172. var userListView = new UserListView(options);
  173. var userSearchPanelView = new UserSearchPanelView(searchOptions);
  174. if (app.isPrerenderingView('projects')) {
  175. this.list.attachView(userListView);
  176. userListView.showBootstrappedDetails();
  177. this.search.attachView(userSearchPanelView);
  178. userSearchPanelView.showBootstrappedDetails();
  179. } else {
  180. this.list.show(userListView);
  181. this.search.show(userSearchPanelView);
  182. }
  183. userListView.on('toggle-search', this.toggleSearchPanel);
  184. if (userCollection.hasSearchCriteria()) {
  185. this.$el.find('.search-bar').slideDown();
  186. }
  187. },
  188. showAbout: function (projectAdministrators, activityTimeseries) {
  189. this.switchTabHighlight('about');
  190. var options = {
  191. model: this.model
  192. };
  193. if (app.isPrerenderingView('projects')) {
  194. options['el'] = '.list > div';
  195. }
  196. options.projectAdministrators = projectAdministrators;
  197. options.activityTimeseries = activityTimeseries;
  198. var projectAboutView = new ProjectAboutView(options);
  199. if (app.isPrerenderingView('projects')) {
  200. this.list.attachView(projectAboutView);
  201. projectAboutView.showBootstrappedDetails();
  202. } else {
  203. this.list.show(projectAboutView);
  204. }
  205. },
  206. switchTabHighlight: function (tab) {
  207. this.activeTab = tab;
  208. this.$el.find('.tab-button').removeClass('selected');
  209. this.$el.find('.' + tab + '-tab-button').addClass('selected');
  210. if ((tab === 'activities' || tab === 'about') && this.search.currentView) {
  211. this.search.currentView.$el.hide();
  212. }
  213. },
  214. toggleSearchPanel: function () {
  215. log('search bar', this.$el.find('.search-bar'));
  216. if (this.$el.find('.search-bar').is(':visible')) {
  217. log('search is visible');
  218. this.$el.find('.search-bar').slideToggle();
  219. } else {
  220. log('search is not visible');
  221. var that = this;
  222. this.$el.find('.search-bar').slideToggle(function () {
  223. that.$el.find('.search-bar #query').focus();
  224. });
  225. }
  226. }
  227. });
  228. return ProjectDetailsView;
  229. });