Bugzilla – Attachment 105837 Details for
Bug 25728
Add the ability to create a new authorised value within the cataloguing module
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 25728: Create AV when cataloguing a bibliographic record
Bug-25728-Create-AV-when-cataloguing-a-bibliograph.patch (text/plain), 10.08 KB, created by
Jonathan Druart
on 2020-06-12 15:20:44 UTC
(
hide
)
Description:
Bug 25728: Create AV when cataloguing a bibliographic record
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-06-12 15:20:44 UTC
Size:
10.08 KB
patch
obsolete
>From c91ad3e4bba448fa8da4a74e101f6e9d48fd5711 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 12 Jun 2020 15:22:54 +0200 >Subject: [PATCH] Bug 25728: Create AV when cataloguing a bibliographic record > >This whole patch set adds the ability to create a new authorised value >directly from the cataloguing module. >It will prevent the cataloger to leave and reload the page if they need >a new one. > >Test plan: >If you are logged in with a patron with the manage_authorised_values >subpermission you will be able to: >* Edit a bibliographic record >* Search for a subfield linked to an authorised values (not the "fake" >AV like itemtypes, branches, cn) >* Click the dropdown list and start searching for a value that does not >exist >* Click enter >* Fill the fields in the popup >* Save >=> Your dropdown list has the new AV :) > >Note: This does not work for the advanced editor. It does not have >select2 applied to the selects. I have hardly tried but failed. > >Sponsored-by: Orex Digital >--- > cataloguing/addbiblio.pl | 9 +- > .../prog/en/modules/cataloguing/addbiblio.tt | 110 +++++++++++++++++- > 2 files changed, 114 insertions(+), 5 deletions(-) > >diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl >index 7d48842c6a..d8d376ea4f 100755 >--- a/cataloguing/addbiblio.pl >+++ b/cataloguing/addbiblio.pl >@@ -170,14 +170,15 @@ sub build_authorized_values_list { > # builds list, depending on authorised value... > > #---- branch >- if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) { >+ my $category = $tagslib->{$tag}->{$subfield}->{authorised_value}; >+ if ( $category eq "branches" ) { > my $libraries = Koha::Libraries->search_filtered({}, {order_by => ['branchname']}); > while ( my $l = $libraries->next ) { > push @authorised_values, $l->branchcode;; > $authorised_lib{$l->branchcode} = $l->branchname; > } > } >- elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) { >+ elsif ( $category eq "itemtypes" ) { > push @authorised_values, ""; > > my $itemtype; >@@ -188,7 +189,7 @@ sub build_authorized_values_list { > } > $value = $itemtype unless ($value); > } >- elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) { >+ elsif ( $category eq "cn_source" ) { > push @authorised_values, ""; > > my $class_sources = GetClassSources(); >@@ -219,6 +220,7 @@ sub build_authorized_values_list { > } > } > $authorised_values_sth->finish; >+ > return { > type => 'select', > id => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield, >@@ -226,6 +228,7 @@ sub build_authorized_values_list { > default => $value, > values => \@authorised_values, > labels => \%authorised_lib, >+ ( ( grep { $_ eq $category } ( qw(branches itemtypes cn_source) ) ) ? () : ( category => $category ) ), > }; > > } >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt >index 66d253e363..d1f6f7d67c 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt >@@ -479,7 +479,70 @@ > [% INCLUDE 'select2.inc' %] > <script> > $(document).ready(function() { >- $('.subfield_line select').select2(); >+ $('.subfield_line select[data-category=""]').select2(); // branches, itemtypes and cn_source >+ >+ [% UNLESS CAN_user_parameters_manage_auth_values %] >+ $('.subfield_line select[data-category!=""]').select2(); >+ [% ELSE %] >+ var current_select2; >+ $('.subfield_line select[data-category!=""]').select2({ >+ tags: true, >+ createTag: function (tag) { >+ return { >+ id: tag.term, >+ text: tag.term, >+ newTag: true >+ }; >+ }, >+ templateResult: function(state) { >+ if (state.newTag) { >+ return state.text + " " + "(select to create)"; >+ } >+ return state.text; >+ } >+ }).on("select2:select", function(e) { >+ if(e.params.data.newTag){ >+ >+ var category = $(this).data("category"); >+ $("#avCreate #new_av_category").html(category); >+ $("#avCreate input[name='category']").val(category); >+ $("#avCreate input[name='value']").val(e.params.data.text); >+ $("#avCreate input[name='description']").val(e.params.data.text); >+ $('#avCreate').modal({show:true}); >+ >+ $(current_select2).val($(current_select2).find("option:first").val()).trigger('change'); >+ >+ current_select2 = this; >+ >+ } >+ }); >+ >+ $("#avCreate").on('hide.bs.modal', function(e){ >+ }); >+ >+ $("#add_new_av").on("submit", function(){ >+ var data = { >+ category: $(this).find('input[name="category"]').val(), >+ value: $(this).find('input[name="value"]').val(), >+ description: $(this).find('input[name="description"]').val(), >+ opac_description: $(this).find('input[name="opac_description"]').val(), >+ }; >+ $.ajax({ >+ type: "POST", >+ url: "/api/v1/authorised_values", >+ data:JSON.stringify(data), >+ success: function(response) { >+ $('#avCreate').modal('hide'); >+ >+ $(current_select2).append('<option selected value="'+data['value']+'">'+data['description']+'</option>'); >+ }, >+ error: function(err) { >+ $("#avCreate .error").html(_("Something went wrong, maybe the value already exists?")) >+ } >+ }); >+ return false; >+ }); >+ [% END %] > }); > </script> > >@@ -846,7 +909,7 @@ > [% ELSIF ( mv.type == 'textarea' ) %] > <textarea cols="70" rows="4" id="[%- mv.id | html -%]" name="[%- mv.name | html -%]" class="input_marceditor" tabindex="1">[%- mv.value | html -%]</textarea> > [% ELSIF ( mv.type == 'select' ) %] >- <select name="[%- mv.name | html -%]" tabindex="1" size="1" class="input_marceditor" id="[%- mv.id | html -%]"> >+ <select name="[%- mv.name | html -%]" tabindex="1" size="1" class="input_marceditor" id="[%- mv.id | html -%]" data-category="[% mv.category | html %]"> > [% FOREACH aval IN mv.values %] > [% IF aval == mv.default %] > <option value="[%- aval | html -%]" selected="selected">[%- mv.labels.$aval | html -%]</option> >@@ -891,6 +954,49 @@ > <input type="hidden" name="duedatespec" value="[% duedatespec | html %]" /> > [%# End of fields for fast cataloging %] > </form> <!-- /name=f --> >+ >+ <div id="avCreate" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="avCreateLabel" aria-hidden="true"> >+ <div class="modal-dialog"> >+ <div class="modal-content"> >+ <div class="modal-header"> >+ <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">Ã</button> >+ <h3 id="avCreateLabel">Create a new authorised value</h3> >+ </div> >+ <form id="add_new_av" method="post"> >+ <div class="modal-body"> >+ <div class="error"></div> >+ <fieldset class="rows"> >+ <ol> >+ <li> >+ <span class="label">Category:</span> >+ <input type="hidden" name="category" value="" /> >+ <span id="new_av_category"></span> >+ </li> >+ <li> >+ <span class="label" for="value">Authorised value:</span> >+ <input type="text" id="value" name="value" /> >+ </li> >+ <li> >+ <span class="label" for="description">Description:</span> >+ <input type="text" id="description" name="description" /> >+ </li> >+ <li> >+ <span class="label" for="opac_description">Description (OPAC):</span> >+ <input type="text" id="opac_description" name="opac_description" /> >+ </li> >+ </ol> >+ </fieldset> >+ </div> >+ <div class="modal-footer"> >+ <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button> >+ <input type="hidden" name="select2" value="" /> >+ <input type="submit" class="btn btn-primary" value="Save"> >+ </div> >+ </form> >+ </div> <!-- /.modal-content --> >+ </div> <!-- /.modal-dialog --> >+ </div> <!-- /#avCreate --> >+ > </div> <!-- /.col-md-10.col-md-offset-1 --> > </div> <!-- /.row --> > >-- >2.20.1
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 25728
:
105837
|
105838
|
105839
|
105840
|
105841
|
105842
|
105852
|
106696
|
106697
|
106698
|
106699
|
106700
|
106701
|
106702
|
108356
|
108357
|
108358
|
108359
|
108360
|
108361
|
108362
|
108883
|
108884
|
108885
|
108886
|
108887
|
108888
|
108889
|
108890
|
108922
|
108923
|
108924
|
108925
|
108926
|
108927
|
108928
|
108929
|
108930
|
108931