2017-04-28 12:24:56 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 - present Instructure, Inc.
|
2011-02-01 09:57:29 +08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2017-04-28 12:24:56 +08:00
|
|
|
* 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/>.
|
2011-02-01 09:57:29 +08:00
|
|
|
*/
|
2011-11-11 00:31:45 +08:00
|
|
|
|
2017-03-23 00:15:02 +08:00
|
|
|
import I18n from 'i18n!question_banks'
|
|
|
|
import $ from 'jquery'
|
2017-05-24 23:19:24 +08:00
|
|
|
import './jquery.ajaxJSON'
|
|
|
|
import './jquery.instructure_date_and_time' /* datetimeString */
|
|
|
|
import './jquery.instructure_forms' /* formSubmit, fillFormData, formErrors */
|
|
|
|
import './jquery.instructure_misc_plugins' /* confirmDelete */
|
|
|
|
import './jquery.keycodes'
|
|
|
|
import './jquery.loadingImg'
|
|
|
|
import './jquery.templateData'
|
2011-11-11 00:31:45 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
$(document).ready(function() {
|
|
|
|
$(".add_bank_link").click(function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
var $bank = $("#question_bank_blank").clone(true).attr('id', 'question_bank_new');
|
|
|
|
$("#questions").prepend($bank.show());
|
|
|
|
$bank.find(".edit_bank_link").click();
|
|
|
|
});
|
|
|
|
$(".question_bank .delete_bank_link").click(function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
$(this).parents(".question_bank").confirmDelete({
|
|
|
|
url: $(this).attr('href'),
|
2011-06-29 00:07:25 +08:00
|
|
|
message: I18n.t("delete_question_bank_prompt", "Are you sure you want to delete this bank of questions?"),
|
2011-02-01 09:57:29 +08:00
|
|
|
success: function() {
|
|
|
|
$(this).slideUp(function() {
|
|
|
|
$(this).remove();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$(".question_bank .bookmark_bank_link").click(function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
var $link = $(this);
|
|
|
|
var $bank = $link.parents(".question_bank");
|
|
|
|
$.ajaxJSON($(this).attr('href'), 'POST', {}, function(data) {
|
|
|
|
$bank.find(".bookmark_bank_link").toggle();
|
2016-01-16 06:38:28 +08:00
|
|
|
$bank.find(".bookmark_bank_link:visible:first").focus();
|
2011-02-01 09:57:29 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
$(".question_bank .edit_bank_link").click(function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
var $bank = $(this).parents(".question_bank");
|
|
|
|
var data = $bank.getTemplateData({textValues: ['title']});
|
|
|
|
$bank.find(".header_content").hide();
|
|
|
|
var $form = $("#edit_bank_form");
|
|
|
|
$bank.find(".header").prepend($form.show());
|
|
|
|
$form.attr('action', $(this).attr('href'));
|
|
|
|
$form.attr('method', 'PUT');
|
|
|
|
if($bank.attr('id') == 'question_bank_new') {
|
|
|
|
$form.attr('action', $("#bank_urls .add_bank_url").attr('href'));
|
|
|
|
$form.attr('method', 'POST');
|
|
|
|
}
|
|
|
|
$form.fillFormData(data, {object_name: 'assessment_question_bank'});
|
|
|
|
$form.find(":text:visible:first").focus().select();
|
|
|
|
});
|
2016-01-16 05:05:21 +08:00
|
|
|
$("#edit_bank_form .bank_name_box").keycodes('return esc tab', function(event) {
|
2011-02-01 09:57:29 +08:00
|
|
|
if(event.keyString == 'esc') {
|
|
|
|
$(this).parents(".question_bank").addClass('dont_save')
|
|
|
|
$(this).blur();
|
|
|
|
} else if(event.keyString == 'return') {
|
|
|
|
$("#edit_bank_form").submit();
|
2016-01-16 05:05:21 +08:00
|
|
|
} else if(event.keyString == 'tab') {
|
|
|
|
$('nav#breadcrumbs a:visible:first').focus()
|
|
|
|
event.preventDefault();
|
2011-02-01 09:57:29 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
$("#edit_bank_form .bank_name_box").blur(function() {
|
|
|
|
var $bank = $(this).parents(".question_bank");
|
2011-04-07 09:23:31 +08:00
|
|
|
if(!$bank.hasClass('dont_save') && !$bank.hasClass('save_in_progress') && $bank.attr('id') != 'question_bank_new') {
|
2011-02-01 09:57:29 +08:00
|
|
|
$("#edit_bank_form").submit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$bank.removeClass('dont_save');
|
|
|
|
$bank.find(".header_content").show();
|
|
|
|
$("body").append($("#edit_bank_form").hide());
|
|
|
|
if($bank.attr('id') == 'question_bank_new') {
|
|
|
|
$bank.remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$("#edit_bank_form").formSubmit({
|
|
|
|
object_name: 'assessment_question_bank',
|
|
|
|
beforeSubmit: function(data) {
|
|
|
|
var $bank = $(this).parents(".question_bank");
|
|
|
|
$bank.attr('id', 'question_bank_adding');
|
|
|
|
try {
|
2011-04-07 09:23:31 +08:00
|
|
|
$bank.addClass('save_in_progress')
|
2011-02-01 09:57:29 +08:00
|
|
|
$bank.find(".bank_name_box").blur();
|
|
|
|
} catch(e) { }
|
|
|
|
$bank.fillTemplateData({
|
|
|
|
data: data
|
|
|
|
});
|
|
|
|
$bank.loadingImage();
|
|
|
|
return $bank;
|
|
|
|
},
|
|
|
|
success: function(data, $bank) {
|
|
|
|
$bank.loadingImage('remove');
|
2011-04-07 09:23:31 +08:00
|
|
|
$bank.removeClass('save_in_progress')
|
2011-02-01 09:57:29 +08:00
|
|
|
var bank = data.assessment_question_bank;
|
2013-09-26 13:26:16 +08:00
|
|
|
bank.last_updated_at = $.datetimeString(bank.updated_at);
|
2011-02-01 09:57:29 +08:00
|
|
|
$bank.fillTemplateData({
|
|
|
|
data: bank,
|
|
|
|
hrefValues: ['id']
|
|
|
|
})
|
2017-03-23 03:40:53 +08:00
|
|
|
// if you can convince fillTemplateData to do this, please be my guest
|
|
|
|
$bank.find('.links a').each(function(_, link) {
|
|
|
|
link.setAttribute('title', link.getAttribute('title').replace('{{ title }}', bank.title));
|
|
|
|
});
|
|
|
|
$bank.find('.links a span').each(function(_, span) {
|
|
|
|
span.textContent = span.textContent.replace('{{ title }}', bank.title);
|
|
|
|
});
|
2016-01-16 05:05:21 +08:00
|
|
|
$bank.find('a.title')[0].focus()
|
2011-02-01 09:57:29 +08:00
|
|
|
},
|
|
|
|
error: function(data, $bank) {
|
|
|
|
$bank.loadingImage('remove');
|
2011-04-07 09:23:31 +08:00
|
|
|
$bank.removeClass('save_in_progress')
|
2011-02-01 09:57:29 +08:00
|
|
|
$bank.find(".edit_bank_link").click();
|
|
|
|
$("#edit_bank_form").formErrors(data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|