diff --git a/cps/admin.py b/cps/admin.py index 386e2125..78cfebf1 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -440,6 +440,14 @@ def load_dialogtexts(element_id): texts["main"] = _('Do you really want to delete this user?') elif element_id == "delete_shelf": texts["main"] = _('Are you sure you want to delete this shelf?') + elif element_id == "select_locale": + texts["main"] = _('Are you sure you want to change locales of selected user(s)?') + elif element_id == "select_default_language": + texts["main"] = _('Are you sure you want to change visible book languages for selected user(s)?') + elif element_id == "role": + texts["main"] = _('Are you sure you want to change the selected role for the selected user(s)?') + elif element_id == "sidebar_view": + texts["main"] = _('Are you sure you want to change the selected visibility restrictions for the selected user(s)?') return json.dumps(texts) diff --git a/cps/static/js/main.js b/cps/static/js/main.js index 6f7e7b56..834b9b30 100644 --- a/cps/static/js/main.js +++ b/cps/static/js/main.js @@ -114,26 +114,23 @@ $(document).ready(function() { } }); -function confirmDialog(id, dataValue, yesFn, noFn) { - var $confirm = $("#GeneralDeleteModal"); - // var dataValue= e.data('value'); // target.data('value'); +function confirmDialog(id, dialogid, dataValue, yesFn, noFn) { + var $confirm = $("#" + dialogid); $confirm.modal('show'); $.ajax({ method:"get", dataType: "json", url: getPath() + "/ajax/loaddialogtexts/" + id, success: function success(data) { - $("#header").html(data.header); - $("#text").html(data.main); + $("#header-"+ dialogid).html(data.header); + $("#text-"+ dialogid).html(data.main); } }); - - - $("#btnConfirmYes").off('click').click(function () { + $("#btnConfirmYes-"+ dialogid).off('click').click(function () { yesFn(dataValue); $confirm.modal("hide"); }); - $("#btnConfirmNo").off('click').click(function () { + $("#btnConfirmNo-"+ dialogid).off('click').click(function () { if (typeof noFn !== 'undefined') { noFn(dataValue); } @@ -483,6 +480,7 @@ $(function() { $("#config_delete_kobo_token").click(function() { confirmDialog( $(this).attr('id'), + "GeneralDeleteModal", $(this).data('value'), function (value) { $.ajax({ @@ -511,6 +509,7 @@ $(function() { $("#btndeluser").click(function() { confirmDialog( $(this).attr('id'), + "GeneralDeleteModal", $(this).data('value'), function(value){ var subform = $('#user_submit').closest("form"); @@ -529,6 +528,7 @@ $(function() { $("#delete_shelf").click(function() { confirmDialog( $(this).attr('id'), + "GeneralDeleteModal", $(this).data('value'), function(value){ window.location.href = window.location.pathname + "/../../shelf/delete/" + value diff --git a/cps/static/js/table.js b/cps/static/js/table.js index 31eff2f0..1512c5f9 100644 --- a/cps/static/js/table.js +++ b/cps/static/js/table.js @@ -237,12 +237,12 @@ $(function() { } $("#domain-allow-table").on("click-cell.bs.table", function (field, value, row, $element) { if (value === 2) { - confirmDialog("btndeletedomain", $element.id, domainHandle); + confirmDialog("btndeletedomain", "GeneralDeleteModal", $element.id, domainHandle); } }); $("#domain-deny-table").on("click-cell.bs.table", function (field, value, row, $element) { if (value === 2) { - confirmDialog("btndeletedomain", $element.id, domainHandle); + confirmDialog("btndeletedomain", "GeneralDeleteModal", $element.id, domainHandle); } }); @@ -508,7 +508,7 @@ $(function() { $("#user-table").on("click-cell.bs.table", function (field, value, row, $element) { if (value === "denied_column_value") { - ConfirmDialog("btndeluser", $element.id, user_handle); + ConfirmDialog("btndeluser", "GeneralDeleteModal", $element.id, user_handle); } }); @@ -621,62 +621,69 @@ function checkboxChange(checkbox, userId, field, field_index) { } }); } +function deactivateHeaderButtons(e) { + $("#user_delete_selection").addClass("disabled"); + $("#user_delete_selection").attr("aria-disabled", true); + $(".check_head").attr("aria-disabled", true); + $(".check_head").attr("disabled", true); + $(".check_head").prop('checked', false); + $(".button_head").attr("aria-disabled", true); + $(".button_head").addClass("disabled"); + $(".header_select").attr("disabled", true); +} function selectHeader(element, field) { - var result = $('#user-table').bootstrapTable('getSelections').map(a => a.id); - $.ajax({ - method:"post", - url: window.location.pathname + "/../../ajax/editlistusers/" + field, - data: {"pk":result, "value": element.value}, - success:function() { + if (element.value !== "None") { + confirmDialog(element.id, "GeneralChangeModal", 0, function () { + var result = $('#user-table').bootstrapTable('getSelections').map(a => a.id); $.ajax({ - method:"get", - url: window.location.pathname + "/../../ajax/listusers", - async: true, - timeout: 900, - success:function(data) { - $("#user-table").bootstrapTable("load", data); - $("#user_delete_selection").addClass("disabled"); - $("#user_delete_selection").attr("aria-disabled", true); - $(".check_head").attr("aria-disabled", true); - $(".check_head").attr("disabled", true); - $(".check_head").prop('checked', false); - $(".button_head").attr("aria-disabled", true); - $(".button_head").addClass("disabled"); - $(".header_select").attr("disabled", true); + method: "post", + url: window.location.pathname + "/../../ajax/editlistusers/" + field, + data: {"pk": result, "value": element.value}, + success: function () { + $.ajax({ + method: "get", + url: window.location.pathname + "/../../ajax/listusers", + async: true, + timeout: 900, + success: function (data) { + $("#user-table").bootstrapTable("load", data); + deactivateHeaderButtons(); + } + }); } }); - } - }); - - console.log("test"); + }); + } } function checkboxHeader(CheckboxState, field, field_index) { - var result = $('#user-table').bootstrapTable('getSelections').map(a => a.id); - $.ajax({ - method:"post", - url: window.location.pathname + "/../../ajax/editlistusers/" + field, - data: {"pk":result, "field_index":field_index, "value": CheckboxState}, - success:function() { - $.ajax({ - method:"get", - url: window.location.pathname + "/../../ajax/listusers", - async: true, - timeout: 900, - success:function(data) { - $("#user-table").bootstrapTable("load", data); - $("#user_delete_selection").addClass("disabled"); - $("#user_delete_selection").attr("aria-disabled", true); - $(".check_head").attr("aria-disabled", true); - $(".check_head").attr("disabled", true); - $(".check_head").prop('checked', false); - $(".button_head").attr("aria-disabled", true); - $(".button_head").addClass("disabled"); - $(".header_select").attr("disabled", true); - } - }); - } + confirmDialog(field, "GeneralChangeModal", 0, function() { + var result = $('#user-table').bootstrapTable('getSelections').map(a => a.id); + $.ajax({ + method: "post", + url: window.location.pathname + "/../../ajax/editlistusers/" + field, + data: {"pk": result, "field_index": field_index, "value": CheckboxState}, + success: function () { + $.ajax({ + method: "get", + url: window.location.pathname + "/../../ajax/listusers", + async: true, + timeout: 900, + success: function (data) { + $("#user-table").bootstrapTable("load", data); + $("#user_delete_selection").addClass("disabled"); + $("#user_delete_selection").attr("aria-disabled", true); + $(".check_head").attr("aria-disabled", true); + $(".check_head").attr("disabled", true); + $(".check_head").prop('checked', false); + $(".button_head").attr("aria-disabled", true); + $(".button_head").addClass("disabled"); + $(".header_select").attr("disabled", true); + } + }); + } + }); }); } diff --git a/cps/templates/layout.html b/cps/templates/layout.html index 643459cd..318140fa 100644 --- a/cps/templates/layout.html +++ b/cps/templates/layout.html @@ -1,4 +1,4 @@ -{% from 'modal_dialogs.html' import restrict_modal, delete_book, filechooser_modal, delete_confirm_modal %} +{% from 'modal_dialogs.html' import restrict_modal, delete_book, filechooser_modal, delete_confirm_modal, change_confirm_modal %} diff --git a/cps/templates/modal_dialogs.html b/cps/templates/modal_dialogs.html index 94e76811..e134236e 100644 --- a/cps/templates/modal_dialogs.html +++ b/cps/templates/modal_dialogs.html @@ -108,13 +108,31 @@ + +{% endmacro %} + +{% macro change_confirm_modal() %} +