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

(-)a/koha-tmpl/intranet-tmpl/prog/js/datatables.js (+91 lines)
Lines 502-504 function filterDataTable( table, column, term ){ Link Here
502
        table.search( term ).draw("page");
502
        table.search( term ).draw("page");
503
    }
503
    }
504
}
504
}
505
506
jQuery.fn.dataTable.ext.errMode = function(settings, note, message) {
507
    console.warn(message);
508
};
509
510
(function($) {
511
512
    $.fn.api = function(options) {
513
        var settings = null;
514
        if(options) {
515
            settings = $.extend(true, {}, dataTablesDefaults, {
516
                        'deferRender': true,
517
                        "paging": true,
518
                        'serverSide': true,
519
                        'searching': true,
520
                        'pagingType': 'full',
521
                        'ajax': {
522
                            'type': 'GET',
523
                            'cache': true,
524
                            'dataSrc': 'data',
525
                            'beforeSend': function(xhr, settings) {
526
                                this._xhr = xhr;
527
                                if(options.embed) {
528
                                    xhr.setRequestHeader('x-koha-embed', Array.isArray(options.embed)?options.embed.join(','):options.embed);
529
                                }
530
                                if(options.header_filter && options.query_parameters) {
531
                                    xhr.setRequestHeader('x-koha-query', options.query_parameters);
532
                                    delete options.query_parameters;
533
                                }
534
                            },
535
                            'dataFilter': function(data, type) {
536
                                var json = {data: JSON.parse(data)};
537
                                if(total = this._xhr.getResponseHeader('x-total-count')) {
538
                                    json.recordsTotal = total;
539
                                    json.recordsFiltered = total;
540
                                }
541
                                return JSON.stringify(json);
542
                            },
543
                            'data': function( data, settings ) {
544
                                var length = data.length;
545
                                var start  = data.start;
546
547
                                var dataSet = {
548
                                    _page: Math.floor(start/length) + 1,
549
                                    _per_page: length
550
                                };
551
552
                                var filter = data.search.value;
553
                                var query_parameters = settings.aoColumns
554
                                .filter(function(col) {
555
                                    return col.bSearchable && typeof col.data == 'string' && (data.columns[col.idx].search.value != '' || filter != '')
556
                                })
557
                                .map(function(col) {
558
                                    var part = {};
559
                                    part[!col.data.includes('.')?'me.'+col.data:col.data] = {like: (data.columns[col.idx].search.value != '' ? data.columns[col.idx].search.value : filter)+'%'};
560
                                    return part;
561
                                });
562
563
                                if(query_parameters.length) {
564
                                    query_parameters = JSON.stringify(query_parameters.length === 1?query_parameters[0]:query_parameters);
565
                                    if(options.header_filter) {
566
                                        options.query_parameters = query_parameters;
567
                                    } else {
568
                                        dataSet.q = query_parameters;
569
                                        delete options.query_parameters;
570
                                    }
571
                                } else {
572
                                    delete options.query_parameters;
573
                                }
574
575
                                dataSet._match = 'starts_with';
576
577
                                if(options.columns) {
578
                                    var order = data.order;
579
                                    order.forEach(function (e,i) {
580
                                        var order_col      = e.column;
581
                                        var order_by       = options.columns[order_col].data;
582
                                        var order_dir      = e.dir == 'asc' ? '+' : '-';
583
                                        dataSet._order_by = order_dir + (!order_by.includes('.')?'me.'+order_by:order_by);
584
                                    });
585
                                }
586
587
                                return dataSet;
588
                            }
589
                        }
590
                    }, options);
591
        }
592
        return $(this).dataTable(settings);
593
    };
594
595
})(jQuery);
(-)a/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js (-1 / +91 lines)
Lines 123-125 jQuery.extend( jQuery.fn.dataTableExt.sort, { Link Here
123
    });
123
    });
124
124
125
}());
125
}());
126
- 
126
127
jQuery.fn.dataTable.ext.errMode = function(settings, note, message) {
128
    console.warn(message);
129
};
130
131
(function($) {
132
133
    $.fn.api = function(options) {
134
        var settings = null;
135
        if(options) {
136
            settings = $.extend(true, {}, dataTablesDefaults, {
137
                        'deferRender': true,
138
                        "paging": true,
139
                        'serverSide': true,
140
                        'searching': true,
141
                        'pagingType': 'full',
142
                        'ajax': {
143
                            'type': 'GET',
144
                            'cache': true,
145
                            'dataSrc': 'data',
146
                            'beforeSend': function(xhr, settings) {
147
                                this._xhr = xhr;
148
                                if(options.embed) {
149
                                    xhr.setRequestHeader('x-koha-embed', Array.isArray(options.embed)?options.embed.join(','):options.embed);
150
                                }
151
                                if(options.header_filter && options.query_parameters) {
152
                                    xhr.setRequestHeader('x-koha-query', options.query_parameters);
153
                                    delete options.query_parameters;
154
                                }
155
                            },
156
                            'dataFilter': function(data, type) {
157
                                var json = {data: JSON.parse(data)};
158
                                if(total = this._xhr.getResponseHeader('x-total-count')) {
159
                                    json.recordsTotal = total;
160
                                    json.recordsFiltered = total;
161
                                }
162
                                return JSON.stringify(json);
163
                            },
164
                            'data': function( data, settings ) {
165
                                var length = data.length;
166
                                var start  = data.start;
167
168
                                var dataSet = {
169
                                    _page: Math.floor(start/length) + 1,
170
                                    _per_page: length
171
                                };
172
173
                                var filter = data.search.value;
174
                                var query_parameters = settings.aoColumns
175
                                .filter(function(col) {
176
                                    return col.bSearchable && typeof col.data == 'string' && (data.columns[col.idx].search.value != '' || filter != '')
177
                                })
178
                                .map(function(col) {
179
                                    var part = {};
180
                                    part[!col.data.includes('.')?'me.'+col.data:col.data] = {like: (data.columns[col.idx].search.value != '' ? data.columns[col.idx].search.value : filter)+'%'};
181
                                    return part;
182
                                });
183
184
                                if(query_parameters.length) {
185
                                    query_parameters = JSON.stringify(query_parameters.length === 1?query_parameters[0]:query_parameters);
186
                                    if(options.header_filter) {
187
                                        options.query_parameters = query_parameters;
188
                                    } else {
189
                                        dataSet.q = query_parameters;
190
                                        delete options.query_parameters;
191
                                    }
192
                                } else {
193
                                    delete options.query_parameters;
194
                                }
195
196
                                dataSet._match = 'starts_with';
197
198
                                if(options.columns) {
199
                                    var order = data.order;
200
                                    order.forEach(function (e,i) {
201
                                        var order_col      = e.column;
202
                                        var order_by       = options.columns[order_col].data;
203
                                        var order_dir      = e.dir == 'asc' ? '+' : '-';
204
                                        dataSet._order_by = order_dir + (!order_by.includes('.')?'me.'+order_by:order_by);
205
                                    });
206
                                }
207
208
                                return dataSet;
209
                            }
210
                        }
211
                    }, options);
212
        }
213
        return $(this).dataTable(settings);
214
    };
215
216
})(jQuery);

Return to bug 24561