Bug 12451 - circulation rule cant be edited if itemtype contains a space character
authorFridolin Somers <fridolin.somers@biblibre.com>
Thu, 19 Jun 2014 08:17:53 +0000 (10:17 +0200)
committerFridolin Somers <fridolin.somers@biblibre.com>
Fri, 12 Dec 2014 08:11:43 +0000 (09:11 +0100)
When an itemtype description contains a space character like " Book"
(often used to set this itemtype as first in sorted lists), the edition
of an existing circulation rule does not work, it selects the default
itemtype. Same for patron category.

It's because the JavaScript code performs a trim on value existing in
table itm = itm.replace(/^\s*|\s*$/g,''); This patch adds trim on select
options in editing line.

Test plan :
- Create an itemtype with a leading or trailling space in description :
  ie " Book"
- Go to cgi-bin/koha/admin/smart-rules.pl
- Create a rule with this itemtype, Unit=hours and Hard due date=Exactly
  on 31/12/2015 (any date)
- Click on Edit on this rule line
  => Without this patch, the default itemtype is selected in edition
     line
  => With this patch, the correct itemtype is selected in edition line

Check others selects are ok :
  - Create a rule with Unit=hours and Hard due date=Exactly on
    31/12/2015 (any date)
  - Click on Edit on this rule line
    => The correct options are selected
Same tests with a patron category containing a leading or trailling space in description

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 4b316bf85681fca76b45463b7152f2e34a018c55)

koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt

index 1c83cc0..8ec6ddf 100644 (file)
@@ -42,7 +42,9 @@ $(document).ready(function() {
                     $(current_column).find("input[type='text']").val(itm);
                     // select the corresponding option
                     $(current_column).find("select option").each(function(){
-                        if ( $(this).text().toLowerCase() == itm.toLowerCase() ) {
+                        opt = $(this).text().toLowerCase();
+                        opt = opt.replace(/^\s*|\s*$/g,'');
+                        if ( opt == itm.toLowerCase() ) {
                             $(this).attr('selected', 'selected');
                         }
                     });