Commit 9521e6e3 authored by lindonb's avatar lindonb

[REF] tablesorter: place custom jquery in a js file to cut down on code when...

[REF] tablesorter: place custom jquery in a js file to cut down on code when there are multiple tables on a page
parent 9be53c1b
......@@ -3327,6 +3327,7 @@ lib/jquery_tiki/inline_edit.js -text
lib/jquery_tiki/multilike.js -text
lib/jquery_tiki/mustread.js -text
lib/jquery_tiki/social.js -text
lib/jquery_tiki/tablesorter.js -text
lib/jquery_tiki/tiki-admin.js -text
lib/jquery_tiki/tiki-ajax_services.js -text
lib/jquery_tiki/tiki-bootstrapmodalfix.js -text
......
......@@ -51,28 +51,11 @@ class Table_Code_WidgetOptionsPager extends Table_Code_WidgetOptions
//ajax processing - this part grabs the html, usually from the smarty template file
//first prepare code to add a row total column using the math widget if set
if (!empty(parent::$s['math']['totals']['row'])) {
foreach(parent::$s['math']['totals']['row'] as $math) {
$filter = !empty($math['filter']) ? '.attr(\'data-tsmath-filter\', \'' . $math['filter'] . '\');'
: '';
$addcol[] = '$(r.rows).each(function(){$(this).append(\'<td data-tsmath ="row-' . $math['formula']
. '"></td >\')' . $filter . '});';
}
$addcol = implode($this->nt, $addcol);
}
$addcol = !empty(parent::$s['math']['totals']['row']) ?
json_encode(parent::$s['math']['totals']['row']) : 0;
$ap = array(
//parse HTML string from entire page
'var parsedpage = $.parseHTML(data), table = $(parsedpage).find(\'' . parent::$tid . '\'), r = {};',
//extract table body rows from html returned by smarty template file
'r.rows = $(table).find(\'tbody tr\');',
!empty($addcol) ? $addcol : null,
//tablesorter needs total rows
'r.total = \'' . $total . '\';',
//extract number of filtered rows for use in row count display
'r.filteredRows = $(table).data(\'count\');',
'r.headers = null;',
//return object
'return r;'
'var rows = tsAjaxGetRows(data, \'' . parent::$tid . '\', ' . $addcol . ', ' . $total . ');',
'return rows;'
);
$p[] = $this->iterate(
$ap,
......@@ -85,88 +68,16 @@ class Table_Code_WidgetOptionsPager extends Table_Code_WidgetOptions
//customAjaxUrl: takes the url parameters generated by Tablesorter and converts to parameters that can
//be used by Tiki
if (!isset(parent::$s['ajax']['custom']) || parent::$s['ajax']['custom'] !== false) {
if (parent::$usecolselector) {
$sortkey = 'sortkey = \'sort-\' + $(\'' . parent::$tid
. ' th:eq(\' + sortindex + \')\').attr(\'id\');';
$filterkey = 'filterkey = \'filter-\' + $(\'' . parent::$tid
. ' th:eq(\' + filterindex + \')\').attr(\'id\');';
} else {
$sortkey = 'sortkey = \'sort-\' + sortindex';
$filterkey = 'filterkey = \'filter-\' + filterindex';
}
$numrows = !empty(parent::$s['ajax']['numrows']) ? parent::$s['ajax']['numrows'] : 'numrows';
$ca = array(
'var vars = {}, urlparams, oneparam, sort, sorts, sortindex, sortkey, filterindex, filterkey,
offset, filtered, colfilters, extfilters, params = [], dir, newurl, p = table.config.pager,
requiredparams;',
//parse out url parameters
'urlparams = url.slice(url.indexOf(\'?\') + 1).split(\'&\');',
'for(var i = 0; i < urlparams.length; i++) {',
' oneparam = urlparams[i].split(\'=\');',
' if (oneparam[0].search(\'sort\') > -1) {',
' sortindex = parseInt(oneparam[0].substr(5, oneparam[0].length - 6));',
' ' . $sortkey,
' vars[sortkey] = oneparam[1];',
' } else if (oneparam[0].search(\'filter\') > -1) {',
' filterindex = parseInt(oneparam[0].substr(7, oneparam[0].length - 8));',
' ' . $filterkey,
' vars[filterkey] = oneparam[1];',
' }',
'}',
//map of columns keys to sort and filter server side parameters
!empty(parent::$s['ajax']['sort']) ? 'sort = ' . json_encode(parent::$s['ajax']['sort']) . ';' : '',
!empty(parent::$s['ajax']['colfilters'])
? 'colfilters = ' . json_encode(parent::$s['ajax']['colfilters']) . ';' : '',
!empty(parent::$s['ajax']['extfilters'])
? 'extfilters = ' . json_encode(parent::$s['ajax']['extfilters']) . ';' : '',
!empty(parent::$s['ajax']['requiredparams'])
? 'requiredparams = ' . json_encode(parent::$s['ajax']['requiredparams']) . ';' : '',
//iterate through url parameters
'$.each(vars, function(key, value) {',
//handle sort parameters
' if (sort && key in sort) {',
' value == 0 ? dir = \'_asc\' : dir = \'_desc\';',
//add sort if not yet defined or add sort for multiple comma-separated sort parameters
' typeof sorts === \'undefined\' ? sorts = sort[key] + dir : sorts += \',\' + sort[key] + dir;',
' }',
//handle column and external filter parameters
' if ($.inArray(value, extfilters) > -1) {',
' params.push(decodeURIComponent(value));',
' } else if (key in colfilters) {',
' colfilters[key] == value ? params.push(colfilters[key][value]) : params.push(colfilters[key]
+ \'=\' + value);',
' }',
'});',
//convert to tiki sort param sort parameter
'if (sorts) {',
' params.push(\'' . parent::$s['ajax']['sortparam'] . '=\' + sorts);',
'}',
//add any required params
'if (typeof requiredparams !== \'undefined\') {',
' $.each(requiredparams, function(key, value) {',
' params.push(key + \'=\' + value);',
' });',
'}',
//offset parameter
'offset = ((p.page * p.size) >= p.filteredRows) ? \'\' : offset = \'&'
. parent::$s['ajax']['offset'] . '=\' + (p.page * p.size); ',
//build url, starting with no parameters
'newurl = url.slice(0,url.indexOf(\'?\'));',
'newurl = newurl + \'?' . $numrows . '=\' + p.size + offset + \'&tsAjax=y\';',
'$.each(params, function(key, value) {',
' newurl = newurl + \'&\' + value;',
'});',
'return newurl;'
);
} else {
$ca = array(
'var p = table.config.pager, offset;',
'offset = ((p.page * p.size) >= p.filteredRows) ? \'\' : \''
. '&' . parent::$s['ajax']['offset'] . '\' + \'=\' + (p.page * p.size);',
'return url + \'&tsAjax=y\' + offset + \'&numrows=\' + p.size;'
);
}
$ajax = parent::$s['ajax'];
$ajax['asort'] = $ajax['sort'];
unset($ajax['sort']);
$ajax['numrows'] = !empty($ajax['numrows']) ? $ajax['numrows'] : 'numrows';
$ajax['colselector'] = parent::$usecolselector ? 1 : 0;
$ajax['tableid'] = parent::$tid;
$ca = [
'var p = table.config.pager, newurl = tsAjaxUrl(url, p, ' . json_encode($ajax) . ');',
'return newurl;'
];
if (count($ca) > 0) {
array_filter($ca);
$p[] = $this->iterate(
......
/**
* $Id$
*
* Utilities used with tablesorter
*/
/**
* Fetch rows from an ajax pagination call
*
* @param data
* @param id
* @param addcol
* @param total
* @returns {{}}
*/
function tsAjaxGetRows (data, id, addcol, total)
{
//parse HTML string from entire page
var parsedpage = $.parseHTML(data), table = $(parsedpage).find(id), r = {};
//extract table body rows from html returned by smarty template file
r.rows = $(table).find('tbody tr');
//add any math total columns
if (addcol) {
$.each(addcol, function (key, value) {
$(r.rows).append('<td data-tsmath="row-' + value['formula'] + '" data-tsmath-filter="*"></td >');
});
}
//tablesorter needs total rows
r.total = total;
r.headers = null;
return r;
}
/**
* Generate an ajax url
*
* @param url
* @param p
* @param a
* @returns {*}
*/
function tsAjaxUrl (url, p, a) {
var vars = {}, urlparams, oneparam, sorts = false, sortindex, sortkey = 'sort-', filterindex, filterkey = 'filter-',
params = [], dir, offset, newurl;
if (a.custom !== false) {
//parse out url parameters
urlparams = url.slice(url.indexOf('?') + 1).split('&');
for(var i = 0; i < urlparams.length; i++) {
oneparam = urlparams[i].split('=');
if (oneparam[0].search('sort') > -1) {
sortindex = parseInt(oneparam[0].substr(5, oneparam[0].length - 6));
if ($.isNumeric(sortindex)) {
sortkey = a.colselector ? sortkey + $(a.tableid + ' th:eq(' + sortindex + ')').attr('id')
: sortkey + sortindex;
vars[sortkey] = oneparam[1];
}
} else if (oneparam[0].search('filter') > -1) {
filterindex = parseInt(oneparam[0].substr(7, oneparam[0].length - 8));
if ($.isNumeric(filterindex)) {
filterkey = a.colselector ? filterkey + $(a.tableid + ' th:eq(' + filterindex + ')').attr('id')
: filterkey + filterindex;
vars[filterkey] = oneparam[1];
}
}
}
//iterate through url parameters
$.each(vars, function(key, value) {
//handle sort parameters
if (a.asort && key in a.asort) {
dir = value == 0 ? '_asc' : '_desc';
//add sort if not yet defined or add sort for multiple comma-separated sort parameters
!sorts ? sorts = a.asort[key] + dir : sorts += ',' + a.asort[key] + dir;
}
//handle column and external filter parameters
if ($.inArray(value, a.extfilters) > -1) {
params.push(decodeURIComponent(value));
} else if (key in a.colfilters) {
a.colfilters[key] == value ? params.push(a.colfilters[key][value]) : params.push(a.colfilters[key] + '='
+ value);
}
});
//convert to tiki sort param sort parameter
if (sorts) {
params.push(a.sortparam + '=' + sorts);
}
//add any required params
if (a.requiredparams) {
$.each(a.requiredparams, function(key, value) {
params.push(key + '=' + value);
});
}
//offset parameter
offset = ((p.page * p.size) >= p.filteredRows) ? '' : '&' + a.offset + '=' + (p.page * p.size);
//build url, starting with no parameters
newurl = url.slice(0,url.indexOf('?'));
newurl = newurl + '?' + a.numrows + '=' + p.size + offset + '&tsAjax=y';
$.each(params, function(key, value) {
newurl = newurl + '&' + value;
});
} else {
offset = ((p.page * p.size) >= p.filteredRows) ? '' : '&' + a.offset + '=' + (p.page * p.size);
newurl = url + '&tsAjax=y' + offset + '&numrows=' + p.size;
}
return newurl;
}
\ No newline at end of file
......@@ -519,6 +519,7 @@ if ( $prefs['feature_jquery_tablesorter'] == 'y' ) {
$headerlib->add_jsfile('vendor/jquery/plugins/tablesorter/js/widgets/widget-columnSelector.js');
$headerlib->add_jsfile('vendor/jquery/plugins/tablesorter/js/parsers/parser-input-select.js');
$headerlib->add_jsfile('vendor/jquery/plugins/tablesorter/js/widgets/widget-math.js');
$headerlib->add_jsfile('lib/jquery_tiki/tablesorter.js');
}
if ( $prefs['feature_jquery_tagcanvas'] == 'y' ) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment