<commit_before>define [
  'i18n!grading_cell'
  'compiled/gradebook2/GRADEBOOK_TRANSLATIONS'
  'underscore'
  'ember'
  'jquery'
  'jquery.ajaxJSON'
], (I18n, GRADEBOOK_TRANSLATIONS, _, Ember, $) ->

  GradingCellComponent = Ember.Component.extend

    value: null

    isPoints: Ember.computed.equal('assignment.grading_type', 'points')
    isPercent: Ember.computed.equal('assignment.grading_type', 'percent')
    isLetterGrade: Ember.computed.equal('assignment.grading_type', 'letter_grade')
    isPassFail: Ember.computed.equal('assignment.grading_type', 'pass_fail')
    nilPointsPossible: Ember.computed.none('assignment.points_possible')
    isGpaScale: Ember.computed.equal('assignment.grading_type', 'gpa_scale')

    passFailGrades: [
        {
          label: I18n.t "grade_ungraded", "Ungraded"
          value: "-"
        }
        {
          label: I18n.t "grade_complete", "Complete"
          value: "complete"
        }
        {
          label: I18n.t "grade_incomplete", "Incomplete"
          value: "incomplete"
        }
    ]

    outOfText: (->
      if @get('isGpaScale')
        ""
      else if @get('isLetterGrade') or @get('isPassFail')
        I18n.t "out_of_with_score", "(%{score} out of %{points})",
          points: @assignment.points_possible
          score: @get('score')
      else if @get('nilPointsPossible')
        I18n.t "out_of_nil", "No points possible"
      else
        I18n.t "out_of", "(out of %{points})", points: @assignment.points_possible
    ).property('submission.score', 'assignment')

    changeGradeURL: ->
      ENV.GRADEBOOK_OPTIONS.change_grade_url

    saveURL: (->
      submission = @get('submission')
      this.changeGradeURL()
        .replace(":assignment", submission.assignment_id)
        .replace(":submission", submission.user_id)
    ).property('submission.assignment_id', 'submission.user_id')

    score: (->
      if @submission.score? then @submission.score else ' -'
    ).property('submission.score')

    ajax: (url, options) ->
      {type, data} = options
      $.ajaxJSON url, type, data

    submissionDidChange: (->
      newVal = if @submission?.grade? then @submission.grade else '-'
      @set 'value', newVal
    ).observes('submission').on('init')

    onUpdateSuccess: (submission) ->
      @sendAction 'on-submit-grade', submission.all_submissions

    onUpdateError: ->
      $.flashError(GRADEBOOK_TRANSLATIONS.submission_update_error)

    focusOut: ->
      return unless submission = @get('submission')
      url = @get('saveURL')
      value = @$('input, select').val()
      if @get('isPassFail') and value == "-"
        value = ''
      return if value == submission.grade
      save = @ajax url,
        type: "PUT"
        data: { "submission[posted_grade]": value }
      save.then @boundUpdateSuccess, @onUpdateError

    bindSave: (->
      @boundUpdateSuccess = _.bind(@onUpdateSuccess, this)
    ).on('init')

    click: ->
      @$('input, select').select()

    focus: ->
      @$('input, select').select()
<commit_msg>add support for excusing assignments in SRGB<commit_after>define [
  'i18n!grading_cell'
  'compiled/gradebook2/GRADEBOOK_TRANSLATIONS'
  'underscore'
  'ember'
  'jquery'
  'jquery.ajaxJSON'
], (I18n, GRADEBOOK_TRANSLATIONS, _, Ember, $) ->

  GradingCellComponent = Ember.Component.extend

    value: null

    isPoints: Ember.computed.equal('assignment.grading_type', 'points')
    isPercent: Ember.computed.equal('assignment.grading_type', 'percent')
    isLetterGrade: Ember.computed.equal('assignment.grading_type', 'letter_grade')
    isPassFail: Ember.computed.equal('assignment.grading_type', 'pass_fail')
    nilPointsPossible: Ember.computed.none('assignment.points_possible')
    isGpaScale: Ember.computed.equal('assignment.grading_type', 'gpa_scale')

    passFailGrades: [
        {
          label: I18n.t "grade_ungraded", "Ungraded"
          value: "-"
        }
        {
          label: I18n.t "grade_complete", "Complete"
          value: "complete"
        }
        {
          label: I18n.t "grade_incomplete", "Incomplete"
          value: "incomplete"
        }
    ]

    outOfText: (->
      if @get('isGpaScale')
        ""
      else if @get('isLetterGrade') or @get('isPassFail')
        I18n.t "out_of_with_score", "(%{score} out of %{points})",
          points: @assignment.points_possible
          score: @get('score')
      else if @get('nilPointsPossible')
        I18n.t "out_of_nil", "No points possible"
      else
        I18n.t "out_of", "(out of %{points})", points: @assignment.points_possible
    ).property('submission.score', 'assignment')

    changeGradeURL: ->
      ENV.GRADEBOOK_OPTIONS.change_grade_url

    saveURL: (->
      submission = @get('submission')
      this.changeGradeURL()
        .replace(":assignment", submission.assignment_id)
        .replace(":submission", submission.user_id)
    ).property('submission.assignment_id', 'submission.user_id')

    score: (->
      if @submission.score? then @submission.score else ' -'
    ).property('submission.score')

    ajax: (url, options) ->
      {type, data} = options
      $.ajaxJSON url, type, data

    submissionDidChange: (->
      newVal = if @submission?.excused
                 'EX'
               else
                 @submission?.grade || '-'

      @set 'value', newVal
    ).observes('submission').on('init')

    onUpdateSuccess: (submission) ->
      @sendAction 'on-submit-grade', submission.all_submissions

    onUpdateError: ->
      $.flashError(GRADEBOOK_TRANSLATIONS.submission_update_error)

    focusOut: ->
      return unless submission = @get('submission')
      url = @get('saveURL')
      value = @$('input, select').val()
      if @get('isPassFail') and value == '-'
        value = ''
      return if value == submission.grade
      data = if value?.toUpperCase() == 'EX'
               { "submission[excuse]": true }
             else
               { "submission[posted_grade]": value }
      save = @ajax url,
        type: "PUT"
        data: data
      save.then @boundUpdateSuccess, @onUpdateError

    bindSave: (->
      @boundUpdateSuccess = _.bind(@onUpdateSuccess, this)
    ).on('init')

    click: ->
      @$('input, select').select()

    focus: ->
      @$('input, select').select()

{'fraction_non_alphanumeric': 0.1460155877206935, 'fraction_numerical': 0.0054079847303960555, 'mean_word_length': 2.7517899761336517, 'pattern_counts': {'":': 7, '<': 3, '<?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': '4234503', 'n_tokens_mistral': 2109, 'n_tokens_neox': 2013, 'n_words': 360}