loadBanks.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (C) 2016 - present Instructure, Inc.
  3. *
  4. * This file is part of Canvas.
  5. *
  6. * Canvas is free software: you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License as published by the Free
  8. * Software Foundation, version 3 of the License.
  9. *
  10. * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
  11. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. * details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. import I18n from 'i18n!load_bank'
  19. import $ from 'jquery'
  20. import addBank from 'jsx/quizzes/question_bank/addBank'
  21. import 'jquery.ajaxJSON' /* ajaxJSON */
  22. import 'jquery.instructure_forms' /* formSubmit, getFormData, formErrors */
  23. import 'jqueryui/dialog'
  24. import 'jquery.instructure_misc_helpers' /* replaceTags */
  25. import 'jquery.instructure_misc_plugins' /* confirmDelete, showIf, .dim */
  26. import 'jquery.keycodes' /* keycodes */
  27. import 'jquery.loadingImg' /* loadingImage */
  28. import 'jquery.templateData' /* fillTemplateData, getTemplateData */
  29. export default function loadBanks () {
  30. var url = $("#bank_urls .managed_banks_url").attr('href');
  31. var $dialog = $("#move_question_dialog");
  32. $dialog.find("li.message").text(I18n.t('loading_banks', "Loading banks..."));
  33. $.ajaxJSON(url, 'GET', {}, function(data) {
  34. for(var idx = 0; idx < data.length; idx++) {
  35. addBank(data[idx].assessment_question_bank);
  36. }
  37. $dialog.addClass('loaded');
  38. $dialog.find("li.bank.blank").show();
  39. $dialog.find("li.message").hide();
  40. }, function(data) {
  41. $dialog.find("li.message").text(I18n.t("error_loading_banks", "Error loading banks"));
  42. });
  43. }