[% FOREACH loo IN loop %]
[% IF ( loo.expand ) %]
@@ -272,8 +283,57 @@
}
}
});
+
+ if( copied = getCopiedPermissions() ){
+ $("#pastePermissions").removeClass("disabled");
+ }
+
+ /* write to the clipboard now */
+ $("#copyPermissions").on("click", function(e){
+ e.preventDefault();
+ let flags = new Object();
+ $("#flag_form input:checkbox").each(function(){
+ flags[ $(this).attr('id') ] = $(this).prop("checked");
+ });
+ formText = JSON.stringify( flags );
+ localStorage.setItem("copiedPermissions", formText );
+ toggleBtnIcon( $(this), "fa-copy", "fa-check" );
+ $("#pastePermissions").removeClass("disabled");
+ });
+
+ $("#pastePermissions").on("click", function(e){
+ e.preventDefault();
+ $(".toggleall_on").click();
+ let copiedPermissions = getCopiedPermissions();
+
+ let checkBox;
+ let checked;
+ for( const permission in copiedPermissions ){
+ checkBox = `${permission}`;
+ checked = `${copiedPermissions[permission]}` == "true" ? true : false;
+ $("#" + checkBox).prop("checked", checked );
+ }
+ });
+
+ $("#clearCopied").on("click", function(e){
+ e.preventDefault();
+ localStorage.removeItem("copiedPermissions");
+ $("#pastePermissions").addClass("disabled");
+ });
});
+ function getCopiedPermissions(){
+ const copied = localStorage.getItem("copiedPermissions");
+ let copiedPermissions;
+ try {
+ copiedPermissions = JSON.parse( copied );
+ return copiedPermissions;
+ } catch ( ex ){
+ console.error("Bad parse: ", ex.message );
+ return false;
+ }
+ }
+
function setLibrarian(){
$('input[name="flag"]').each(function() {
if($(this).attr('id') != "flag-0" && !$(this).hasClass('superlib') ){
diff --git a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js
index e424f2870b..71db55ae88 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js
@@ -340,6 +340,7 @@ function logOut() {
localStorage.removeItem("bibs_selected");
localStorage.removeItem("patron_search_selections");
localStorage.removeItem("item_search_selections");
+ localStorage.removeItem("copiedPermissions");
}
function openHelp() {
@@ -787,3 +788,20 @@ function selectBsTabByHash(tabs_container_id) {
$("#" + tabs_container_id + " a:first").tab("show");
}
}
+
+/**
+ * Fades out a Font Awesome icon, fades in a replacement, and back
+ * @param {object} element - jQuery object representing the icon's container
+ * @param {string} start - The icon which will be temporarily replaced
+ * @param {string} replacement - The icon which will be the temporary replacement
+ */
+function toggleBtnIcon( element, start, replacement ){
+ let icon = element.find( "." + start );
+ icon.fadeOut( 1000, function(){
+ $(this).removeClass( start ).addClass( replacement ).fadeIn( 1000, function(){
+ $(this).fadeOut( 1000, function(){
+ $(this).removeClass( replacement ).addClass( start ).fadeIn( 1000 );
+ });
+ });
+ });
+}