(MT #1654) Adding jquery.tablesorter and jquery.tablesorter.pager support for authorised_values.pl

This commit is contained in:
Stéphane Delaune 2010-08-31 11:59:26 +02:00 committed by Chris Cormack
parent 1242ec7cc4
commit d950e509ff
6 changed files with 220 additions and 12 deletions

View file

@ -0,0 +1,184 @@
(function($) {
$.extend({
tablesorterPager: new function() {
function updatePageDisplay(c) {
var s = $(c.cssPageDisplay,c.container).val((c.page+1) + c.seperator + c.totalPages);
}
function setPageSize(table,size) {
var c = table.config;
c.size = size;
c.totalPages = Math.ceil(c.totalRows / c.size);
c.pagerPositionSet = false;
moveToPage(table);
fixPosition(table);
}
function fixPosition(table) {
var c = table.config;
if(!c.pagerPositionSet && c.positionFixed) {
var c = table.config, o = $(table);
if(o.offset) {
c.container.css({
top: o.offset().top + o.height() + 'px',
position: 'absolute'
});
}
c.pagerPositionSet = true;
}
}
function moveToFirstPage(table) {
var c = table.config;
c.page = 0;
moveToPage(table);
}
function moveToLastPage(table) {
var c = table.config;
c.page = (c.totalPages-1);
moveToPage(table);
}
function moveToNextPage(table) {
var c = table.config;
c.page++;
if(c.page >= (c.totalPages-1)) {
c.page = (c.totalPages-1);
}
moveToPage(table);
}
function moveToPrevPage(table) {
var c = table.config;
c.page--;
if(c.page <= 0) {
c.page = 0;
}
moveToPage(table);
}
function moveToPage(table) {
var c = table.config;
if(c.page < 0 || c.page > (c.totalPages-1)) {
c.page = 0;
}
renderTable(table,c.rowsCopy);
}
function renderTable(table,rows) {
var c = table.config;
var l = rows.length;
var s = (c.page * c.size);
var e = (s + c.size);
if(e > rows.length ) {
e = rows.length;
}
var tableBody = $(table.tBodies[0]);
// clear the table body
$.tablesorter.clearTableBody(table);
for(var i = s; i < e; i++) {
//tableBody.append(rows[i]);
var o = rows[i];
var l = o.length;
for(var j=0; j < l; j++) {
tableBody[0].appendChild(o[j]);
}
}
fixPosition(table,tableBody);
$(table).trigger("applyWidgets");
if( c.page >= c.totalPages ) {
moveToLastPage(table);
}
updatePageDisplay(c);
}
this.appender = function(table,rows) {
var c = table.config;
c.rowsCopy = rows;
c.totalRows = rows.length;
c.totalPages = Math.ceil(c.totalRows / c.size);
renderTable(table,rows);
};
this.defaults = {
size: 10,
offset: 0,
page: 0,
totalRows: 0,
totalPages: 0,
container: null,
cssNext: '.next',
cssPrev: '.prev',
cssFirst: '.first',
cssLast: '.last',
cssPageDisplay: '.pagedisplay',
cssPageSize: '.pagesize',
seperator: "/",
positionFixed: true,
appender: this.appender
};
this.construct = function(settings) {
return this.each(function() {
config = $.extend(this.config, $.tablesorterPager.defaults, settings);
var table = this, pager = config.container;
$(this).trigger("appendCache");
config.size = parseInt($(".pagesize",pager).val());
$(config.cssFirst,pager).click(function() {
moveToFirstPage(table);
return false;
});
$(config.cssNext,pager).click(function() {
moveToNextPage(table);
return false;
});
$(config.cssPrev,pager).click(function() {
moveToPrevPage(table);
return false;
});
$(config.cssLast,pager).click(function() {
moveToLastPage(table);
return false;
});
$(config.cssPageSize,pager).change(function() {
setPageSize(table,parseInt($(this).val()));
return false;
});
});
};
}
});
// extend plugin scope
$.fn.extend({
tablesorterPager: $.tablesorterPager.construct
});
})(jQuery);

View file

@ -5,6 +5,16 @@
<!-- TMPL_IF name="delete_confirm" --> &rsaquo; Confirm Deletion<!-- /TMPL_IF -->
<!-- TMPL_IF name="else" -->Authorized values<!-- /TMPL_IF --></title>
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.tablesorter.pager.js"></script>
<script type="text/javascript" id="js">$(document).ready(function() {
// call the tablesorter plugin
$("#table_authorized_values").tablesorter({
sortList: [[1,0]]
}).tablesorterPager({container: $("#pagertable_authorized_values"),positionFixed: false,size: 20});
}); </script>
<script type="text/JavaScript" language="JavaScript">
//<![CDATA[
$(document).ready(function() {
@ -21,7 +31,6 @@
<body>
<!-- TMPL_INCLUDE NAME="header.inc" -->
<!-- TMPL_INCLUDE NAME="cat-search.inc" -->
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; <!-- TMPL_IF name="add_form" --> <a href="/cgi-bin/koha/admin/authorised_values.pl">Authorized Values</a> &rsaquo; <!-- TMPL_IF name="action_modify" -->Modify authorized value<!-- /TMPL_IF -->
<!-- TMPL_IF name="action_add_value" -->New authorized value<!-- /TMPL_IF -->
<!-- TMPL_IF name="action_add_category" -->New category<!-- /TMPL_IF --><!-- /TMPL_IF -->
@ -211,9 +220,29 @@
<!-- TMPL_IF EXPR="category eq 'NOT_LOAN'" -->
<p>Statuses to describe why an item is not for loan</p>
<!-- /TMPL_IF -->
<table>
<caption>Authorized values for category <!-- TMPL_VAR name="category" --> :</caption>
<tr>
<h3>Authorized values for category <!-- TMPL_VAR name="category" --> :</h3>
<span id="pagertable_authorized_values" class="pager">
<form class="formpager">&nbsp;<strong>page(s)</strong>&nbsp;:
<img src="<!-- TMPL_VAR name="interface" -->/prog/img/first.png" class="first"/>
<img src="<!-- TMPL_VAR name="interface" -->/prog/img/prev.png" class="prev"/>
<input type="text" size="5" class="pagedisplay"/>
<img src="<!-- TMPL_VAR name="interface" -->/prog/img/next.png" class="next"/>
<img src="<!-- TMPL_VAR name="interface" -->/prog/img/last.png" class="last"/>
, entries/page :
<select class="pagesize">
<option value="10">10</option>
<option selected="selected" value="20">20</option>
<option value="30">30</option>
<option value="40">40</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
</form>
</span>
<table id="table_authorized_values" cellspacing="1" class="tablesorter">
<thead><tr>
<th>Authorized value</th>
<th>Description</th>
<th>Description (OPAC)</th>
@ -221,9 +250,10 @@
<th>Edit</th>
<th>Delete</th>
</tr>
</thead><tbody>
<!-- TMPL_LOOP name="loop" -->
<!-- TMPL_UNLESS name="__odd__" -->
<tr class="highlight">
<tr>
<!-- TMPL_ELSE -->
<tr>
<!-- /TMPL_UNLESS -->
@ -235,7 +265,7 @@
<td><a href="<!-- TMPL_VAR name="delete" -->">Delete</a></td>
</tr>
<!-- /TMPL_LOOP -->
</table>
</tbody></table>
<!-- TMPL_IF NAME="isprevpage" -->
<form class="inline" action="<!-- TMPL_VAR NAME="script_name" -->" method="post">
@ -243,12 +273,6 @@
<input type="submit" value="&lt;&lt; Previous" /></form>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="nextpage" -->
<form class="inline" action="<!-- TMPL_VAR NAME="script_name" -->" method="post">
<input type="hidden" name="offset" value="<!-- TMPL_VAR NAME="nextpage" -->" /><input type="hidden" name="searchfield" value="<!-- TMPL_VAR NAME="searchfield" -->" />
<input type="submit" value="Next Page &gt;&gt;" /></form>
<!-- /TMPL_IF -->
<!-- /TMPL_IF -->
</div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 720 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 737 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 736 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 745 B