Bugzilla – Attachment 152854 Details for
Bug 34092
patron-autocomplete.js and patron-search.inc search logic should match
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34092: Move patron_autocomplete to staff-global.js
Bug-34092-Move-patronautocomplete-to-staff-globalj.patch (text/plain), 12.17 KB, created by
Paul Derscheid
on 2023-06-29 09:13:22 UTC
(
hide
)
Description:
Bug 34092: Move patron_autocomplete to staff-global.js
Filename:
MIME Type:
Creator:
Paul Derscheid
Created:
2023-06-29 09:13:22 UTC
Size:
12.17 KB
patch
obsolete
>From 2a945b759e560f53e9f8a6ae8ec8be0aab8dac82 Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@ptfs-europe.com> >Date: Mon, 26 Jun 2023 10:22:19 +0000 >Subject: [PATCH] Bug 34092: Move patron_autocomplete to staff-global.js > >Remove patron-autocomplete.js file > >Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de> >--- > .../prog/en/includes/js_includes.inc | 1 - > .../prog/js/patron-autocomplete.js | 134 ----------------- > .../intranet-tmpl/prog/js/staff-global.js | 135 ++++++++++++++++++ > 3 files changed, 135 insertions(+), 135 deletions(-) > delete mode 100644 koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc >index a5159b0150..1e687f8ab7 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc >@@ -29,7 +29,6 @@ > [% INCLUDE 'js-date-format.inc' %] > [% INCLUDE 'js-patron-get-age.inc' %] > [% INCLUDE 'js-patron-format-address.inc' %] >-[% Asset.js("js/patron-autocomplete.js") | $raw %] > > [% INCLUDE 'validator-strings.inc' %] > [% IF ( IntranetUserJS ) %] >diff --git a/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js b/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js >deleted file mode 100644 >index cff6a257fd..0000000000 >--- a/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js >+++ /dev/null >@@ -1,134 +0,0 @@ >-function patron_autocomplete(node, options) { >- let link_to; >- let url_params; >- let on_select_callback; >- let leading_wildcard = defaultPatronSearchMethod === 'contains' ? '%' : ''; >- if ( options ) { >- if ( options['link-to'] ) { >- link_to = options['link-to']; >- } >- if ( options['url-params'] ) { >- url_params = options['url-params']; >- } >- if ( options['on-select-callback'] ) { >- on_select_callback = options['on-select-callback']; >- } >- } >- return node.autocomplete({ >- source: function( request, response ) { >- let q = [] >- >- // Add each pattern in search term for each search field >- let pattern_subquery_and = []; >- request.term.split(/[\s,]+/) >- .filter(function(s){ return s.length }) >- .forEach(function(pattern,i){ >- let pattern_subquery_or = []; >- defaultPatronSearchFields.split(',').forEach(function(field,i){ >- pattern_subquery_or.push( >- { ["me." + field]: { 'like': leading_wildcard + pattern + '%' } } >- ); >- }); >- pattern_subquery_and.push(pattern_subquery_or); >- }); >- q.push({ "-and": pattern_subquery_and }); >- >- // Add full search term for each search field >- let term_subquery_or = []; >- defaultPatronSearchFields.split(',').forEach(function (field, i) { >- term_subquery_or.push( >- { ["me." + field]: { 'like': leading_wildcard + request.term + '%' } } >- ); >- }); >- q.push({ "-or": term_subquery_or }); >- >- let params = { >- '_page': 1, >- '_per_page': 10, >- 'q': JSON.stringify(q), >- '_order_by': '+me.surname,+me.firstname', >- }; >- $.ajax({ >- data: params, >- type: 'GET', >- url: '/api/v1/patrons', >- headers: { >- "x-koha-embed": "library" >- }, >- success: function(data) { >- return response(data); >- }, >- error: function(e) { >- if ( e.state() != 'rejected' ) { >- alert( __("An error occurred. Check the logs") ); >- } >- return response(); >- } >- }); >- }, >- minLength: 3, >- select: function( event, ui ) { >- if ( ui.item.link ) { >- window.location.href = ui.item.link; >- } else if ( on_select_callback ) { >- return on_select_callback(event, ui); >- } >- }, >- focus: function( event, ui ) { >- event.preventDefault(); // Don't replace the text field >- }, >- }) >- .data( "ui-autocomplete" ) >- ._renderItem = function( ul, item ) { >- if ( link_to ) { >- item.link = link_to == 'circ' >- ? "/cgi-bin/koha/circ/circulation.pl" >- : link_to == 'reserve' >- ? "/cgi-bin/koha/reserve/request.pl" >- : "/cgi-bin/koha/members/moremember.pl"; >- item.link += ( url_params ? '?' + url_params + '&' : "?" ) + 'borrowernumber=' + item.patron_id; >- } else { >- item.link = null; >- } >- >- var cardnumber = ""; >- if( item.cardnumber != "" ){ >- // Display card number in parentheses if it exists >- cardnumber = " (" + item.cardnumber + ") "; >- } >- if( item.library_id == loggedInLibrary ){ >- loggedInClass = "ac-currentlibrary"; >- } else { >- loggedInClass = ""; >- } >- return $( "<li></li>" ) >- .addClass( loggedInClass ) >- .data( "ui-autocomplete-item", item ) >- .append( >- "" >- + ( item.link ? "<a href=\"" + item.link + "\">" : "<a>" ) >- + ( item.surname ? item.surname.escapeHtml() : "" ) + ", " >- + ( item.firstname ? item.firstname.escapeHtml() : "" ) >- + cardnumber.escapeHtml() >- + " <small>" >- + ( item.date_of_birth >- ? $date(item.date_of_birth) >- + "<span class=\"age_years\"> (" >- + $get_age(item.date_of_birth) >- + " " >- + __("years") >- + ")</span>," >- : "" >- ) + " " >- + $format_address(item, { no_line_break: true, include_li: false }) + " " >- + ( !singleBranchMode >- ? >- "<span class=\"ac-library\">" >- + item.library.name.escapeHtml() >- + "</span>" >- : "" ) >- + "</small>" >- + "</a>" ) >- .appendTo( ul ); >- }; >-} >diff --git a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js >index c4890ae20e..04219caa40 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js >@@ -398,3 +398,138 @@ function saveOrClearSimpleSearchParams() { > localStorage.setItem('cat_search_pulldown_selection', pulldown_selection ); > localStorage.setItem('searchbox_value', searchbox_value ); > } >+ >+function patron_autocomplete(node, options) { >+ let link_to; >+ let url_params; >+ let on_select_callback; >+ let leading_wildcard = defaultPatronSearchMethod === 'contains' ? '%' : ''; >+ if (options) { >+ if (options['link-to']) { >+ link_to = options['link-to']; >+ } >+ if (options['url-params']) { >+ url_params = options['url-params']; >+ } >+ if (options['on-select-callback']) { >+ on_select_callback = options['on-select-callback']; >+ } >+ } >+ return node.autocomplete({ >+ source: function (request, response) { >+ let q = [] >+ >+ // Add each pattern in search term for each search field >+ let pattern_subquery_and = []; >+ request.term.split(/[\s,]+/) >+ .filter(function (s) { return s.length }) >+ .forEach(function (pattern, i) { >+ let pattern_subquery_or = []; >+ defaultPatronSearchFields.split(',').forEach(function (field, i) { >+ pattern_subquery_or.push( >+ { ["me." + field]: { 'like': leading_wildcard + pattern + '%' } } >+ ); >+ }); >+ pattern_subquery_and.push(pattern_subquery_or); >+ }); >+ q.push({ "-and": pattern_subquery_and }); >+ >+ // Add full search term for each search field >+ let term_subquery_or = []; >+ defaultPatronSearchFields.split(',').forEach(function (field, i) { >+ term_subquery_or.push( >+ { ["me." + field]: { 'like': leading_wildcard + request.term + '%' } } >+ ); >+ }); >+ q.push({ "-or": term_subquery_or }); >+ >+ let params = { >+ '_page': 1, >+ '_per_page': 10, >+ 'q': JSON.stringify(q), >+ '_order_by': '+me.surname,+me.firstname', >+ }; >+ $.ajax({ >+ data: params, >+ type: 'GET', >+ url: '/api/v1/patrons', >+ headers: { >+ "x-koha-embed": "library" >+ }, >+ success: function (data) { >+ return response(data); >+ }, >+ error: function (e) { >+ if (e.state() != 'rejected') { >+ alert(__("An error occurred. Check the logs")); >+ } >+ return response(); >+ } >+ }); >+ }, >+ minLength: 3, >+ select: function (event, ui) { >+ if (ui.item.link) { >+ window.location.href = ui.item.link; >+ } else if (on_select_callback) { >+ return on_select_callback(event, ui); >+ } >+ }, >+ focus: function (event, ui) { >+ event.preventDefault(); // Don't replace the text field >+ }, >+ }) >+ .data("ui-autocomplete") >+ ._renderItem = function (ul, item) { >+ if (link_to) { >+ item.link = link_to == 'circ' >+ ? "/cgi-bin/koha/circ/circulation.pl" >+ : link_to == 'reserve' >+ ? "/cgi-bin/koha/reserve/request.pl" >+ : "/cgi-bin/koha/members/moremember.pl"; >+ item.link += (url_params ? '?' + url_params + '&' : "?") + 'borrowernumber=' + item.patron_id; >+ } else { >+ item.link = null; >+ } >+ >+ var cardnumber = ""; >+ if (item.cardnumber != "") { >+ // Display card number in parentheses if it exists >+ cardnumber = " (" + item.cardnumber + ") "; >+ } >+ if (item.library_id == loggedInLibrary) { >+ loggedInClass = "ac-currentlibrary"; >+ } else { >+ loggedInClass = ""; >+ } >+ return $("<li></li>") >+ .addClass(loggedInClass) >+ .data("ui-autocomplete-item", item) >+ .append( >+ "" >+ + (item.link ? "<a href=\"" + item.link + "\">" : "<a>") >+ + (item.surname ? item.surname.escapeHtml() : "") + ", " >+ + (item.firstname ? item.firstname.escapeHtml() : "") >+ + cardnumber.escapeHtml() >+ + " <small>" >+ + (item.date_of_birth >+ ? $date(item.date_of_birth) >+ + "<span class=\"age_years\"> (" >+ + $get_age(item.date_of_birth) >+ + " " >+ + __("years") >+ + ")</span>," >+ : "" >+ ) + " " >+ + $format_address(item, { no_line_break: true, include_li: false }) + " " >+ + (!singleBranchMode >+ ? >+ "<span class=\"ac-library\">" >+ + item.library.name.escapeHtml() >+ + "</span>" >+ : "") >+ + "</small>" >+ + "</a>") >+ .appendTo(ul); >+ }; >+} >-- >2.30.2
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 34092
:
152682
|
152683
|
152684
|
152698
|
152830
|
152831
|
152832
|
152854
|
152855
|
152856
|
152882
|
152883
|
152884
|
152885
|
152891