Commit 23e00618 authored by alexeyomelchenko's avatar alexeyomelchenko Committed by Robert Lyon

Bug 1650414: Eliminate Pager from table renderer

behatnotneeded: same functionality

Change-Id: If32959e6f11b70d799d5951f3d900238a8cfa1df
Signed-off-by: 's avataralexeyomelchenko <alexeyomelchenko@catalyst.net.nz>
parent 1d72469a
......@@ -94,7 +94,7 @@ $form = pieform(array(
));
$smarty = smarty(array('tablerenderer', 'Pager'));
$smarty = smarty(array('tablerenderer'));
$smarty->assign('form', $form);
$smarty->assign('PAGEHEADING', hsc(TITLE));
$smarty->display('form.tpl');
......
......@@ -82,7 +82,7 @@ $form = pieform(array(
));
$smarty = smarty(array('tablerenderer', 'Pager'));
$smarty = smarty(array('tablerenderer'));
$smarty->assign('form', $form);
$smarty->assign('PAGEHEADING', hsc(TITLE));
$smarty->display('form.tpl');
......
......@@ -155,7 +155,7 @@ jQuery(function($) {
EOF;
$smarty = smarty(array('tablerenderer', 'Pager'));
$smarty = smarty(array('tablerenderer'));
$smarty->assign('form', $form);
$smarty->assign('PAGEHEADING', hsc(TITLE));
$smarty->assign('INLINEJAVASCRIPT', $inlinejs);
......
......@@ -55,7 +55,7 @@ $form = pieform(array(
));
$smarty = smarty(array('tablerenderer', 'Pager'));
$smarty = smarty(array('tablerenderer'));
$smarty->assign('form', $form);
$smarty->assign('PAGEHEADING', hsc(TITLE));
$smarty->display('form.tpl');
......
......@@ -132,7 +132,6 @@ var table = new TableRenderer(
);
table.updateOnLoad();
table.emptycontent = {$strnoimagesfound};
table.paginate = false;
table.updatecallback = function(response) {
var defaultIcon = filter(function (i) { return i.isdefault == 't'; }, response.data);
......@@ -349,7 +348,7 @@ function settings_submit_delete(Pieform $form, $values) {
}
$smarty = smarty(
array('tablerenderer', 'Pager'),
array('tablerenderer'),
array(),
array(),
array(
......
......@@ -34,7 +34,7 @@ $compositetypes = array(
$inlinejs = ArtefactTypeResumeComposite::get_js($compositetypes);
$compositeforms = ArtefactTypeResumeComposite::get_forms($compositetypes);
$smarty = smarty(array('tablerenderer', 'Pager'));
$smarty = smarty(array('tablerenderer'));
$smarty->assign('compositeforms', $compositeforms);
$smarty->assign('INLINEJAVASCRIPT', $inlinejs);
$smarty->assign('SUBPAGENAV', PluginArtefactResume::submenu_items());
......
......@@ -29,7 +29,7 @@ $compositetypes = array('employmenthistory', 'educationhistory');
$inlinejs = ArtefactTypeResumeComposite::get_js($compositetypes);
$compositeforms = ArtefactTypeResumeComposite::get_forms($compositetypes);
$smarty = smarty(array('tablerenderer', 'Pager'));
$smarty = smarty(array('tablerenderer'));
$smarty->assign('compositeforms', $compositeforms);
$smarty->assign('INLINEJAVASCRIPT', $inlinejs);
$smarty->assign('SUBPAGENAV', PluginArtefactResume::submenu_items());
......
......@@ -39,7 +39,7 @@ jQuery(function($) {
});
});';
$smarty = smarty(array('tablerenderer', 'Pager'));
$smarty = smarty(array('tablerenderer'));
$smarty->assign('goals', $goals);
$smarty->assign('skills', $skills);
$smarty->assign('INLINEJAVASCRIPT', $js);
......
......@@ -50,7 +50,7 @@ $form = pieform(array(
)
));
$smarty = smarty(array('tablerenderer', 'Pager'));
$smarty = smarty(array('tablerenderer'));
$smarty->assign('form', $form);
$smarty->assign('heading', $group->name);
$smarty->assign('subheading', TITLE);
......
......@@ -68,7 +68,7 @@ $form = pieform(array(
)
);
$smarty = smarty(array('tablerenderer', 'Pager'));
$smarty = smarty(array('tablerenderer'));
$smarty->assign('form', $form);
$smarty->assign('INLINEJAVASCRIPT', $js);
$smarty->assign('heading', $group->name);
......
/**
* Pager module for MochiKit
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
try {
if (
typeof(MochiKit.Base) == 'undefined' ||
typeof(MochiKit.DOM) == 'undefined' ||
typeof(MochiKit.Signal) == 'undefined'
) {
throw "";
}
} catch (e) {
throw "MochiKit.Pagination depends on MochiKit.Base, MochiKit.DOM and MochiKit.Signal!";
}
if (typeof(MochiKit.Pagination) == 'undefined') {
MochiKit.Pagination = {};
}
MochiKit.Pagination.NAME = 'Pagination';
MochiKit.Pagination.VERSION = '0.1';
MochiKit.Pagination.__repr__ = function () { return '[' + this.NAME + ' ' + this.VERSION + ']'; };
MochiKit.Pagination.toString = function () { return this.__repr__(); };
MochiKit.Pagination.EXPORT = [
'Pager'
];
MochiKit.Pagination.Pager = function (count, limit, options) {
var cls = arguments.callee;
if (!(this instanceof cls)) {
return new cls(count, limit, options);
}
this.__init__(count, limit, options);
};
MochiKit.Pagination.Pager.prototype = {
__class__: MochiKit.Pagination.Pager,
__init__: function (count, limit, options) {
var d = MochiKit.DOM;
var b = MochiKit.Base;
this.options = b.update({
currentPage: 1,
linkOptions: {
'href': '',
'style': 'padding-left: 1ex; padding-right: 1ex;'
},
currentPageOptions: {
'style': 'padding-left: 1ex; padding-right: 1ex;'
},
displayFirstAndLast: true,
firstPageString: '<<',
previousPageString: '<',
nextPageString: '>',
lastPageString: '>>',
morePagesString: '...', // can be null
pageChangeCallback: null,
contextPageCount: 2
}, options || {});
this.options.lastPage = Math.floor( ( count - 1 ) / limit ) + 1;
if (this.options.lastPage < 1) {
this.options.lastPage = 1;
}
this.instances = [];
},
repr: function () {
return '[' + this.__class__.NAME + ", options:" + MochiKit.Base.repr(this.options) + "]";
},
dump: function() {
logDebug(this.instances);
},
newDisplayInstance: function() {
var instance = DIV({'style': 'text-align: center'});
this.instances.push(instance);
this.renderInstances();
return instance;
},
goToPage: function(pageNumber, e) {
this.options.currentPage = pageNumber;
if (typeof(this.options.pageChangeCallback) == 'function') {
this.options.pageChangeCallback(pageNumber);
}
this.renderInstances();
e.stop();
},
renderNumber: function(n) {
var page;
if ( n == this.options.currentPage ) {
page = SPAN(this.options.currentPageOptions, n);
}
else {
page = A(this.options.linkOptions, n);
connect(page, 'onclick', this, partial(this.goToPage, n));
}
return page;
},
removeAllInstances: function() {
forEach(this.instances, function(instance) {
removeElement(instance);
});
},
renderInstances: function() {
var options = this.options;
var goToPage = this.goToPage;
var self = this;
forEach(this.instances, function (instance) {
var childNodes = [];
var morePagesAfter = false;
var morePagesBefore = false;
var i;
if ( options.lastPage <= options.contextPageCount * 2 + 1 ) {
// we just always display all numbers (there's not that many)
for ( i = 1; i <= options.lastPage; i = i + 1 ) {
childNodes.push(self.renderNumber(i));
}
}
else if ( options.currentPage <= options.contextPageCount + 1 ) {
// the case where we display 1 to contextPageCount*2+1
morePagesAfter = true;
for ( i = 1; i <= options.contextPageCount * 2 + 1; i = i + 1 ) {
childNodes.push(self.renderNumber(i));
}
}
else if ( options.currentPage >= options.lastPage - options.contextPageCount ) {
// the case where we display lastPage - contextPageCount*2
morePagesBefore = true;
for ( i = options.lastPage - options.contextPageCount * 2; i <= options.lastPage; i = i + 1 ) {
childNodes.push(self.renderNumber(i));
}
}
else {
// we're somewhere in the middle
morePagesAfter = true;
morePagesBefore = true;
for ( i = options.currentPage - options.contextPageCount; i <= options.currentPage + options.contextPageCount; i = i + 1 ) {
childNodes.push(self.renderNumber(i));
}
}
if (options.morePagesString) {
if (morePagesBefore) {
childNodes.unshift(SPAN(null, options.morePagesString));
}
else {
childNodes.unshift(SPAN({'style': 'visibility: hidden'}, options.morePagesString));
}
if (morePagesAfter) {
childNodes.push(SPAN(null, options.morePagesString));
}
else {
childNodes.push(SPAN({'style': 'visibility: hidden'}, options.morePagesString));
}
}
var previousPage = A(options.linkOptions, options.previousPageString);
if (options.currentPage == 1) {
previousPage.style.visibility = 'hidden';
}
connect(previousPage, 'onclick', self, partial(goToPage, options.currentPage - 1));
childNodes.unshift(previousPage);
if (options.displayFirstAndLast) {
var firstPage = A(options.linkOptions, options.firstPageString);
if (options.currentPage == 1) {
firstPage.style.visibility = 'hidden';
}
connect(firstPage, 'onclick', self, partial(goToPage, 1));
childNodes.unshift(firstPage);
}
var nextPage = A(options.linkOptions, options.nextPageString);
if (options.currentPage == options.lastPage) {
nextPage.style.visibility = 'hidden';
}
connect(nextPage, 'onclick', self, partial(goToPage, options.currentPage + 1));
childNodes.push(nextPage);
if (options.displayFirstAndLast) {
var lastPage = A(options.linkOptions, options.lastPageString);
if (options.currentPage == options.lastPage) {
lastPage.style.visibility = 'hidden';
}
connect(lastPage, 'onclick', self, partial(goToPage, options.lastPage));
childNodes.push(lastPage);
}
forEach(instance.childNodes, function(node) {
disconnectAll(node);
});
replaceChildNodes(instance, childNodes);
});
}
};
MochiKit.Pagination.__new__ = function () {
MochiKit.Base.nameFunctions(this);
this.EXPORT_TAGS = {
":common": this.EXPORT,
":all": MochiKit.Base.concat(this.EXPORT, this.EXPORT_OK)
};
};
MochiKit.Pagination.__new__();
MochiKit.Base._exportSymbols(this, MochiKit.Pagination);
......@@ -21,9 +21,6 @@ return function (target, source, columns, options) {
this.options = options;
this.offset = 0;
this.limit = 10;
this.paginate = true;
this.paginate_simple = true;
this.paginate_firstlast = true;
this.statevars = ['offset','limit'];
this.emptycontent = undefined; // Something to display when no results are found
this.rowfunction = function(rowdata, rownumber, data) { return $('<tr>', {'class': 'r' + (rownumber % 2)}); };
......@@ -64,11 +61,6 @@ return function (target, source, columns, options) {
self.table.append(self.tfoot);
}
if (self.paginate) {
self.linkspan = self.columns.length > 0 ? self.columns.length : 1;
self.assertPager(self.offset, self.limit, self.count);
}
if (TableRendererPageLoaded) {
if (typeof(self.emptycontent) != 'undefined') {
self.emptycontent = $('<div>').append(self.emptycontent);
......@@ -83,69 +75,6 @@ return function (target, source, columns, options) {
}
};
this.assertPager = function (offset, limit, count) {
if (!count) {
return;
}
if(!self.pager || self.pager.options.lastPage != Math.floor( (count-1) / limit ) + 1 ) {
if (self.pager) {
if (self.headRow.length) {
self.headRow.remove();
}
if (self.footRow.length) {
self.footRow.remove();
}
self.pager.removeAllInstances();
}
self.pager = new Pager(count, limit,
$.extend(
null,
self.defaultPagerOptions,
self.pagerOptions,
{ 'currentPage': Math.floor(offset / limit) + 1 }
)
);
if (self.pager.options.lastPage == 1) {
self.headRow = null;
self.footRow = null;
return;
}
self.headRow = $('<tr>').append($('<td>', {'colspan': self.linkspan }).append(self.pager.newDisplayInstance()))[0];
self.footRow = $('<tr>').append($('<td>', {'colspan': self.linkspan }).append(self.pager.newDisplayInstance()))[0];
if ( self.thead.firstChild ) {
$(self.headRow).insertBefore(self.thead.children().first());
}
else {
self.thead.append(self.headRow);
}
self.tfoot.append(self.footRow);
}
};
this.pageChange = function(n) {
self.lastArgs.offset = ( n - 1 ) * self.limit;
self.doupdate(self.lastArgs);
};
this.onFirstPage = function () {
if (self.offset == 0) {
return true;
}
return false;
};
this.onLastPage = function () {
// logDebug('offset=' + self.offset + ', limit=' + self.limit + ', count=' + self.count);
if ( self.offset + self.limit >= self.count ) {
return true;
}
return false;
};
this.renderdata = function(data, options) {
self.tbody.empty();
var rownumber = 0;
......@@ -209,12 +138,6 @@ return function (target, source, columns, options) {
console.error('tablerenderer call updatecallback(', response, ') failed.');
}
if (self.paginate) {
if (typeof(self.assertPager) == 'function') {
self.assertPager(self.offset, self.limit, self.count);
}
}
if (typeof(self.emptycontent) != 'undefined') {
// Make sure the emptycontent is in a div
if (self.emptycontent[0].nodeName != 'DIV') {
......@@ -251,42 +174,6 @@ return function (target, source, columns, options) {
}, null, true);
};
this.goFirstPage = function() {
self.lastArgs.offset = 0;
self.doupdate(self.lastArgs);
};
this.goPrevPage = function() {
if ( self.offset > 0 ) {
if ( self.offset - self.limit < 0 ) {
self.lastArgs.offset = 0;
self.doupdate(self.lastArgs);
}
else {
self.lastArgs.offset = self.offset - self.limit;
self.doupdate(self.lastArgs);
}
}
else {
console.warn('Already on the first page (' + self.offset + ', ' + self.limit + ', ' + self.count + ')');
}
};
this.goNextPage = function() {
if ( self.offset + self.limit < self.count ) {
self.lastArgs.offset = self.offset + self.limit;
self.doupdate(self.lastArgs);
}
else {
console.warn('Already on the last page (' + self.offset + ', ' + self.limit + ', ' + self.count + ')');
}
};
this.goLastPage = function() {
self.lastArgs.offset = Math.floor( ( self.count - 1 ) / self.limit) * self.limit;
self.doupdate(self.lastArgs);
};
this.updateOnLoad = function(request_args) {
self.updateOnLoadFlag = true;
if ( TableRendererPageLoaded ) {
......@@ -297,15 +184,6 @@ return function (target, source, columns, options) {
}
};
this.defaultPagerOptions =
{ 'pageChangeCallback': self.pageChange,
'previousPageString': get_string('prevpage'),
'nextPageString': get_string('nextpage'),
'lastPageString': get_string('lastpage'),
'firstPageString': get_string('firstpage')
};
this.pagerOptions = {};
if ( TableRendererPageLoaded ) {
this.init();
}
......
......@@ -33,7 +33,7 @@ results.rowfunction = function (r, rownumber, d) {
var titleElement;
if (r.links && r.links._default) {
titleElement = [jQuery('<h3>',{'class': 'title'}), jQuery('<a>', {'href': r.links._default, 'text': r.title}))];
titleElement = [jQuery('<h3>',{'class': 'title'}), jQuery('<a>', {'href': r.links._default, 'text': r.title})];
delete r.links._default;
}
else {
......@@ -79,7 +79,7 @@ else {
$javascript .= 'results.query = \'\';';
}
$smarty = smarty(array('tablerenderer', 'Pager'), array(), array(), array('sidebars' => true));
$smarty = smarty(array('tablerenderer'), array(), array(), array('sidebars' => true));
$smarty->assign('query', $query);
$smarty->assign('artefacttype', $artefacttype);
$smarty->assign('INLINEJAVASCRIPT', $javascript);
......
......@@ -63,7 +63,7 @@ $form = pieform(array(
));
$smarty = smarty(array('tablerenderer', 'Pager'));
$smarty = smarty(array('tablerenderer'));
$smarty->assign('form', $form);
$smarty->assign('PAGEHEADING', hsc(TITLE));
$smarty->display('form.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