diff --git a/cps/static/js/table.js b/cps/static/js/table.js index caf98980..31eff2f0 100644 --- a/cps/static/js/table.js +++ b/cps/static/js/table.js @@ -246,7 +246,7 @@ $(function() { } }); - $("#restrictModal").on("hidden.bs.modal", function () { + $("#restrictModal").on("hidden.bs.modal", function (e) { // Destroy table and remove hooks for buttons $("#restrict-elements-table").unbind(); $("#restrict-elements-table").bootstrapTable("destroy"); @@ -255,8 +255,54 @@ $(function() { $("#h2").addClass("hidden"); $("#h3").addClass("hidden"); $("#h4").addClass("hidden"); + $("#add_element").val(""); }); - function startTable(type, userId) { + + function startTable(target, userId) { + var type = 0; + switch(target) { + case "get_column_values": + type = 1; + $("#h2").removeClass("hidden"); + break; + case "get_tags": + type = 0; + $("#h1").removeClass("hidden"); + break; + case "get_user_column_values": + type = 3; + $("#h4").removeClass("hidden"); + break; + case "get_user_tags": + type = 2; + $("#h3").removeClass("hidden"); + break; + case "denied_tags": + type = 2; + $("#h2").removeClass("hidden"); + $("#submit_allow").addClass("hidden"); + $("#submit_restrict").removeClass("hidden"); + break; + case "allowed_tags": + type = 2; + $("#h2").removeClass("hidden"); + $("#submit_restrict").addClass("hidden"); + $("#submit_allow").removeClass("hidden"); + break; + case "allowed_column_value": + type = 3; + $("#h2").removeClass("hidden"); + $("#submit_restrict").addClass("hidden"); + $("#submit_allow").removeClass("hidden"); + break; + case "denied_column_value": + type = 3; + $("#h2").removeClass("hidden"); + $("#submit_allow").addClass("hidden"); + $("#submit_restrict").removeClass("hidden"); + break; + } + $("#restrict-elements-table").bootstrapTable({ formatNoMatches: function () { return ""; @@ -270,6 +316,10 @@ $(function() { return {classes: "bg-dark-danger"}; } }, + onLoadSuccess: function () { + $(".no-records-found").addClass("hidden"); + $(".fixed-table-loading").addClass("hidden"); + }, onClickCell: function (field, value, row) { if (field === 3) { $.ajax ({ @@ -323,24 +373,18 @@ $(function() { return; }); } - $("#get_column_values").on("click", function() { - startTable(1, 0); - $("#h2").removeClass("hidden"); - }); - $("#get_tags").on("click", function() { - startTable(0, 0); - $("#h1").removeClass("hidden"); - }); - $("#get_user_column_values").on("click", function() { - startTable(3, $(this).data("id")); - $("#h4").removeClass("hidden"); - }); - - $("#get_user_tags").on("click", function() { - startTable(2, $(this).data("id")); - $(this)[0].blur(); - $("#h3").removeClass("hidden"); + $("#restrictModal").on("show.bs.modal", function(e) { + var target = $(e.relatedTarget).attr('id'); + var dataId; + $(e.relatedTarget).one('focus', function(e){$(this).blur();}); + //$(e.relatedTarget).blur(); + if ($(e.relatedTarget).hasClass("button_head")) { + dataId = $('#user-table').bootstrapTable('getSelections').map(a => a.id); + } else { + dataId = $(e.relatedTarget).data("id"); + } + startTable(target, dataId); }); // User table handling @@ -487,17 +531,23 @@ $(function() { $(".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); } else { $("#user_delete_selection").removeClass("disabled"); $("#user_delete_selection").attr("aria-disabled", false); $(".check_head").attr("aria-disabled", false); $(".check_head").removeAttr("disabled"); - + $(".button_head").attr("aria-disabled", false); + $(".button_head").removeClass("disabled"); + $(".header_select").removeAttr("disabled"); } }); }); + /* Function for deleting domain restrictions */ function TableActions (value, row) { return [ @@ -572,6 +622,36 @@ function checkboxChange(checkbox, userId, field, field_index) { }); } +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() { + $.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); + } + }); + } + }); + + console.log("test"); +} + function checkboxHeader(CheckboxState, field, field_index) { var result = $('#user-table').bootstrapTable('getSelections').map(a => a.id); $.ajax({ @@ -591,6 +671,9 @@ function checkboxHeader(CheckboxState, field, field_index) { $(".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/config_view_edit.html b/cps/templates/config_view_edit.html index d87e9f81..e0a8094c 100644 --- a/cps/templates/config_view_edit.html +++ b/cps/templates/config_view_edit.html @@ -141,8 +141,8 @@ - {{_('Add Allowed/Denied Tags')}} - {{_('Add Allowed/Denied custom column values')}} + {{_('Add Allowed/Denied Tags')}} + {{_('Add Allowed/Denied custom column values')}} diff --git a/cps/templates/modal_dialogs.html b/cps/templates/modal_dialogs.html index da00834c..94e76811 100644 --- a/cps/templates/modal_dialogs.html +++ b/cps/templates/modal_dialogs.html @@ -22,7 +22,7 @@
- +
diff --git a/cps/templates/user_table.html b/cps/templates/user_table.html index bc6fac65..2e883956 100644 --- a/cps/templates/user_table.html +++ b/cps/templates/user_table.html @@ -1,5 +1,5 @@ {% extends "layout.html" %} -{% macro user_table_row(parameter, edit_text, show_text, validate, button=False) -%} +{% macro user_table_row(parameter, edit_text, show_text, validate, button=False, id=0) -%} {% if button %} -
{{edit_text}}

+
{{edit_text}}

{% endif %} {{ show_text }} @@ -47,7 +47,7 @@ data-editable-source={{url}} {% if validate %}data-edit-validate="{{ _('This Field is Required') }}"{% endif %}>
- {% for language in languages %} @@ -69,7 +69,7 @@ data-editable-source={{url}} {% if validate %}data-edit-validate="{{ _('This Field is Required') }}"{% endif %}>
- {% for translation in translations %} @@ -104,10 +104,10 @@ {{ user_table_row('kindle_mail', _('Enter Kindle E-mail Address'), _('Kindle E-mail'), true) }} {{ user_select_translations('locale', url_for('admin.table_get_locale'), _('Locale'), true) }} {{ user_select_languages('default_language', url_for('admin.table_get_default_lang'), _('Visible Book Languages'), true) }} - {{ user_table_row('denied_tags', _("Edit Denied Tags"), _("Denied Tags"), true, true) }} - {{ user_table_row('allowed_tags', _("Edit Allowed Tags"), _("Allowed Tags"), true, true) }} - {{ user_table_row('allowed_column_value', _("Edit Allowed Column Values"), _("Allowed Column Values"), true, true) }} - {{ user_table_row('denied_column_value', _("Edit Denied Column Values"), _("Denied Columns Values"), true, true) }} + {{ user_table_row('denied_tags', _("Edit Denied Tags"), _("Denied Tags"), false, true, 0) }} + {{ user_table_row('allowed_tags', _("Edit Allowed Tags"), _("Allowed Tags"), false, true, 1) }} + {{ user_table_row('allowed_column_value', _("Edit Allowed Column Values"), _("Allowed Column Values"), false, true, 2) }} + {{ user_table_row('denied_column_value', _("Edit Denied Column Values"), _("Denied Columns Values"), false, true, 3) }} {{ user_checkbox_row("role", "admin_role", _('Admin'), visiblility, all_roles)}} {{ user_checkbox_row("role", "download_role",_('Upload'), visiblility, all_roles)}} {{ user_checkbox_row("role", "upload_role", _('Download'), visiblility, all_roles)}} @@ -130,13 +130,14 @@ {{ user_checkbox_row("sidebar_view", "sidebar_archived", _('Show archived books'), visiblility, sidebar_settings)}} {{ user_checkbox_row("sidebar_view", "sidebar_download", _('Show Downloaded Books'), visiblility, sidebar_settings)}} {{ user_checkbox_row("sidebar_view", "sidebar_list", _('Show Books List'), visiblility, sidebar_settings)}} -
{{_('Delete User')}}

{{_('Delete User')}} +
{{_('Delete User')}}

{{_('Delete User')}} {% endblock %} {% block modal %} {{ delete_confirm_modal() }} +{{ restrict_modal() }} {% endblock %} {% block js %}