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

Return to bug 34058