canvas-lms/public/javascripts/quiz_show.js

218 lines
7.8 KiB
JavaScript
Raw Normal View History

2011-02-01 09:57:29 +08:00
/**
* Copyright (C) 2011 Instructure, Inc.
*
* This file is part of Canvas.
*
* Canvas is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3 of the License.
*
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
define([
AMD Conversion "Trivial" JavaScript / CoffeeScript changes -------------------------------------------------- For the most part, all javascript was simply wrapped in `require` or `define`. The dependencies were found with a script that matched regexes in the files, it errs on the side of listing too many dependencies, so its worth double checking each file's dependencies (over time, anyway). i18n API changes -------------------------------------------------- No longer have to do I18n.scoped calls, just list i18n as a dependency with the scope and it's imported already scoped require ['i18n!some_scope'], (I18n) -> I18n.t 'im_scoped', 'I'm scoped!' JS bundling now done with r.js, not Jammit -------------------------------------------------- We don't use jammit to bundle JS anymore. Simply list dependencies for your JS modules in the file and RequireJS handles the rest. To optimize the JavaScript, first make sure you have node.js 0.4.12+ installed and then run: $ rake js:build The app defaults to the optimized build in production. You can use non-optimized in production by putting ?debug_assets=true in the url just like before. You can also test the optimized JavaScript in development with ?optimized_js=true. Significant changes -------------------------------------------------- These files have "real" changes to them (unlike the JavaScript that is simply wrapped in require and define). Worth taking a really close look at: - app/helpers/application_helper.rb - app/views/layouts/application.html.erb - config/assets.yml - config/build.js - lib/handlebars/handlebars.rb - lib/i18n_extraction/js_extractor.rb - lib/tasks/canvas.rake - lib/tasks/i18n.rake - lib/tasks/js.rake Change-Id: I4bc5ecb1231f331aaded0fef2bcc1f3a9fe482a7 Reviewed-on: https://gerrit.instructure.com/6986 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Ryan Florence <ryanf@instructure.com>
2011-11-11 00:31:45 +08:00
'i18n!quizzes.show',
'jquery' /* $ */,
'compiled/views/MessageStudentsDialog',
'quiz_arrows',
'quiz_inputs',
'compiled/models/Quiz',
'compiled/views/PublishButtonView',
'compiled/quizzes/dump_events',
'jsx/conditional_release_stats/index',
AMD Conversion "Trivial" JavaScript / CoffeeScript changes -------------------------------------------------- For the most part, all javascript was simply wrapped in `require` or `define`. The dependencies were found with a script that matched regexes in the files, it errs on the side of listing too many dependencies, so its worth double checking each file's dependencies (over time, anyway). i18n API changes -------------------------------------------------- No longer have to do I18n.scoped calls, just list i18n as a dependency with the scope and it's imported already scoped require ['i18n!some_scope'], (I18n) -> I18n.t 'im_scoped', 'I'm scoped!' JS bundling now done with r.js, not Jammit -------------------------------------------------- We don't use jammit to bundle JS anymore. Simply list dependencies for your JS modules in the file and RequireJS handles the rest. To optimize the JavaScript, first make sure you have node.js 0.4.12+ installed and then run: $ rake js:build The app defaults to the optimized build in production. You can use non-optimized in production by putting ?debug_assets=true in the url just like before. You can also test the optimized JavaScript in development with ?optimized_js=true. Significant changes -------------------------------------------------- These files have "real" changes to them (unlike the JavaScript that is simply wrapped in require and define). Worth taking a really close look at: - app/helpers/application_helper.rb - app/views/layouts/application.html.erb - config/assets.yml - config/build.js - lib/handlebars/handlebars.rb - lib/i18n_extraction/js_extractor.rb - lib/tasks/canvas.rake - lib/tasks/i18n.rake - lib/tasks/js.rake Change-Id: I4bc5ecb1231f331aaded0fef2bcc1f3a9fe482a7 Reviewed-on: https://gerrit.instructure.com/6986 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Ryan Florence <ryanf@instructure.com>
2011-11-11 00:31:45 +08:00
'jquery.instructure_date_and_time' /* dateString, time_field, datetime_field */,
'jqueryui/dialog',
'compiled/jquery/fixDialogButtons',
'compiled/jquery.rails_flash_notifications',
AMD Conversion "Trivial" JavaScript / CoffeeScript changes -------------------------------------------------- For the most part, all javascript was simply wrapped in `require` or `define`. The dependencies were found with a script that matched regexes in the files, it errs on the side of listing too many dependencies, so its worth double checking each file's dependencies (over time, anyway). i18n API changes -------------------------------------------------- No longer have to do I18n.scoped calls, just list i18n as a dependency with the scope and it's imported already scoped require ['i18n!some_scope'], (I18n) -> I18n.t 'im_scoped', 'I'm scoped!' JS bundling now done with r.js, not Jammit -------------------------------------------------- We don't use jammit to bundle JS anymore. Simply list dependencies for your JS modules in the file and RequireJS handles the rest. To optimize the JavaScript, first make sure you have node.js 0.4.12+ installed and then run: $ rake js:build The app defaults to the optimized build in production. You can use non-optimized in production by putting ?debug_assets=true in the url just like before. You can also test the optimized JavaScript in development with ?optimized_js=true. Significant changes -------------------------------------------------- These files have "real" changes to them (unlike the JavaScript that is simply wrapped in require and define). Worth taking a really close look at: - app/helpers/application_helper.rb - app/views/layouts/application.html.erb - config/assets.yml - config/build.js - lib/handlebars/handlebars.rb - lib/i18n_extraction/js_extractor.rb - lib/tasks/canvas.rake - lib/tasks/i18n.rake - lib/tasks/js.rake Change-Id: I4bc5ecb1231f331aaded0fef2bcc1f3a9fe482a7 Reviewed-on: https://gerrit.instructure.com/6986 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Ryan Florence <ryanf@instructure.com>
2011-11-11 00:31:45 +08:00
'jquery.instructure_misc_plugins' /* ifExists, confirmDelete */,
'jquery.disableWhileLoading',
AMD Conversion "Trivial" JavaScript / CoffeeScript changes -------------------------------------------------- For the most part, all javascript was simply wrapped in `require` or `define`. The dependencies were found with a script that matched regexes in the files, it errs on the side of listing too many dependencies, so its worth double checking each file's dependencies (over time, anyway). i18n API changes -------------------------------------------------- No longer have to do I18n.scoped calls, just list i18n as a dependency with the scope and it's imported already scoped require ['i18n!some_scope'], (I18n) -> I18n.t 'im_scoped', 'I'm scoped!' JS bundling now done with r.js, not Jammit -------------------------------------------------- We don't use jammit to bundle JS anymore. Simply list dependencies for your JS modules in the file and RequireJS handles the rest. To optimize the JavaScript, first make sure you have node.js 0.4.12+ installed and then run: $ rake js:build The app defaults to the optimized build in production. You can use non-optimized in production by putting ?debug_assets=true in the url just like before. You can also test the optimized JavaScript in development with ?optimized_js=true. Significant changes -------------------------------------------------- These files have "real" changes to them (unlike the JavaScript that is simply wrapped in require and define). Worth taking a really close look at: - app/helpers/application_helper.rb - app/views/layouts/application.html.erb - config/assets.yml - config/build.js - lib/handlebars/handlebars.rb - lib/i18n_extraction/js_extractor.rb - lib/tasks/canvas.rake - lib/tasks/i18n.rake - lib/tasks/js.rake Change-Id: I4bc5ecb1231f331aaded0fef2bcc1f3a9fe482a7 Reviewed-on: https://gerrit.instructure.com/6986 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Ryan Florence <ryanf@instructure.com>
2011-11-11 00:31:45 +08:00
'message_students' /* messageStudents */
], function(I18n, $, MessageStudentsDialog, QuizArrowApplicator, inputMethods, Quiz, PublishButtonView, QuizLogAuditingEventDumper, CyoeStats) {
$(document).ready(function () {
if(ENV.QUIZ_SUBMISSION_EVENTS_URL) {
QuizLogAuditingEventDumper(true);
}
$('#preview_quiz_button').click(function(e){
$('#js-sequential-warning-dialogue div a').attr('href',$('#preview_quiz_button').attr('href'));
});
function ensureStudentsLoaded(callback) {
if ($('#quiz_details').length) {
return callback();
} else {
return $.get($("#quiz_details_wrapper").data('url'), function(html) {
$("#quiz_details_wrapper").html(html);
callback();
});
}
}
var arrowApplicator = new QuizArrowApplicator();
arrowApplicator.applyArrows();
// quiz_show is being pulled into ember show for now. only hide inputs
// when we don't have a .allow-inputs
if (!$('.allow-inputs').length) {
inputMethods.disableInputs('[type=radio], [type=checkbox]');
inputMethods.setWidths();
}
$('form.edit_quizzes_quiz').on('submit', function(e) {
e.preventDefault();
e.stopImmediatePropagation();
$(this).find('.loading').removeClass('hidden');
var data = $(this).serializeArray();
var url = $(this).attr('action');
$.ajax({
url: url,
data: data,
type: 'POST',
success: function() {
$('.edit_quizzes_quiz').parents('.alert').hide();
}
});
});
$(".delete_quiz_link").click(function(event) {
event.preventDefault();
var deleteConfirmMessage = I18n.t('confirms.delete_quiz', "Are you sure you want to delete this quiz?");
submittedCount = parseInt($('#quiz_details_wrapper').data('submitted-count'));
if (submittedCount > 0) {
deleteConfirmMessage += "\n\n" + I18n.t('confirms.delete_quiz_submissions_warning',
{'one': "Warning: 1 student has already taken this quiz. If you delete it, any completed submissions will be deleted and no longer appear in the gradebook.",
'other': "Warning: %{count} students have already taken this quiz. If you delete it, any completed submissions will be deleted and no longer appear in the gradebook."},
{'count': submittedCount});
2011-02-01 09:57:29 +08:00
}
$("nothing").confirmDelete({
url: $(this).attr('href'),
message: deleteConfirmMessage,
success: function() {
window.location.href = ENV.QUIZZES_URL;
}
});
2011-02-01 09:57:29 +08:00
});
var hasOpenedQuizDetails = false;
$(".quiz_details_link").click(function(event) {
event.preventDefault();
$("#quiz_details_wrapper").disableWhileLoading(
ensureStudentsLoaded(function() {
var $quizResultsText = $('#quiz_details_text');
$("#quiz_details").slideToggle();
if (hasOpenedQuizDetails) {
if (ENV.IS_SURVEY) {
$quizResultsText.text(I18n.t('links.show_student_survey_results',
'Show Student Survey Results'));
} else {
$quizResultsText.text(I18n.t('links.show_student_quiz_results',
'Show Student Quiz Results'));
}
} else {
if (ENV.IS_SURVEY) {
$quizResultsText.text(I18n.t('links.hide_student_survey_results',
'Hide Student Survey Results'));
} else {
$quizResultsText.text(I18n.t('links.hide_student_quiz_results',
'Hide Student Quiz Results'));
}
}
hasOpenedQuizDetails = !hasOpenedQuizDetails;
})
);
});
$(".message_students_link").click(function(event) {
event.preventDefault();
ensureStudentsLoaded(function(){
var submissionList = ENV.QUIZ_SUBMISSION_LIST;
var unsubmittedStudents = submissionList.UNSUBMITTED_STUDENTS;
var submittedStudents = submissionList.SUBMITTED_STUDENTS;
var haveTakenQuiz = I18n.t('students_who_have_taken_the_quiz', "Students who have taken the quiz");
var haveNotTakenQuiz = I18n.t('students_who_have_not_taken_the_quiz', "Students who have NOT taken the quiz");
var dialog = new MessageStudentsDialog({
context: ENV.QUIZ.title,
recipientGroups: [
{ name: haveTakenQuiz, recipients: submittedStudents },
{ name: haveNotTakenQuiz, recipients: unsubmittedStudents }
]
});
dialog.open();
});
});
$("#let_students_take_this_quiz_button").ifExists(function($link){
var $unlock_for_how_long_dialog = $("#unlock_for_how_long_dialog");
$link.click(function(){
$unlock_for_how_long_dialog.dialog('open');
return false;
});
don't parse datetime_suggest for getFormData refs CNVS-19515 getFormData (and things that use its result, e.g. processData on formSubmit) now returns iso8601 values for datetime_fields instead of the formatted suggest string. this means they no longer need to be parsed and reformatted before submission from forms, inclusion in redirect parameters, etc. to support this, and for general use, a datetime_field now has two additional data attributes: iso8601: an iso8601 formatting version of the unfudged date value invalid: a boolean indicating if the form had an invalid input (distinct from valid but blank input; both would cause the date data attribute to be null) also removed a couple calls to getFormData that weren't even used also cleans up some nearby code around the "course concludes at midnight" warning, so that it displays if the conclude_at is set to midnight in the context timezone (or profile timezone if no context timezone) instead midnight in the browser timezone. test-plan: - regression tests, particularly around browser vs. profile timezone, for: * setting term start/end dates * setting course start/conclude dates * setting section start/end dates * setting unlock at on new context module * "add assignment" form from the assignment list: - preservation of due date when clicking "more options" - setting due date on form submission * editing assignment due date from calendar * editing assignment overridden due date from calendar * create a quiz, lock it, then unlock it until a specific date * changing attachment and folder lock/unlock dates - set profile timezone to differ from browser timezone. set course conclude at to midnight in profile timezone; should show "course ends at midnight" warning - set course conclude at to midnight in browser timezone; should not show "course ends at midnight" warning - set course timezone to differ from profile timezone. set course conclude at to midnight in course timezone; should show "course ends at midnight" warning - set course conclude at to midnight in profile timezone; should not show "course ends at midnight" warning Change-Id: I55179d4416eb07cdda0e94abc79d2c9f948a5387 Reviewed-on: https://gerrit.instructure.com/53188 Tested-by: Jenkins Reviewed-by: Ethan Vizitei <evizitei@instructure.com> QA-Review: Jeremy Putnam <jeremyp@instructure.com> Product-Review: Jacob Fugal <jacob@instructure.com>
2015-04-10 01:06:47 +08:00
var $lock_at = $(this).find('.datetime_field');
$unlock_for_how_long_dialog.dialog({
autoOpen: false,
modal: true,
resizable: false,
width: 400,
buttons: {
'Unlock' : function(){
$('#quiz_unlock_form')
// append this back to the form since it got moved to be a child of body when we called .dialog('open')
.append($(this).dialog('destroy'))
don't parse datetime_suggest for getFormData refs CNVS-19515 getFormData (and things that use its result, e.g. processData on formSubmit) now returns iso8601 values for datetime_fields instead of the formatted suggest string. this means they no longer need to be parsed and reformatted before submission from forms, inclusion in redirect parameters, etc. to support this, and for general use, a datetime_field now has two additional data attributes: iso8601: an iso8601 formatting version of the unfudged date value invalid: a boolean indicating if the form had an invalid input (distinct from valid but blank input; both would cause the date data attribute to be null) also removed a couple calls to getFormData that weren't even used also cleans up some nearby code around the "course concludes at midnight" warning, so that it displays if the conclude_at is set to midnight in the context timezone (or profile timezone if no context timezone) instead midnight in the browser timezone. test-plan: - regression tests, particularly around browser vs. profile timezone, for: * setting term start/end dates * setting course start/conclude dates * setting section start/end dates * setting unlock at on new context module * "add assignment" form from the assignment list: - preservation of due date when clicking "more options" - setting due date on form submission * editing assignment due date from calendar * editing assignment overridden due date from calendar * create a quiz, lock it, then unlock it until a specific date * changing attachment and folder lock/unlock dates - set profile timezone to differ from browser timezone. set course conclude at to midnight in profile timezone; should show "course ends at midnight" warning - set course conclude at to midnight in browser timezone; should not show "course ends at midnight" warning - set course timezone to differ from profile timezone. set course conclude at to midnight in course timezone; should show "course ends at midnight" warning - set course conclude at to midnight in profile timezone; should not show "course ends at midnight" warning Change-Id: I55179d4416eb07cdda0e94abc79d2c9f948a5387 Reviewed-on: https://gerrit.instructure.com/53188 Tested-by: Jenkins Reviewed-by: Ethan Vizitei <evizitei@instructure.com> QA-Review: Jeremy Putnam <jeremyp@instructure.com> Product-Review: Jacob Fugal <jacob@instructure.com>
2015-04-10 01:06:47 +08:00
.find('#quiz_lock_at').val($lock_at.data('iso8601')).end()
.submit();
}
}
don't parse datetime_suggest for getFormData refs CNVS-19515 getFormData (and things that use its result, e.g. processData on formSubmit) now returns iso8601 values for datetime_fields instead of the formatted suggest string. this means they no longer need to be parsed and reformatted before submission from forms, inclusion in redirect parameters, etc. to support this, and for general use, a datetime_field now has two additional data attributes: iso8601: an iso8601 formatting version of the unfudged date value invalid: a boolean indicating if the form had an invalid input (distinct from valid but blank input; both would cause the date data attribute to be null) also removed a couple calls to getFormData that weren't even used also cleans up some nearby code around the "course concludes at midnight" warning, so that it displays if the conclude_at is set to midnight in the context timezone (or profile timezone if no context timezone) instead midnight in the browser timezone. test-plan: - regression tests, particularly around browser vs. profile timezone, for: * setting term start/end dates * setting course start/conclude dates * setting section start/end dates * setting unlock at on new context module * "add assignment" form from the assignment list: - preservation of due date when clicking "more options" - setting due date on form submission * editing assignment due date from calendar * editing assignment overridden due date from calendar * create a quiz, lock it, then unlock it until a specific date * changing attachment and folder lock/unlock dates - set profile timezone to differ from browser timezone. set course conclude at to midnight in profile timezone; should show "course ends at midnight" warning - set course conclude at to midnight in browser timezone; should not show "course ends at midnight" warning - set course timezone to differ from profile timezone. set course conclude at to midnight in course timezone; should show "course ends at midnight" warning - set course conclude at to midnight in profile timezone; should not show "course ends at midnight" warning Change-Id: I55179d4416eb07cdda0e94abc79d2c9f948a5387 Reviewed-on: https://gerrit.instructure.com/53188 Tested-by: Jenkins Reviewed-by: Ethan Vizitei <evizitei@instructure.com> QA-Review: Jeremy Putnam <jeremyp@instructure.com> Product-Review: Jacob Fugal <jacob@instructure.com>
2015-04-10 01:06:47 +08:00
});
$lock_at.datetime_field();
});
$('#lock_this_quiz_now_link').ifExists(function($link) {
$link.click(function(e) {
e.preventDefault();
$('#quiz_lock_form').submit();
})
2011-02-01 09:57:29 +08:00
});
if ($('ul.page-action-list').find('li').length > 0) {
$('ul.page-action-list').show();
}
$('#publish_quiz_form').formSubmit({
beforeSubmit: function(data) {
$(this).find('button').attr('disabled', true).text(I18n.t('buttons.publishing', "Publishing..."));
},
success: function(data) {
$(this).find('button').text(I18n.t('buttons.already_published', "Published!"));
location.reload();
2011-02-01 09:57:29 +08:00
}
});
var $el = $('#quiz-publish-link');
var model = new Quiz($.extend(ENV.QUIZ, {unpublishable: !$el.hasClass("disabled")}));
var view = new PublishButtonView({model: model, el: $el});
quiz index page redesign for draft state fixes CNVS-5674 changes 1. implement redesign of quizzes index with publish icon 2. adds header toggler to styleguide for item groups and condensed item groups 3. refactor publish button code to fix onmouseleave event issue test plan: in styleguide 1. check that item group headers toggle open/closed on quizzes#show with :enable_draft = true 1. publish button continues to publish/unpublish and remember state 2. disabled the publish button when there are student submissions on quizzes#index :enable_draft = false 1. make sure quizzes index page functions the same as before draft state features on quizzes#index as a teacher with :enable_draft = true 1. shows 'no quizzes' message when there are no assignment or open quizzes 2. greys out unpublished quizzes 3. can publish and unpublish with the new publish icon in each row 4. disables the publish icon on the row when there are student submissions 5. editing/deleting quizzes works (and deleting prompts to confirm) 6. the 'search for quiz' widget filters the quizzes as you type on quizzes#index as a student with :enable_draft = true 1. unpublished quizzes are not visible 2. publish icon or edit/delete links are not visible Change-Id: Ida140d5e30761a520b118d0c62fb45bcf1a3a008 Reviewed-on: https://gerrit.instructure.com/22121 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Myller de Araujo <myller@instructure.com> Reviewed-by: Ryan Florence <ryanf@instructure.com> Product-Review: Derek DeVries <ddevries@instructure.com>
2013-06-27 00:28:20 +08:00
var refresh = function() {
location.href = location.href;
}
view.on("publish", refresh);
view.on("unpublish", refresh);
view.render();
var graphsRoot = document.getElementById('crs-graphs')
var detailsParent = document.getElementById('not_right_side')
CyoeStats.init(graphsRoot, detailsParent)
});
2011-02-01 09:57:29 +08:00
});