<commit_before>class AvatarPopupGroupSwitcher extends AvatarPopup

  constructor:->
    @notLoggedInMessage = 'Login required to switch groups'
    super

  viewAppended:->

    super

    @pending             = 0
    @notPopulated        = yes
    @notPopulatedPending = yes
    groupsController     = KD.getSingleton "groupsController"
    router               = KD.getSingleton "router"


    @_popupList = new PopupList
      itemClass  : PopupGroupListItem

    @_popupListPending = new PopupList
      itemClass  : PopupGroupListItemPending

    # does not work yet
    # @_popupListPending.on 'PendingCountDecreased', @bound 'decreasePendingCount'
    # @_popupListPending.on 'UpdateGroupList',       @bound 'populateGroups'
    # KD.whoami().on        'NewPendingInvitation',  @bound 'populatePendingGroups'

    @listControllerPending = new KDListViewController
      lazyLoaderOptions   :
        partial           : ''
        spinnerOptions    :
          loaderOptions   :
            color         : '#6BB197'
          size            :
            width         : 32
      view                : @_popupListPending

    @listController = new KDListViewController
      lazyLoaderOptions   :
        partial           : ''
        spinnerOptions    :
          loaderOptions   :
            color         : '#6BB197'
          size            :
            width         : 32
      view                : @_popupList

    @listController.on "AvatarPopupShouldBeHidden", @bound 'hide'

    @avatarPopupContent.addSubView @invitesHeader = new KDView
      height   : "auto"
      cssClass : "sublink top hidden"
      partial  : "You have pending group invitations:"

    @avatarPopupContent.addSubView new KDCustomHTMLView
      tagName    : 'span'
      cssClass   : 'icon help'
      tooltip    :
        title    : "Here you'll find the groups that you are a member of, clicking one of them will take you to a new browser tab."

    @addSubView @groupSubMenuWrapper = new KDCustomHTMLView
      partial  : '<div class="kdview content"></div>'
      cssClass : 'avatararea-popup notifications group-switcher submenu' # this is a hack, just to use the same position w/ notifications dropdown

    @groupSubMenuWrapper.setCss 'right', 293

    {entryPoint} = KD.config
    createGroupLink = new KDCustomHTMLView
      tagName    : 'a'
      attributes : href : '/Pricing/Team'
      cssClass   : 'bottom bb hidden'
      partial    : 'Create a group'
      click      : (event)=>
        KD.utils.stopDOMEvent event
        router.handleRoute '/Pricing/CreateGroup', entryPoint : 'koding'
        @hide()

    if KD.isLoggedIn()
      KD.singleton("paymentController").fetchSubscriptionsWithPlans tags: ["custom-plan"], (err, subscriptions) ->
        return KD.showError err  if err
        createGroupLink.show()   unless subscriptions.length

    backToKoding = new KDCustomHTMLView
      tagName    : 'a'
      attributes : href : '/'
      cssClass   : 'bottom bb'
      partial    : 'Go back to Koding'
      click      : (event)=>
        KD.utils.stopDOMEvent event
        location.href = '/'

    groupsController.ready ->
      backToKoding.destroy()  if groupsController.getCurrentGroup().slug is 'koding'


    @groupSubMenuWrapper.addSubView createGroupLink, '.content'
    @groupSubMenuWrapper.addSubView backToKoding, '.content'
    @groupSubMenuWrapper.addSubView @listControllerPending.getView(), '.content'
    @groupSubMenuWrapper.addSubView @listController.getView(), '.content'


    submenuShown = no

    @avatarPopupContent.bindEvent 'mousemove'
    @avatarPopupContent.on 'mousemove', (event)=>
      return  if $(event.target).closest().is '.submenu'
      @groupSubMenuWrapper.unsetClass 'active'

    handleSubMenu = (event)=>
      KD.utils.stopDOMEvent event
      submenuShown = yes
      @groupSubMenuWrapper.setClass 'active'
      @populateGroups()

    @avatarPopupContent.addSubView new KDCustomHTMLView
      tagName    : 'a'
      attributes : href : '#'
      cssClass   : 'bottom'
      partial    : 'Your groups'
      bind       : 'mouseenter mousemove'
      mouseenter : handleSubMenu
      click      : handleSubMenu
      mousemove  : KD.utils.stopDOMEvent

    @avatarPopupContent.addSubView new KDCustomHTMLView
      tagName    : 'a'
      attributes : href : '/Account'
      cssClass   : 'bottom separator'
      partial    : 'Account settings'
      click      : (event)=>
        KD.utils.stopDOMEvent event
        router.handleRoute '/Account'
        @hide()


    @avatarPopupContent.addSubView new KDCustomHTMLView
      tagName    : 'a'
      attributes : href : '/Environments'
      cssClass   : 'bottom'
      partial    : 'Environments'
      click      : (event)=>
        KD.utils.stopDOMEvent event
        router.handleRoute '/Environments'
        @hide()

    @avatarPopupContent.addSubView new KDCustomHTMLView
      tagName    : 'a'
      cssClass   : 'bottom'
      partial    : 'System Health Check'
      click      : (event)=>
        @_modal = new TroubleshootModal
        @hide()

    @avatarPopupContent.addSubView dashboardLink = new KDCustomHTMLView
      tagName  : "a"<commit_msg>Troubleshoot: regressed unused @_modal variable from avatarareagroupswitcherpopup<commit_after>class AvatarPopupGroupSwitcher extends AvatarPopup

  constructor:->
    @notLoggedInMessage = 'Login required to switch groups'
    super

  viewAppended:->

    super

    @pending             = 0
    @notPopulated        = yes
    @notPopulatedPending = yes
    groupsController     = KD.getSingleton "groupsController"
    router               = KD.getSingleton "router"


    @_popupList = new PopupList
      itemClass  : PopupGroupListItem

    @_popupListPending = new PopupList
      itemClass  : PopupGroupListItemPending

    # does not work yet
    # @_popupListPending.on 'PendingCountDecreased', @bound 'decreasePendingCount'
    # @_popupListPending.on 'UpdateGroupList',       @bound 'populateGroups'
    # KD.whoami().on        'NewPendingInvitation',  @bound 'populatePendingGroups'

    @listControllerPending = new KDListViewController
      lazyLoaderOptions   :
        partial           : ''
        spinnerOptions    :
          loaderOptions   :
            color         : '#6BB197'
          size            :
            width         : 32
      view                : @_popupListPending

    @listController = new KDListViewController
      lazyLoaderOptions   :
        partial           : ''
        spinnerOptions    :
          loaderOptions   :
            color         : '#6BB197'
          size            :
            width         : 32
      view                : @_popupList

    @listController.on "AvatarPopupShouldBeHidden", @bound 'hide'

    @avatarPopupContent.addSubView @invitesHeader = new KDView
      height   : "auto"
      cssClass : "sublink top hidden"
      partial  : "You have pending group invitations:"

    @avatarPopupContent.addSubView new KDCustomHTMLView
      tagName    : 'span'
      cssClass   : 'icon help'
      tooltip    :
        title    : "Here you'll find the groups that you are a member of, clicking one of them will take you to a new browser tab."

    @addSubView @groupSubMenuWrapper = new KDCustomHTMLView
      partial  : '<div class="kdview content"></div>'
      cssClass : 'avatararea-popup notifications group-switcher submenu' # this is a hack, just to use the same position w/ notifications dropdown

    @groupSubMenuWrapper.setCss 'right', 293

    {entryPoint} = KD.config
    createGroupLink = new KDCustomHTMLView
      tagName    : 'a'
      attributes : href : '/Pricing/Team'
      cssClass   : 'bottom bb hidden'
      partial    : 'Create a group'
      click      : (event)=>
        KD.utils.stopDOMEvent event
        router.handleRoute '/Pricing/CreateGroup', entryPoint : 'koding'
        @hide()

    if KD.isLoggedIn()
      KD.singleton("paymentController").fetchSubscriptionsWithPlans tags: ["custom-plan"], (err, subscriptions) ->
        return KD.showError err  if err
        createGroupLink.show()   unless subscriptions.length

    backToKoding = new KDCustomHTMLView
      tagName    : 'a'
      attributes : href : '/'
      cssClass   : 'bottom bb'
      partial    : 'Go back to Koding'
      click      : (event)=>
        KD.utils.stopDOMEvent event
        location.href = '/'

    groupsController.ready ->
      backToKoding.destroy()  if groupsController.getCurrentGroup().slug is 'koding'


    @groupSubMenuWrapper.addSubView createGroupLink, '.content'
    @groupSubMenuWrapper.addSubView backToKoding, '.content'
    @groupSubMenuWrapper.addSubView @listControllerPending.getView(), '.content'
    @groupSubMenuWrapper.addSubView @listController.getView(), '.content'


    submenuShown = no

    @avatarPopupContent.bindEvent 'mousemove'
    @avatarPopupContent.on 'mousemove', (event)=>
      return  if $(event.target).closest().is '.submenu'
      @groupSubMenuWrapper.unsetClass 'active'

    handleSubMenu = (event)=>
      KD.utils.stopDOMEvent event
      submenuShown = yes
      @groupSubMenuWrapper.setClass 'active'
      @populateGroups()

    @avatarPopupContent.addSubView new KDCustomHTMLView
      tagName    : 'a'
      attributes : href : '#'
      cssClass   : 'bottom'
      partial    : 'Your groups'
      bind       : 'mouseenter mousemove'
      mouseenter : handleSubMenu
      click      : handleSubMenu
      mousemove  : KD.utils.stopDOMEvent

    @avatarPopupContent.addSubView new KDCustomHTMLView
      tagName    : 'a'
      attributes : href : '/Account'
      cssClass   : 'bottom separator'
      partial    : 'Account settings'
      click      : (event)=>
        KD.utils.stopDOMEvent event
        router.handleRoute '/Account'
        @hide()


    @avatarPopupContent.addSubView new KDCustomHTMLView
      tagName    : 'a'
      attributes : href : '/Environments'
      cssClass   : 'bottom'
      partial    : 'Environments'
      click      : (event)=>
        KD.utils.stopDOMEvent event
        router.handleRoute '/Environments'
        @hide()

    @avatarPopupContent.addSubView new KDCustomHTMLView
      tagName    : 'a'
      cssClass   : 'bottom'
      partial    : 'System Health Check'
      click      : (event)=>
        new TroubleshootModal
        @hide()

    @avatarPopupContent.addSubView dashboardLink = new KDCustomHTMLView
      tagName  : "a"
{'fraction_non_alphanumeric': 0.08645533141210375, 'fraction_numerical': 0.003073967339097022, 'mean_word_length': 2.30612892981899, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3747547', 'n_tokens_mistral': 3073, 'n_tokens_neox': 2966, 'n_words': 700}