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

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

Return to bug 24561