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

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patronfields.inc (+9 lines)
Lines 99-103 Link Here
99
                <option value=[% s_o | html %]>[% display_name | $raw %]</option>
99
                <option value=[% s_o | html %]>[% display_name | $raw %]</option>
100
            [% END %]
100
            [% END %]
101
        [% END %]
101
        [% END %]
102
        [% IF Koha.Preference('ExtendedPatronAttributes') %]
103
            [% FOREACH attribute IN ExtendedAttributeTypes.all( staff_searchable => 1 ) %]
104
                [% IF searchfieldstype == "_ATTR_" _ attribute.code %]
105
                    <option value=[% "_ATTR_" _ attribute.code | html %] selected="selected">[% attribute.description | html %]</option>
106
                [% ELSE %]
107
                    <option value=[% "_ATTR_" _ attribute.code | html %]>[% attribute.description | html %]</option>
108
                [% END %]
109
            [% END %]
110
        [% END %]
102
    </select>
111
    </select>
103
[%- END -%]
112
[%- END -%]
(-)a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js (-7 / +17 lines)
Lines 575-581 function buildPatronSearchQuery(term, options) { Link Here
575
575
576
    let q = [];
576
    let q = [];
577
    let leading_wildcard;
577
    let leading_wildcard;
578
    let search_fields;
578
    let search_fields = [];
579
    let patterns = term.split(/[\s,]+/).filter(function (s) { return s.length });
579
    let patterns = term.split(/[\s,]+/).filter(function (s) { return s.length });
580
580
581
    // Bail if no patterns
581
    // Bail if no patterns
Lines 591-599 function buildPatronSearchQuery(term, options) { Link Here
591
        leading_wildcard = defaultPatronSearchMethod === 'contains' ? '%' : '';
591
        leading_wildcard = defaultPatronSearchMethod === 'contains' ? '%' : '';
592
    }
592
    }
593
593
594
    let searched_attribute_fields = [];
594
    // Search fields: If search_fields option exists, we use that
595
    // Search fields: If search_fields option exists, we use that
595
    if (typeof options !== 'undefined' && options.search_fields) {
596
    if (typeof options !== 'undefined' && options.search_fields) {
596
        search_fields = expandPatronSearchFields(options.search_fields);
597
        expand_fields = expandPatronSearchFields(options.search_fields);
598
        expand_fields.split('\|').forEach(function (field, i) {
599
            if( field.startsWith('_ATTR_') ){
600
                let attr_field = field.replace("_ATTR_","");
601
                searched_attribute_fields.push( attr_field );
602
            } else {
603
                search_fields.push( field );
604
            }
605
        });
597
    // If not, we use DefaultPatronSearchFields system preference instead
606
    // If not, we use DefaultPatronSearchFields system preference instead
598
    } else {
607
    } else {
599
        search_fields = defaultPatronSearchFields;
608
        search_fields = defaultPatronSearchFields;
Lines 603-609 function buildPatronSearchQuery(term, options) { Link Here
603
    let pattern_subquery_and = [];
612
    let pattern_subquery_and = [];
604
    patterns.forEach(function (pattern, i) {
613
    patterns.forEach(function (pattern, i) {
605
            let pattern_subquery_or = [];
614
            let pattern_subquery_or = [];
606
            search_fields.split('\|').forEach(function (field, i) {
615
            search_fields.forEach(function (field, i) {
607
                pattern_subquery_or.push(
616
                pattern_subquery_or.push(
608
                    { ["me." + field]: { 'like': leading_wildcard + pattern + '%' } }
617
                    { ["me." + field]: { 'like': leading_wildcard + pattern + '%' } }
609
                );
618
                );
Lines 620-628 function buildPatronSearchQuery(term, options) { Link Here
620
        });
629
        });
621
    q.push({ "-and": pattern_subquery_and });
630
    q.push({ "-and": pattern_subquery_and });
622
631
632
623
    // Add full search term for each search field
633
    // Add full search term for each search field
624
    let term_subquery_or = [];
634
    let term_subquery_or = [];
625
    search_fields.split('\|').forEach(function (field, i) {
635
    search_fields.forEach(function (field, i) {
626
        term_subquery_or.push(
636
        term_subquery_or.push(
627
            { ["me." + field]: { 'like': leading_wildcard + term + '%' } }
637
            { ["me." + field]: { 'like': leading_wildcard + term + '%' } }
628
        );
638
        );
Lines 630-642 function buildPatronSearchQuery(term, options) { Link Here
630
    q.push({ "-or": term_subquery_or });
640
    q.push({ "-or": term_subquery_or });
631
641
632
    // Add each pattern for each extended patron attributes
642
    // Add each pattern for each extended patron attributes
633
    if (typeof options !== 'undefined' && options.search_fields == 'standard' && options.extended_attribute_types && extendedPatronAttributes) {
643
    if ( typeof options !== 'undefined' && ( (options.search_fields == 'standard' && options.extended_attribute_types) || searched_attribute_fields ) && extendedPatronAttributes) {
644
        extended_attribute_codes_to_search = (searched_attribute_fields.length > 0) ? searched_attribute_fields : options.extended_attribute_types;
634
        extended_attribute_subquery_and = [];
645
        extended_attribute_subquery_and = [];
635
        patterns.forEach(function (pattern, i) {
646
        patterns.forEach(function (pattern, i) {
636
            let extended_attribute_sub_or = [];
647
            let extended_attribute_sub_or = [];
637
            extended_attribute_sub_or.push({
648
            extended_attribute_sub_or.push({
638
                "extended_attributes.value": { "like": leading_wildcard + pattern + '%' },
649
                "extended_attributes.value": { "like": leading_wildcard + pattern + '%' },
639
                "extended_attributes.code": options.extended_attribute_types
650
                "extended_attributes.code": extended_attribute_codes_to_search
640
            });
651
            });
641
            extended_attribute_subquery_and.push(extended_attribute_sub_or);
652
            extended_attribute_subquery_and.push(extended_attribute_sub_or);
642
        });
653
        });
643
- 

Return to bug 26916