Handles when contact_id exceeds greatest or least contact_id.

* will go to the closest contact_id, nice behavior.
This commit is contained in:
Jonathan Rosenbaum
2017-10-31 07:03:00 +00:00
parent b63df15721
commit bc3c7450fd
2 changed files with 33 additions and 1 deletions
+23 -1
View File
@@ -5,11 +5,33 @@ $(function(){
$.ajaxSetup({async:false});
var contact_id = $("#contact_id").text();
if (contact_id) {
$("table").attr("width","");
// handle logic for previous and next buttons
//var prev, next;
var prev = Number(contact_id) - 1, next = Number(contact_id) + 1;
if (prev <= 0) {
prev = 1;
}
if (next === 0) {
next = 1;
}
$.post("json/reports.php", { total: 1 }, function (data) {
var obj = $.parseJSON(data);
if (contact_id > obj.total) {
prev = obj.total;
next = obj.total;
} else if (contact_id === obj.total) {
next = obj.total;
}
});
$(".stats-left").attr("href","/individual_history_log.php?contact_id=" + prev);
$(".stats-right").attr("href","/individual_history_log.php?contact_id=" + next);