Commit 1b05a031 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Merge "Bug 1829803: Allow more optional values for the 'showmore' pagination"

parents 96396c5c e0df7f63
......@@ -311,22 +311,25 @@ var paginatorProxy = new PaginatorProxy();
// 'Show more' pagination
function pagination_showmore(btn) {
var params = {};
params.offset = parseInt(btn.data('offset'), 10);
params.orderby = btn.data('orderby');
if (Number.isInteger(btn.data('group'))) {
params.group = btn.data('group');
}
if (btn.data('institution').length) {
params.institution = btn.data('institution');
}
var btndata = btn.data();
$.each(btndata, function(key, value) {
if (key != 'jsonscript' && value.length != 0) {
if ($.isNumeric(value)) {
value = parseInt(value, 10);
}
params[key] = value;
}
});
sendjsonrequest(config['wwwroot'] + btn.data('jsonscript'), params, 'POST', function(data) {
var btnid = btn.prop('id');
btn.parent().replaceWith(data.data.tablerows);
// we have a new 'showmore' button so wire it up
jQuery('#' + btnid).on('click', function() {
jQuery('#' + btnid).on('click', function(e) {
e.preventDefault();
pagination_showmore(jQuery(this));
});
jQuery('#' + btnid).on('keydown', function(e) {
e.preventDefault();
if (e.keyCode == $j.ui.keyCode.SPACE || e.keyCode == $j.ui.keyCode.ENTER) {
pagination_showmore(jQuery(this));
}
......
......@@ -83,7 +83,7 @@ if (!empty($groupid)) {
'limit' => $limit,
'offset' => $offset,
'orderby' => 'atoz',
'group' => $groupid,
'extra' => array('group' => $groupid),
'databutton' => 'showmorebtn',
'jsonscript' => 'json/viewlist.php',
));
......
......@@ -4472,8 +4472,8 @@ class View {
'limit' => $limit,
'offset' => $offset,
'orderby' => $orderby,
'group' => $group,
'institution' => $institution,
'extra' => array('group' => $group,
'institution' => $institution),
'databutton' => 'showmorebtn',
'jsonscript' => 'json/viewlist.php',
));
......
......@@ -4424,9 +4424,8 @@ function build_pagination($params) {
* - orderby: What order the results will be returned in
* - databutton: The ID of the 'Show more' button
*
* Optional include:
* - group: Group id the pagination is for
* - institution: Institution name the pagination is for
* Optional:
* - extra: An array of key / values that you want to add as data options
*/
function build_showmore_pagination($params) {
// Bail if the required attributes are not present
......@@ -4440,22 +4439,27 @@ function build_showmore_pagination($params) {
if ((int) $params['count'] > ((int) $params['offset'] + (int) $params['limit'])) {
// Need to add 'showmore' button
$output = '<div class="showmore">' . "\n";
$output .= ' <div id="' . $params['databutton'] . '" class="btn btn-secondary"';
$output .= ' <button id="' . $params['databutton'] . '" class="btn btn-secondary"';
$output .= ' data-orderby="' . $params['orderby'] . '"';
$output .= ' data-offset="' . ((int) $params['offset'] + (int) $params['limit']) . '"';
$output .= ' data-group="' . (isset($params['group']) ? $params['group'] : '') . '"';
$output .= ' data-jsonscript="' . $params['jsonscript'] . '"';
$output .= ' data-institution="' . (isset($params['institution']) ? $params['institution'] : '') . '"';
if (!empty($params['extra']) && is_array($params['extra'])) {
foreach ($params['extra'] as $key => $value) {
$output .= ' data-' . $key . '="' . $value . '"';
}
}
$output .= ' tabindex="0">';
$output .= get_string('showmore', 'mahara') . '</div>' . "\n";
$output .= get_string('showmore', 'mahara') . '</button>' . "\n";
$output .= '</div>';
$js = 'jQuery("#' . $params['databutton'] . '").on("click", function() {';
$js = 'jQuery("#' . $params['databutton'] . '").on("click", function(e) {';
$js .= ' e.preventDefault();';
$js .= ' pagination_showmore(jQuery(this));';
$js .= '});' . "\n";
$js .= 'jQuery("#' . $params['databutton'] . '").on("keydown", function(e) {';
$js .= ' if (e.keyCode == $j.ui.keyCode.SPACE || e.keyCode == $j.ui.keyCode.ENTER) {';
$js .= ' e.preventDefault();';
$js .= ' pagination_showmore(jQuery(this));';
$js .= ' }';
$js .= '});' . "\n";
......
......@@ -346,4 +346,6 @@
.showmore {
text-align: center;
clear: both;
width: 100%;
cursor: pointer;
}
......@@ -81,7 +81,7 @@ if (!$can_edit) {
'count' => $data->count,
'limit' => $limit,
'offset' => $offset,
'group' => $group->id,
'extra' => array('group' => $group->id),
'databutton' => 'showmorebtn',
'jsonscript' => 'json/viewlist.php',
'orderby' => 'atoz',
......
......@@ -10,6 +10,10 @@ Background:
# extra tables not currently in this feature file: ...the following ~
# institutions, group memberships, institution memberships, permissions, messages, ... exist
Given the following site settings are set:
| field | value |
| licensemetadata | 0 |
Given the following "users" exist:
# Available fields: username*, password*, email*, firstname*, lastname*, institution, role, authname, remoteusername, studentid, preferredname, town, country, occupation
| username | password | email | firstname | lastname | institution | authname | role |
......
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