API Docs for:
Show:

File: Report\callFeedbackRating.js

/*================================================================================================================\
+
+ Project     : GODATA-VECV
+ Filename    : callFeedbackRating.js
+ Module Name : ReportModule
+ Purpose     : To show and export Call Feedback Rating report.
+ Coded By    : Pankaj Khandal
+
+================================================================================================================*/


/**
* To show and export reports.
* @module ReportModule
*/

/**
* To show and export Call Feedback Rating report.
* @class CallFeedbackRating
* @constructor
*/

/**
* Global References: To store ajax request's XHR objects.
* @for CallFeedbackRating
*/
var xhr_report = null;
var xhr_exportExport = null;


//================== FILTERS Section Start =========================
/**
* To populate state combobox.
* @method loadStateChoices
* @for HdBusLmdContrCallFeedbackRatingibution
*/
function loadStateChoices() {
    utcMinutes = parseInt(UtcMinutes, 10);
    UserId = userId;

    $.ajax({
        type: "POST",
        url: WCFRESTURL.GetStateListIdWise,
        data: { Token: securityToken, UtcMinutes: utcMinutes, UserId: UserId },
        dataType: "json",
        success: function (data) {
            $("#stateCombobox").kendoComboBox({
                dataTextField: "StateAlias",
                dataValueField: "StateId",
                filter: "contains",
                dataSource: data,
                change: function () {
                    // loading cities according to state id
                    loadCityChoices($("#stateCombobox").val());
                    loadDealerChoices($("#stateCombobox").data("kendoComboBox").text(), $("#cityCombobox").data("kendoComboBox").text());
                }
            });
        },
        complete: function () {
            //$("#stateCombobox").data('kendoComboBox').select(0);
        },
        error: function (jqXHR, textStatus, errorThrown) {
        }
    });
}

/**
* To populate city combobox.
* @method loadCityChoices
* @param {String} stateId id of state
* @for CallFeedbackRating
*/
function loadCityChoices(stateId) {
    utcMinutes = parseInt(UtcMinutes, 10);
    UserId = userId;

    $.ajax({
        type: "POST",
        url: WCFRESTURL.GetCityListStateIdWise,
        data: { Token: securityToken, UtcMinutes: utcMinutes, UserId: UserId, StateId: stateId },
        dataType: "json",
        success: function (data) {
            $("#cityCombobox").kendoComboBox({
                dataTextField: "CityName",
                dataValueField: "CityId",
                filter: "contains",
                dataSource: data,
                change: function () {
                    loadDealerChoices($("#stateCombobox").data("kendoComboBox").text(), $("#cityCombobox").data("kendoComboBox").text());
                }
            });
        },
        complete: function () {
            $("#cityCombobox").data("kendoComboBox").text('');
        },
        error: function (jqXHR, textStatus, errorThrown) {
        }
    });
}

/**
* To populate city combobox.
* @method loadCityChoices
* @param {String} state state-name
* @param {String} city city-name
* @for CallFeedbackRating
*/
function loadDealerChoices(state, city) {
    utcMinutes = parseInt(UtcMinutes, 10);
    UserId = userId;

    $.ajax({
        type: "POST",
        url: WCFRESTURL.GetDealerStateCityWise,
        data: { Token: securityToken, UtcMinutes: utcMinutes, UserId: UserId, DealerStateParam: state, DealerCityParam: city },
        dataType: "json",
        success: function (data) {
            $("#dealerCombobox").kendoComboBox({
                dataTextField: "DealerDealerName",
                dataValueField: "DealerId",
                filter: "contains",
                dataSource: data,
            });
        },
        complete: function () {
            $("#dealerCombobox").data("kendoComboBox").text('');
        },
        error: function (jqXHR, textStatus, errorThrown) {
        }
    });
}
//================== FILTERS Section End =========================

/**
* To get filter parameters and show report and showing/hiding export functionality accordingly. 
* @method showReport
* @for CallFeedbackRating
*/
function showReport() {
    // hiding the excel icon
    $('.excelIcon').hide();

    // Making the target Div Container empty
    $('#divGrid').empty();

    var startDate = $("#fromDatePicker").val(),
        endDate = $("#fromDatePicker").val(),
        state = $("#stateCombobox").data("kendoComboBox").text(),
        city = $("#cityCombobox").data("kendoComboBox").text(),
        dealerId = $("#dealerCombobox").val();

    // sending the Ajax request to show the outage report and hadling its completion
    if (xhr_report && xhr_report.readystate != 4) {
        xhr_report.abort();
    }
    xhr_report = $.ajax({
        type: "POST",
        url: "/Report/ShowCallFeedbackRating/",
        data: {  fromDate: startDate, toDate: endDate, state: state, city: city, dealerId: dealerId },
        success: function (data) {
            // populating HTML on page
            $('#divGrid').html(data);
            // Showing/Hising the Excel Icon according to received data.
            if (data.length < 300) { $('.excelIcon').hide(); }
            else { $('.excelIcon').show(); }
        },
        complete: function () {
            $("#tab_CallFeedbackParams").trigger("click");
        },
        error: function (data) {
            // hiding the excel icon
            $('.excelIcon').hide();
            console.log("Error");
        }
    });
}

/**
* To get filter parameters and export report. 
* @method exportReport
* @for CallFeedbackRating
*/
function exportReport() {
    var startDate = $("#fromDatePicker").val(),
        endDate = $("#fromDatePicker").val(),
        state = $("#stateCombobox").data("kendoComboBox").text(),
        city = $("#cityCombobox").data("kendoComboBox").text(),
        dealerId = $("#dealerCombobox").val();

    // sending ajax request to export ICR Unique Users and Data Usage to Excel, and hadling its completion
    if (xhr_exportExport && xhr_exportExport.readystate != 4) {
        xhr_exportExport.abort();
    }
    xhr_exportExport = $.ajax({
        type: "POST",
        url: "/Report/ExportCallFeedbackRating/",
        data: {  fromDate: startDate, toDate: endDate, state: state, city: city, dealerId: dealerId },
        success: function (data) {
            // making the generated Excel available for downloading.
            window.location.href = data;
        },
        complete: function () {
        },
        error: function (data) {
            console.log("Error in Export to Excel");
        }
    });
}

/**
* Fired when Html-DOM is ready.
* @event $(document).ready
* @for CallFeedbackRating
*/
$(document).ready(function () {
    // populating state, city & dealer comboboxes
    loadStateChoices();
    loadCityChoices($("#stateCombobox").val())
    loadDealerChoices($("#stateCombobox").val(), $("#cityCombobox").val());

    //Tab functionality
    $("#tab_CallFeedbackParams").click(function () {
        $(this).addClass('selected');
        $('#tab_CallFeedBackRating').removeClass('selected');
        $('#CallFeedbackParamsDiv').show();
        $('#CallFeedBackRatingDiv').hide();
    });
    $("#tab_CallFeedBackRating").click(function () {
        $(this).addClass('selected');
        $('#tab_CallFeedbackParams').removeClass('selected');
        $('#CallFeedbackParamsDiv').hide();
        $('#CallFeedBackRatingDiv').show();
    });
    // First tab is triggered
    $("#tab_CallFeedbackParams").trigger("click");
});