Skip to content
Snippets Groups Projects
Commit 48ae8ef1 authored by Alfredo Sumaran's avatar Alfredo Sumaran
Browse files

Activate tab according URL

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