BigW Consortium Gitlab

Commit eed8b179 by Alfredo Sumaran

Handle default tab

parent c6b27550
class @UserTabs class @UserTabs
actions: ['activity', 'groups', 'contributed', 'personal'], actions: ['activity', 'groups', 'contributed', 'personal'],
defaultAction: 'activity', defaultAction: 'activity',
tabButtonSelector: '.nav-links a[data-toggle="tab"]'
constructor: -> constructor: (@opts = {}) ->
# Store the `location` object, allowing for easier stubbing in tests # Store the `location` object, allowing for easier stubbing in tests
@_location = location @_location = location
@loaded = {}
@bindEvents() @bindEvents()
@setTabState()
# Set default tab
source = $(".#{@defaultAction}-tab a").attr('href')
@setTab(source, @defaultAction)
bindEvents: -> bindEvents: ->
$(document).on 'shown.bs.tab', '.nav-links a[data-toggle="tab"]', @tabShown $(document).on 'shown.bs.tab', @tabButtonSelector, @tabShown
setTabState: ->
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')
source = $target.attr('href') source = $target.attr('href')
@loadTab(source, action) @setTab(source, action)
@setCurrentAction(action) @setCurrentAction(action)
setTab: (source, action) ->
return if @loaded[action] is true
if action is 'activity'
@loadActivities(source)
if action is 'groups'
@loadTab(source, action)
if action is 'contributed'
@loadTab(source, action)
if action is 'personal'
@loadTab(source, action)
loadTab: (source, action) -> loadTab: (source, action) ->
@_get $.ajax
beforeSend: => @toggleLoading(true)
complete: => @toggleLoading(false)
dataType: 'json'
type: 'GET'
url: "#{source}.json" url: "#{source}.json"
success: (data) => success: (data) =>
tabSelector = 'div#' + action tabSelector = 'div#' + action
document.querySelector(tabSelector).innerHTML = data.html document.querySelector(tabSelector).innerHTML = data.html
@loaded[action] = true
toggleLoading: (status) -> loadActivities: (source) ->
$('.loading-status .loading').toggle(status) return if @loaded['activity'] is true
_get: (options) -> $calendarWrap = $('.user-calendar')
defaults = { $calendarWrap.load($calendarWrap.data('url'))
beforeSend: => @toggleLoading(true)
complete: => @toggleLoading(false)
dataType: 'json'
type: 'GET'
}
options = $.extend({}, defaults, options) new Activities()
@loaded['activity'] = true
$.ajax(options) toggleLoading: (status) ->
$('.loading-status .loading').toggle(status)
setCurrentAction: (action) -> setCurrentAction: (action) ->
# Remove possible actions from URL # Remove possible actions from URL
......
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