From a392f5904adec7beae5e3f025f86e120b0466391 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 21 Jun 2017 16:24:57 +0200 Subject: [PATCH] Bug 18834: Add js to dynamically alter the permission options If we we move from Private to Public or vice versa, this actually has an impact on the permissions combo. If we go back to a private list without shares, we could remove Anyone. If we switch to public and the list had no shares, we could add Anyone. Handled in a js sub AdjustPerms, triggered by onchange of the category combo. Test plan: [1] Edit a private list without shares in OPAC. Toggle category. Check if the permissions combo changes accordingly. [2] Edit a public list in staff. Toggle category and check. Signed-off-by: Marcel de Rooy Signed-off-by: Lee Jamison --- .../prog/en/modules/virtualshelves/shelves.tt | 22 +++++++++++++++++++++- .../opac-tmpl/bootstrap/en/modules/opac-shelves.tt | 22 +++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt index 179a6da..612449b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt @@ -306,6 +306,26 @@ function placeHold () { return false; } } + +function AdjustPerms() { + var category = $("#category").val(); + var count_perms = $("#allow_changes_from option").length; + + // If we move to Private, remove Anyone if we did not have shares + // Note: the number of shares is not tested real-time (just template var) + if( category == 1 ) { + [% IF !shelf.is_shared %] + $("#allow_changes_from option[value='2']").remove(); + [% END %] + } + // But if we move to Public, we may need to add it (again) + else if( category == 2 && count_perms == 2 ) { + $("#allow_changes_from").append( $('[% ELSE %][% END %]
  • - [% IF shelf.is_private %] [% ELSE %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt index afe350c..c267248 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt @@ -579,7 +579,7 @@ [% IF Koha.Preference('OpacAllowPublicListCreation') OR category == PUBLIC %]
  • - [% IF shelf.is_private %] [% ELSE %] @@ -954,6 +954,26 @@ function Check(f) { alert(alertString2); } } + +function AdjustPerms() { + var category = $("#category").val(); + var count_perms = $("#allow_changes_from option").length; + + // If we move to Private, remove Anyone if we did not have shares + // Note: the number of shares is not tested real-time (just template var) + if( category == 1 ) { + [% IF !shelf.is_shared %] + $("#allow_changes_from option[value='2']").remove(); + [% END %] + } + // But if we move to Public, we may need to add it (again) + else if( category == 2 && count_perms == 2 ) { + $("#allow_changes_from").append( $('