API Docs for:
Show:

File: Inventory\ManageFleet_Detail.js

/**
* To Manage Fleet
* @module Inventory
*/

/**
* This class contains functions related to show device details and their state (Operational/Non-operational/Disabled/Archive/All")
* @class ManageFleet_details
* @constructor
*/

//Global variables
var activeRequest_Edit;
var vRegNo = "";
var ConfirmDealerName = "";
var vRowIndex = "0";
/**
* Function of Binding Of Grid And set Delete Button In Vechile Grid.
* @method onRowBoundVechile
* @param {Object} e Contains Complete kendo grid property
* @for ManageFleet_Detail
*/
function onRowBoundDealer(e) {
    // Add Edit and delete icon.
    $('.k-grid-Edit').text("").removeClass("k-button k-button-icontext").html("<span class='k-icon k-edit'></span>");
    $('.k-grid-Delete').text("").removeClass("k-button k-button-icontext").html("<span class='k-icon k-delete'></span>");

    var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
    // called common file function to show title on mouse hover.
    addTitleAttribute();
    // called common file function to show title on mouse hover.
    addTitleAttribute();
    // severity functionality
    var data = this.dataSource.view();
    // Show Delete button in Grid if We add New Row And Hide Delete button in grid if Row is Already Inserted 

    //for (var i = 0; i < data.length; i++) {
    //    if (data[i].VanId != "") {
    //        $("#gridDealer").data("kendoGrid").tbody.find("tr[data-uid='" + data[i].uid + "']").find('td').find('#cmdDelete').find("span").removeClass("k-icon k-delete");
    //    }
    //    else {
    //        $("#gridDealer").data("kendoGrid").tbody.find("tr[data-uid='" + data[i].uid + "']").find('td').find('#cmdVanLocation').removeAttr("id");
    //    }
    //}
    // show no data available message when grid has no data.
    //displayNoResultManageFleet(e)
}
/**
* Function to set the van Location.
* @method ShowVanLocation
* @param {Object} e Contains Complete Grid Selected Row Object
* @for ManageFleet_Detail
*/
function ShowVanLocation(e) {
    addKendoWindowToDiv("#divShowVanLocation", "Set Van Location", "1000px", 250);
    // Get selected row
    var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
    // Add Van Detail model
    oDealer = {};
    oDealer.VanId = dataItem.VanId;
    oDealer.VanAlias = dataItem.VanAlias;
    oDealer.VanState = dataItem.VanState;
    oDealer.VanCity = dataItem.VanCity;
    oDealer.VanModelName = dataItem.VanModelName;
    oDealer.VanRegistrationNo = dataItem.VanRegistrationNo;
    oDealer.ServiceEngineerName = dataItem.ServiceEngineerName;
    oDealer.ServiceEngineerContactNumber = dataItem.ServiceEngineerContactNumber;
    oDealer.ServiceEngineerApplicationLicenseKey = dataItem.ServiceEngineerApplicationLicenseKey;
    oDealer.VanIsVisitedInterState = dataItem.VanIsVisitedInterState;

    //// Ajax request for edit ; if exist then kill it.

    if (activeRequest_Edit && activeRequest_Edit.readystate != 4) {
        activeRequest_Edit.abort();
    }
    if (dataItem.VanId == "") {
        //jAlert("Please First Add Van", 'message');
        jAlert(MANAGE_FLEET_MESSAGES.addVanRequired, 'message');
    }
    else {
        activeRequest_Edit = $.ajax({
            type: "GET",
            url: "/Inventory/ShowDealerVanDetail",
            data: oDealer,
            success: function (data) {
                $("#divShowVanLocation").html('');
                $("#divShowVanLocation").parent().addClass("responsive_popup") //addClass for respond the menu
                $("#divShowVanLocation").html(data);
                //open form in new dialog box
                $("#divShowVanLocation").data("kendoWindow").open();
                $("#btnSaveVan").prop('value', 'Update');
                SetKendoWindowTitle("#divShowVanLocation", "Set Van Location");

            },
            error: function (data) {
                console.log(data);
            }
        });
    }
    // Add Van Detail model
}

