Bugzilla – Attachment 106697 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), 16.33 KB, created by
Hugo Agud
on 2020-07-09 10:04:36 UTC
(
hide
)
Description:
Bug 25728: Create AV when adding a new item
Filename:
MIME Type:
Creator:
Hugo Agud
Created:
2020-07-09 10:04:36 UTC
Size:
16.33 KB
patch
obsolete
>From e21706bfe46ce8fd2932fce40a3f2f79244a69f2 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: Your Full Name <your_email> >--- > cataloguing/additem.pl | 2 + > .../en/includes/modals/cataloguing_create_av.inc | 41 ++++++++ > .../prog/en/modules/cataloguing/addbiblio.tt | 114 +-------------------- > .../prog/en/modules/cataloguing/additem.tt | 8 +- > koha-tmpl/intranet-tmpl/prog/js/cataloging.js | 64 +++++++++++- > .../intranet-tmpl/prog/js/cataloging_additem.js | 2 - > 6 files changed, 117 insertions(+), 114 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 130ff0a3f2..85e9128550 100755 >--- a/cataloguing/additem.pl >+++ b/cataloguing/additem.pl >@@ -231,6 +231,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 { >@@ -240,6 +241,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/cataloguing/addbiblio.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt >index 667b7ecf56..5c284b4f7d 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,9 @@ > <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> > [% Asset.js("js/cataloging.js") | $raw %] > [% INCLUDE 'strings.inc' %] > [% Asset.js("js/browser.js") | $raw %] >@@ -483,75 +486,6 @@ > [% Asset.css("css/addbiblio.css") | $raw %] > > [% INCLUDE 'select2.inc' %] >-<script> >- $(document).ready(function() { >- $('.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> >- > </head> > <body id="cat_addbiblio" class="cat"> > >@@ -961,47 +895,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 2d64bef70f..53ab1c45b8 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt >@@ -8,6 +8,9 @@ > [% 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> > [% Asset.js("js/cataloging.js") | $raw %] > [% INCLUDE 'columns_settings.inc' %] > [% INCLUDE 'strings.inc' %] >@@ -160,7 +163,7 @@ > [% IF ( mv.readonly ) %] > <select name="field_value" id="[%- mv.id | html -%]" size="1" class="input_marceditor" readonly="readonly" disabled="disabled"> > [% ELSE %] >- <select name="field_value" id="[%- mv.id | html -%]" size="1" class="input_marceditor"> >+ <select name="field_value" id="[%- mv.id | html -%]" size="1" class="input_marceditor" data-category="[% mv.category | html %]"> > [% END %] > [% FOREACH aval IN mv.values %] > [% IF aval == mv.default %] >@@ -262,6 +265,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..792059eacb 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/cataloging.js >@@ -515,9 +515,71 @@ 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'); > }); >+ >+ $('.subfield_line select[data-category=""]').select2(); // branches, itemtypes and cn_source >+ >+ if ( ! 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; >+ >+ } >+ }); >+ >+ $("#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; >+ }); >+ } > }); >diff --git a/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js b/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js >index e3e746764a..233c5da99b 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js >@@ -71,8 +71,6 @@ $(document).ready(function(){ > addSingleBlock.toggle(); > multiCopyControl.toggle(); > }); >- >- $('.subfield_line select').select2(); > }); > > function Check(f) { >-- >2.11.0
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