Commit f972d231 authored by lindonb's avatar lindonb

[ENH] tablesorter: avoid the extra ajax call upon page initialization; reduce...

[ENH] tablesorter: avoid the extra ajax call upon page initialization; reduce code by using serVars function
parent e7f4cee6
......@@ -11,7 +11,7 @@
{$liend = ''}
{/if}
{if !$tsOn && ($cant_pages > 1 or $initial or $find)}
{if !$ts.enabled && ($cant_pages > 1 or $initial or $find)}
{initials_filter_links}
{/if}
......@@ -35,8 +35,8 @@
{/if}
{assign var='pagefound' value='n'}
<div id="{$ts_tableid}-div" class="{if $js === 'y'}table-responsive{/if} ts-wrapperdiv" {if $tsOn}style="visibility:hidden;"{/if}> {*the table-responsive class cuts off dropdown menus *}
<table id="{$ts_tableid}" class="table normal table-striped table-hover" data-count="{$cant|escape}">
<div id="{$ts.tableid}-div" class="{if $js === 'y'}table-responsive{/if} ts-wrapperdiv" {if $ts.enabled}style="visibility:hidden;"{/if}> {*the table-responsive class cuts off dropdown menus *}
<table id="{$ts.tableid}" class="table normal table-striped table-hover" data-count="{$cant|escape}">
<thead>
<tr>
{if isset($checkboxes_on) and $checkboxes_on eq 'y'}
......@@ -420,7 +420,7 @@
</tbody>
</table>
</div>
{if !$tsAjax}
{if !$ts.ajax}
{if $checkboxes_on eq 'y' && count($listpages) > 0} {* what happens to the checked items? *}
<p align="left"> {*on the left to have it close to the checkboxes*}
<label for="submit_mult">{tr}Perform action with checked:{/tr}</label>
......@@ -474,7 +474,7 @@
</form>
{/if}
{if !isset($tsOn) or !$tsOn}
{if !isset($ts.enabled) or !$ts.enabled}
{pagination_links cant=$cant step=$maxRecords offset=$offset clean=$clean}{/pagination_links}
{/if}
{/if}
\ No newline at end of file
......@@ -241,6 +241,8 @@ $smarty->assign('find', $find);
$smarty->assign_by_ref('sort_mode', $sort_mode);
if (isset($_REQUEST['numrows'])) {
$maxRecords = $_REQUEST['numrows'];
} else {
$maxRecords = $prefs['maxRecords'];
}
$channels = $commentslib->list_forums($offset, $maxRecords, $sort_mode, $find);
$max = count($channels["data"]);
......@@ -256,23 +258,6 @@ for ($i = 0; $i < $max; $i++) {
$channels["data"][$i]["individual"] = 'n';
}
}
//add tablesorter sorting and filtering
$ts = Table_Check::setVars('adminforums', true);
//initialize tablesorter
if ($ts['enabled'] && !$ts['ajax']) {
//set tablesorter code
Table_Factory::build(
'TikiAdminForums',
array(
'id' => $ts['tableid'],
'total' => $channels['cant'],
)
);
//rows returned need to be empty on first pass for tablesorter pagination to work right
$channels['data'] = [];
}
$smarty->assign_by_ref('channels', $channels["data"]);
$smarty->assign_by_ref('cant', $channels["cant"]);
$cat_type = 'forum';
......@@ -304,6 +289,20 @@ if (preg_match('/^([\d\.]+)([gmk])?$/i', $maxAttachSize, $matches) && !empty($ma
$maxAttachSize*= 1024;
}
}
//add tablesorter sorting and filtering
$ts = Table_Check::setVars('adminforums', true);
if ($ts['enabled'] && !$ts['ajax']) {
//set tablesorter code
Table_Factory::build(
'TikiAdminForums',
array(
'id' => $ts['tableid'],
'total' => $channels['cant'],
)
);
}
$smarty->assign_by_ref('maxAttachSize', $maxAttachSize);
$oneday = 60 * 60 * 24;
......
......@@ -546,29 +546,30 @@ if ($tiki_p_admin == 'y') {
$all_groups[] = $g;
}
}
//get users
$users = $userlib->get_users(
$offset,
$numrows,
$sort_mode,
$find,
$initial,
true,
$filterGroup,
$filterEmail,
!empty($_REQUEST['filterEmailNotConfirmed']),
!empty($_REQUEST['filterNotValidated']),
!empty($_REQUEST['filterNeverLoggedIn'])
);
$smarty->assign_by_ref('users', $users['data']);
$smarty->assign_by_ref('cant', $users['cant']);
if (isset($_REQUEST['add'])) {
$cookietab = '2';
}
//add tablesorter sorting and filtering
$ts = Table_Check::setVars('adminusers', true);
if (!$ts['enabled'] || ($ts['enabled'] && $ts['ajax'])) {
$users = $userlib->get_users(
$offset,
$numrows,
$sort_mode,
$find,
$initial,
true,
$filterGroup,
$filterEmail,
!empty($_REQUEST['filterEmailNotConfirmed']),
!empty($_REQUEST['filterNotValidated']),
!empty($_REQUEST['filterNeverLoggedIn'])
);
}
if ($ts['enabled'] && !$ts['ajax']) {
$users['cant'] = $userlib->count_users('');
//rows returned need to be empty on first pass for tablesorter pagination to work right
$users['data'] = $users['cant'] > 0 ? true : false;
//delete anonymous out of group list used for dropdown
$ts_groups = array_flip($all_groups);
unset($ts_groups['Anonymous']);
......@@ -580,23 +581,16 @@ if ($ts['enabled'] && !$ts['ajax']) {
'id' => $ts['tableid'],
'total' => $users['cant'],
'columns' => array(
'#groups' => array(
'filter' => array(
'options' => $ts_groups
)
'#groups' => array(
'filter' => array(
'options' => $ts_groups
)
)
),
),
)
);
}
$smarty->assign_by_ref('users', $users['data']);
$smarty->assign_by_ref('cant', $users['cant']);
if (isset($_REQUEST['add'])) {
$cookietab = '2';
}
if (count($errors) > 0) {
Feedback::error(['mes' => $errors], 'session');
}
......
......@@ -49,9 +49,22 @@ $smarty->assign_by_ref('sort_mode', $sort_mode);
$channels = $commentslib->list_forums($offset, $maxRecords, $sort_mode, $find);
Perms::bulk(array( 'type' => 'forum' ), 'object', $channels['data'], 'forumId');
$temp_max = count($channels["data"]);
for ($i = 0; $i < $temp_max; $i++) {
$forumperms = Perms::get(array( 'type' => 'forum', 'object' => $channels['data'][$i]['forumId'] ));
$channels["data"][$i]["individual_tiki_p_forum_read"] = $forumperms->forum_read ? 'y' : 'n';
$channels["data"][$i]["individual_tiki_p_forum_post"] = $forumperms->forum_post ? 'y' : 'n';
$channels["data"][$i]["individual_tiki_p_forum_post_topic"] = $forumperms->forum_post_topic ? 'y' : 'n';
$channels["data"][$i]["individual_tiki_p_forum_vote"] = $forumperms->forum_vote ? 'y' : 'n';
$channels["data"][$i]["individual_tiki_p_admin_forum"] = $forumperms->admin_forum ? 'y' : 'n';
}
$smarty->assign_by_ref('channels', $channels["data"]);
$smarty->assign('cant', $channels["cant"]);
include_once ('tiki-section_options.php');
//add tablesorter sorting and filtering
$ts = Table_Check::setVars('forums', true);
//initialize tablesorter
if ($ts['enabled'] && !$ts['ajax']) {
//set tablesorter code
Table_Factory::build(
......@@ -61,22 +74,8 @@ if ($ts['enabled'] && !$ts['ajax']) {
'total' => $channels["cant"],
)
);
unset($channels);
} else {
$temp_max = count($channels["data"]);
for ($i = 0; $i < $temp_max; $i++) {
$forumperms = Perms::get(array( 'type' => 'forum', 'object' => $channels['data'][$i]['forumId'] ));
$channels["data"][$i]["individual_tiki_p_forum_read"] = $forumperms->forum_read ? 'y' : 'n';
$channels["data"][$i]["individual_tiki_p_forum_post"] = $forumperms->forum_post ? 'y' : 'n';
$channels["data"][$i]["individual_tiki_p_forum_post_topic"] = $forumperms->forum_post_topic ? 'y' : 'n';
$channels["data"][$i]["individual_tiki_p_forum_vote"] = $forumperms->forum_vote ? 'y' : 'n';
$channels["data"][$i]["individual_tiki_p_admin_forum"] = $forumperms->admin_forum ? 'y' : 'n';
}
$smarty->assign_by_ref('channels', $channels["data"]);
$smarty->assign('cant', $channels["cant"]);
include_once ('tiki-section_options.php');
}
ask_ticket('forums');
// Display the template
if ($ts['ajax']) {
......
......@@ -190,16 +190,8 @@ if (!empty($_REQUEST['submit_mult']) && isset($_REQUEST['checked'])) {
}
//add tablesorter sorting and filtering
$tsOn = Table_Check::isEnabled(true);
$smarty->assign('tsOn', $tsOn);
$tsAjax = Table_Check::isAjaxCall();
$smarty->assign('tsAjax', $tsAjax);
static $iid = 0;
++$iid;
$ts_tableid = 'listpages' . $iid;
$smarty->assign('ts_tableid', $ts_tableid);
if ($tsAjax) {
$ts = Table_Check::setVars('listpages', true);
if ($ts['ajax']) {
if (!empty($_REQUEST['categPath_ts']) || !empty($_REQUEST['categ_ts'])) {
if (!empty($_REQUEST['categPath_ts'])) {
$req = $_REQUEST['categPath_ts'];
......@@ -360,23 +352,18 @@ if (!empty($multiprint_pages)) {
if (!isset($listpages_orphans)) {
$listpages_orphans = false;
}
if (!$tsOn || ($tsOn && $tsAjax)) {
$listpages = $tikilib->list_pages(
$offset,
$maxRecords,
$sort_mode,
$find,
$initial,
$exact_match,
false,
true,
$listpages_orphans,
$filter
);
} else {
//get count only on first pass with tablesorter on so pagination works right
$listpages = $tikilib->list_pages(null, null, null, null, null, null, null, null, null, null, true);
}
$listpages = $tikilib->list_pages(
$offset,
$maxRecords,
$sort_mode,
$find,
$initial,
$exact_match,
false,
true,
$listpages_orphans,
$filter
);
possibly_look_for_page_aliases($find);
// Only show the 'Actions' column if the user can do at least one action on one of the listed pages
......@@ -451,7 +438,7 @@ if (!empty($multiprint_pages)) {
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
// Exact match and single result, go to page directly
if ( count($listpages['data']) == 1 && !$tsAjax) {
if ( count($listpages['data']) == 1 && !$ts['ajax']) {
$result = reset($listpages['data']);
if ( TikiLib::strtolower($find) == TikiLib::strtolower($result['pageName']) ) {
$wikilib = TikiLib::lib('wiki');
......@@ -460,7 +447,7 @@ if (!empty($multiprint_pages)) {
}
}
if ($tsOn && !$tsAjax) {
if ($ts['enabled'] && !$ts['ajax']) {
//create dropdown lists for category name and path filters
$cnames = array();
$cpaths = array();
......@@ -528,7 +515,7 @@ if (!empty($multiprint_pages)) {
$sortcol = array_search($sort, $cols);
$settings = array(
'id' => $ts_tableid,
'id' => $ts['tableid'],
'total' => $listpages['cant'],
'vars' => array(
'show_actions' => $show_actions,
......@@ -594,7 +581,7 @@ if (!empty($multiprint_pages)) {
}
} else {
// Display the template
if ($tsAjax) {
if ($ts['ajax']) {
$smarty->display($listpages_orphans ? 'tiki-orphan_pages.tpl' : 'tiki-listpages.tpl');
} else {
$smarty->assign('mid', ($listpages_orphans ? 'tiki-orphan_pages.tpl' : 'tiki-listpages.tpl'));
......
......@@ -319,7 +319,6 @@ if (!isset($_REQUEST['reply_state']))
else
$reply_state = $_REQUEST['reply_state'];
//need the info on all threads so leave this even on initial non-ajax load
$comments_coms = $commentslib->get_forum_topics(
$_REQUEST['forumId'],
$comments_offset,
......@@ -342,27 +341,6 @@ $comments_cant = $commentslib->count_forum_topics(
$type_param,
$reply_state
);
//initialize tablesorter
if ($ts['enabled'] && !$ts['ajax']) {
//set tablesorter code
Table_Factory::build(
'TikiViewforum',
array(
'id' => $ts['tableid'],
'total' => $comments_cant,
'pager' => array(
'max' => $_REQUEST['comments_per_page'],
),
'ajax' => array(
'requiredparams' => array(
'forumId' => $_REQUEST['forumId'],
),
),
)
);
$comments_coms = [];
}
$last_comments = $commentslib->get_last_forum_posts($_REQUEST['forumId'], $forum_info['forum_last_n']);
......@@ -477,6 +455,26 @@ if ($prefs['feature_forum_parse'] == 'y') {
$smarty->assign_by_ref('plugins', $plugins);
}
//initialize tablesorter
if ($ts['enabled'] && !$ts['ajax']) {
//set tablesorter code
Table_Factory::build(
'TikiViewforum',
array(
'id' => $ts['tableid'],
'total' => $comments_cant,
'pager' => array(
'max' => $_REQUEST['comments_per_page'],
),
'ajax' => array(
'requiredparams' => array(
'forumId' => $_REQUEST['forumId'],
),
),
)
);
}
ask_ticket('view-forum');
if ($ts['ajax']) {
$smarty->display('tiki-view_forum.tpl');
......
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