Commit bb1eb4b5 authored by Alfredo Sumaran's avatar Alfredo Sumaran

Set actions dinamically and offer defaultAction as a optional parameter

parent 3c9e860f
...@@ -50,11 +50,10 @@ ...@@ -50,11 +50,10 @@
# </div> # </div>
# #
class @UserTabs class @UserTabs
actions: ['activity', 'groups', 'contributed', 'projects'],
defaultAction: 'activity',
constructor: (opts) -> constructor: (opts) ->
{ {
@action = 'activity' @action = 'activity'
@defaultAction = 'activity'
@parentEl = $(document) @parentEl = $(document)
} = opts } = opts
...@@ -63,16 +62,21 @@ class @UserTabs ...@@ -63,16 +62,21 @@ class @UserTabs
# Store the `location` object, allowing for easier stubbing in tests # Store the `location` object, allowing for easier stubbing in tests
@_location = location @_location = location
# Set tab states
@loaded = {} @loaded = {}
for item in @parentEl.find('.nav-links a')
@loaded[$(item).attr 'data-action'] = false
@bindEvents() # Actions
@tabStateInit() @actions = Object.keys @loaded
currAction = @defaultAction if @action is 'show' @bindEvents()
# Set active tab # Set active tab
source = $(".#{currAction}-tab a").attr('href') @action = @defaultAction if @action is 'show'
@activateTab(currAction) source = $(".#{@action}-tab a").attr('href')
@activateTab(@action)
bindEvents: -> bindEvents: ->
# Turn off existing event listeners # Turn off existing event listeners
...@@ -81,10 +85,6 @@ class @UserTabs ...@@ -81,10 +85,6 @@ class @UserTabs
# Set event listeners # Set event listeners
@parentEl.on 'shown.bs.tab', '.nav-links a[data-toggle="tab"]', @tabShown @parentEl.on 'shown.bs.tab', '.nav-links a[data-toggle="tab"]', @tabShown
tabStateInit: ->
for action in @actions
@loaded[action] = false
tabShown: (event) => tabShown: (event) =>
$target = $(event.target) $target = $(event.target)
action = $target.data('action') action = $target.data('action')
......
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