<commit_before>class IDE.ChatSettingsPane extends KDTabPaneView

  JView.mixin @constructor

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

    options.cssClass = 'chat-settings'

    super options, data

    @rtm = options.rtm

    @createElements()

    @on 'CollaborationStarted', => @toggleButtons 'started'
    @on 'CollaborationEnded',   => @toggleButtons 'ended'

    @on 'ParticipantJoined', @bound 'addParticipant'
    @on 'ParticipantLeft',   @bound 'removeParticipant'


  createElements: ->

    channel = @getData()

    @title = new KDCustomHTMLView
      tagName  : 'h3'
      cssClass : 'workspace-name'
      partial  : 'My Workspace'

    @chevron = new KDCustomHTMLView
      tagName  : 'figure'
      cssClass : 'pm-title-chevron'

    @link = new KDCustomHTMLView
      tagName    : 'a'
      cssClass   : 'session-link'
      partial    : link = KD.utils.groupifyLink "IDE/#{channel.id}", yes
      attributes : href : link
      # click      : (event) ->
      #   KD.utils.stopDOMEvent event
      #   # errs saying 'Discontiguous selection is not supported.' needs research - SY
      #   KD.utils.selectText @getElement()

    @startSession = new KDButtonView
      title    : 'START SESSION'
      cssClass : 'solid green'
      callback : @bound 'initiateSession'

    @endSession = new KDButtonView
      title    : 'END SESSION'
      disabled : yes
      cssClass : 'solid red hidden'
      callback : @bound 'stopSession'

    @back = new KDButtonView
      title    : 'back to chat'
      cssClass : 'solid green mini'
      callback : => @getDelegate().showChatPane()

    @defaultSetting = new KDSelectBox
      defaultValue  : 'edit'
      selectOptions : [
        { title : 'CAN READ', value : 'read'}
        { title : 'CAN EDIT', value : 'edit'}
      ]

    @everyone = new KDCustomHTMLView
      tagName  : 'ul'
      cssClass : 'settings everyone loading'

    @everyone.addSubView new KDLoaderView
      showLoader : yes
      size       :
        width    : 24

    @everyone.addSubView new KDCustomHTMLView
      cssClass : 'label'
      partial  : 'Fetching participants...'


  initiateSession: ->

    @startSession.disable()
    {appManager} = KD.singletons

    appManager.tell 'IDE', 'startCollaborationSession', (err, channel) =>

      return @startSession.enable()  if err

      @toggleButtons 'started'


  stopSession: ->

    @endSession.disable()
    {appManager} = KD.singletons

    appManager.tell 'IDE', 'stopCollaborationSession', (err, channel) =>

      return @endSession.enable()  if err

      @toggleButtons 'ended'


  toggleButtons: (state) ->
    startButton = @startSession
    endButton   = @endSession

    if state is 'started'
      endButton.show()
      endButton.enable()
      startButton.hide()
      startButton.disable()
    else
      startButton.show()
      startButton.enable()
      endButton.hide()
      endButton.disable()


  createParticipantsList: ->

    @everyone.unsetClass 'loading'
    @everyone.destroySubViews()

    participants      = @rtm.getFromModel('participants').asArray()
    @participantViews = {}

    for participant in participants
      @createParticipantView participant


  createParticipantView: (data) =>

    view = new IDE.ChatParticipantView {}, data
    @participantViews[data.nickname] = view
    @everyone.addSubView view


  removeParticipant: (username) ->

    @participantViews[username]?.destroy()
    delete @participantViews[username]


  addParticipant: (nickname) ->

    return  if @participantViews[nickname]

    @createParticipantView { nickname }


  viewAppended: JView::viewAppended

  setTemplate: JView::setTemplate


  pistachio: ->

    """
    <header>
    {{> @title}}{{> @chevron}}
    {{> @link}}
    <div class='buttons'>
      {{> @startSession}} {{> @endSession}}
    </div>
    </header>
    <ul class='settings default'>
      <li><label>Anyone who joins</label>{{> @defaultSetting}}</li>
    </ul>
    {{> @everyone}}
    {{> @back}}
    """
