View | Details | Raw Unified | Return to bug 37054
Collapse All | Expand All

(-)a/Koha/Template/Plugin/Branches.pm (+23 lines)
Lines 27-32 use C4::Koha; Link Here
27
use C4::Context;
27
use C4::Context;
28
use Koha::Cache::Memory::Lite;
28
use Koha::Cache::Memory::Lite;
29
use Koha::Libraries;
29
use Koha::Libraries;
30
use JSON qw( decode_json );
30
31
31
sub GetName {
32
sub GetName {
32
    my ( $self, $branchcode ) = @_;
33
    my ( $self, $branchcode ) = @_;
Lines 194-197 sub GetBranchSpecificCSS { Link Here
194
    return $opacusercss;
195
    return $opacusercss;
195
}
196
}
196
197
198
sub GetBranchCustomization {
199
    my ( $self, $branchcode, $key ) = @_;
200
201
    return q{} unless defined $branchcode;
202
203
    my $library             = Koha::Libraries->find($branchcode);
204
    my $customizations_json = $library ? $library->ui_staff_customization : q{};
205
    my $customizations      = decode_json($customizations_json);
206
207
    return q{} unless defined $key;
208
209
    my @keys  = split /\./, $key;
210
    my $value = $customizations;
211
212
    for my $k (@keys) {
213
        return q{} unless ref $value eq 'HASH' && exists $value->{$k};
214
        $value = $value->{$k};
215
    }
216
217
    return defined $value ? $value : q{};
218
}
219
197
1;
220
1;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-open.inc (-6 / +7 lines)
Lines 34-44 Link Here
34
34
35
[% IF ( bidi ) %]<html lang="[% lang | html %]" dir="[% bidi | html %]">[% ELSE %]<html lang="[% lang | html %]">[% END %]
35
[% IF ( bidi ) %]<html lang="[% lang | html %]" dir="[% bidi | html %]">[% ELSE %]<html lang="[% lang | html %]">[% END %]
36
<head>
36
<head>
37
[% SET ui_staff_customization = Branches.GetLoggedInBranch.ui_staff_customization %]
37
[% SET ui_staff_color_background = Branches.GetBranchCustomization( Branches.GetLoggedInBranchcode, 'colors.background') %]
38
[% IF ui_staff_customization %]
38
39
    <style>
39
<style>
40
    [% IF ui_staff_color_background %]
40
        :root {
41
        :root {
41
            --library-color: [% ui_staff_customization | html %]
42
            --library-color: [% ui_staff_color_background | html %]
42
        }
43
        }
43
    </style>
44
    [% END %]
44
[% END %]
45
</style>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt (-8 / +43 lines)
Lines 2-7 Link Here
2
[% USE raw %]
2
[% USE raw %]
3
[% USE Asset %]
3
[% USE Asset %]
4
[% USE TablesSettings %]
4
[% USE TablesSettings %]
5
[% USE Branches %]
5
[%- USE KohaSpan -%]
6
[%- USE KohaSpan -%]
6
[% USE KohaTimes %]
7
[% USE KohaTimes %]
7
[% PROCESS 'i18n.inc' %]
8
[% PROCESS 'i18n.inc' %]
Lines 9-14 Link Here
9
[% INCLUDE 'doc-head-open.inc' %]
10
[% INCLUDE 'doc-head-open.inc' %]
10
[% IF library %][% SET OpacLibraryInfo = library.opac_info( lang => lang ) %][% END %]
11
[% IF library %][% SET OpacLibraryInfo = library.opac_info( lang => lang ) %][% END %]
11
12
13
[% SET ui_staff_color_background = Branches.GetBranchCustomization( Branches.GetLoggedInBranchcode, 'colors.background') %]
14
12
<title
15
<title
13
    >[% FILTER collapse %]
16
    >[% FILTER collapse %]
14
        [% IF op == 'add_form' %]
17
        [% IF op == 'add_form' %]
Lines 512-522 Link Here
512
                        <label for="colorpicker">Primary branch color: </label>
515
                        <label for="colorpicker">Primary branch color: </label>
513
                    </div>
516
                    </div>
514
                    <div class="fg-input">
517
                    <div class="fg-input">
515
                        <input type="color" name="colorpicker" id="colorpicker" value="[% library.ui_staff_customization | html %]" />
518
                        <input type="color" id="colorpicker" value="[% ui_staff_color_background | html %]" />
516
                        <input type="text" name="ui_staff_customization" id="ui_staff_customization" readonly="readonly" size="10" maxlength="16" value="[% library.ui_staff_customization | html %]" />
519
                        <input type="text" id="ui_staff_customization_background" readonly="readonly" size="10" maxlength="16" value="[% ui_staff_color_background | html %]" />
517
                        <a href="#" class="clear_color"><i class="fa fa-fw fa-trash-can"></i> Clear</a>
520
                        <a href="#" class="clear_color"><i class="fa fa-fw fa-trash-can"></i> Clear</a>
518
                    </div>
521
                    </div>
519
                </div>
522
                </div>
523
                <input type="hidden" name="ui_staff_customization" id="ui_staff_customization" value="[% library.ui_staff_customization | html %]" />
520
            </fieldset>
524
            </fieldset>
521
            [% IF additional_fields.size %]
525
            [% IF additional_fields.size %]
522
                [% INCLUDE 'additional-fields-entry.inc' available=additional_fields values=additional_field_values wrap_fieldset=1 %]
526
                [% INCLUDE 'additional-fields-entry.inc' available=additional_fields values=additional_field_values wrap_fieldset=1 %]
Lines 817-822 Link Here
817
        }
