       panel.removeClass('collapsed').removeClass('no-transition')
       $.removeCookie(cookie)
 
-  collapsePanelsIfNeededAtStart: ->
-    @panels.each((index, el) =>
-      cookie = "panel-collapsed-#{index}"
-      if $.cookie(cookie)
-        $(el).addClass('no-transition')
-        @collapseOrNot($(el), true)
-        @replaceButton($(el).parent().find('.fa-caret-up'), true)
-    )
-
+  cookieNameForIndex: (index) ->
+    "panel-collapsed-#{index}"
 
 $(document).on 'ready page:load', ->
   new UserSync('.user-sync')
class UserSync

  constructor: (selector) ->
    @collapseButtons = $("#{selector} .collapse-btn")
    @panels = $("#{selector} .panel")
    @collapsePanelsIfNeededAtStart()

    @collapseButtons.click((ev) =>
      button = $(ev.target)
      panel = $(ev.target).parent().parent().parent().find('.panel')
      collapse = button.hasClass('fa-caret-up')
      @replaceButton(button, collapse)
      @collapseOrNot(panel, collapse)
    )

  replaceButton: (btn, collapse) ->
    if collapse

    else
      btn.removeClass('fa-caret-down').addClass('fa-caret-up')

  modifyPanel: (panel, collapse) ->
    index = $('.panel.project-list').index(panel)
    cookie = @cookieNameForIndex(index)
    if collapse
      panel.addClass('collapsed')
      $.cookie(cookie, true, {expires: 1})
