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

(-)a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js (-11 / +21 lines)
Lines 518-530 function patron_autocomplete(node, options) { Link Here
518
 * Build patron search query
518
 * Build patron search query
519
 * - term: The full search term input by the user
519
 * - term: The full search term input by the user
520
 * You can then pass a list of options:
520
 * You can then pass a list of options:
521
 * - search_type: String 'contains' or 'starts_with', defaults to DefaultPatronSearchMethod system preference
521
 * - search_type: (String) 'contains' or 'starts_with', defaults to defaultPatronSearchMethod (see js_includes.inc)
522
 * - search_fields: String comma-separated list of specific fields, defaults to DefaultPatronSearchFields system preference
522
 * - search_fields: (String) comma-separated list of specific fields, defaults to defaultPatronSearchFields (see js_includes.inc)
523
 * - extended_attribute_types: JSON object containing the patron attribute types to be searched on
523
 * - extended_attribute_types: (JSON object) contains the patron searchable attribute types to be searched on (see patron-search.inc)
524
 * - table_prefix: (String) table name to prefix the fields with, defaults to 'me'
524
 */
525
 */
525
function buildPatronSearchQuery(term, options) {
526
function buildPatronSearchQuery(term, options) {
526
527
527
    let q = [];
528
    let q = [];
529
    let table_prefix;
528
    let leading_wildcard;
530
    let leading_wildcard;
529
    let search_fields;
531
    let search_fields;
530
    let patterns = term.split(/[\s,]+/).filter(function (s) { return s.length });
532
    let patterns = term.split(/[\s,]+/).filter(function (s) { return s.length });
Lines 534-551 function buildPatronSearchQuery(term, options) { Link Here
534
        return;
536
        return;
535
    }
537
    }
536
538
537
    // Leading wildcard: If search_type option exists, we use that
539
    // Table prefix: If table_prefix options exists, use that
540
    if (typeof options !== 'undefined' && options.table_prefix) {
541
        table_prefix = options.table_prefix;
542
    // If not, default to 'me'
543
    } else {
544
        table_prefix = 'me';
545
    }
546
547
    // Leading wildcard: If search_type option exists, use that
538
    if (typeof options !== 'undefined' && options.search_type) {
548
    if (typeof options !== 'undefined' && options.search_type) {
539
        leading_wildcard = options.search_type === "contains" ? '%' : '';
549
        leading_wildcard = options.search_type === "contains" ? '%' : '';
540
    // If not, we use DefaultPatronSearchMethod system preference instead
550
    // If not, use DefaultPatronSearchMethod system preference instead
541
    } else {
551
    } else {
542
        leading_wildcard = defaultPatronSearchMethod === 'contains' ? '%' : '';
552
        leading_wildcard = defaultPatronSearchMethod === 'contains' ? '%' : '';
543
    }
553
    }
544
554
545
    // Search fields: If search_fields option exists, we use that
555
    // Search fields: If search_fields option exists, use that
546
    if (typeof options !== 'undefined' && options.search_fields) {
556
    if (typeof options !== 'undefined' && options.search_fields) {
547
        search_fields = options.search_fields;
557
        search_fields = options.search_fields;
548
    // If not, we use DefaultPatronSearchFields system preference instead
558
    // If not, use DefaultPatronSearchFields system preference instead
549
    } else {
559
    } else {
550
        search_fields = defaultPatronSearchFields;
560
        search_fields = defaultPatronSearchFields;
551
    }
561
    }
Lines 556-567 function buildPatronSearchQuery(term, options) { Link Here
556
            let pattern_subquery_or = [];
566
            let pattern_subquery_or = [];
557
            defaultPatronSearchFields.split(',').forEach(function (field, i) {
567
            defaultPatronSearchFields.split(',').forEach(function (field, i) {
558
                pattern_subquery_or.push(
568
                pattern_subquery_or.push(
559
                    { ["me." + field]: { 'like': leading_wildcard + pattern + '%' } }
569
                    { [table_prefix + "." + field]: { 'like': leading_wildcard + pattern + '%' } }
560
                );
570
                );
561
                if (field == 'dateofbirth') {
571
                if (field == 'dateofbirth') {
562
                    try {
572
                    try {
563
                        let d = $date_to_rfc3339(pattern);
573
                        let d = $date_to_rfc3339(pattern);
564
                        pattern_subquery_or.push({ ["me." + field]: d });
574
                        pattern_subquery_or.push({ [table_prefix + "." + field]: d });
565
                    } catch {
575
                    } catch {
566
                        // Hide the warning if the date is not correct
576
                        // Hide the warning if the date is not correct
567
                    }
577
                    }
Lines 575-586 function buildPatronSearchQuery(term, options) { Link Here
575
    let term_subquery_or = [];
585
    let term_subquery_or = [];
576
    defaultPatronSearchFields.split(',').forEach(function (field, i) {
586
    defaultPatronSearchFields.split(',').forEach(function (field, i) {
577
        term_subquery_or.push(
587
        term_subquery_or.push(
578
            { ["me." + field]: { 'like': leading_wildcard + term + '%' } }
588
            { [table_prefix + "." + field]: { 'like': leading_wildcard + term + '%' } }
579
        );
589
        );
580
    });
590
    });
581
    q.push({ "-or": term_subquery_or });
591
    q.push({ "-or": term_subquery_or });
582
592
583
    // Add each pattern for each extended patron attributes
593
    // Add each pattern for each extended patron attributes
594
    // extendedPatronAttributes: ExtendedPatronAttributes system preference (see js_includes.inc)
584
    if (typeof options !== 'undefined' && options.extended_attribute_types && extendedPatronAttributes) {
595
    if (typeof options !== 'undefined' && options.extended_attribute_types && extendedPatronAttributes) {
585
        extended_attribute_subquery_and = [];
596
        extended_attribute_subquery_and = [];
586
        patterns.forEach(function (pattern, i) {
597
        patterns.forEach(function (pattern, i) {
587
- 

Return to bug 34058