<commit_before>define [
  'i18n!course_settings'
  'jquery'
  'underscore'
  'Backbone'
  'compiled/views/course_settings/EditSectionsView'
  'compiled/views/course_settings/InvitationsView'
  'compiled/views/course_settings/LinkToStudentsView'
  'compiled/models/User'
  'jst/courses/settings/UserView'
  'compiled/str/underscore'
  'str/htmlEscape'
  'compiled/jquery.whenAll'
  'compiled/jquery.kylemenu'
], (I18n, $, _, Backbone, EditSectionsView, InvitationsView, LinkToStudentsView, User, userViewTemplate, toUnderscore, h) ->

  editSectionsDialog = null
  linkToStudentsDialog = null
  invitationDialog = null

  class UserView extends Backbone.View

    tagName: 'li'

    className: 'user admin-link-hover-area'

    events:
      'click .admin-links [data-event]': 'handleMenuEvent'

    render: =>
      @$el.disableWhileLoading @data().done (data) =>
        @$el.addClass data.typeClass
        @$el.attr 'id', "user_#{data.id}"
        @$el.attr 'title',  if data.isPending
                              I18n.t 'pending', 'pending acceptance'
                            else
                              "#{data.name}: #{data.login_id}"
        @$el.html userViewTemplate(data)
      this

    getUserData: (id) ->
      $.get("/api/v1/courses/#{ENV.COURSE_ID}/users/#{id}", include:['enrollments'])

    data: ->
      dfd = $.Deferred()
      dfds = []
      data = $.extend @model.toJSON(),
        url: "#{ENV.COURSE_ROOT_URL}/users/#{@model.get('id')}"
        permissions: ENV.PERMISSIONS
        isObserver: @model.hasEnrollmentType('ObserverEnrollment')
        isPending: @model.pending()
      for en in data.enrollments
        en.pending = @model.pending()
        en.typeClass = toUnderscore en.type
        section = ENV.CONTEXTS['sections'][en.course_section_id]
        en.sectionTitle = h section.name if section
      if data.isObserver
        users = {}
        for en in data.enrollments
          users[en.associated_user_id] ||= en.enrollment_state in ['creation_pending', 'invited'] if en.associated_user_id
        data.enrollments = []
        for id, pending of users
          dfds.push @getUserData(id).done (user) =>
            ob = {pending}
            ob.sectionTitle = I18n.t('observing_user', '*Observing*: %{user_name}', wrapper: '<i>$1</i>', user_name: user.name)
            for en in user.enrollments
              section = ENV.CONTEXTS['sections'][en.course_section_id]
              ob.sectionTitle += h(I18n.t('#support.array.words_connector') + section.name) if section
            data.enrollments.push ob
      # if a dfd fails (e.g. observee was removed from course), we still want
      # the observer to render (possibly with other observees)
      $.whenAll(dfds...).then ->
        dfd.resolve(data)
      dfd.promise()

    reload: =>
      @$el.disableWhileLoading @model.fetch
        data: ENV.USER_PARAMS
        success: => @render()

    resendInvitation: (e) ->
      invitationDialog ||= new InvitationsView
      invitationDialog.model = @model
      invitationDialog.render().show()

    editSections: (e) ->
      editSectionsDialog ||= new EditSectionsView
      editSectionsDialog.model = @model
      editSectionsDialog.off 'updated'
      editSectionsDialog.on 'updated', @reload
      editSectionsDialog.render().show()

    linkToStudents: (e) ->
      linkToStudentsDialog ||= new LinkToStudentsView
      linkToStudentsDialog.model = @model
      linkToStudentsDialog.off 'updated'
      linkToStudentsDialog.on 'updated', @reload
      linkToStudentsDialog.render().show()

    removeFromCourse: (e) ->
      return unless confirm I18n.t('links.unenroll_user_course', 'Remove User from Course')
      @$el.hide()
      success = =>
        for e in @model.get('enrollments')
          e_type = e.typeClass.split('_')[0]
          c.innerText = parseInt(c.innerText) - 1 for c in $(".#{e_type}_count")
      failure = =>
        @$el.show()
      deferreds = _.map @model.get('enrollments'), (e) ->
        $.ajaxJSON "#{ENV.COURSE_ROOT_URL}/unenroll/#{e.id}", 'DELETE'
      $.when(deferreds...).then success, failure

    handleMenuEvent : (e) =>
      e.preventDefault()
      method = $(e.currentTarget).data 'event'
      @[method].call this, e
