Bugzilla – Attachment 184838 Details for
Bug 37054
Allow for custom library colors in the staff interface
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37054: Store and retrieve values in JSON
Bug-37054-Store-and-retrieve-values-in-JSON.patch (text/plain), 6.76 KB, created by
Lucas Gass (lukeg)
on 2025-07-29 20:34:08 UTC
(
hide
)
Description:
Bug 37054: Store and retrieve values in JSON
Filename:
MIME Type:
Creator:
Lucas Gass (lukeg)
Created:
2025-07-29 20:34:08 UTC
Size:
6.76 KB
patch
obsolete
>From 6b8c0042451f9598cd44e5d59c96edf7460eb618 Mon Sep 17 00:00:00 2001 >From: Lucas Gass <lucas@bywatersolutions.com> >Date: Tue, 29 Jul 2025 20:29:20 +0000 >Subject: [PATCH] Bug 37054: Store and retrieve values in JSON > >--- > Koha/Template/Plugin/Branches.pm | 23 +++++++++ > .../prog/en/includes/doc-head-open.inc | 13 ++--- > .../prog/en/modules/admin/branches.tt | 50 ++++++++++++++++--- > 3 files changed, 73 insertions(+), 13 deletions(-) > >diff --git a/Koha/Template/Plugin/Branches.pm b/Koha/Template/Plugin/Branches.pm >index 3329a9c859b..e91cb046e02 100644 >--- a/Koha/Template/Plugin/Branches.pm >+++ b/Koha/Template/Plugin/Branches.pm >@@ -27,6 +27,7 @@ use C4::Koha; > use C4::Context; > use Koha::Cache::Memory::Lite; > use Koha::Libraries; >+use JSON qw( decode_json ); > > sub GetName { > my ( $self, $branchcode ) = @_; >@@ -194,4 +195,26 @@ sub GetBranchSpecificCSS { > return $opacusercss; > } > >+sub GetBranchCustomization { >+ my ( $self, $branchcode, $key ) = @_; >+ >+ return q{} unless defined $branchcode; >+ >+ my $library = Koha::Libraries->find($branchcode); >+ my $customizations_json = $library ? $library->ui_staff_customization : q{}; >+ my $customizations = decode_json($customizations_json); >+ >+ return q{} unless defined $key; >+ >+ my @keys = split /\./, $key; >+ my $value = $customizations; >+ >+ for my $k (@keys) { >+ return q{} unless ref $value eq 'HASH' && exists $value->{$k}; >+ $value = $value->{$k}; >+ } >+ >+ return defined $value ? $value : q{}; >+} >+ > 1; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-open.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-open.inc >index 18eb86ca410..1082b191e7a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-open.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-open.inc >@@ -34,11 +34,12 @@ > > [% IF ( bidi ) %]<html lang="[% lang | html %]" dir="[% bidi | html %]">[% ELSE %]<html lang="[% lang | html %]">[% END %] > <head> >-[% SET ui_staff_customization = Branches.GetLoggedInBranch.ui_staff_customization %] >-[% IF ui_staff_customization %] >- <style> >+[% SET ui_staff_color_background = Branches.GetBranchCustomization( Branches.GetLoggedInBranchcode, 'colors.background') %] >+ >+<style> >+ [% IF ui_staff_color_background %] > :root { >- --library-color: [% ui_staff_customization | html %] >+ --library-color: [% ui_staff_color_background | html %] > } >- </style> >-[% END %] >+ [% END %] >+</style> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt >index 295f4ed77e7..af06a754a5f 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt >@@ -2,6 +2,7 @@ > [% USE raw %] > [% USE Asset %] > [% USE TablesSettings %] >+[% USE Branches %] > [%- USE KohaSpan -%] > [% USE KohaTimes %] > [% PROCESS 'i18n.inc' %] >@@ -9,6 +10,8 @@ > [% INCLUDE 'doc-head-open.inc' %] > [% IF library %][% SET OpacLibraryInfo = library.opac_info( lang => lang ) %][% END %] > >+[% SET ui_staff_color_background = Branches.GetBranchCustomization( Branches.GetLoggedInBranchcode, 'colors.background') %] >+ > <title > >[% FILTER collapse %] > [% IF op == 'add_form' %] >@@ -512,11 +515,12 @@ > <label for="colorpicker">Primary branch color: </label> > </div> > <div class="fg-input"> >- <input type="color" name="colorpicker" id="colorpicker" value="[% library.ui_staff_customization | html %]" /> >- <input type="text" name="ui_staff_customization" id="ui_staff_customization" readonly="readonly" size="10" maxlength="16" value="[% library.ui_staff_customization | html %]" /> >+ <input type="color" id="colorpicker" value="[% ui_staff_color_background | html %]" /> >+ <input type="text" id="ui_staff_customization_background" readonly="readonly" size="10" maxlength="16" value="[% ui_staff_color_background | html %]" /> > <a href="#" class="clear_color"><i class="fa fa-fw fa-trash-can"></i> Clear</a> > </div> > </div> >+ <input type="hidden" name="ui_staff_customization" id="ui_staff_customization" value="[% library.ui_staff_customization | html %]" /> > </fieldset> > [% IF additional_fields.size %] > [% INCLUDE 'additional-fields-entry.inc' available=additional_fields values=additional_field_values wrap_fieldset=1 %] >@@ -817,6 +821,26 @@ > } > </style> > <script> >+ function updateCustomizations() { >+ let customizations = { colors: {} }; >+ try { >+ var currentJson = $hiddenField.val(); >+ if (currentJson) { >+ customizations = JSON.parse(currentJson); >+ } >+ } catch(e) { >+ customizations = { colors: {} }; >+ } >+ if (!customizations.colors) customizations.colors = {}; >+ >+ // Get value from colorpicker, fallback to input >+ let background = $('#colorpicker').val() || $('#ui_staff_customization_background').val(); >+ if ( background ) { >+ customizations.colors.background = background; >+ } >+ $('#ui_staff_customization').val(JSON.stringify(customizations)); >+ } >+ > var table_settings = [% TablesSettings.GetTableSettings( 'admin', 'libraries', 'libraries', 'json' ) | $raw %]; > var calendarFirstDayOfWeek = '[% Koha.Preference('CalendarFirstDayOfWeek') | html %]'; > >@@ -1032,14 +1056,26 @@ > } > $( "#" + target ).hide(); > }); >- $("#colorpicker").on("change", function(){ >- let ui_staff_customization = this.value; >- $("#ui_staff_customization").val( ui_staff_customization ); >+ >+ $('#colorpicker').on('change input', function() { >+ var color = $(this).val(); >+ $('#ui_staff_customization_background').val(color); >+ updateCustomizations(); >+ }); >+ >+ $('#ui_staff_customization_background').on('change blur', function() { >+ var color = $(this).val(); >+ if (color.match(/^#[0-9A-Fa-f]{6}$/)) { >+ $('#colorpicker').val(color); >+ } >+ updateCustomizations(); > }); > >- $(".clear_color").on("click", function(e){ >+ $('.clear_color').on('click', function(e) { > e.preventDefault(); >- $("#ui_staff_customization, #colorpicker").val( "" ); >+ $('#colorpicker').val(""); >+ $('#ui_staff_customization_background').val(''); >+ updateCustomizations(); > }); > </script> > [% END %] >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 37054
:
167577
|
167578
|
167579
|
167590
|
167595
|
167596
|
167597
|
167598
|
167609
|
167612
|
167613
|
167614
|
167615
|
167616
|
167618
|
167625
|
171221
|
171222
|
171223
|
171224
|
171225
|
171226
|
175991
|
175992
|
175993
|
175994
|
175995
|
175996
|
176014
|
176015
|
176016
|
176615
|
176616
|
180329
|
180330
|
180331
|
180332
|
180333
|
180334
|
184825
|
184826
|
184827
|
184828
|
184829
|
184830
|
184831
| 184838 |
184903