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

(-)a/koha-tmpl/intranet-tmpl/prog/js/datatables.js (-14 / +15 lines)
Lines 492-506 jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { Link Here
492
492
493
    /**
493
    /**
494
    * Create a new dataTables instance that uses the Koha RESTful API's as a data source
494
    * Create a new dataTables instance that uses the Koha RESTful API's as a data source
495
    * @param  {Object}  options         Please see the dataTables documentation for further details
495
    * @param  {Object}  options                      Please see the dataTables settings documentation for further
496
    *                                   We extend the options set with the `criteria` key which allows
496
    *                                                details
497
    *                                   the developer to select the match type to be applied during searches
497
    * @param  {string}  [options.criteria=contains]  A koha specific extension to the dataTables settings block that
498
    *                                   Valid keys are: `contains`, `starts_with`, `ends_with` and `exact`
498
    *                                                allows setting the 'comparison operator' used in searches
499
    * @param  {Object}  table_settings The arrayref as returned by TableSettings.GetTableSettings function available
499
    *                                                Supports `contains`, `starts_with`, `ends_with` and `exact` match
500
    *                                   from the columns_settings template toolkit include
500
    * @param  {string}  [options.columns.*.criteria] As above, but at the column definition level
501
    * @param  {Boolean} add_filters     Add a filters row as the top row of the table
501
    * @param  {Object}  table_settings               The arrayref as returned by TableSettings.GetTableSettings function
502
    * @param  {Object}  default_filters Add a set of default search filters to apply at table initialisation
502
    *                                                available from the columns_settings template toolkit include
503
    * @return {Object}                  The dataTables instance
503
    * @param  {Boolean} add_filters                  Add a filters row as the top row of the table
504
    * @param  {Object}  default_filters              Add a set of default search filters to apply at table initialisation
505
    * @return {Object}                               The dataTables instance
504
    */
506
    */
505
    $.fn.kohaTable = function(options, table_settings, add_filters, default_filters) {
507
    $.fn.kohaTable = function(options, table_settings, add_filters, default_filters) {
506
        var settings = null;
508
        var settings = null;
Lines 570-576 jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { Link Here
570
                                    _per_page: length
572
                                    _per_page: length
571
                                };
573
                                };
572
574
573
                                function build_query(col, value){
575
                                function build_query(col, value, is_column){
574
576
575
                                    // escape SQL special characters
577
                                    // escape SQL special characters
576
                                    value = value.replace(/(\%|\_|\\)/g, "\\$1" );
578
                                    value = value.replace(/(\%|\_|\\)/g, "\\$1" );
Lines 580-586 jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { Link Here
580
                                    for (var i=0;i<attributes.length;i++){
582
                                    for (var i=0;i<attributes.length;i++){
581
                                        var part = {};
583
                                        var part = {};
582
                                        var attr = attributes[i];
584
                                        var attr = attributes[i];
583
                                        let criteria = options.criteria;
585
                                        let criteria = is_column ? col.criteria || options.criteria : options.criteria;
584
                                        if ( value.match(/^\^(.*)\$$/) ) {
586
                                        if ( value.match(/^\^(.*)\$$/) ) {
585
                                            value = value.replace(/^\^/, '').replace(/\$$/, '');
587
                                            value = value.replace(/^\^/, '').replace(/\$$/, '');
586
                                            criteria = "exact";
588
                                            criteria = "exact";
Lines 601-607 jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { Link Here
601
                                })
603
                                })
602
                                .map(function(col) {
604
                                .map(function(col) {
603
                                    var value = data.columns[col.idx].search.value;
605
                                    var value = data.columns[col.idx].search.value;
604
                                    return build_query(col, value)
606
                                    return build_query(col, value, 1)
605
                                })
607
                                })
606
                                .map(function r(e){
608
                                .map(function r(e){
607
                                    return ($.isArray(e) ? $.map(e, r) : e);
609
                                    return ($.isArray(e) ? $.map(e, r) : e);
Lines 614-620 jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { Link Here
614
                                })
616
                                })
615
                                .map(function(col) {
617
                                .map(function(col) {
616
                                    var value = filter;
618
                                    var value = filter;
617
                                    return build_query(col, value)
619
                                    return build_query(col, value, 0)
618
                                })
620
                                })
619
                                .map(function r(e){
621
                                .map(function r(e){
620
                                    return ($.isArray(e) ? $.map(e, r) : e);
622
                                    return ($.isArray(e) ? $.map(e, r) : e);
621
- 

Return to bug 29302