<commit_msg>fix wording on remove-user prompt; fixes #9758<commit_after>define [
  'i18n!course_settings'
  'jquery'
  'underscore'
  'Backbone'
  'compiled/views/course_settings/EditSectionsView'
  'compiled/views/course_settings/InvitationsView'
  'compiled/views/course_settings/LinkToStudentsView'
  'compiled/models/User'
  'jst/courses/settings/UserView'
  'compiled/str/underscore'
  'str/htmlEscape'
  'compiled/jquery.whenAll'
  'compiled/jquery.kylemenu'
], (I18n, $, _, Backbone, EditSectionsView, InvitationsView, LinkToStudentsView, User, userViewTemplate, toUnderscore, h) ->

  editSectionsDialog = null
  linkToStudentsDialog = null
  invitationDialog = null

  class UserView extends Backbone.View

    tagName: 'li'

    className: 'user admin-link-hover-area'

    events:
      'click .admin-links [data-event]': 'handleMenuEvent'

    render: =>
      @$el.disableWhileLoading @data().done (data) =>
        @$el.addClass data.typeClass
        @$el.attr 'id', "user_#{data.id}"
        @$el.attr 'title',  if data.isPending
                              I18n.t 'pending', 'pending acceptance'
                            else
                              "#{data.name}: #{data.login_id}"
        @$el.html userViewTemplate(data)
      this

    getUserData: (id) ->
      $.get("/api/v1/courses/#{ENV.COURSE_ID}/users/#{id}", include:['enrollments'])

    data: ->
      dfd = $.Deferred()
      dfds = []
      data = $.extend @model.toJSON(),
        url: "#{ENV.COURSE_ROOT_URL}/users/#{@model.get('id')}"
        permissions: ENV.PERMISSIONS
        isObserver: @model.hasEnrollmentType('ObserverEnrollment')
        isPending: @model.pending()
      for en in data.enrollments
        en.pending = @model.pending()
        en.typeClass = toUnderscore en.type
        section = ENV.CONTEXTS['sections'][en.course_section_id]
        en.sectionTitle = h section.name if section
      if data.isObserver
        users = {}
        for en in data.enrollments
          users[en.associated_user_id] ||= en.enrollment_state in ['creation_pending', 'invited'] if en.associated_user_id
        data.enrollments = []
        for id, pending of users
          dfds.push @getUserData(id).done (user) =>
            ob = {pending}
            ob.sectionTitle = I18n.t('observing_user', '*Observing*: %{user_name}', wrapper: '<i>$1</i>', user_name: user.name)
            for en in user.enrollments
              section = ENV.CONTEXTS['sections'][en.course_section_id]
              ob.sectionTitle += h(I18n.t('#support.array.words_connector') + section.name) if section
            data.enrollments.push ob
      # if a dfd fails (e.g. observee was removed from course), we still want
      # the observer to render (possibly with other observees)
      $.whenAll(dfds...).then ->
        dfd.resolve(data)
      dfd.promise()

    reload: =>
      @$el.disableWhileLoading @model.fetch
        data: ENV.USER_PARAMS
        success: => @render()

    resendInvitation: (e) ->
      invitationDialog ||= new InvitationsView
      invitationDialog.model = @model
      invitationDialog.render().show()

    editSections: (e) ->
      editSectionsDialog ||= new EditSectionsView
      editSectionsDialog.model = @model
      editSectionsDialog.off 'updated'
      editSectionsDialog.on 'updated', @reload
      editSectionsDialog.render().show()

    linkToStudents: (e) ->
      linkToStudentsDialog ||= new LinkToStudentsView
      linkToStudentsDialog.model = @model
      linkToStudentsDialog.off 'updated'
      linkToStudentsDialog.on 'updated', @reload
      linkToStudentsDialog.render().show()

    removeFromCourse: (e) ->
      return unless confirm I18n.t('delete_confirm', 'Are you sure you want to remove this user?')
      @$el.hide()
      success = =>
        for e in @model.get('enrollments')
          e_type = e.typeClass.split('_')[0]
          c.innerText = parseInt(c.innerText) - 1 for c in $(".#{e_type}_count")
      failure = =>
        @$el.show()
      deferreds = _.map @model.get('enrollments'), (e) ->
        $.ajaxJSON "#{ENV.COURSE_ROOT_URL}/unenroll/#{e.id}", 'DELETE'
      $.when(deferreds...).then success, failure

    handleMenuEvent : (e) =>
      e.preventDefault()
      method = $(e.currentTarget).data 'event'
      @[method].call this, e

{'fraction_non_alphanumeric': 0.13521423554202763, 'fraction_numerical': 0.00421446967923203, 'mean_word_length': 2.6665236051502146, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 41, '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': '1458217', 'n_tokens_mistral': 2746, 'n_tokens_neox': 2685, 'n_words': 527}