Commit 48ae8ef1 authored by Alfredo Sumaran's avatar Alfredo Sumaran

Activate tab according URL

parent 8c90b6ec
class @UserTabs class @UserTabs
actions: ['activity', 'groups', 'contributed', 'personal'], actions: ['activity', 'groups', 'contributed_projects', 'projects'],
defaultAction: 'activity', defaultAction: 'activity',
tabButtonSelector: '.nav-links a[data-toggle="tab"]'
constructor: (@opts = {}) -> constructor: (@opts = {}) ->
# Store the `location` object, allowing for easier stubbing in tests # Store the `location` object, allowing for easier stubbing in tests
...@@ -9,16 +8,20 @@ class @UserTabs ...@@ -9,16 +8,20 @@ class @UserTabs
@loaded = {} @loaded = {}
@bindEvents() @bindEvents()
@setTabState() @tabStateInit()
# Set default tab action = @opts.action
source = $(".#{@defaultAction}-tab a").attr('href') action = @defaultAction if action == 'show'
@setTab(source, @defaultAction)
# Set active tab
source = $(".#{action}-tab a").attr('href')
@activateTab(action)
@setTab(source, action)
bindEvents: -> bindEvents: ->
$(document).on 'shown.bs.tab', @tabButtonSelector, @tabShown $(document).on 'shown.bs.tab', '.nav-links a[data-toggle="tab"]', @tabShown
setTabState: -> tabStateInit: ->
for action in @actions for action in @actions
@loaded[action] = false @loaded[action] = false
...@@ -30,6 +33,9 @@ class @UserTabs ...@@ -30,6 +33,9 @@ class @UserTabs
@setTab(source, action) @setTab(source, action)
@setCurrentAction(action) @setCurrentAction(action)
activateTab: (action) ->
$(".nav-links .#{action}-tab a").tab('show')
setTab: (source, action) -> setTab: (source, action) ->
return if @loaded[action] is true return if @loaded[action] is true
...@@ -39,10 +45,10 @@ class @UserTabs ...@@ -39,10 +45,10 @@ class @UserTabs
if action is 'groups' if action is 'groups'
@loadTab(source, action) @loadTab(source, action)
if action is 'contributed' if action is 'contributed_projects'
@loadTab(source, action) @loadTab(source, action)
if action is 'personal' if action is 'projects'
@loadTab(source, action) @loadTab(source, action)
loadTab: (source, action) -> loadTab: (source, action) ->
......
...@@ -70,17 +70,17 @@ ...@@ -70,17 +70,17 @@
= @user.location = @user.location
%ul.nav-links.center %ul.nav-links.center
%li.activity-tab.active %li.activity-tab
= link_to user_calendar_activities_path, data: {target: 'div#activity', action: 'activity', toggle: 'tab'} do = link_to user_calendar_activities_path, data: {target: 'div#activity', action: 'activity', toggle: 'tab'} do
Activity Activity
%li.groups-tab %li.groups-tab
= link_to user_groups_path, data: {target: 'div#groups', action: 'groups', toggle: 'tab'} do = link_to user_groups_path, data: {target: 'div#groups', action: 'groups', toggle: 'tab'} do
Groups Groups
%li.contributed-tab %li.contributed_projects-tab
= link_to user_contributed_projects_path, data: {target: 'div#contributed', action: 'contributed', toggle: 'tab'} do = link_to user_contributed_projects_path, data: {target: 'div#contributed_projects', action: 'contributed_projects', toggle: 'tab'} do
Contributed projects Contributed projects
%li.personal-tab %li.projects-tab
= link_to user_projects_path, data: {target: 'div#personal', action: 'personal', toggle: 'tab'} do = link_to user_projects_path, data: {target: 'div#projects', action: 'projects', toggle: 'tab'} do
Personal projects Personal projects
%div{ class: container_class } %div{ class: container_class }
...@@ -99,10 +99,10 @@ ...@@ -99,10 +99,10 @@
#groups.tab-pane #groups.tab-pane
- # This tab is always loaded via AJAX - # This tab is always loaded via AJAX
#contributed.tab-pane #contributed_projects.tab-pane
- # This tab is always loaded via AJAX - # This tab is always loaded via AJAX
#personal.tab-pane #projects.tab-pane
- # This tab is always loaded via AJAX - # This tab is always loaded via AJAX
.loading-status .loading-status
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment