|
96 | 96 | var pluginName = 'ufTable', |
97 | 97 | defaults = { |
98 | 98 | DEBUG : false, |
| 99 | + site : site, // global site variables |
99 | 100 | dataUrl : '', |
100 | 101 | msgTarget : $('#alerts-page'), |
101 | 102 | addParams : {}, |
|
224 | 225 | this.settings = $.extend(true, {}, defaults, lateDefaults, options); |
225 | 226 | this._defaults = defaults; |
226 | 227 | this._name = pluginName; |
| 228 | + this._debugAjax = (typeof this.settings.site !== 'undefined') && this.settings.site.debug.ajax; |
227 | 229 |
|
228 | 230 | // Fall back to attributes from data-*, default values if not specified in options |
229 | 231 | var pagerContainer = this.settings.tablesorter.widgetOptions.pager_selectors.container; |
|
279 | 281 |
|
280 | 282 | // Locate and compile templates for any string-identified column renderers |
281 | 283 | // At the same time, build out a numerically indexed array of templates |
282 | | - this.columnTemplates = []; |
| 284 | + this.columnTemplatesIndexed = []; |
283 | 285 | for (var col = 0; col < columns.length; col++) { |
284 | 286 | var columnName = columns[col].data('column-name'); |
285 | 287 | if (!columnTemplates[columnName] && this.settings.DEBUG) { |
286 | 288 | console.error("No template found for column '" + columnName + "'."); |
287 | 289 | } |
288 | 290 | var columnTemplate = columnTemplates[columnName]; |
289 | 291 | if (typeof columnTemplate === 'string') { |
290 | | - this.columnTemplates.push(Handlebars.compile($(columnTemplate).html())); |
| 292 | + this.columnTemplatesIndexed.push(Handlebars.compile($(columnTemplate).html())); |
291 | 293 | } else { |
292 | | - this.columnTemplates.push(columnTemplate); |
| 294 | + this.columnTemplatesIndexed.push(columnTemplate); |
293 | 295 | } |
294 | 296 | } |
295 | 297 |
|
296 | 298 | // Locate and compile row template |
297 | 299 | this.rowTemplate = Handlebars.compile('<tr>'); |
298 | | - // If rowTemplateSelector is set, then find the DOM element that it references, which contains the template |
| 300 | + // If rowTemplateSelector is set, then find the DOM element that it references, which contains the template |
299 | 301 | if (this.settings.rowTemplate) { |
300 | 302 | var rowTemplate = this.settings.rowTemplate; |
301 | 303 | if (typeof rowTemplate === 'string') { |
|
339 | 341 |
|
340 | 342 | // Get sort column and order |
341 | 343 | var sortOrders = { |
342 | | - '0' : 'asc', |
343 | | - '1' : 'desc' |
| 344 | + '0': 'asc', |
| 345 | + '1': 'desc' |
344 | 346 | }; |
345 | 347 |
|
346 | 348 | // Set sorts in URL. Assumes each th has a data-column-name attribute that corresponds to the name in the API |
|
440 | 442 | var cellData = { |
441 | 443 | rownum: row, |
442 | 444 | row : data.rows[row], // It is safe to use the data from the API because Handlebars escapes HTML |
443 | | - site : site |
| 445 | + site : this.settings.site |
444 | 446 | }; |
445 | 447 |
|
446 | 448 | rows += this.rowTemplate(cellData); |
447 | 449 |
|
448 | | - for (var col = 0; col < this.columnTemplates.length; col++) { |
449 | | - rows += this.columnTemplates[col](cellData); |
| 450 | + for (var col = 0; col < this.columnTemplatesIndexed.length; col++) { |
| 451 | + rows += this.columnTemplatesIndexed[col](cellData); |
450 | 452 | } |
451 | 453 |
|
452 | 454 | rows += '</tr>'; |
|
530 | 532 | Plugin.prototype._ajaxError = function(jqXHR) { |
531 | 533 | if (typeof jqXHR === 'object') { |
532 | 534 | // Error messages |
533 | | - if ((typeof site !== 'undefined') && site.debug.ajax && jqXHR.responseText) { |
| 535 | + if (this._debugAjax && jqXHR.responseText) { |
534 | 536 | document.write(jqXHR.responseText); |
535 | 537 | document.close(); |
536 | 538 | } else { |
|
617 | 619 | if (component === 'filter') { |
618 | 620 | var decodedFilters = []; |
619 | 621 | // Extract filter names and values for the specified table |
620 | | - var filters = urlObject.filter ? urlObject.filter : []; |
621 | | - if (filters[tableId]) { |
622 | | - var filters = filters[tableId]; |
| 622 | + var pageFilters = urlObject.filter ? urlObject.filter : []; |
| 623 | + if (pageFilters[tableId]) { |
| 624 | + var tableFilters = pageFilters[tableId]; |
623 | 625 | // Build a numerically indexed array of filter values |
624 | 626 | var len = config.$headerIndexed.length; |
625 | 627 | for (var index = 0; index < len; index++) { |
626 | 628 | var columnName = $(config.$headerIndexed[index][0]).attr(wo.sort2Hash_headerTextAttr); |
627 | | - if (filters[columnName] && filters[columnName] != this.settings.filterAllField) { |
628 | | - decodedFilters.push(filters[columnName]); |
| 629 | + if (tableFilters[columnName] && tableFilters[columnName] != this.settings.filterAllField) { |
| 630 | + decodedFilters.push(tableFilters[columnName]); |
629 | 631 | } else { |
630 | 632 | decodedFilters.push(''); |
631 | 633 | } |
632 | 634 | } |
633 | 635 | // Convert array of filter values to a delimited string |
634 | 636 | result = decodedFilters.join(wo.sort2Hash_separator); |
635 | 637 | // make sure to use decodeURIComponent on the result |
636 | | - return decodeURIComponent( result ); |
| 638 | + return decodeURIComponent(result); |
637 | 639 | } else { |
638 | 640 | return ''; |
639 | 641 | } |
|
0 commit comments