<commit_before>define [
  'compiled/gradebook2/GRADEBOOK_TRANSLATIONS'
  'jquery'
  'underscore'
  'compiled/gradebook2/Turnitin'
  'jquery.ajaxJSON'
], (GRADEBOOK_TRANSLATIONS, $, _, {extractData}) ->

  class SubmissionCell

    constructor: (@opts) ->
      @init()

    init: () ->
      submission = @opts.item[@opts.column.field]
      @$wrapper = $(@cellWrapper('<input class="grade"/>')).appendTo(@opts.container)
      @$input = @$wrapper.find('input').focus().select()

    destroy: () ->
      @$input.remove()

    focus: () ->
      @$input.focus()

    loadValue: () ->
      @val = @opts.item[@opts.column.field].grade || ""
      @$input.val(@val)
      @$input[0].defaultValue = @val
      @$input.select()

    serializeValue: () ->
      @$input.val()

    applyValue: (item, state) ->
      item[@opts.column.field].grade = state
      @wrapper?.remove()
      @postValue(item, state)
      # TODO: move selection down to the next row, same column

    postValue: (item, state) ->
      submission = item[@opts.column.field]
      url = @opts.grid.getOptions().change_grade_url
      url = url.replace(":assignment", submission.assignment_id).replace(":submission", submission.user_id)
      $.ajaxJSON url, "PUT", { "submission[posted_grade]": state }, (submission) =>
        $.publish 'submissions_updated', [submission.all_submissions]

    isValueChanged: () ->
      @val != @$input.val()

    validate: () ->
      { valid: true, msg: null }

    @formatter: (row, col, submission, assignment) ->
      this.prototype.cellWrapper(submission.grade, {submission: submission, assignment: assignment, editable: false})

    cellWrapper: (innerContents, options = {}) ->
      opts = $.extend({}, {
        classes: '',
        editable: true
      }, options)
      opts.submission ||= @opts.item[@opts.column.field]
      opts.assignment ||= @opts.column.object
      specialClasses = SubmissionCell.classesBasedOnSubmission(opts.submission, opts.assignment)

      opts.classes += ' no_grade_yet ' unless opts.submission.grade
      innerContents ?= if opts.submission?.submission_type then '<span class="submission_type_icon" />' else '-'

      if turnitin = extractData(opts.submission)
        specialClasses.push('turnitin')
        innerContents += "<span class='gradebook-cell-turnitin #{turnitin.state}-score' />"

      tooltipText = $.map(specialClasses, (c)-> GRADEBOOK_TRANSLATIONS["submission_tooltip_#{c}"]).join ', '

      """
      #{ if tooltipText then '<div class="gradebook-tooltip">'+ tooltipText + '</div>' else ''}
      <div class="gradebook-cell #{ if opts.editable then 'gradebook-cell-editable focus' else ''} #{opts.classes} #{specialClasses.join(' ')}">
        <a href="#" data-user-id=#{opts.submission.user_id} data-assignment-id=#{opts.assignment.id} class="gradebook-cell-comment"><span class="gradebook-cell-comment-label">submission comments</span></a>
        #{innerContents}
      </div>
      """

    @classesBasedOnSubmission: (submission={}, assignment={}) ->
      classes = []
      classes.push('resubmitted') if submission.grade_matches_current_submission == false
      if assignment.due_at && submission.submitted_at
        classes.push('late') if submission.submission_type isnt 'online_quiz' && (submission.submitted_at.timestamp > assignment.due_at.timestamp)
        classes.push('late') if submission.submission_type is 'online_quiz' && ((submission.submitted_at.timestamp - assignment.due_at.timestamp) > 30)
      classes.push('dropped') if submission.drop
      classes.push('ungraded') if ''+assignment.submission_types is "not_graded"
      classes.push('muted') if assignment.muted
      classes.push(submission.submission_type) if submission.submission_type
      classes<commit_msg>increase late time padding on quizzes in gradebook2<commit_after>define [
  'compiled/gradebook2/GRADEBOOK_TRANSLATIONS'
  'jquery'
  'underscore'
  'compiled/gradebook2/Turnitin'
  'jquery.ajaxJSON'
], (GRADEBOOK_TRANSLATIONS, $, _, {extractData}) ->

  class SubmissionCell

    constructor: (@opts) ->
      @init()

    init: () ->
      submission = @opts.item[@opts.column.field]
      @$wrapper = $(@cellWrapper('<input class="grade"/>')).appendTo(@opts.container)
      @$input = @$wrapper.find('input').focus().select()

    destroy: () ->
      @$input.remove()

    focus: () ->
      @$input.focus()

    loadValue: () ->
      @val = @opts.item[@opts.column.field].grade || ""
      @$input.val(@val)
      @$input[0].defaultValue = @val
      @$input.select()

    serializeValue: () ->
      @$input.val()

    applyValue: (item, state) ->
      item[@opts.column.field].grade = state
      @wrapper?.remove()
      @postValue(item, state)
      # TODO: move selection down to the next row, same column

    postValue: (item, state) ->
      submission = item[@opts.column.field]
      url = @opts.grid.getOptions().change_grade_url
      url = url.replace(":assignment", submission.assignment_id).replace(":submission", submission.user_id)
      $.ajaxJSON url, "PUT", { "submission[posted_grade]": state }, (submission) =>
        $.publish 'submissions_updated', [submission.all_submissions]

    isValueChanged: () ->
      @val != @$input.val()

    validate: () ->
      { valid: true, msg: null }

    @formatter: (row, col, submission, assignment) ->
      this.prototype.cellWrapper(submission.grade, {submission: submission, assignment: assignment, editable: false})

    cellWrapper: (innerContents, options = {}) ->
      opts = $.extend({}, {
        classes: '',
        editable: true
      }, options)
      opts.submission ||= @opts.item[@opts.column.field]
      opts.assignment ||= @opts.column.object
      specialClasses = SubmissionCell.classesBasedOnSubmission(opts.submission, opts.assignment)

      opts.classes += ' no_grade_yet ' unless opts.submission.grade
      innerContents ?= if opts.submission?.submission_type then '<span class="submission_type_icon" />' else '-'

      if turnitin = extractData(opts.submission)
        specialClasses.push('turnitin')
        innerContents += "<span class='gradebook-cell-turnitin #{turnitin.state}-score' />"

      tooltipText = $.map(specialClasses, (c)-> GRADEBOOK_TRANSLATIONS["submission_tooltip_#{c}"]).join ', '

      """
      #{ if tooltipText then '<div class="gradebook-tooltip">'+ tooltipText + '</div>' else ''}
      <div class="gradebook-cell #{ if opts.editable then 'gradebook-cell-editable focus' else ''} #{opts.classes} #{specialClasses.join(' ')}">
        <a href="#" data-user-id=#{opts.submission.user_id} data-assignment-id=#{opts.assignment.id} class="gradebook-cell-comment"><span class="gradebook-cell-comment-label">submission comments</span></a>
        #{innerContents}
      </div>
      """

    @classesBasedOnSubmission: (submission={}, assignment={}) ->
      classes = []
      classes.push('resubmitted') if submission.grade_matches_current_submission == false
      if assignment.due_at && submission.submitted_at
        classes.push('late') if submission.submission_type isnt 'online_quiz' && (submission.submitted_at.timestamp > assignment.due_at.timestamp)
        classes.push('late') if submission.submission_type is 'online_quiz' && ((submission.submitted_at.timestamp - assignment.due_at.timestamp) > 60)
      classes.push('dropped') if submission.drop
      classes.push('ungraded') if ''+assignment.submission_types is "not_graded"
      classes.push('muted') if assignment.muted
      classes.push(submission.submission_type) if submission.submission_type
      classes
{'fraction_non_alphanumeric': 0.15936675461741426, 'fraction_numerical': 0.0014511873350923482, 'mean_word_length': 3.528673835125448, 'pattern_counts': {'":': 6, '<': 25, '<?xml version=': 0, '>': 61, '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': '6980785', 'n_tokens_mistral': 2354, 'n_tokens_neox': 2282, 'n_words': 404}