Commit 873fdcd7 authored by Francois Marier's avatar Francois Marier
Browse files

Pagination on Group Members page now uses pajinator.js (AJAX)



/js/groupmembersearch.js is no longer needed and has been deleted
Signed-off-by: default avatarRuslan Kabalin <ruslan.kabalin@luns.net.uk>
Signed-off-by: default avatarFrancois Marier <francois@catalyst.net.nz>
parent 1f558cf9
......@@ -34,7 +34,7 @@ require_once('searchlib.php');
require_once(get_config('docroot') . 'interaction/lib.php');
define('GROUP', param_integer('id'));
$membershiptype = param_alpha('membershiptype', null);
$membershiptype = param_variable('membershiptype', '');
$group = group_current_group();
if (!is_logged_in() && !$group->public) {
......@@ -80,13 +80,51 @@ if ('admin' == $role) {
}
}
$smarty = smarty(array('groupmembersearch'));
$searchform = pieform(array(
'name' => 'search',
'renderer' => 'oneline',
'elements' => array(
'id' => array(
'type' => 'hidden',
'value' => $group->id
),
'membershiptype' => array(
'type' => 'hidden',
'value' => $membershiptype
),
'query' => array(
'type' => 'text',
'defaultvalue' => $query
),
'submit' => array(
'type' => 'submit',
'value' => get_string('search')
)
)
));
$js = <<< EOF
addLoadEvent(function () {
p = {$pagination['javascript']}
connect('search_submit', 'onclick', function (event) {
replaceChildNodes('messages');
var params = {'query': $('search_query').value, 'id':$('search_id').value, 'membershiptype':$('search_membershiptype').value};
p.sendQuery(params);
event.stop();
});
});
EOF;
$smarty = smarty(array('paginator'));
$smarty->assign('INLINEJAVASCRIPT', $js);
$smarty->assign('heading', $group->name);
$smarty->assign('query', $query);
$smarty->assign('form', $searchform);
$smarty->assign('results', $html);
$smarty->assign('pagination', $pagination['html']);
$smarty->assign('instructions', $instructions);
$smarty->assign('membershiptype', $membershiptype);
$smarty->display('group/members.tpl');
?>
function search_submit(Pieform $form, $values) {
redirect('/group/members.php?id=' . $values['id'] . (!empty($values['query']) ? '&query=' . urlencode($values['query']) : '') . (!empty($values['membershiptype']) ? '&membershiptype=' . urlencode($values['membershiptype']) : ''));
}
......@@ -43,7 +43,7 @@ if (!is_logged_in() && !$group->public) {
throw new AccessDeniedException();
}
$membershiptype = param_alpha('membershiptype', null);
$membershiptype = param_variable('membershiptype', '');
if (!empty($membershiptype)) {
if (group_user_access($id) != 'admin') {
......@@ -58,6 +58,7 @@ json_reply(false, array(
'data' => array(
'tablerows' => $html,
'pagination' => $pagination['html'],
'pagination_js' => $pagination['javascript'],
'count' => $count,
'results' => $count . ' ' . ($count == 1 ? get_string('result') : get_string('results')),
'offset' => $offset,
......
/**
* 'Speeds up' the group member search if the user has javascript enabled in their
* browser
*
* Copyright: 2006-2008 Catalyst IT Ltd
* This file is licensed under the same terms as Mahara itself
*/
function UserSearch() {
var self = this;
this.init = function () {
self.rewriteQueryButton();
self.rewritePaging();
self.params = {};
}
this.searchByChildLink = function (element) {
var children = getElementsByTagAndClassName('a', null, element);
if (children.length == 1) {
var href = getNodeAttribute(children[0], 'href');
self.params = parseQueryString(href.substring(href.indexOf('?')+1, href.length));
self.doSearch();
}
}
this.changePage = function(e) {
e.stop();
self.searchByChildLink(this);
}
this.rewritePaging = function() {
forEach(getElementsByTagAndClassName('span', 'pagination', 'pagination'), function(i) {
connect(i, 'onclick', self.changePage);
});
}
this.rewriteQueryButton = function() {
connect($('query-button'), 'onclick', self.newQuery);
}
this.newQuery = function(e) {
self.params = {};
self.params.query = $('query').value;
self.params.id = $('groupid').value;
self.doSearch();
e.stop();
}
this.doSearch = function() {
self.params.action = 'search';
sendjsonrequest('membersearchresults.php', self.params, 'POST', function(data) {
var tbody = getElementsByTagAndClassName('tbody', null, 'results')[0];
if (
(document.all && document.documentElement && typeof(document.documentElement.style.maxHeight) != "undefined" && !window.opera)
||
(/Konqueror|AppleWebKit|KHTML/.test(navigator.userAgent))) {
var temp = DIV({'id':'ie-workaround'});
temp.innerHTML = '<table><tbody>' + data.data.tablerows + '</tbody></table>';
swapDOM(tbody, temp.childNodes[0].childNodes[0]);
removeElement(temp);
}
else {
tbody.innerHTML = data.data.tablerows;
}
$('pagination').innerHTML = data.data.pagination;
if (data.data.count) {
self.rewritePaging();
}
});
}
addLoadEvent(self.init);
}
userSearch = new UserSearch();
{include file="header.tpl"}
<form action="{$WWWROOT}group/members.php" method="post">
<input type="hidden" id="groupid" name="id" value="{$GROUP->id|escape}">
<div class="searchform">
<label>{str tag='Query' section='admin'}:
<input type="text" name="query" id="query" value="{$query|escape}">
</label>
<button id="query-button" type="submit">{str tag="go"}</button>
{if $membershiptype}<input type="hidden" name="membershiptype" value="{$membershiptype|escape}" />{/if}
</div>
<div>
{$instructions}
</div>
</form>
{$form}
{if $membershiptype}<h3>{str tag=pendingmembers section=group}</h3>{/if}
<div id="results">
<table id="membersearchresults" class="tablerenderer fullwidth listing twocolumn">
......
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