From cb993cdfba74072dbd8b3e0c99dd5279e0302ee3 Mon Sep 17 00:00:00 2001 From: Owen Leonard <oleonard@myacpl.org> Date: Thu, 13 Jan 2022 12:33:34 +0000 Subject: [PATCH] Bug 7374: Add remote image option for authorized values This patch adds the option of using a remote image for an authorized value, just as you can with item types. To test, apply the patch and go to Administration -> Authorized values. - Click "CCODE" to view the collection authorized values. - Edit a collection code. - In the form, under "Choose an icon," there should now be a "Remote image" tab. - Enter a remote image url, e.g. https://via.placeholder.com/50/FF0000/FFFFFF.png - Click "Save." - After the page redirects to the list of collection codes you should see your image in the table next to the code you edited. - Test that you can still edit a collection to set "No image" or to use one of the local image sets. - Test that remote images can also be added when adding a new collection. - Make sure "ccode" is in the "AdvancedSearchTypes" sytem preference. - Go to the catalog's advanced search page and click the "Collection" tab. - You should see your collection image in the list of collections. - Perform the same check in the OPAC. Signed-off-by: Lucas Gass <lucas@bywatersolutions.com> --- admin/authorised_values.pl | 16 ++++--- .../en/modules/admin/authorised_values.tt | 43 +++++++++++++++---- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/admin/authorised_values.pl b/admin/authorised_values.pl index f772a84be7..83bbf22821 100755 --- a/admin/authorised_values.pl +++ b/admin/authorised_values.pl @@ -78,10 +78,7 @@ if ($op eq 'add_form') { if ( $av ) { $template->param( category_name => $av->category, - authorised_value => $av->authorised_value, - lib => $av->lib, - lib_opac => $av->lib_opac, - id => $av->id, + av => $av, imagesets => C4::Koha::getImageSets( checked => $av->imageurl ), ); } else { @@ -97,8 +94,13 @@ if ($op eq 'add_form') { } elsif ($op eq 'add') { my $new_authorised_value = $input->param('authorised_value'); my $new_category = $input->param('category'); - my $imageurl = $input->param( 'imageurl' ) || ''; - $imageurl = '' if $imageurl =~ /removeImage/; + my $image = $input->param( 'image' ) || ''; + my $imageurl = + $image eq 'removeImage' ? '' + : ( + $image eq 'remoteImage' ? $input->param('remoteImage') + : $image + ); my $duplicate_entry = 0; my @branches = grep { $_ ne q{} } $input->multi_param('branches'); @@ -229,7 +231,7 @@ if ( $op eq 'list' ) { $row_data{authorised_value} = $av->authorised_value; $row_data{lib} = $av->lib; $row_data{lib_opac} = $av->lib_opac; - $row_data{imageurl} = getitemtypeimagelocation( 'intranet', $av->imageurl ); + $row_data{image} = getitemtypeimagelocation( 'intranet', $av->imageurl ); $row_data{branches} = $av->library_limits ? $av->library_limits->as_list : []; $row_data{id} = $av->id; push(@loop_data, \%row_data); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt index aa09e7603e..315e74ee80 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt @@ -118,17 +118,17 @@ <li> <label for="authorised_value">Authorized value: </label> [% IF ( action_modify ) %] - <input type="hidden" id="id" name="id" value="[% id | html %]" /> + <input type="hidden" id="id" name="id" value="[% av.id | html %]" /> [% END %] - <input type="text" id="authorised_value" name="authorised_value" value="[% authorised_value | html %]" maxlength="80" class="focus" /> + <input type="text" id="authorised_value" name="authorised_value" value="[% av.authorised_value | html %]" maxlength="80" class="focus" /> </li> <li> <label for="lib">Description: </label> - <input type="text" name="lib" id="lib" value="[% lib | html %]" maxlength="200" /> + <input type="text" name="lib" id="lib" value="[% av.lib | html %]" maxlength="200" /> </li> <li> <label for="lib_opac">Description (OPAC): </label> - <input type="text" name="lib_opac" id="lib_opac" value="[% lib_opac | html %]" maxlength="200" /> + <input type="text" name="lib_opac" id="lib_opac" value="[% av.lib_opac | html %]" maxlength="200" /> </li> <li><label for="branches">Library limitations: </label> <select id="branches" name="branches" multiple size="10"> @@ -152,11 +152,18 @@ [% FOREACH imageset IN imagesets %] [% IF ( imageset.imagesetactive ) %]<li class="ui-tabs-active">[% ELSE %]<li>[% END %]<a href="#[% imageset.imagesetname | uri %]">[% imageset.imagesetname | html %]</a></li> [% END %] + [% IF av.imageurl.match('^http') %] + <li class="ui-tabs-active"> + [% ELSE %] + <li> + [% END %] + <a href="#remote">Remote image</a> + </li> </ul> <div id="none"> <ul> <li> - <label for="noimage">No image: </label><input type="radio" name="imageurl" id="noimage" value="removeImage" /> + <label for="noimage">No image: </label><input type="radio" name="image" id="noimage" value="removeImage" /> </li> </ul> <br class="clear" /> @@ -173,11 +180,11 @@ [% ELSE %] [% END %] [% IF ( image.checked ) %] - <input type="radio" name="imageurl" value="[% image.KohaImage | html %]" checked="checked" /> + <input type="radio" name="image" value="[% image.KohaImage | html %]" checked="checked" /> [% ELSE %] [% IF ( image.KohaImage ) %] <!-- to delete the radio button if there is no image after --> - <input type="radio" name="imageurl" value="[% image.KohaImage | html %]" /> + <input type="radio" name="image" value="[% image.KohaImage | html %]" /> [% END %] [% END %] </label> @@ -187,12 +194,30 @@ <br class="clear" /> </div> [% END # /FOREACH imageset %] + + <div id="remote"> + <ul> + <li> + <label for="remote_image_check"> Remote image:</label> + [% IF av.imageurl.match('^http') %] + <input type="radio" id="remote_image_check" name="image" value="remoteImage" checked="checked" /> + <input type="text" name="remoteImage" size="48" maxlength="200" value="[% av.imageurl | html %]" onmousedown="document.getElementById('remote_image_check').checked = true;" /> + <img src="[% av.imageurl | html %]" alt="" /> + [% ELSE %] + <input type="radio" id="remote_image_check" name="image" value="remoteImage" /> + <input type="text" name="remoteImage" size="48" maxlength="200" value="" onmousedown="document.getElementById('remote_image_check').checked = true;" /> + [% END %] + </li> + </ul> + <br class="clear" /> + </div> + </div> <!-- /#icons --> [% END # /IF action_add_category %] </fieldset> <fieldset class="action"> - <input type="hidden" name="id" value="[% id | html %]" /> + <input type="hidden" name="id" value="[% av.id | html %]" /> <input type="submit" value="Save" /> <a class="cancel" href="/cgi-bin/koha/admin/authorised_values.pl?searchfield=[% category_name | url %]">Cancel</a> </fieldset> @@ -289,7 +314,7 @@ <td>[% loo.lib | html %]</td> <td>[% loo.lib_opac | html %]</td> <td> - [% IF ( loo.imageurl ) %]<img src="[% loo.imageurl | url %]" alt=""/>[% ELSE %] [% END %]</td> + [% IF ( loo.image ) %]<img src="[% loo.image | url %]" alt=""/>[% ELSE %] [% END %]</td> <td> [% IF loo.branches.size > 0 %] [% branches_str = "" %] -- 2.20.1