Bugzilla – Attachment 108884 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 adding a new item
Bug-25728-Create-AV-when-adding-a-new-item.patch (text/plain), 17.32 KB, created by
Jonathan Druart
on 2020-08-22 09:37:45 UTC
(
hide
)
Description:
Bug 25728: Create AV when adding a new item
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-08-22 09:37:45 UTC
Size:
17.32 KB
patch
obsolete
>From 647f345c6eb96d80acff0ef48d67a978370ccfab Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 8 Jun 2020 16:00:48 +0200 >Subject: [PATCH] Bug 25728: Create AV when adding a new item > >We do a bit of refactoring to make the code reusable. > >Test plan: >Same as the first patch but when adding/editing an item > >QA note: There is a warning from the QA tools > FAIL koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt > FAIL js_in_body > A <script> tag found inside head, must be moved to the body (see bug 17858) >I don't think how we could avoid it. > >Sponsored-by: Orex Digital > >Signed-off-by: Hugo Agud <hagud@orex.es> >--- > cataloguing/additem.pl | 2 + > .../includes/modals/cataloguing_create_av.inc | 41 +++++++ > .../en/modules/authorities/authorities.tt | 3 +- > .../prog/en/modules/cataloguing/addbiblio.tt | 115 +----------------- > .../prog/en/modules/cataloguing/additem.tt | 14 ++- > koha-tmpl/intranet-tmpl/prog/js/cataloging.js | 66 +++++++++- > 6 files changed, 126 insertions(+), 115 deletions(-) > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/modals/cataloguing_create_av.inc > >diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl >index a971089168..2d0ba7e397 100755 >--- a/cataloguing/additem.pl >+++ b/cataloguing/additem.pl >@@ -247,6 +247,7 @@ sub generate_subfield_form { > id => $subfield_data{id}, > maxlength => $subfield_data{maxlength}, > value => $value, >+ ( ( grep { $_ eq $subfieldlib->{authorised_value}} ( qw(branches itemtypes cn_source) ) ) ? () : ( category => $subfieldlib->{authorised_value}) ), > }; > } > else { >@@ -256,6 +257,7 @@ sub generate_subfield_form { > values => \@authorised_values, > labels => \%authorised_lib, > default => $value, >+ ( ( grep { $_ eq $subfieldlib->{authorised_value}} ( qw(branches itemtypes cn_source) ) ) ? () : ( category => $subfieldlib->{authorised_value}) ), > }; > } > } >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/modals/cataloguing_create_av.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/modals/cataloguing_create_av.inc >new file mode 100644 >index 0000000000..995a5ae337 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/modals/cataloguing_create_av.inc >@@ -0,0 +1,41 @@ >+<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 --> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt >index 961b4b25e6..fb33a1631c 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt >@@ -5,6 +5,7 @@ > <title>Koha › Authorities › [% IF ( authid ) %]Modify authority #[% authid | html %] ([% authtypetext | html %])[% ELSE %]Adding authority ([% authtypetext | html %])[% END %]</title> > [% INCLUDE 'doc-head-close.inc' %] > [% Asset.js("lib/hc-sticky.js") | $raw %] >+[% INCLUDE 'select2.inc' %] > [% Asset.js("js/cataloging.js") | $raw %] > > <script> >@@ -167,8 +168,6 @@ function confirmnotdup(redirect){ > </script> > [% Asset.css("css/addbiblio.css") | $raw %] > >-[% INCLUDE 'select2.inc' %] >- > </head> > <body id="auth_authorities" class="auth"> > >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 8de093209d..4f4fc5901c 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt >@@ -5,6 +5,10 @@ > <title>Koha › Cataloging › [% IF ( biblionumber ) %]Editing [% title | html %] (Record number [% biblionumber | html %])[% ELSE %]Add MARC record[% END %]</title> > [% INCLUDE 'doc-head-close.inc' %] > [% Asset.js("lib/hc-sticky.js") | $raw %] >+<script> >+ var CAN_user_parameters_manage_auth_values = "[% CAN_user_parameters_manage_auth_values | html %]"; >+</script> >+[% INCLUDE 'select2.inc' %] > [% Asset.js("js/cataloging.js") | $raw %] > [% INCLUDE 'strings.inc' %] > [% Asset.js("js/browser.js") | $raw %] >@@ -482,75 +486,6 @@ > </script> > [% Asset.css("css/addbiblio.css") | $raw %] > >-[% INCLUDE 'select2.inc' %] >-<script> >- $(document).ready(function() { >- [% IF CAN_user_parameters_manage_auth_values %] >- 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; >- >- } >- }).on("select2:clear", function () { >- $(this).on("select2:opening.cancelOpen", function (evt) { >- evt.preventDefault(); >- >- $(this).off("select2:opening.cancelOpen"); >- }); >- }); >- >- $("#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> >- > </head> > <body id="cat_addbiblio" class="cat"> > >@@ -964,47 +899,7 @@ > [%# 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 --> >+ [% INCLUDE 'modals/cataloguing_create_av.inc' %] > > </div> <!-- /.col-md-10.col-md-offset-1 --> > </div> <!-- /.row --> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt >index 5ae41036a5..e05b55f2ef 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt >@@ -8,11 +8,14 @@ > [% INCLUDE 'doc-head-close.inc' %] > [% Asset.css("css/addbiblio.css") | $raw %] > [% INCLUDE 'datatables.inc' %] >+<script> >+ var CAN_user_parameters_manage_auth_values = "[% CAN_user_parameters_manage_auth_values | html %]"; >+</script> >+[% INCLUDE 'select2.inc' %] > [% Asset.js("js/cataloging.js") | $raw %] > [% INCLUDE 'columns_settings.inc' %] > [% INCLUDE 'strings.inc' %] > [% Asset.js("js/browser.js") | $raw %] >-[% INCLUDE 'select2.inc' %] > [% INCLUDE 'calendar.inc' %] > [% INCLUDE 'str/cataloging_additem.inc' %] > [% Asset.js("js/cataloging_additem.js") | $raw %] >@@ -160,7 +163,11 @@ > [% IF ( mv.readonly || ite.IS_RETURN_CLAIM ) %] > <select name="field_value" id="[%- mv.id | html -%]" size="1" class="input_marceditor select2" readonly="readonly" disabled="disabled"> > [% ELSE %] >- <select name="field_value" id="[%- mv.id | html -%]" size="1" class="input_marceditor select2"> >+ [% IF mv.category AND CAN_user_parameters_manage_auth_values %] >+ <select name="field_value" id="[%- mv.id | html -%]" size="1" class="input_marceditor" data-category="[% mv.category | html %]"> >+ [% ELSE %] >+ <select name="field_value" id="[%- mv.id | html -%]" size="1" class="input_marceditor select2"> >+ [% END %] > [% END %] > [% FOREACH aval IN mv.values %] > [% IF aval == mv.default %] >@@ -266,6 +273,9 @@ > > > </form> >+ >+ [% INCLUDE 'modals/cataloguing_create_av.inc' %] >+ > </div> <!-- /#cataloguing_additem_newitem --> > </div> <!-- /.col-sm-10 --> > </div> <!-- /.row --> >diff --git a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js b/koha-tmpl/intranet-tmpl/prog/js/cataloging.js >index c74d953979..3c4d6fbe87 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/cataloging.js >@@ -515,9 +515,73 @@ function CheckImportantSubfields(p){ > return total; > } > >- $(document).ready(function() { >+$(document).ready(function() { > $("input.input_marceditor, input.indicator").addClass('noEnterSubmit'); > $(document).ajaxSuccess(function() { > $("input.input_marceditor, input.indicator").addClass('noEnterSubmit'); > }); >+ >+ if ( CAN_user_parameters_manage_auth_values ) { >+ 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; >+ >+ } >+ }).on("select2:clear", function () { >+ $(this).on("select2:opening.cancelOpen", function (evt) { >+ evt.preventDefault(); >+ >+ $(this).off("select2:opening.cancelOpen"); >+ }); >+ }); >+ >+ $("#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; >+ }); >+ } > }); >-- >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