API Docs for:
Show:

File: Notifications\notifications.js

/*================================================================================================================\
+
+ 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 = "";
var newCount = "";
var xhr_getNotificationCount;

/**
* 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');
            }
            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);
        }
    });
}