821
        }
818
    </style>
822
    </style>
819
    <script>
823
    <script>
824
        function updateCustomizations() {
825
            let customizations = { colors: {} };
826
            try {
827
                var currentJson = $hiddenField.val();
828
                if (currentJson) {
829
                    customizations = JSON.parse(currentJson);
830
                }
831
            } catch(e) {
832
                customizations = { colors: {} };
833
            }
834
            if (!customizations.colors) customizations.colors = {};
835
836
            // Get value from colorpicker, fallback to input
837
            let background = $('#colorpicker').val() || $('#ui_staff_customization_background').val();
838
            if ( background ) {
839
                customizations.colors.background = background;
840
            }
841
            $('#ui_staff_customization').val(JSON.stringify(customizations));
842
        }
843
820
        var table_settings = [% TablesSettings.GetTableSettings( 'admin', 'libraries', 'libraries', 'json' ) | $raw %];
844
        var table_settings = [% TablesSettings.GetTableSettings( 'admin', 'libraries', 'libraries', 'json' ) | $raw %];
821
        var calendarFirstDayOfWeek = '[% Koha.Preference('CalendarFirstDayOfWeek') | html %]';
845
        var calendarFirstDayOfWeek = '[% Koha.Preference('CalendarFirstDayOfWeek') | html %]';
822
846
Lines 1032-1045 Link Here
1032
            }
1056
            }
1033
            $( "#" + target ).hide();
1057
            $( "#" + target ).hide();
1034
        });
1058
        });
1035
        $("#colorpicker").on("change", function(){
1059
1036
            let ui_staff_customization = this.value;
1060
        $('#colorpicker').on('change input', function() {
1037
            $("#ui_staff_customization").val( ui_staff_customization );
1061
            var color = $(this).val();
1062
            $('#ui_staff_customization_background').val(color);
1063
            updateCustomizations();
1064
        });
1065
1066
        $('#ui_staff_customization_background').on('change blur', function() {
1067
            var color = $(this).val();
1068
            if (color.match(/^#[0-9A-Fa-f]{6}$/)) {
1069
                $('#colorpicker').val(color);
1070
            }
1071
            updateCustomizations();
1038
        });
1072
        });
1039
1073
1040
        $(".clear_color").on("click", function(e){
1074
        $('.clear_color').on('click', function(e) {
1041
            e.preventDefault();
1075
            e.preventDefault();
1042
            $("#ui_staff_customization, #colorpicker").val( "" );
1076
            $('#colorpicker').val("");
1077
            $('#ui_staff_customization_background').val('');
1078
            updateCustomizations();
1043
        });
1079
        });
1044
    </script>
1080
    </script>
1045
[% END %]
1081
[% END %]
1046
- 

Return to bug 37054