/**
* This library has been customized to address some specific scenarios applicable only to InfoArmy. Customizations have to be redone if this library is upgraded.
*
* Customizations:
* 1. Rending value should be done only for enter and tab key
* 2. validating input value and showing Error on invalid Entry
*
*/
$.fn.dataTableExt.oPagination.input = {
"fnInit" : function(oSettings, nPaging, fnCallbackDraw) {
var nFirst = document.createElement('span');
var nPrevious = document.createElement('span');
var nNext = document.createElement('span');
var nLast = document.createElement('span');
var nInput = document.createElement('input');
var nPage = document.createElement('span');
var nOf = document.createElement('span');
nFirst.innerHTML = oSettings.oLanguage.oPaginate.sFirst;
nPrevious.innerHTML = oSettings.oLanguage.oPaginate.sPrevious;
nNext.innerHTML = oSettings.oLanguage.oPaginate.sNext;
nLast.innerHTML = oSettings.oLanguage.oPaginate.sLast;
nFirst.className = "paginate_button first";
nPrevious.className = "paginate_button previous";
nNext.className = "paginate_button next";
nLast.className = "paginate_button last";
nOf.className = "paginate_of";
nPage.className = "paginate_page";
if (oSettings.sTableId !== '') {
nPaging.setAttribute('id', oSettings.sTableId + '_paginate');
nPrevious.setAttribute('id', oSettings.sTableId + '_previous');
nPrevious.setAttribute('id', oSettings.sTableId + '_previous');
nNext.setAttribute('id', oSettings.sTableId + '_next');
nLast.setAttribute('id', oSettings.sTableId + '_last');
}
nInput.type = "text";
nInput.className = "validate";
nInput.style.width = "15px";
nInput.style.display = "inline";
nPage.innerHTML = "Page ";
nPaging.appendChild(nFirst);
nPaging.appendChild(nPrevious);
nPaging.appendChild(nPage);
nPaging.appendChild(nInput);
nPaging.appendChild(nOf);
nPaging.appendChild(nNext);
nPaging.appendChild(nLast);
$(nFirst).click(function() {
if (oSettings._iDisplayStart === 0) {
} else {
oSettings.oApi._fnPageChange(oSettings, "first");
fnCallbackDraw(oSettings);
}
});
$(nPrevious).click(function() {
if (oSettings._iDisplayStart === 0) {
} else {
oSettings.oApi._fnPageChange(oSettings, "previous");
fnCallbackDraw(oSettings);
}
});
$(nNext).click(function() {
if (oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay()) {
} else {
oSettings.oApi._fnPageChange(oSettings, "next");
fnCallbackDraw(oSettings);
}
});
$(nLast).click(function() {
if (oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay()) {
} else {
oSettings.oApi._fnPageChange(oSettings, "last");
fnCallbackDraw(oSettings);
}
});
$(nInput)
.keydown(
function(e) {
if ((e.which != 13) && (e.which != 9)) {
return;
}
if (this.value === "" || this.value.match(/[^0-9]/)) {
nInput.style.border = "1px solid #f00";
// $(this).insertBefore('test');
$('.dataTables_paginate').find('span.form_error_message').remove();
$('.dataTables_paginate')
.append(
"Please enter only numbers");
$(this)
.mouseenter(
function() {
$(this)
.parent(
'.dataTables_paginate')
.find(
'span.form_error_message')
.css("visibility",
"visible");
})
.mouseleave(
function() {
$(this)
.parent(
'.dataTables_paginate')
.find(
'span.form_error_message')
.css("visibility",
"hidden");
});
return;
}
if (parseInt(this.value) == 0) {
nInput.style.border = "1px solid #f00";
// $(this).insertBefore('test');
$('.dataTables_paginate').find('span.form_error_message').remove();
$('.dataTables_paginate')
.append(
"Please enter only numbers starting from 1");
$(this)
.mouseenter(
function() {
$(this)
.parent(
'.dataTables_paginate')
.find(
'span.form_error_message')
.css("visibility",
"visible");
})
.mouseleave(
function() {
$(this)
.parent(
'.dataTables_paginate')
.find(
'span.form_error_message')
.css("visibility",
"hidden");
});
return;
}
else {
nInput.style.border = "1px solid #666";
$(
".dataTables_paginate span.form_error_message")
.remove();
}
/*if ( e.which == 38 || e.which == 39 )
{
this.value++;
}
else if ( (e.which == 37 || e.which == 40) && this.value > 1 )
{
this.value--;
}*/
var iNewStart = oSettings._iDisplayLength
* (this.value - 1);
if (iNewStart > oSettings.fnRecordsDisplay()) {
/* Display overrun */
oSettings._iDisplayStart = (Math
.ceil((oSettings.fnRecordsDisplay() - 1)
/ oSettings._iDisplayLength) - 1)
* oSettings._iDisplayLength;
fnCallbackDraw(oSettings);
return;
}
oSettings._iDisplayStart = iNewStart;
fnCallbackDraw(oSettings);
});
function showNumberOnlyError() {
/* Nothing entered or non-numeric character */
}
/* Take the brutal approach to cancelling text selection */
$('span', nPaging).bind('mousedown', function() {
return false;
});
$('span', nPaging).bind('selectstart', function() {
return false;
});
},
"fnUpdate" : function(oSettings, fnCallbackDraw) {
if (!oSettings.aanFeatures.p) {
return;
}
/* Loop over each instance of the pager */
var an = oSettings.aanFeatures.p;
for ( var i = 0, iLen = an.length; i < iLen; i++) {
var buttons = an[i].getElementsByTagName('span');
if (oSettings._iDisplayStart === 0) {
buttons[0].className = "paginate_disabled_first";
buttons[1].className = "paginate_disabled_previous";
} else {
buttons[0].className = "paginate_enabled_first";
buttons[1].className = "paginate_enabled_previous";
}
if (oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay()) {
buttons[4].className = "paginate_disabled_next";
buttons[5].className = "paginate_disabled_last";
} else {
buttons[4].className = "paginate_enabled_next";
buttons[5].className = "paginate_enabled_last";
}
}
var iPages = Math.ceil((oSettings.fnRecordsDisplay())
/ oSettings._iDisplayLength);
var iCurrentPage = Math.ceil(oSettings._iDisplayStart
/ oSettings._iDisplayLength) + 1;
/* Loop over each instance of the pager */
var an = oSettings.aanFeatures.p;
for ( var i = 0, iLen = an.length; i < iLen; i++) {
var spans = an[i].getElementsByTagName('span');
var inputs = an[i].getElementsByTagName('input');
spans[3].innerHTML = " of " + iPages + "";
inputs[0].value = iCurrentPage;
}
}
};
$.fn.dataTableExt.oPagination.listbox = {
/*
* Function: oPagination.listbox.fnInit
* Purpose: Initalise dom elements required for pagination with listbox input
* Returns: -
* Inputs: object:oSettings - dataTables settings object
* node:nPaging - the DIV which contains this pagination control
* function:fnCallbackDraw - draw function which must be called on update
*/
"fnInit" : function(oSettings, nPaging, fnCallbackDraw) {
var nInput = document.createElement('select');
var nPage = document.createElement('span');
var nOf = document.createElement('span');
nOf.className = "paginate_of";
nPage.className = "paginate_page";
if (oSettings.sTableId !== '') {
nPaging.setAttribute('id', oSettings.sTableId + '_paginate');
}
nInput.style.display = "inline";
nPage.innerHTML = "Page ";
nPaging.appendChild(nPage);
nPaging.appendChild(nInput);
nPaging.appendChild(nOf);
$(nInput).change(
function(e) { // Set DataTables page property and redraw the grid on listbox change event.
window.scroll(0, 0); //scroll to top of page
if (this.value === "" || this.value.match(/[^0-9]/)) { /* Nothing entered or non-numeric character */
nInput.style.border = "1px solid #f00";
showNumberOnlyError();
return;
}
if (parseInt(this.value) == 0) {
return;
}
else{
nInput.style.border = "1px solid #666";
}
var iNewStart = oSettings._iDisplayLength
* (this.value - 1);
if (iNewStart > oSettings.fnRecordsDisplay()) { /* Display overrun */
oSettings._iDisplayStart = (Math.ceil((oSettings
.fnRecordsDisplay() - 1)
/ oSettings._iDisplayLength) - 1)
* oSettings._iDisplayLength;
fnCallbackDraw(oSettings);
return;
}
oSettings._iDisplayStart = iNewStart;
fnCallbackDraw(oSettings);
}); /* Take the brutal approach to cancelling text selection */
$('span', nPaging).bind('mousedown', function() {
return false;
});
$('span', nPaging).bind('selectstart', function() {
return false;
});
},
/*
* Function: oPagination.listbox.fnUpdate
* Purpose: Update the listbox element
* Returns: -
* Inputs: object:oSettings - dataTables settings object
* function:fnCallbackDraw - draw function which must be called on update
*/
"fnUpdate" : function(oSettings, fnCallbackDraw) {
if (!oSettings.aanFeatures.p) {
return;
}
var iPages = Math.ceil((oSettings.fnRecordsDisplay())
/ oSettings._iDisplayLength);
var iCurrentPage = Math.ceil(oSettings._iDisplayStart
/ oSettings._iDisplayLength) + 1; /* Loop over each instance of the pager */
var an = oSettings.aanFeatures.p;
for ( var i = 0, iLen = an.length; i < iLen; i++) {
var spans = an[i].getElementsByTagName('span');
var inputs = an[i].getElementsByTagName('select');
var elSel = inputs[0];
if (elSel.options.length != iPages) {
elSel.options.length = 0; //clear the listbox contents
for ( var j = 0; j < iPages; j++) { //add the pages
var oOption = document.createElement('option');
oOption.text = j + 1;
oOption.value = j + 1;
try {
elSel.add(oOption, null); // standards compliant; doesn't work in IE
} catch (ex) {
elSel.add(oOption); // IE only
}
}
spans[1].innerHTML = " nbsp;of nbsp;" + iPages;
}
elSel.value = iCurrentPage;
}
}
};