<commit_before>class TeamworkAppView extends KDView

  constructor: (options = {}, data) ->

    super options, data

    @emit "ready"

    if location.search.match "chromeapp"
      KD.getSingleton("mainView").enableFullscreen()
      window.parent.postMessage "TeamworkReady", "*"

  handleQuery: (query) ->
    @teamworkApp = @createApp query  unless @teamworkApp
    return  @teamworkApp.emit "NewSessionRequested"  unless query
    if query.sessionKey then @handleSessionKey query.sessionKey
    else if query.importUrl then @handleImportUrl query.importUrl
    else @teamworkApp.emit "NewSessionRequested"

  handleSessionKey: (sessionKey) ->
    return @restoreLocation()  if sessionKey is @teamworkApp.getOption "sessionKey"
    @teamworkApp.emit "JoinSessionRequested", sessionKey

  handleImportUrl: (importUrl) ->
    @teamworkApp.emit "ImportRequested", importUrl

  restoreLocation: ->
    @setLocation @teamworkApp.getOption "sessionKey"

  setLocation: (sessionKey) ->
    KD.singleton("router").handleRoute "/Teamwork?sessionKey=#{sessionKey}"

  createApp: (query) ->
    return new TeamworkApp
      delegate : this
      query    : query<commit_msg>teamwork: show window chooser modal if requested session is different than current<commit_after>class TeamworkAppView extends KDView

  constructor: (options = {}, data) ->

    super options, data

    @emit "ready"

    if location.search.match "chromeapp"
      KD.getSingleton("mainView").enableFullscreen()
      window.parent.postMessage "TeamworkReady", "*"

  handleQuery: (query) ->
    @teamworkApp = @createApp query  unless @teamworkApp
    return  @teamworkApp.emit "NewSessionRequested"  unless query
    if query.sessionKey then @handleSessionKey query.sessionKey
    else if query.importUrl then @handleImportUrl query.importUrl
    else @teamworkApp.emit "NewSessionRequested"

  handleSessionKey: (sessionKey) ->
    currentSessionKey = @teamworkApp.getOption "sessionKey"
    return @restoreLocation()  if sessionKey is currentSessionKey

    if currentSessionKey
    then @showChooseWindowModal sessionKey
    else @teamworkApp.emit "JoinSessionRequested", sessionKey

  handleImportUrl: (importUrl) ->
    @teamworkApp.emit "ImportRequested", importUrl

  showChooseWindowModal: (sessionKey) ->
    modal = new KDModalView
      title      : "Choose session window"
      content    : "Where do you want to open session #{sessionKey}?"
      cssClass   : "tw-modal"
      overlay    : yes
        buttons         :
          CurrentWindow :
            title       : "Current window"
            callback    : =>
              @teamworkApp.emit "JoinSessionRequested", sessionKey
              modal.destroy()
          NewWindow     :
            title       : "New window"
            callback    : =>
              @restoreLocation()
              window.open "#{window.location.origin}/Teamwork?sessionKey=#{sessionKey}", "_blank"
              modal.destroy()

  restoreLocation: ->
    @setLocation @teamworkApp.getOption "sessionKey"

  setLocation: (sessionKey) ->
    KD.singleton("router").handleRoute "/Teamwork?sessionKey=#{sessionKey}"

  createApp: (query) ->
    return new TeamworkApp
      delegate : this
      query    : query
{'fraction_non_alphanumeric': 0.09582689335394126, 'fraction_numerical': 0.0, 'mean_word_length': 3.1808785529715764, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, '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': '5500392', 'n_tokens_mistral': 909, 'n_tokens_neox': 875, 'n_words': 216}