Bugzilla – Attachment 161446 Details for
Bug 35908
There is no length limit for what's presented in datatables
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35908: Add truncateStringForDisplay
Bug-35908-Add-truncateStringForDisplay.patch (text/plain), 4.96 KB, created by
Pedro Amorim
on 2024-01-25 16:19:55 UTC
(
hide
)
Description:
Bug 35908: Add truncateStringForDisplay
Filename:
MIME Type:
Creator:
Pedro Amorim
Created:
2024-01-25 16:19:55 UTC
Size:
4.96 KB
patch
obsolete
>From 38c71d7d7fcc191a67b83ae793b035ebcfaedb58 Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@ptfs-europe.com> >Date: Thu, 25 Jan 2024 15:08:11 -0100 >Subject: [PATCH] Bug 35908: Add truncateStringForDisplay > >Test plan: >1) Create a new patron category, visit: >/cgi-bin/koha/admin/categories.pl?op=add_form >2) Add a category code, en enrollment period, a category type and a really long description like: >"This is a real long description of the patron category code for demo purposes This is a real long description of the patron category code for demo purposes"" >3) Now do the same but for a library, visit: >/cgi-bin/koha/admin/branches.pl?op=add_form >4) Add a library code and a really long name like: >"This is a real long library name for demo purposes This is a real long library name for demo purposes" >5) Visit patrons home: >/cgi-bin/koha/members/members-home.pl >6) Hit "Search". Notice the "library" and "category" columns grow in width to match the largest option (added in previous steps) >7) Edit a patron, assign that patron the library and category above, go back to the table. >8) Repeat 5) and 6). Notice how the table looks >9) Apply patch. Refresh the patron table and notice how it looks. >--- > .../prog/en/includes/patron-search.inc | 4 ++-- > koha-tmpl/intranet-tmpl/prog/js/datatables.js | 2 +- > koha-tmpl/intranet-tmpl/prog/js/staff-global.js | 16 ++++++++++++++++ > 3 files changed, 19 insertions(+), 3 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc >index 11fc20a8e2b..de7359edadf 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc >@@ -513,7 +513,7 @@ > if( !singleBranchMode && data == logged_in_library_id ) { > return "<span class=\"currentlibrary\">" + escape_str(library_name) + "</span>"; > } else { >- return escape_str(library_name); >+ return escape_str(truncateStringForDisplay(library_name)); > } > } > } >@@ -523,7 +523,7 @@ > "searchable": true, > "orderable": true, > "render": function( data, type, row, meta ) { >- return escape_str(categories_map[data.toLowerCase()].description); >+ return escape_str(truncateStringForDisplay(categories_map[data.toLowerCase()].description)); > } > } > [% CASE 'dateexpiry' %] >diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js >index 73a1900326e..8c70b66cc05 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js >@@ -846,7 +846,7 @@ function _dt_add_filters(table_node, table_dt, filters_options = {}) { > filters_options[i] = filters_options[i]() > } > $(filters_options[i]).each(function(){ >- let o = $('<option value="%s">%s</option>'.format(this._id, this._str)); >+ let o = $('<option value="%s" title="%s">%s</option>'.format(this._id, this._str, truncateStringForDisplay(this._str))); > if ( existing_search === this._id ) { > o.prop("selected", "selected"); > } >diff --git a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js >index ab24a9304e2..cf2e2d6ae88 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js >@@ -339,6 +339,22 @@ function playSound( sound ) { > document.getElementById("audio-alert").innerHTML = '<audio src="' + sound + '" autoplay="autoplay" autobuffer="autobuffer"></audio>'; > } > >+/** >+ * Truncates a given string to a specified number of characters while preserving whole words. >+ * >+ * @param {string} string - The input string to be truncated >+ * @param {number} [chars=50] - The number of characters to truncate the string to >+ * @return {string} The truncated string with whole words preserved >+ */ >+function truncateStringForDisplay(string, chars=50) { >+ if (chars >= string.length) return string; >+ let truncated_str = string.substring(0, chars); >+ let last_word_boundary = truncated_str.match(/\b/gi).pop(); >+ let last_word_boundary_index = >+ truncated_str.lastIndexOf(last_word_boundary); >+ return truncated_str.substring(0, last_word_boundary_index) + "..."; >+} >+ > // For keeping the text when navigating the search tabs > function keep_text(clicked_index) { > var searchboxes = document.getElementsByClassName("head-searchbox"); >-- >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 35908
: 161446 |
161529
|
161530
|
161536