View | Details | Raw Unified | Return to bug 34058
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js (-9 / +18 lines)
Lines 567-579 function expandPatronSearchFields(search_fields) { Link Here
567
 * Build patron search query
567
 * Build patron search query
568
 * - term: The full search term input by the user
568
 * - term: The full search term input by the user
569
 * You can then pass a list of options:
569
 * You can then pass a list of options:
570
 * - search_type: String 'contains' or 'starts_with', defaults to DefaultPatronSearchMethod system preference
570
 * - search_type: (String) 'contains' or 'starts_with', defaults to defaultPatronSearchMethod (see js_includes.inc)
571
 * - search_fields: String comma-separated list of specific fields, defaults to DefaultPatronSearchFields system preference
571
 * - search_fields: (String) comma-separated list of specific fields, defaults to defaultPatronSearchFields (see js_includes.inc)
572
 * - extended_attribute_types: JSON object containing the patron attribute types to be searched on
572
 * - extended_attribute_types: (JSON object) contains the patron searchable attribute types to be searched on (see patron-search.inc)
573
 * - table_prefix: (String) table name to prefix the fields with, defaults to 'me'
573
 */
574
 */
574
function buildPatronSearchQuery(term, options) {
575
function buildPatronSearchQuery(term, options) {
575
576
576
    let q = [];
577
    let q = [];
578
    let table_prefix;
577
    let leading_wildcard;
579
    let leading_wildcard;
578
    let search_fields = [];
580
    let search_fields = [];
579
    let patterns = term.split(/[\s,]+/).filter(function (s) { return s.length });
581
    let patterns = term.split(/[\s,]+/).filter(function (s) { return s.length });
Lines 583-592 function buildPatronSearchQuery(term, options) { Link Here
583
        return q;
585
        return q;
584
    }
586
    }
585
587
586
    // Leading wildcard: If search_type option exists, we use that
588
    // Table prefix: If table_prefix options exists, use that
589
    if (typeof options !== 'undefined' && options.table_prefix) {
590
        table_prefix = options.table_prefix;
591
    // If not, default to 'me'
592
    } else {
593
        table_prefix = 'me';
594
    }
595
596
    // Leading wildcard: If search_type option exists, use that
587
    if (typeof options !== 'undefined' && options.search_type) {
597
    if (typeof options !== 'undefined' && options.search_type) {
588
        leading_wildcard = options.search_type === "contains" ? '%' : '';
598
        leading_wildcard = options.search_type === "contains" ? '%' : '';
589
    // If not, we use DefaultPatronSearchMethod system preference instead
599
    // If not, use DefaultPatronSearchMethod system preference instead
590
    } else {
600
    } else {
591
        leading_wildcard = defaultPatronSearchMethod === 'contains' ? '%' : '';
601
        leading_wildcard = defaultPatronSearchMethod === 'contains' ? '%' : '';
592
    }
602
    }
Lines 614-625 function buildPatronSearchQuery(term, options) { Link Here
614
            let pattern_subquery_or = [];
624
            let pattern_subquery_or = [];
615
            search_fields.forEach(function (field, i) {
625
            search_fields.forEach(function (field, i) {
616
                pattern_subquery_or.push(
626
                pattern_subquery_or.push(
617
                    { ["me." + field]: { 'like': leading_wildcard + pattern + '%' } }
627
                    { [table_prefix + "." + field]: { 'like': leading_wildcard + pattern + '%' } }
618
                );
628
                );
619
                if (field == 'dateofbirth') {
629
                if (field == 'dateofbirth') {
620
                    try {
630
                    try {
621
                        let d = $date_to_rfc3339(pattern);
631
                        let d = $date_to_rfc3339(pattern);
622
                        pattern_subquery_or.push({ ["me." + field]: d });
632
                        pattern_subquery_or.push({ [table_prefix + "." + field]: d });
623
                    } catch {
633
                    } catch {
624
                        // Hide the warning if the date is not correct
634
                        // Hide the warning if the date is not correct
625
                    }
635
                    }
Lines 634-640 function buildPatronSearchQuery(term, options) { Link Here
634
    let term_subquery_or = [];
644
    let term_subquery_or = [];
635
    search_fields.forEach(function (field, i) {
645
    search_fields.forEach(function (field, i) {
636
        term_subquery_or.push(
646
        term_subquery_or.push(
637
            { ["me." + field]: { 'like': leading_wildcard + term + '%' } }
647
            { [table_prefix + "." + field]: { 'like': leading_wildcard + term + '%' } }
638
        );
648
        );
639
    });
649
    });
640
    q.push({ "-or": term_subquery_or });
650
    q.push({ "-or": term_subquery_or });
641
- 

Return to bug 34058