/**
* Function to Update the Van Detail.
* @method editDealer
* @param {Object} e Contains Complete Grid Selected Row Object
* @for ManageFleet_Detail
*/
function editDealer(e) {
    addKendoWindowToDiv("#divCreateDealer", "Edit Van Detail", "833px", 385);
    // Get selected row
    var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
    vSelectedRow = this.dataItem($(e.currentTarget).closest("tr"));
    vDealerContactNoOnFocus = $("#DealerContactNo").val();
    // Add Van Detail model
    oDealer = {};
    oDealer.VanId = dataItem.VanId;
    oDealer.VanAlias = dataItem.VanAlias;
    oDealer.VanState = dataItem.VanState;
    oDealer.VanCity = dataItem.VanCity;
    oDealer.VanModelName = dataItem.VanModelName;
    oDealer.VanRegistrationNo = dataItem.VanRegistrationNo;
    oDealer.ServiceEngineerName = dataItem.ServiceEngineerName;
    oDealer.ServiceEngineerContactNumber = dataItem.ServiceEngineerContactNumber;
    oDealer.ServiceEngineerApplicationLicenseKey = dataItem.ServiceEngineerApplicationLicenseKey;
    oDealer.VanIsVisitedInterState = dataItem.VanIsVisitedInterState;
    //// Ajax request for edit ; if exist then kill it.

    if (activeRequest_Edit && activeRequest_Edit.readystate != 4) {
        activeRequest_Edit.abort();
    }
    $("#div_load").show();
    activeRequest_Edit = $.ajax({
        type: "GET",
        url: "/Inventory/AddorEditVanDetail",
        data: oDealer,
        success: function (data) {
            $("#divCreateDealer").html('');
            $("#divCreateDealer").html(data);
            //open form in new dialog box
            $("#divCreateDealer").data("kendoWindow").open();
            $("#btnSaveVan").prop('value', 'Update');
            SetKendoWindowTitle("#divCreateDealer", "Edit Van Detail");
            $("#divShowVanLocation").html("");
            //LoadCityListOnDealer(0);
            LoadCityListForVan($("#ddState option:selected").val(), dataItem.VanCity);
            vRegistrationNoOnFocus = dataItem.VanRegistrationNo;
            //The Registration No is added till it is not inserted in DB
            //if (dataItem.VanId == "") {
            //    $('#VanRegistrationNo').attr('readonly', false);
            //}
            //else {
            //    $('#VanRegistrationNo').attr('readonly', true);
            //}
            //$('#VanModelName').attr('readonly', true);
            vRegNo = $('#VanRegistrationNo').val();

            HideVanDetailMessage();

        },
        error: function (data) {
            console.log(data);
        }, complete: function () {
            $("#div_load").hide();
        }
    });
    // Add Van Detail model
}

/**
* This function is used  to Delete Van Detail In Grid.
* @method DeleteDealer
* @param {Object} e Contains Complete Grid Selected Row Object
* @for ManageFleet_Detail
*/
function DeleteDealer(e) {
    var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
    var grid = $("#gridDealer").data("kendoGrid");
    datasource = grid.dataSource;
    //jConfirm("Do you want to delete the Van Name <b>" + dataItem.VanAlias + '</b> ?', 'Delete', function (result) {
    jConfirm(MANAGE_FLEET_MESSAGES.confirmDeleteVan + " <b>" + dataItem.VanAlias + '</b> ?', 'Delete', function (result) {
        if (result) {
            dataItem.IsDeletedVan = true;
            if (dataItem.VanId == "")
                datasource.remove(dataItem);
            else {
                $(e.currentTarget).closest("tr").hide();
                for (var i = 0; i <= datasource.total() - 1; i++) {
                    var datasourceItem = datasource.at(i);
                    if (dataItem.VanId === datasourceItem.VanId) {
                        datasourceItem.set("IsDeletedVan", true);
                    }
                }
            }

        }
    });
}

/**
* Function to show Dealer details.
* @method AddOrEditFleet
* @for ManageFleet_Detail
*/
function showDealerDetails() {
    //function call on click of Dealer list table's row
    $("#tableDealerList tbody tr").click(function (e) {

        var dealerId, $this;
        $this = $(this);
        console.log($this);
        dealerId = e.currentTarget.id;
        vRowIndex = e.currentTarget.rowIndex;
        //Add button hide show
        $("#btnAdd,#btnDelete").show();

        // add selected class on selected row
        $('#tableDealerList > tbody > tr').removeClass("SelectedRow");
        $this.addClass("SelectedRow");

        // ajax request to get non-vecv user detail
        if (activeRequest_UserDetails && activeRequest_UserDetails.readystate != 4) {
            activeRequest_UserDetails.abort();
        }
        GetDealerDetailByID(dealerId);
    });

}