<commit_msg>ChatSettingsPane: Handle collaboration started and ended phases.<commit_after>class IDE.ChatSettingsPane extends KDTabPaneView

  JView.mixin @constructor

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

    options.cssClass = 'chat-settings'

    super options, data

    @rtm = options.rtm

    @createElements()

    @on 'CollaborationNotInitialized', => @everyone.destroySubViews()
    @on 'ParticipantJoined', @bound 'addParticipant'
    @on 'ParticipantLeft',   @bound 'removeParticipant'

    @on 'CollaborationEnded', =>
      @toggleButtons 'ended'
      @everyone.destroySubViews()

    @on 'CollaborationStarted', =>
      @toggleButtons 'started'
      @createParticipantsList()


  createElements: ->

    channel = @getData()

    @title = new KDCustomHTMLView
      tagName  : 'h3'
      cssClass : 'workspace-name'
      partial  : 'My Workspace'

    @chevron = new KDCustomHTMLView
      tagName  : 'figure'
      cssClass : 'pm-title-chevron'

    @link = new KDCustomHTMLView
      tagName    : 'a'
      cssClass   : 'session-link'
      partial    : link = KD.utils.groupifyLink "IDE/#{channel.id}", yes
      attributes : href : link
      # click      : (event) ->
      #   KD.utils.stopDOMEvent event
      #   # errs saying 'Discontiguous selection is not supported.' needs research - SY
      #   KD.utils.selectText @getElement()

    @startSession = new KDButtonView
      title    : 'START SESSION'
      cssClass : 'solid green'
      callback : @bound 'initiateSession'

    @endSession = new KDButtonView
      title    : 'END SESSION'
      disabled : yes
      cssClass : 'solid red hidden'
      callback : @bound 'stopSession'

    @back = new KDButtonView
      title    : 'back to chat'
      cssClass : 'solid green mini'
      callback : => @getDelegate().showChatPane()

    @defaultSetting = new KDSelectBox
      defaultValue  : 'edit'
      selectOptions : [
        { title : 'CAN READ', value : 'read'}
        { title : 'CAN EDIT', value : 'edit'}
      ]

    @everyone = new KDCustomHTMLView
      tagName  : 'ul'
      cssClass : 'settings everyone loading'

    @everyone.addSubView new KDLoaderView
      showLoader : yes
      size       :
        width    : 24

    @everyone.addSubView new KDCustomHTMLView
      cssClass : 'label'
      partial  : 'Fetching participants...'


  initiateSession: ->

    @startSession.disable()
    {appManager} = KD.singletons

    appManager.tell 'IDE', 'startCollaborationSession', (err, channel) =>

      return @startSession.enable()  if err

      @toggleButtons 'started'


  stopSession: ->

    @endSession.disable()
    {appManager} = KD.singletons

    appManager.tell 'IDE', 'stopCollaborationSession', (err, channel) =>

      return @endSession.enable()  if err

      @toggleButtons 'ended'


  toggleButtons: (state) ->
    startButton = @startSession
    endButton   = @endSession

    if state is 'started'
      endButton.show()
      endButton.enable()
      startButton.hide()
      startButton.disable()
    else
      startButton.show()
      startButton.enable()
      endButton.hide()
      endButton.disable()


  createParticipantsList: ->

    @everyone.unsetClass 'loading'
    @everyone.destroySubViews()

    participants      = @rtm.getFromModel('participants').asArray()
    @participantViews = {}

    for participant in participants
      @createParticipantView participant


  createParticipantView: (data) =>

    view = new IDE.ChatParticipantView {}, data
    @participantViews[data.nickname] = view
    @everyone.addSubView view


  removeParticipant: (username) ->

    @participantViews[username]?.destroy()
    delete @participantViews[username]


  addParticipant: (nickname) ->

    return  if @participantViews[nickname]

    @createParticipantView { nickname }


  viewAppended: JView::viewAppended

  setTemplate: JView::setTemplate


  pistachio: ->

    """
    <header>
    {{> @title}}{{> @chevron}}
    {{> @link}}
    <div class='buttons'>
      {{> @startSession}} {{> @endSession}}
    </div>
    </header>
    <ul class='settings default'>
      <li><label>Anyone who joins</label>{{> @defaultSetting}}</li>
    </ul>
    {{> @everyone}}
    {{> @back}}
    """

{'fraction_non_alphanumeric': 0.11979039727029003, 'fraction_numerical': 0.00073117231294175, 'mean_word_length': 2.695182350292661, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 72, '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': '920223', 'n_tokens_mistral': 2627, 'n_tokens_neox': 2434, 'n_words': 559}