397 lines
12 KiB
JavaScript
397 lines
12 KiB
JavaScript
/*================================================================================================================\
|
|
+
|
|
+ Project : GoData-VECV
|
|
+ Filename : notifications.js
|
|
+ Module Name : Notifications
|
|
+ Purpose : For display notifications
|
|
+ Coded By : Parul Gupta
|
|
+
|
|
+================================================================================================================*/
|
|
|
|
/**
|
|
* To display notifications
|
|
* @module Notifications
|
|
*/
|
|
|
|
|
|
/**
|
|
* This class contains functionality of Notfications for CCE & Dealer.
|
|
* @class Notifications
|
|
* @constructor
|
|
*/
|
|
|
|
|
|
//Global variables
|
|
var previousCount = "", previousKamCount = "";
|
|
var newCount = "", newKamCount = "";
|
|
var xhr_getNotificationCount, xhr_getKamNotificationCount;
|
|
|
|
/**
|
|
* Function to bind all notifications data in drop down
|
|
* @method getNotifications
|
|
* @param {String} controller The name of controller action
|
|
* @for Notifications
|
|
*/
|
|
function getNotifications(controller) {
|
|
//console.log(controller);
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/Notifications/" + controller + "/",
|
|
success: function (data) {
|
|
$("#divNotifications").html('');
|
|
$("#divNotifications").html(data);
|
|
},
|
|
error: function (data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Function to get notifications total count in drop down
|
|
* @method getNotificationCount
|
|
* @param {String} controller The name of controller action
|
|
* @for Notifications
|
|
*/
|
|
function getNotificationCount(controller) {
|
|
//console.log(controller);
|
|
previousCount = $("#spanCount").text();
|
|
//console.log(previousCount);
|
|
var notificationCount;
|
|
|
|
if (xhr_getNotificationCount && xhr_getNotificationCount.readystate != 4) {
|
|
//console.log(xhr_getNotificationCount);
|
|
xhr_getNotificationCount.abort();
|
|
}
|
|
xhr_getNotificationCount = $.ajax({
|
|
type: "POST",
|
|
url: "/Notifications/" + controller + "/",
|
|
success: function (data) {
|
|
//console.log(data);
|
|
if (data.success == true) {
|
|
if (data.total > 0) {
|
|
notificationCount = data.total;
|
|
$("#spanCount").text(notificationCount);
|
|
$("#divNotificationCount").show();
|
|
} else if (data.total == 0) {
|
|
notificationCount = data.total;
|
|
$("#spanCount").text(notificationCount);
|
|
$("#divNotificationCount").hide();
|
|
}
|
|
}
|
|
},
|
|
global: false,
|
|
error: function (data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
* Function to display notifications.
|
|
* @method displayNotifications
|
|
* @for Notifications
|
|
*/
|
|
function displayNotifications() {
|
|
|
|
//function call on click of div
|
|
$("#divShowNotification").click(function (e) {
|
|
|
|
//add and remove hide, show class
|
|
if ($("#divNotifications").hasClass('hide')) {
|
|
//if (document.getElementById('toggleDiv').style.display == "none") {
|
|
// $("#divNotifications").show();
|
|
// $("#divNotifications").removeClass('hide');
|
|
//} else {
|
|
// $("#toggleDiv").hide();
|
|
// $("#divNotifications").show();
|
|
// $("#divNotifications").removeClass('hide');
|
|
//}
|
|
|
|
if (document.getElementById('toggleDiv').style.display != "none") {
|
|
$("#toggleDiv").hide();
|
|
$("#divNotifications").show();
|
|
$("#divNotifications").removeClass('hide');
|
|
} else if (document.getElementById('divKamNotifications').style.display != "none") {
|
|
$("#divKamNotifications").hide();
|
|
$("#divNotifications").show();
|
|
$("#divNotifications").removeClass('hide');
|
|
} else {
|
|
$("#divNotifications").show();
|
|
$("#divNotifications").removeClass('hide');
|
|
}
|
|
|
|
getNotifications(controller);
|
|
|
|
//hide on mouse click anywhere on page if it displays notifications div
|
|
e.stopPropagation();
|
|
|
|
} else {
|
|
$("#divNotifications").hide();
|
|
$("#divNotifications").addClass('hide');
|
|
e.stopPropagation();
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Function to display notification count.
|
|
* @method showNotificationCount
|
|
* @for Notifications
|
|
*/
|
|
function showNotificationCount() {
|
|
|
|
getNotificationCount(countController);
|
|
|
|
var audioElement = document.createElement('audio');
|
|
audioElement.setAttribute('src', '../../Content/css/FacebookPop.mp3');
|
|
audioElement.pause();
|
|
|
|
setTimeout(function () {
|
|
newCount = $("#spanCount").text();
|
|
if (newCount == "") {
|
|
newCount = "0";
|
|
}
|
|
if (previousCount == "") {
|
|
previousCount = "0";
|
|
}
|
|
if (newCount > previousCount) {
|
|
audioElement.play();
|
|
}
|
|
}, 1000 * 2);
|
|
}
|
|
|
|
|
|
/**
|
|
* Function to display notifications on dealer page and remove seen notification from notification div.
|
|
* @method showDealerNotificationData
|
|
* @for Notifications
|
|
*/
|
|
function showDealerNotificationData($this) {
|
|
var ticketid = $this.id;
|
|
var assignedTo = document.getElementById(ticketid).getAttribute('data-assignedTo');
|
|
var notificationId = document.getElementById(ticketid).getAttribute('data-Id');
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/Notifications/RemoveSeenNotificationsDealer/",
|
|
data: { ticketId: notificationId },
|
|
success: function (data) {
|
|
if (data.success == true) {
|
|
window.location.href = "/TicketAdministration_Dealer/Index?complaintNo=" + ticketid + "&assignedTo=" + assignedTo;
|
|
}
|
|
},
|
|
error: function (data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
* Function to display notifications on cce page and remove seen notification from notification div.
|
|
* @method showNotificationData
|
|
* @for Notifications
|
|
*/
|
|
function showNotificationData($this) {
|
|
var ticketid = $this.id;
|
|
var notificationId = document.getElementById(ticketid).getAttribute('data-Id');
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/Notifications/RemoveSeenNotifications/",
|
|
data: { ticketId: notificationId },
|
|
success: function (data) {
|
|
if (data.success == true) {
|
|
window.location.href = "/Ticket/TicketAdministration?complaintNo=" + ticketid;
|
|
}
|
|
},
|
|
error: function (data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
|
|
|
|
//======================================================== KAM Notifications =============================================//
|
|
|
|
|
|
|
|
/**
|
|
* Function to display KAM notification count.
|
|
* @method showKamNotificationCount
|
|
* @for Notifications
|
|
*/
|
|
function showKamNotificationCount() {
|
|
getKamNotificationCount(kamCountController);
|
|
|
|
var audioElement = document.createElement('audio');
|
|
audioElement.setAttribute('src', '../../Content/css/FacebookPop.mp3');
|
|
audioElement.pause();
|
|
|
|
setTimeout(function () {
|
|
newKamCount = $("#spanKamCount").text();
|
|
if (newKamCount == "") {
|
|
newKamCount = "0";
|
|
}
|
|
if (previousKamCount == "") {
|
|
previousKamCount = "0";
|
|
}
|
|
if (newKamCount > previousKamCount) {
|
|
audioElement.play();
|
|
}
|
|
}, 1000 * 2);
|
|
}
|
|
|
|
|
|
/**
|
|
* Function to get KAM notifications total count in drop down
|
|
* @method getKamNotificationCount
|
|
* @param {String} kamCountController The name of controller action
|
|
* @for Notifications
|
|
*/
|
|
function getKamNotificationCount(kamCountController) {
|
|
previousKamCount = $("#spanKamCount").text();
|
|
var notificationCount;
|
|
|
|
if (xhr_getKamNotificationCount && xhr_getKamNotificationCount.readystate != 4) {
|
|
xhr_getKamNotificationCount.abort();
|
|
}
|
|
xhr_getKamNotificationCount = $.ajax({
|
|
type: "POST",
|
|
url: "/Notifications/" + kamCountController + "/",
|
|
success: function (data) {
|
|
//console.log(data);
|
|
if (data.success == true) {
|
|
if (data.total > 0) {
|
|
notificationCount = data.total;
|
|
$("#spanKamCount").text(notificationCount);
|
|
$("#divKamNotificationCount").show();
|
|
} else if (data.total == 0) {
|
|
notificationCount = data.total;
|
|
$("#spanKamCount").text(notificationCount);
|
|
$("#divKamNotificationCount").hide();
|
|
}
|
|
}
|
|
},
|
|
global: false,
|
|
error: function (data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
* Function to display KAM notifications.
|
|
* @method displayKamNotifications
|
|
* @for Notifications
|
|
*/
|
|
function displayKamNotifications() {
|
|
|
|
//function call on click of div
|
|
$("#divShowKamNotification").click(function (e) {
|
|
|
|
//add and remove hide, show class
|
|
if ($("#divKamNotifications").hasClass('hide')) {
|
|
|
|
if (document.getElementById('toggleDiv').style.display != "none") {
|
|
$("#toggleDiv").hide();
|
|
$("#divKamNotifications").show();
|
|
$("#divKamNotifications").removeClass('hide');
|
|
} else if (document.getElementById('divNotifications').style.display != "none") {
|
|
$("#divNotifications").hide();
|
|
$("#divKamNotifications").show();
|
|
$("#divKamNotifications").removeClass('hide');
|
|
} else {
|
|
$("#divKamNotifications").show();
|
|
$("#divKamNotifications").removeClass('hide');
|
|
}
|
|
|
|
getKamNotifications(kamController);
|
|
|
|
//hide on mouse click anywhere on page if it displays notifications div
|
|
e.stopPropagation();
|
|
|
|
} else {
|
|
$("#divKamNotifications").hide();
|
|
$("#divKamNotifications").addClass('hide');
|
|
e.stopPropagation();
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
* Function to bind all KAM notifications data in drop down
|
|
* @method getKamNotifications
|
|
* @param {String} kam_Controller The name of controller action
|
|
* @for Notifications
|
|
*/
|
|
function getKamNotifications(kam_Controller) {
|
|
//console.log(kamController);
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/Notifications/" + kam_Controller + "/",
|
|
success: function (data) {
|
|
$("#divKamNotifications").html('');
|
|
$("#divKamNotifications").html(data);
|
|
},
|
|
error: function (data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
* Function to display notifications on cce page and remove seen notification from notification div.
|
|
* @method showNotificationDataKAM
|
|
* @for Notifications
|
|
*/
|
|
function showNotificationDataKAM($this) {
|
|
var ticketid = $("#" + $this.id).parent().prev().attr('id');
|
|
var notificationId = document.getElementById(ticketid).getAttribute('data-Id');
|
|
var kamVehicleRegistration = document.getElementById(ticketid).getAttribute('data-RegistrationNo');
|
|
window.location.href = "/Ticket/TicketAdministration?vRegistrationNo=" + kamVehicleRegistration + "&KamComplaintNo=" + ticketid + "&Notification=" + notificationId;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Function to display notifications on cce page and remove seen notification from notification div.
|
|
* @method removeNotificationDataKAM
|
|
* @for Notifications
|
|
*/
|
|
function removeNotificationDataKAM($this) {
|
|
var ticketid = $("#" + $this.id).parent().prev().attr('id');
|
|
var notificationId = document.getElementById(ticketid).getAttribute('data-Id');
|
|
var kamVehicleRegistration = document.getElementById(ticketid).getAttribute('data-RegistrationNo');
|
|
|
|
jConfirm("Are you sure you want to ignore/decline this ticket?", "Message", function (result) {
|
|
if (result) {
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/Notifications/RemoveKamTicket/",
|
|
data: { kamTicketId: ticketid, notificationId: notificationId },
|
|
success: function (data) {
|
|
if (data.success == true) {
|
|
|
|
getKamNotificationCount(kamCountController);
|
|
setTimeout(function () { $("#divShowKamNotification").trigger('click'); }, 200);
|
|
}
|
|
},
|
|
error: function (data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
}
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|