Bugzilla – Attachment 82708 Details for
Bug 21091
Move add item template JavaScript to a separate file
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21091: Move add item template JavaScript to a separate file
Bug-21091-Move-add-item-template-JavaScript-to-a-s.patch (text/plain), 14.98 KB, created by
Owen Leonard
on 2018-11-28 18:34:07 UTC
(
hide
)
Description:
Bug 21091: Move add item template JavaScript to a separate file
Filename:
MIME Type:
Creator:
Owen Leonard
Created:
2018-11-28 18:34:07 UTC
Size:
14.98 KB
patch
obsolete
>From 7cb24daac558c734f5e2a6acc66e1c047180a9ba Mon Sep 17 00:00:00 2001 >From: Owen Leonard <oleonard@myacpl.org> >Date: Wed, 28 Nov 2018 17:51:10 +0000 >Subject: [PATCH] Bug 21091: Move add item template JavaScript to a separate > file > >This patch moves the JavaScript in the add item template to separate >files: 1 JS file and 1 include file containing translatable strings. > >While moving the JS to cataloging_additem.js I have made some changes to >quiet ESLint warnings (spacing, variable definition). > >To test, apply the patch and open the add item page for an existing >record. Test the various JS-driven functionalities: > >- Table sorting >- Table column configuration >- Table searching >- Table inline edit/delete links (click anywhere in the table row) >- Add multiple item form show/hide >- Add multiple item warning when adding 100+ items >--- > .../prog/en/includes/str/cataloging_additem.inc | 16 +++ > .../prog/en/modules/cataloguing/additem.tt | 140 ++------------------- > .../intranet-tmpl/prog/js/cataloging_additem.js | 119 ++++++++++++++++++ > 3 files changed, 142 insertions(+), 133 deletions(-) > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/str/cataloging_additem.inc > create mode 100644 koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/str/cataloging_additem.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/str/cataloging_additem.inc >new file mode 100644 >index 0000000..51494a2 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/str/cataloging_additem.inc >@@ -0,0 +1,16 @@ >+<script> >+ var searchid = '[% searchid | html %]'; >+ var biblionumber = '[% biblionumber | html %]'; >+ var frameworkcode = '[% frameworkcode | html %]'; >+ var popup = '[% popup | html %]'; >+ var opisadd = '[% opisadd | html %]'; >+ var LABEL_EDIT_ITEM = _("Edit item"); >+ var LABEL_DELETE_ITEM = _("Delete item"); >+ var MSG_FORM_NOT_SUBMITTED = _("Form not submitted because of the following problem(s)"); >+ var MSG_MANDATORY_FIELDS_EMPTY = _("%s mandatory fields empty (highlighted)"); >+ var MSG_ADD_MULTIPLE_ITEMS = _("You are about to add %s items. Continue?"); >+ var MSG_ENTER_NUM_ITEMS = _("Please enter a number of items to create."); >+ var MSG_CONFIRM_DELETE_ITEM = _("Are you sure you want to delete this item?"); >+ var MSG_CONFIRM_ADD_ITEM = _("Are you sure you want to add a new item? Any changes made on this page will be lost."); >+ var columns_settings = [% ColumnsSettings.GetColumns( 'cataloguing', 'additem', 'itemst', 'json' ) | $raw %]; >+</script> >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 4aaf0f7..828860b 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt >@@ -2,148 +2,21 @@ > [% USE Asset %] > [% USE Koha %] > [% USE ColumnsSettings %] >- > [% INCLUDE 'doc-head-open.inc' %] > <title>Koha › Cataloging › [% title | html %] [% IF ( author ) %] by [% author | html %][% END %] (Record #[% biblionumber | html %]) › Items</title> >-[% Asset.css("css/datatables.css") | $raw %] > [% INCLUDE 'doc-head-close.inc' %] >+[% Asset.css("css/datatables.css") | $raw %] >+[% Asset.css("css/addbiblio.css") | $raw %] > [% INCLUDE 'datatables.inc' %] > [% Asset.js("js/cataloging.js") | $raw %] > [% INCLUDE 'columns_settings.inc' %] > [% INCLUDE 'browser-strings.inc' %] > [% Asset.js("js/browser.js") | $raw %] >-<script type="text/javascript"> >-//<![CDATA[ >- var browser = KOHA.browser('[% searchid | html %]', parseInt('[% biblionumber | html %]', 10)); >- browser.show(); >- >-$(document).ready(function(){ >- >- // Remove the onclick event defined in browser.js, >- // otherwise the deletion confirmation will not work correctly >- $('a[href*="biblionumber="]').off('click'); >- >- [% IF (popup) %] >- [% IF (opisadd) %] >- window.close(); >- [% END %] >- [% END %] >- $("fieldset.rows input, fieldset.rows select").addClass("noEnterSubmit"); >- /* Inline edit/delete links */ >- var biblionumber = $("input[name='biblionumber']").attr("value"); >- $("tr.editable").each(function(){ >- $(this).find("td:not(:first)").on('click', function(){ >- var rowid = $(this).parent().attr("id"); >- num_rowid = rowid.replace("row",""); >- $(".linktools").remove(); >- var edit_link = $('<a href="/cgi-bin/koha/cataloguing/additem.pl?op=edititem&frameworkcode=[% frameworkcode | uri %]&biblionumber=[% biblionumber | uri %]&itemnumber='+num_rowid+'&searchid=[% searchid | uri %]#edititem"></a>'); >- $(edit_link).text(_("Edit item")); >- var delete_link = $('<a href="/cgi-bin/koha/cataloguing/additem.pl?op=delitem&frameworkcode=[% frameworkcode | uri %]&biblionumber=[% biblionumber | uri %]&itemnumber='+num_rowid+'&searchid=[% searchid | uri %]"></a>'); >- $(delete_link).text(_("Delete item")); >- $(delete_link).on('click', function(e) { >- return confirm_deletion(); >- }); >- var tools_node = $('<span class="linktools"></span>'); >- $(tools_node).append(edit_link); >- $(tools_node).append(delete_link); >- $(this).append(tools_node); >- }); >- }); >- >- $("#addnewitem").click(function(){ >- if ( confirm(_("Are you sure you want to add a new item? Any changes made on this page will be lost.")) ){ >- window.location.href = "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=[% biblionumber | html %]"; >- } >- }); >- >- var columns_settings = [% ColumnsSettings.GetColumns( 'cataloguing', 'additem', 'itemst', 'json' ) | $raw %] >- // Skip the first column >- columns_settings.unshift( { cannot_be_toggled: "1" } ); >- >- var itemst = KohaTable("itemst", { >- "aoColumnDefs": [ >- { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false }, >- ], >- 'bPaginate': false, >- 'bInfo': false, >- "bAutoWidth": false, >- "bKohaColumnsUseNames": true >- }, columns_settings); >- >- var multiCopyControl = $("#add_multiple_copies_span"); >- var addMultipleBlock = $("#addmultiple"); >- var addSingleBlock = $("#addsingle"); >- multiCopyControl.hide(); >- $("#add_multiple_copies").on("click",function(e){ >- e.preventDefault; >- addMultipleBlock.toggle(); >- addSingleBlock.toggle(); >- multiCopyControl.toggle(); >- $('body,html').animate({ scrollTop: $('body').height() }, 100); >- }); >- $("#cancel_add_multiple").on("click",function(e){ >- e.preventDefault(); >- addMultipleBlock.toggle(); >- addSingleBlock.toggle(); >- multiCopyControl.toggle(); >- }); >-}); >- >-function Check(f) { >- var total_errors = CheckMandatorySubfields(f); >- if (total_errors==0) { >- // Explanation about this line: >- // In case of limited edition permission, we have to prevent user from modifying some fields. >- // But there is no such thing as readonly attribute for select elements. >- // So we use disabled instead. But disabled prevent values from being passed through the form at submit. >- // So we "un-disable" the elements just before submitting. >- // That's a bit clumsy, and if someone comes up with a better solution, feel free to improve that. >- $("select[name=field_value]").prop('disabled', false); >- return true; >- } else { >- var alertString2 = _("Form not submitted because of the following problem(s)"); >- alertString2 += "\n------------------------------------------------------------------------------------\n"; >- alertString2 += "\n- " + _("%s mandatory fields empty (highlighted)").format(total_errors); >- alert(alertString2); >- return false; >- } >- return true; >-} >-function CheckMultipleAdd(f) { >- >- if (!f || isNaN(f) || !parseInt(f) == f || f <= 0) { >- alert(_("Please enter a number of items to create.")); >- return false; >- } >- <!-- Add a soft-limit of 99 with a reminder about potential data entry error --> >- if (f>99) { >- return confirm(_("You are about to add %s items. Continue?").format(f)); >- } >-} >-function Dopop(link,i) { >- defaultvalue=document.forms[0].field_value[i].value; >- newin=window.open(link+"&result="+defaultvalue,"valuebuilder",'width=500,height=400,toolbar=false,scrollbars=yes'); >-} >- >-function confirm_deletion() { >- return confirm(_("Are you sure you want to delete this item?")); >-} >- >-//]]> >-</script> >-[% Asset.css("css/addbiblio.css") | $raw %] >- > [% INCLUDE 'select2.inc' %] >-<script type="text/javascript"> >- $(document).ready(function() { >- $('.subfield_line select').select2(); >- }); >-</script> >- >-[% IF ( bidi ) %] >- [% Asset.css("css/right-to-left.css") | $raw %] >-[% END %] >+[% INCLUDE 'str/cataloging_additem.inc' %] >+[% Asset.js("js/cataloging_additem.js") | $raw %] > </head> >+ > <body id="cat_additem" class="cat"> > [% INCLUDE 'header.inc' %] > [% INCLUDE 'cataloging-search.inc' %] >@@ -364,7 +237,7 @@ function confirm_deletion() { > <input type="button" id="addnewitem" value="Add a new item"> > <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblionumber | uri %]">Cancel</a> > [% END %]</fieldset> >- >+ > [%# Fields for fast cataloging %] > <input type="hidden" name="circborrowernumber" value="[% circborrowernumber | html %]" /> > <input type="hidden" name="stickyduedate" value="[% stickyduedate | html %]" /> >@@ -380,4 +253,5 @@ function confirm_deletion() { > > </div> > </div> >+ > [% INCLUDE 'intranet-bottom.inc' %] >diff --git a/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js b/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js >new file mode 100644 >index 0000000..cf9eb7f >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js >@@ -0,0 +1,119 @@ >+/* global KOHA searchid biblionumber frameworkcode popup opisadd LABEL_EDIT_ITEM LABEL_DELETE_ITEM MSG_FORM_NOT_SUBMITTED MSG_MANDATORY_FIELDS_EMPTY MSG_ADD_MULTIPLE_ITEMS MSG_ENTER_NUM_ITEMS MSG_CONFIRM_DELETE_ITEM MSG_CONFIRM_ADD_ITEM columns_settings CheckMandatorySubfields CheckMultipleAdd */ >+ >+var browser = KOHA.browser(searchid, parseInt(biblionumber, 10)); >+browser.show(); >+ >+$(document).ready(function(){ >+ >+ // Remove the onclick event defined in browser.js, >+ // otherwise the deletion confirmation will not work correctly >+ $('a[href*="biblionumber="]').off('click'); >+ >+ if( popup ){ >+ if( opisadd ){ >+ window.close(); >+ } >+ } >+ >+ $("fieldset.rows input, fieldset.rows select").addClass("noEnterSubmit"); >+ /* Inline edit/delete links */ >+ var biblionumber = $("input[name='biblionumber']").attr("value"); >+ $("tr.editable").each(function(){ >+ $(this).find("td:not(:first)").on('click', function(){ >+ var rowid = $(this).parent().attr("id"); >+ var num_rowid = rowid.replace("row",""); >+ $(".linktools").remove(); >+ var edit_link = $('<a href="/cgi-bin/koha/cataloguing/additem.pl?op=edititem&frameworkcode=' + frameworkcode + '&biblionumber=' + biblionumber + '&itemnumber=' + num_rowid + '&searchid=' + searchid + '#edititem"></a>'); >+ $(edit_link).text( LABEL_EDIT_ITEM ); >+ var delete_link = $('<a href="/cgi-bin/koha/cataloguing/additem.pl?op=delitem&frameworkcode=' + frameworkcode + '&biblionumber=' + biblionumber + '&itemnumber=' + num_rowid + '&searchid=' + searchid + '"></a>'); >+ $(delete_link).text( LABEL_DELETE_ITEM ); >+ $(delete_link).on('click', function() { >+ return confirm_deletion(); >+ }); >+ var tools_node = $('<span class="linktools"></span>'); >+ $(tools_node).append(edit_link); >+ $(tools_node).append(delete_link); >+ $(this).append(tools_node); >+ }); >+ }); >+ >+ $("#addnewitem").click(function(){ >+ if ( confirm( MSG_CONFIRM_ADD_ITEM ) ){ >+ window.location.href = "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=" + biblionumber; >+ } >+ }); >+ >+ // Skip the first column >+ columns_settings.unshift( { cannot_be_toggled: "1" } ); >+ >+ var itemst = KohaTable("itemst", { >+ "aoColumnDefs": [ >+ { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false }, >+ ], >+ 'bPaginate': false, >+ 'bInfo': false, >+ "bAutoWidth": false, >+ "bKohaColumnsUseNames": true >+ }, columns_settings); >+ >+ var multiCopyControl = $("#add_multiple_copies_span"); >+ var addMultipleBlock = $("#addmultiple"); >+ var addSingleBlock = $("#addsingle"); >+ multiCopyControl.hide(); >+ $("#add_multiple_copies").on("click",function(e){ >+ e.preventDefault; >+ addMultipleBlock.toggle(); >+ addSingleBlock.toggle(); >+ multiCopyControl.toggle(); >+ $('body,html').animate({ scrollTop: $('body').height() }, 100); >+ }); >+ $("#cancel_add_multiple").on("click",function(e){ >+ e.preventDefault(); >+ addMultipleBlock.toggle(); >+ addSingleBlock.toggle(); >+ multiCopyControl.toggle(); >+ }); >+ >+ $('.subfield_line select').select2(); >+}); >+ >+function Check(f) { >+ var total_errors = CheckMandatorySubfields(f); >+ if (total_errors==0) { >+ // Explanation about this line: >+ // In case of limited edition permission, we have to prevent user from modifying some fields. >+ // But there is no such thing as readonly attribute for select elements. >+ // So we use disabled instead. But disabled prevent values from being passed through the form at submit. >+ // So we "un-disable" the elements just before submitting. >+ // That's a bit clumsy, and if someone comes up with a better solution, feel free to improve that. >+ $("select[name=field_value]").prop('disabled', false); >+ return true; >+ } else { >+ var alertString2 = MSG_FORM_NOT_SUBMITTED; >+ alertString2 += "\n------------------------------------------------------------------------------------\n"; >+ alertString2 += "\n- " + "%s " + MSG_MANDATORY_FIELDS_EMPTY.format(total_errors); >+ alert(alertString2); >+ return false; >+ } >+} >+ >+function CheckMultipleAdd(f) { >+ >+ if (!f || isNaN(f) || !parseInt(f) == f || f <= 0) { >+ alert( MSG_ENTER_NUM_ITEMS ); >+ return false; >+ } >+ // Add a soft-limit of 99 with a reminder about potential data entry error >+ if (f>99) { >+ return confirm( MSG_ADD_MULTIPLE_ITEMS.format(f)); >+ } >+} >+ >+function Dopop(link,i) { >+ var defaultvalue=document.forms[0].field_value[i].value; >+ var newin=window.open(link+"&result=" + defaultvalue,"valuebuilder",'width=500,height=400,toolbar=false,scrollbars=yes'); >+} >+ >+function confirm_deletion() { >+ return confirm( MSG_CONFIRM_DELETE_ITEM ); >+} >\ No newline at end of file >-- >2.1.4
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 21091
:
77135
|
77876
|
82707
|
82708
|
85205
|
85499
|
85500
|
85626
|
85627