From 200e8eb02763b162fa0fba1ac48d4b337199c0b0 Mon Sep 17 00:00:00 2001 From: jorg-vr Date: Tue, 8 Aug 2023 10:39:49 +0200 Subject: [PATCH] Replace jquery html calls by new function --- app/javascript/packs/frame.js | 3 ++- app/views/activity_read_states/index.js.erb | 2 +- app/views/annotations/question_index.js.erb | 2 +- app/views/evaluations/add_users.js.erb | 2 +- app/views/evaluations/create.js.erb | 4 ++-- app/views/evaluations/edit.js.erb | 2 +- app/views/evaluations/show.js.erb | 4 ++-- app/views/events/index.js.erb | 2 +- app/views/feedbacks/edit.js.erb | 2 +- app/views/feedbacks/show.js.erb | 2 +- app/views/notifications/index.js.erb | 2 +- app/views/rights_requests/approve.js.erb | 2 +- app/views/rights_requests/reject.js.erb | 2 +- app/views/score_items/add_all.js.erb | 2 +- app/views/score_items/index.js.erb | 6 +++--- 15 files changed, 20 insertions(+), 19 deletions(-) diff --git a/app/javascript/packs/frame.js b/app/javascript/packs/frame.js index d6530d30be..be0081768e 100644 --- a/app/javascript/packs/frame.js +++ b/app/javascript/packs/frame.js @@ -13,7 +13,7 @@ import { Alert, Button, Collapse, Dropdown, Modal, Popover, Tab, Tooltip } from const bootstrap = { Alert, Button, Collapse, Dropdown, Modal, Popover, Tab, Tooltip }; window.bootstrap = bootstrap; -import { initTooltips, ready } from "utilities.ts"; +import { initTooltips, ready, setHTMLExecuteScripts } from "utilities.ts"; import { initClipboard } from "copy"; import { themeState } from "state/Theme"; @@ -22,6 +22,7 @@ const dodona = window.dodona || {}; dodona.initTooltips = initTooltips; dodona.ready = ready; dodona.setTheme = theme => themeState.selectedTheme = theme; +dodona.setHTMLExecuteScripts = setHTMLExecuteScripts; window.dodona = dodona; // Initialize clipboard.js diff --git a/app/views/activity_read_states/index.js.erb b/app/views/activity_read_states/index.js.erb index c2383e4edc..d6b1fe6d75 100644 --- a/app/views/activity_read_states/index.js.erb +++ b/app/views/activity_read_states/index.js.erb @@ -1 +1 @@ -$("#read-states-table-wrapper").html("<%= escape_javascript(render partial: 'read_states_table', locals: {read_states: @read_states, activity: @activity, course: @course, user: @user}) %>"); +dodona.setHTMLExecuteScripts(document.querySelector("#read-states-table-wrapper"), "<%= escape_javascript(render partial: 'read_states_table', locals: {read_states: @read_states, activity: @activity, course: @course, user: @user}) %>"); diff --git a/app/views/annotations/question_index.js.erb b/app/views/annotations/question_index.js.erb index ea3fa12498..942e429281 100644 --- a/app/views/annotations/question_index.js.erb +++ b/app/views/annotations/question_index.js.erb @@ -1 +1 @@ -$("#questions-table-wrapper").html("<%= escape_javascript(render partial: 'questions_table_with_pagination', locals: {questions: @questions}) %>"); +dodona.setHTMLExecuteScripts(document.querySelector("#questions-table-wrapper"), "<%= escape_javascript(render partial: 'questions_table_with_pagination', locals: {questions: @questions}) %>"); diff --git a/app/views/evaluations/add_users.js.erb b/app/views/evaluations/add_users.js.erb index 4e9c172610..13bd30fb6a 100644 --- a/app/views/evaluations/add_users.js.erb +++ b/app/views/evaluations/add_users.js.erb @@ -1,3 +1,3 @@ -$("#users-table-wrapper").html("<%= escape_javascript(render partial: 'members_table', locals: {course_memberships: @course_memberships, confirm: false}) %>") +dodona.setHTMLExecuteScripts(document.querySelector("#users-table-wrapper"), "<%= escape_javascript(render partial: 'members_table', locals: {course_memberships: @course_memberships, confirm: false}) %>") window.dodona.initTooltips(); window.dodona.initCheckboxes(); diff --git a/app/views/evaluations/create.js.erb b/app/views/evaluations/create.js.erb index d84f2b5013..07036938c5 100644 --- a/app/views/evaluations/create.js.erb +++ b/app/views/evaluations/create.js.erb @@ -1,6 +1,6 @@ $("#info-panel .answer").text("<%= l @evaluation.deadline, format: :long %>"); -$("#users-step-wrapper").html("<%= raw escape_javascript(render partial: 'add_users') %>"); +dodona.setHTMLExecuteScripts(document.querySelector("#users-step-wrapper"), "<%= raw escape_javascript(render partial: 'add_users') %>"); window.dodona.initTooltips(); window.dodona.toUsersStep(); window.dodona.setEvaluationUrl("<%= evaluation_url(@evaluation) %>"); -$("#items-step").html("<%= raw escape_javascript(render partial: 'score_items') %>"); +dodona.setHTMLExecuteScripts(document.querySelector("#items-step"), "<%= raw escape_javascript(render partial: 'score_items') %>"); diff --git a/app/views/evaluations/edit.js.erb b/app/views/evaluations/edit.js.erb index 3f0ee9d861..37ca3232aa 100644 --- a/app/views/evaluations/edit.js.erb +++ b/app/views/evaluations/edit.js.erb @@ -1,3 +1,3 @@ -$("#users-table-wrapper").html("<%= escape_javascript(render partial: 'members_table', locals: {course_memberships: @course_memberships, confirm: @should_confirm}) %>") +dodona.setHTMLExecuteScripts(document.querySelector("#users-table-wrapper"), "<%= escape_javascript(render partial: 'members_table', locals: {course_memberships: @course_memberships, confirm: @should_confirm}) %>") window.dodona.initTooltips(); window.dodona.initCheckboxes(); diff --git a/app/views/evaluations/show.js.erb b/app/views/evaluations/show.js.erb index 8747eddc02..3be8b2a260 100644 --- a/app/views/evaluations/show.js.erb +++ b/app/views/evaluations/show.js.erb @@ -1,2 +1,2 @@ -$("#evaluation-table-wrapper").html("<%= escape_javascript(render 'evaluation_table', feedbacks: @feedbacks, evaluation: @evaluation, users: @users) %>") -$("#evaluation-grade-table-wrapper").html("<%= escape_javascript(render 'evaluation_grade_table', feedbacks: @feedbacks, evaluation: @evaluation, users: @users) %>") +dodona.setHTMLExecuteScripts(document.querySelector("#evaluation-table-wrapper"), "<%= escape_javascript(render 'evaluation_table', feedbacks: @feedbacks, evaluation: @evaluation, users: @users) %>") +dodona.setHTMLExecuteScripts(document.querySelector("#evaluation-grade-table-wrapper"), "<%= escape_javascript(render 'evaluation_grade_table', feedbacks: @feedbacks, evaluation: @evaluation, users: @users) %>") diff --git a/app/views/events/index.js.erb b/app/views/events/index.js.erb index 50c4674839..ed6ead185b 100644 --- a/app/views/events/index.js.erb +++ b/app/views/events/index.js.erb @@ -1 +1 @@ -$("#events-table-wrapper").html("<%= escape_javascript(render partial: 'events/events_table', locals: {events: @events}) %>") +dodona.setHTMLExecuteScripts(document.querySelector("#events-table-wrapper"), "<%= escape_javascript(render partial: 'events/events_table', locals: {events: @events}) %>") diff --git a/app/views/feedbacks/edit.js.erb b/app/views/feedbacks/edit.js.erb index 9cda3aa7ac..15460db2c0 100644 --- a/app/views/feedbacks/edit.js.erb +++ b/app/views/feedbacks/edit.js.erb @@ -1 +1 @@ -$("#submissions-table-wrapper").html("<%= escape_javascript(render partial: 'submissions_table', locals: { submissions: @submissions }) %>") +dodona.setHTMLExecuteScripts(document.querySelector("#submissions-table-wrapper"), "<%= escape_javascript(render partial: 'submissions_table', locals: { submissions: @submissions }) %>") diff --git a/app/views/feedbacks/show.js.erb b/app/views/feedbacks/show.js.erb index caa266874a..ebd8b9cda7 100644 --- a/app/views/feedbacks/show.js.erb +++ b/app/views/feedbacks/show.js.erb @@ -1 +1 @@ -$("#feedback-actions-holder").html("<%= escape_javascript(render partial: "feedbacks/feedback_actions") %>"); +dodona.setHTMLExecuteScripts(document.querySelector("#feedback-actions-holder"), "<%= escape_javascript(render partial: "feedbacks/feedback_actions") %>"); diff --git a/app/views/notifications/index.js.erb b/app/views/notifications/index.js.erb index 03f5ea2eae..ff9e956076 100644 --- a/app/views/notifications/index.js.erb +++ b/app/views/notifications/index.js.erb @@ -1,4 +1,4 @@ -$(".notification-dropdown").html("<%= escape_javascript render(partial: 'notifications/small_notifications_table', locals: { notifications: @notifications }) %>"); +dodona.setHTMLExecuteScripts(document.querySelector(".notification-dropdown"), "<%= escape_javascript render(partial: 'notifications/small_notifications_table', locals: { notifications: @notifications }) %>"); <% if @notifications.any? %> document.getElementById("navbar-notifications").classList.remove("hidden"); <% end %> diff --git a/app/views/rights_requests/approve.js.erb b/app/views/rights_requests/approve.js.erb index 1bca659b89..ae432c51a0 100644 --- a/app/views/rights_requests/approve.js.erb +++ b/app/views/rights_requests/approve.js.erb @@ -1 +1 @@ -$("#requests-table-wrapper").html("<%= escape_javascript(render partial: 'requests_table', locals: { requests: @requests }) %>"); +dodona.setHTMLExecuteScripts(document.querySelector("#requests-table-wrapper"), "<%= escape_javascript(render partial: 'requests_table', locals: { requests: @requests }) %>"); diff --git a/app/views/rights_requests/reject.js.erb b/app/views/rights_requests/reject.js.erb index 1bca659b89..ae432c51a0 100644 --- a/app/views/rights_requests/reject.js.erb +++ b/app/views/rights_requests/reject.js.erb @@ -1 +1 @@ -$("#requests-table-wrapper").html("<%= escape_javascript(render partial: 'requests_table', locals: { requests: @requests }) %>"); +dodona.setHTMLExecuteScripts(document.querySelector("#requests-table-wrapper"), "<%= escape_javascript(render partial: 'requests_table', locals: { requests: @requests }) %>"); diff --git a/app/views/score_items/add_all.js.erb b/app/views/score_items/add_all.js.erb index 6dbcb56d10..1435d1e615 100644 --- a/app/views/score_items/add_all.js.erb +++ b/app/views/score_items/add_all.js.erb @@ -1,2 +1,2 @@ $("#add-score-item-to-all").modal("hide"); -$("#items-step").html("<%= raw escape_javascript(render partial: 'evaluations/score_items') %>"); +dodona.setHTMLExecuteScripts(document.querySelector("#items-step"), "<%= raw escape_javascript(render partial: 'evaluations/score_items') %>"); diff --git a/app/views/score_items/index.js.erb b/app/views/score_items/index.js.erb index c0aa15595d..2cb78c2568 100644 --- a/app/views/score_items/index.js.erb +++ b/app/views/score_items/index.js.erb @@ -2,9 +2,9 @@ modal = $(".modal-<%= evaluation_exercise.id %>"); if (modal.is(":visible")) { modal.on("hidden.bs.modal", () => { - $("#card-<%= evaluation_exercise.id %>").html("<%= escape_javascript(render 'score_items/exercise', evaluation_exercise: evaluation_exercise, new: new) %>"); + dodona.setHTMLExecuteScripts(document.querySelector("#card-<%= evaluation_exercise.id %>"), "<%= escape_javascript(render 'score_items/exercise', evaluation_exercise: evaluation_exercise, new: new) %>"); }).modal("hide"); } else { - $("#card-<%= evaluation_exercise.id %>").html("<%= escape_javascript(render 'score_items/exercise', evaluation_exercise: evaluation_exercise, new: new) %>"); + dodona.setHTMLExecuteScripts(document.querySelector("#card-<%= evaluation_exercise.id %>"), "<%= escape_javascript(render 'score_items/exercise', evaluation_exercise: evaluation_exercise, new: new) %>"); } -$(".summary-text").html("<%= t('score_items.new.summary_html', count: @evaluation.score_items.count, score: format_score(@evaluation.maximum_score)) %>"); \ No newline at end of file +dodona.setHTMLExecuteScripts(document.querySelector(".summary-text"), "<%= t('score_items.new.summary_html', count: @evaluation.score_items.count, score: format_score(@evaluation.maximum_score)) %>");