summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfredo Sumaran <alfredo@gitlab.com>2016-02-29 19:12:06 -0500
committerAlfredo Sumaran <alfredo@gitlab.com>2016-02-29 19:12:06 -0500
commiteed8b179b686fa98256a79e5ae8d2b5967bc5ecd (patch)
tree31bcb42032c656d92e5a9f8edef39da4bc800618
parentc6b27550c82c8c123047cae5c85bf3271a531d6a (diff)
downloadgitlab-ce-eed8b179b686fa98256a79e5ae8d2b5967bc5ecd.tar.gz
Handle default tab
-rw-r--r--app/assets/javascripts/user_tabs.js.coffee58
1 files changed, 43 insertions, 15 deletions
diff --git a/app/assets/javascripts/user_tabs.js.coffee b/app/assets/javascripts/user_tabs.js.coffee
index d2bb7d9c4ed..0b285f6ad80 100644
--- a/app/assets/javascripts/user_tabs.js.coffee
+++ b/app/assets/javascripts/user_tabs.js.coffee
@@ -1,45 +1,73 @@
class @UserTabs
actions: ['activity', 'groups', 'contributed', 'personal'],
defaultAction: 'activity',
+ tabButtonSelector: '.nav-links a[data-toggle="tab"]'
- constructor: ->
+ constructor: (@opts = {}) ->
# Store the `location` object, allowing for easier stubbing in tests
@_location = location
+ @loaded = {}
@bindEvents()
+ @setTabState()
+
+ # Set default tab
+ source = $(".#{@defaultAction}-tab a").attr('href')
+ @setTab(source, @defaultAction)
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) =>
$target = $(event.target)
action = $target.data('action')
source = $target.attr('href')
- @loadTab(source, action)
+ @setTab(source, 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) ->
- @_get
+ $.ajax
+ beforeSend: => @toggleLoading(true)
+ complete: => @toggleLoading(false)
+ dataType: 'json'
+ type: 'GET'
url: "#{source}.json"
success: (data) =>
tabSelector = 'div#' + action
document.querySelector(tabSelector).innerHTML = data.html
+ @loaded[action] = true
- toggleLoading: (status) ->
- $('.loading-status .loading').toggle(status)
+ loadActivities: (source) ->
+ return if @loaded['activity'] is true
- _get: (options) ->
- defaults = {
- beforeSend: => @toggleLoading(true)
- complete: => @toggleLoading(false)
- dataType: 'json'
- type: 'GET'
- }
+ $calendarWrap = $('.user-calendar')
+ $calendarWrap.load($calendarWrap.data('url'))
- options = $.extend({}, defaults, options)
+ new Activities()
+ @loaded['activity'] = true
- $.ajax(options)
+ toggleLoading: (status) ->
+ $('.loading-status .loading').toggle(status)
setCurrentAction: (action) ->
# Remove possible actions from URL