/**
* This function is used  to Delete Van Detail In Grid.
* @method GetDealerDetailByID
* @param {String} dealerID Dealer Id that is used to Get the Detail.
* @for ManageFleet_Detail
*/
function GetDealerDetailByID(dealerID) {
    $("#div_load").show();
    activeRequest_UserDetails = $.ajax({
        type: "POST",
        url: "/Inventory/AddOrEditFleet/",
        data: { sDealerId: dealerID },
        success: function (data) {
            $("#divAddOrEditFleet").html('');
            $("#divAddOrEditFleet").html(data);
            stateVal = $("#ddState").val();
            LoadCityList(stateVal);
            //$("#ddOrganization").hide();
            //$("#ddState").hide();
            //$("#ddCity").hide();
            //$("#DealerOrganizationName").show();
            //$("#DealerStateName").show();
            //$("#DealerCity").show();
            vDealerContactNoOnFocus = $("#DealerContactNo").val();
            HideDealerDetailMessage();
            HideVanDetailMessage();
            $("#btnSaveFleet").prop('value', 'Update');
            ConfirmDealerName = $("#DealerDealerName").val();
            $("#NewDealerId").prop('readonly', true);
        },
        complete: function () {
            $("#div_load").hide();
        },
        error: function (data) {
            console.log(data);
        }
    });
}



/**
* This Function to Hide the dealer Validation Messages.
* @method HideDealerDetailMessage
* @for ManageFleet_Detail
*/
function HideDealerDetailMessage() {
    $("#spnDealerId").hide();
    $("#spnOrganizationId").hide();
    $("#spnDealerName").hide();
    $("#spnDealerState").hide();
    $("#spnDealerCity").hide();
    $("#spnDealerContactNo").hide();
    $("#spnDealerContactNo").html("");

}

/**
* This function is Used to Hide The Validation Message For  Dealer Van Detail.
* @method HideVanDetailMessage
* @for ManageFleet_Detail
*/
function HideVanDetailMessage() {
    $("#spnVanName").hide();
    $("#spnVanState").hide();
    $("#spanVanCity").hide();
    $("#spanVanModelName").hide();
    $("#spanVanRegistration").hide();
    $("#spanVanServiceEngineerName").hide();
    $("#spanVanServiceEngineerContactNo").hide();
    $("#spnDealerContactNo").html("");
}

/**
* This function is Used to See Or Set The Van Location.
* @method HideVanDetailMessage
* @for ManageFleet_Detail
*/
function SetDealerLocation() {
    if (AllValidAddVanDetail()) {
        addKendoWindowToDiv("#divShowDealerLocation", "Set Dealer Location", "833px", 435);
        $("#divShowDealerLocation").parent().addClass("responsive_popup") //addClass for respond the menu
        // Get selected row

        if (activeRequest_Edit && activeRequest_Edit.readystate != 4) {
            activeRequest_Edit.abort();
        }

        activeRequest_Edit = $.ajax({
            type: "GET",
            url: "/Inventory/ShowDealerMap",
            success: function (data) {
                $("#divShowDealerLocation").html('');
                $("#divShowDealerLocation").html(data);
                //open form in new dialog box
                $("#divShowDealerLocation").data("kendoWindow").open();

                SetKendoWindowTitle("#divShowDealerLocation", "Set Dealer Location");
            },
            error: function (data) {
                console.log(data);
            }
        });
    }
    // Add Van Detail model
    //$("#divCreateDealer").parent().addClass("responsive_popup")
}


/**
* This function is Used to Check Whether the keypress No is Entered or Not.
* @method isNumber
* @param {Object} e Get Event Detail
* @param {Object} t Get Textbox Detail
* @for ManageFleet_Detail
*/

function isNumber(e, t) {

    try {
        if (window.event) {
            var charCode = window.event.keyCode;
        }
        else if (e) {
            var charCode = e.which;
        }
        else { return true; }
        if (charCode > 31 && (charCode < 48 || charCode > 57)) {
            return false;
        }
        return true;
    }
    catch (err) {
        alert(err.Description);
    }
}

/**
* This function is Used to Hide The Validation Message For  Add Van Detail.
* @method AllValidAddVanDetail
* @for ManageFleet_Detail
*/
function AllValidAddVanDetail() {
    HideDealerDetailMessage();
    var DealerState = $("#ddState option:selected").val();
    var DealerCity = $("#ddCity option:selected").val();

    var vResult = false;
    if (DealerState == "")
        $("#spnDealerState").show();
    else if (DealerCity == "" || DealerCity == "-Select-")
        $("#spnDealerCity").show();
    else if (vDealerContactExist == true)
        jAlert(vDealerContactNoExistMsg, 'message');
    else
        vResult = true;

    return vResult;
}