Ejemplo n.º 1
0
  update = (newData) => {
    $.extend(this.submission, newData)
    this.submission.moreThanOneSubmission = this.submission.submission_history.length > 1
    this.submission.loading = false
    this.submission.submission_history.forEach((submission) => {
      submission.submission_comments && submission.submission_comments.forEach((comment) => {
        comment.url = `${this.options.context_url}/users/${comment.author_id}`
        const urlPrefix = `${location.protocol}//${location.host}`
        comment.image_url = `${urlPrefix}/images/users/${comment.author_id}`
      })
      submission.turnitin = extractDataForTurnitin(submission, `submission_${submission.id}`, this.options.context_url)
      submission.attachments && submission.attachments.forEach((attachment) => {
        attachment.turnitin = extractDataForTurnitin(submission, `attachment_${attachment.id}`, this.options.context_url)
      })
    })

    if (this.options.anonymous) {
      this.submission.submission_comments.forEach((comment) => {
        if(comment.author.id !== ENV.current_user_id) {
          comment.anonymous = comment.author.anonymous = true;
          comment.author_name = I18n.t('Student');
        }
      });
    }

    if (this.submission.excused) {
      this.submission.grade = 'EX'
    } else if (['points', 'percent'].includes(this.assignment.grading_type)) {
      this.submission.grade = GradeFormatHelper.formatGrade(this.submission.grade)
    }
    this.dialog.html(submissionDetailsDialog(this.submission))
    this.dialog.find('select').trigger('change')
    return this.scrollCommentsToBottom()
  }
Ejemplo n.º 2
0
  constructor (assignment, student, options) {
    this.assignment = assignment
    this.student = student
    this.options = options
    const speedGraderUrl = this.options.speed_grader_enabled
      ? `${this.options.context_url}/gradebook/speed_grader?assignment_id=${this.assignment.id}#%7B%22student_id%22%3A${this.student.id}%7D`
      : null

    this.url = this.options.change_grade_url.replace(':assignment', this.assignment.id).replace(':submission', this.student.id)
    const submission = this.student[`assignment_${this.assignment.id}`]
    this.submission = $.extend({}, submission, {
      label: `student_grading_${this.assignment.id}`,
      inputName: 'submission[posted_grade]',
      assignment: this.assignment,
      speedGraderUrl,
      loading: true,
      showPointsPossible:
        (this.assignment.points_possible || this.assignment.points_possible === '0') &&
        this.assignment.grading_type !== 'gpa_scale',
      formattedPointsPossible: I18n.n(this.assignment.points_possible),
      shouldShowExcusedOption: true,
      isInPastGradingPeriodAndNotAdmin: submission.gradeLocked
    })
    this.submission[`assignment_grading_type_is_${this.assignment.grading_type}`] = true
    if (this.submission.excused) this.submission.grade = 'EX'
    this.$el = $('<div class="use-css-transitions-for-show-hide" style="padding:0;"/>')
    this.$el.html(submissionDetailsDialog(this.submission))

    this.dialog = this.$el.dialog({
      title: this.student.name,
      width: 600,
      resizable: false
    })

    this.dialog.on('dialogclose', this.options.onClose)
    this.dialog
      .delegate('select[id="submission_to_view"]', 'change', event => this.dialog.find('.submission_detail').each(function (index) {
        $(this).showIf(index === event.currentTarget.selectedIndex)
      }))
      .delegate('.submission_details_grade_form', 'submit', (event) => {
        event.preventDefault()
        let formData = $(event.currentTarget).getFormData()
        const rawGrade = formData['submission[posted_grade]']
        if (rawGrade.toUpperCase() === 'EX') {
          formData = {'submission[excuse]': true}
        } else {
          formData['submission[posted_grade]'] = GradeFormatHelper.delocalizeGrade(rawGrade)
        }
        $(event.currentTarget.form).disableWhileLoading(
          $.ajaxJSON(this.url, 'PUT', formData, (data) => {
            this.update(data)
            if (!data.excused) {
              const outlierScoreHelper = new OutlierScoreHelper(this.submission.score, this.submission.assignment.points_possible)
              if (outlierScoreHelper.hasWarning()) {
                $.flashWarning(outlierScoreHelper.warningMessage())
              }
            }
            $.publish('submissions_updated', [this.submission.all_submissions])
            setTimeout(() => this.dialog.dialog('close'), 500)
          })
        )
      })
      .delegate('.submission_details_add_comment_form', 'submit', (event) => {
        event.preventDefault()
        $(event.currentTarget).disableWhileLoading(
          $.ajaxJSON(this.url, 'PUT', $(event.currentTarget).getFormData(), (data) => {
            this.update(data)
            setTimeout(() => this.dialog.dialog('close'), 500)
          })
        )
      })

    const url = `${this.url}&include[]=submission_history&include[]=submission_comments&include[]=rubric_assessment`
    const deferred = $.ajaxJSON(url, 'GET', {}, this.update)
    this.dialog.find('.submission_details_comments').disableWhileLoading(deferred)
  }