Skip to content

Commit c17dcdd

Browse files
committed
ufTable - factor out global site into config variable
1 parent 6d383e3 commit c17dcdd

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

app/sprinkles/core/assets/userfrosting/js/uf-table.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
var pluginName = 'ufTable',
9797
defaults = {
9898
DEBUG : false,
99+
site : site, // global site variables
99100
dataUrl : '',
100101
msgTarget : $('#alerts-page'),
101102
addParams : {},
@@ -224,6 +225,7 @@
224225
this.settings = $.extend(true, {}, defaults, lateDefaults, options);
225226
this._defaults = defaults;
226227
this._name = pluginName;
228+
this._debugAjax = (typeof this.settings.site !== 'undefined') && this.settings.site.debug.ajax;
227229

228230
// Fall back to attributes from data-*, default values if not specified in options
229231
var pagerContainer = this.settings.tablesorter.widgetOptions.pager_selectors.container;
@@ -279,23 +281,23 @@
279281

280282
// Locate and compile templates for any string-identified column renderers
281283
// At the same time, build out a numerically indexed array of templates
282-
this.columnTemplates = [];
284+
this.columnTemplatesIndexed = [];
283285
for (var col = 0; col < columns.length; col++) {
284286
var columnName = columns[col].data('column-name');
285287
if (!columnTemplates[columnName] && this.settings.DEBUG) {
286288
console.error("No template found for column '" + columnName + "'.");
287289
}
288290
var columnTemplate = columnTemplates[columnName];
289291
if (typeof columnTemplate === 'string') {
290-
this.columnTemplates.push(Handlebars.compile($(columnTemplate).html()));
292+
this.columnTemplatesIndexed.push(Handlebars.compile($(columnTemplate).html()));
291293
} else {
292-
this.columnTemplates.push(columnTemplate);
294+
this.columnTemplatesIndexed.push(columnTemplate);
293295
}
294296
}
295297

296298
// Locate and compile row template
297299
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
299301
if (this.settings.rowTemplate) {
300302
var rowTemplate = this.settings.rowTemplate;
301303
if (typeof rowTemplate === 'string') {
@@ -339,8 +341,8 @@
339341

340342
// Get sort column and order
341343
var sortOrders = {
342-
'0' : 'asc',
343-
'1' : 'desc'
344+
'0': 'asc',
345+
'1': 'desc'
344346
};
345347

346348
// Set sorts in URL. Assumes each th has a data-column-name attribute that corresponds to the name in the API
@@ -440,13 +442,13 @@
440442
var cellData = {
441443
rownum: row,
442444
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
444446
};
445447

446448
rows += this.rowTemplate(cellData);
447449

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);
450452
}
451453

452454
rows += '</tr>';
@@ -530,7 +532,7 @@
530532
Plugin.prototype._ajaxError = function(jqXHR) {
531533
if (typeof jqXHR === 'object') {
532534
// Error messages
533-
if ((typeof site !== 'undefined') && site.debug.ajax && jqXHR.responseText) {
535+
if (this._debugAjax && jqXHR.responseText) {
534536
document.write(jqXHR.responseText);
535537
document.close();
536538
} else {
@@ -617,23 +619,23 @@
617619
if (component === 'filter') {
618620
var decodedFilters = [];
619621
// 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];
623625
// Build a numerically indexed array of filter values
624626
var len = config.$headerIndexed.length;
625627
for (var index = 0; index < len; index++) {
626628
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]);
629631
} else {
630632
decodedFilters.push('');
631633
}
632634
}
633635
// Convert array of filter values to a delimited string
634636
result = decodedFilters.join(wo.sort2Hash_separator);
635637
// make sure to use decodeURIComponent on the result
636-
return decodeURIComponent( result );
638+
return decodeURIComponent(result);
637639
} else {
638640
return '';
639641
}

0 commit comments

Comments
 (0)