Add paging to the customize page.

This commit is contained in:
Sébastien Lucas 2013-06-26 21:28:04 +02:00
parent 0e7f282563
commit 15237ee78d
4 changed files with 21 additions and 8 deletions

View file

@ -437,9 +437,9 @@ class Page
public function isPaginated () public function isPaginated ()
{ {
global $config; global $config;
return ($config['cops_max_item_per_page'] != -1 && return (getCurrentOption ("max_item_per_page") != -1 &&
$this->totalNumber != -1 && $this->totalNumber != -1 &&
$this->totalNumber > $config['cops_max_item_per_page']); $this->totalNumber > getCurrentOption ("max_item_per_page"));
} }
public function getNextLink () public function getNextLink ()
@ -447,7 +447,7 @@ class Page
global $config; global $config;
$currentUrl = $_SERVER['QUERY_STRING']; $currentUrl = $_SERVER['QUERY_STRING'];
$currentUrl = preg_replace ("/\&n=.*?$/", "", "?" . $_SERVER['QUERY_STRING']); $currentUrl = preg_replace ("/\&n=.*?$/", "", "?" . $_SERVER['QUERY_STRING']);
if (($this->n) * $config['cops_max_item_per_page'] < $this->totalNumber) { if (($this->n) * getCurrentOption ("max_item_per_page") < $this->totalNumber) {
return new LinkNavigation ($currentUrl . "&n=" . ($this->n + 1), "next", "Page suivante"); return new LinkNavigation ($currentUrl . "&n=" . ($this->n + 1), "next", "Page suivante");
} }
return NULL; return NULL;
@ -467,7 +467,7 @@ class Page
public function getMaxPage () public function getMaxPage ()
{ {
global $config; global $config;
return ceil ($this->totalNumber / $config['cops_max_item_per_page']); return ceil ($this->totalNumber / getCurrentOption ("max_item_per_page"));
} }
public function containsBook () public function containsBook ()
@ -772,7 +772,7 @@ abstract class Base
global $config; global $config;
$totalResult = -1; $totalResult = -1;
if ($config['cops_max_item_per_page'] != -1 && $n != -1) if (getCurrentOption ("max_item_per_page") != -1 && $n != -1)
{ {
// First check total number of results // First check total number of results
$result = self::getDb ($database)->prepare (str_format ($query, "count(*)", $filter)); $result = self::getDb ($database)->prepare (str_format ($query, "count(*)", $filter));
@ -781,7 +781,7 @@ abstract class Base
// Next modify the query and params // Next modify the query and params
$query .= " limit ?, ?"; $query .= " limit ?, ?";
array_push ($params, ($n - 1) * $config['cops_max_item_per_page'], $config['cops_max_item_per_page']); array_push ($params, ($n - 1) * getCurrentOption ("max_item_per_page"), getCurrentOption ("max_item_per_page"));
} }
$result = self::getDb ($database)->prepare(str_format ($query, $columns, $filter)); $result = self::getDb ($database)->prepare(str_format ($query, $columns, $filter));

View file

@ -11,13 +11,15 @@
require_once ("base.php"); require_once ("base.php");
header ("Content-Type:application/xhtml+xml;charset=utf-8"); header ("Content-Type:text/html;charset=utf-8");
$database = GetUrlParam (DB); $database = GetUrlParam (DB);
$use_fancybox = ""; $use_fancybox = "";
if (getCurrentOption ("use_fancyapps") == 1) { if (getCurrentOption ("use_fancyapps") == 1) {
$use_fancybox = "checked='checked'"; $use_fancybox = "checked='checked'";
} }
$max_item_per_page = getCurrentOption ("max_item_per_page");
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
@ -30,7 +32,11 @@
<link rel="stylesheet" type="text/css" href="<?php echo getUrlWithVersion(getCurrentCss ()) ?>" media="screen" /> <link rel="stylesheet" type="text/css" href="<?php echo getUrlWithVersion(getCurrentCss ()) ?>" media="screen" />
<link rel="stylesheet" type="text/css" href="<?php echo getUrlWithVersion("resources/normalize/normalize.css") ?>" /> <link rel="stylesheet" type="text/css" href="<?php echo getUrlWithVersion("resources/normalize/normalize.css") ?>" />
<script type="text/javascript"> <script type="text/javascript">
function updateCookie (id) { function updateCookie (id) {
if($(id).prop('pattern') && !$(id).val().match(new RegExp ($(id).prop('pattern')))) {
return;
}
var name = $(id).attr('id'); var name = $(id).attr('id');
var value = $(id).val (); var value = $(id).val ();
$.cookie(name, value); $.cookie(name, value);
@ -105,6 +111,10 @@
<h2><?php echo localize ("customize.fancybox") ?></h2> <h2><?php echo localize ("customize.fancybox") ?></h2>
<h4><input type="checkbox" onchange="updateCookieFromCheckbox (this);" id="use_fancyapps" <?php echo $use_fancybox ?> /></h4> <h4><input type="checkbox" onchange="updateCookieFromCheckbox (this);" id="use_fancyapps" <?php echo $use_fancybox ?> /></h4>
</article> </article>
<article class="frontpage">
<h2><?php echo localize ("customize.paging") ?></h2>
<h4><input type="number" onchange="updateCookie (this);" id="max_item_per_page" value="<?php echo $max_item_per_page ?>" min="-1" max="1200" pattern="^[-+]?[0-9]+$" /></h4>
</article>
</section> </section>
<footer> <footer>

View file

@ -326,6 +326,8 @@
"paging.previous.alternate":"Previous", "paging.previous.alternate":"Previous",
"customize.title":"Customize COPS UI", "customize.title":"Customize COPS UI",
"customize.style":"Theme", "customize.style":"Theme",
"customize.fancybox":"Use a Lightbox",
"customize.fancybox":"Use Fancybox", "customize.fancybox":"Use Fancybox",
"customize.paging":"Max number of books per page (-1 to disable)",
"fin":"fin" "fin":"fin"
} }

View file

@ -119,7 +119,8 @@
"paging.previous.alternate":"Précédent", "paging.previous.alternate":"Précédent",
"customize.title":"Paramétrage de COPS", "customize.title":"Paramétrage de COPS",
"customize.style":"Thème", "customize.style":"Thème",
"customize.fancybox":"Utiliser Fancybox", "customize.fancybox":"Utiliser une Lightbox",
"customize.paging":"Nombre de livres par page (-1 pour désactiver)",
"languages.eng":"Anglais", "languages.eng":"Anglais",
"languages.fra":"Français", "languages.fra":"Français",
"fin":"fin" "fin":"fin"