EOS/Scripts/Inventory/ManageFleet_Detail.js
Nidhi Bhargava f0c1ab20e1 code push
2025-09-04 16:25:07 +05:30

515 lines
18 KiB
JavaScript

/**
* 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();
openKendoWindowInCenter("#divShowVanLocation")
$("#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", 350);
// Get selected row
// alert('ee');
var vanfueltype = "";
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();
openKendoWindowInCenter("#divCreateDealer");
$("#btnSaveVan").prop('value', 'Update');
SetKendoWindowTitle("#divCreateDealer", "Edit Van Detail");
$("#divShowVanLocation").html("");
//LoadCityListOnDealer(0);
//LoadStateListRegionWise('ddOrganization', 'ddState');
//setTimeout(function () {
// $("#ddState").val($('#hdnDealerStateId').val());
//LoadCityListForVan($('#hdnDealerStateId').val(), dataItem.VanCity);
//}, 500);
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();
var apiUrl = url + "Api/Admin?get=s&fuel_type=tt";
// alert(_type);
$.ajax({
type: "Post",
url: apiUrl,
data: { Token: securityToken, dealerId: dataItem.VanId, fuelValue: 'van' },
success: function (data) {
// alert(data.substring(0, 2))
// var arr = data.split('&');
// alert( arr[0] + "aa" + arr[1] );
vanfueltype = data;
setTimeout(function () {
var combobox = $("#fueltypeComboboxVan").data("kendoComboBox");//This "instantiates it"
if (vanfueltype.toLowerCase() == "electric") {
combobox.value("Electric");
}
else if (vanfueltype.toLowerCase() == "diesel,cng") {
combobox.value("Diesel/CNG");
}
else if (vanfueltype.toLowerCase() == "diesel,cng,electric") {
combobox.value("Diesel/CNG/Electric");
}
// $("#ddVehicleType").data("kendoAutoComplete").value(fueltype);
}, 1000);
}
});
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);
}
}
}
}
});
}
/**
* 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 ReleaseDevice(VanAlias, VanId) {
var grid = $("#gridDealer").data("kendoGrid");
datasource = grid.dataSource;
console.log(datasource);
//jConfirm("Do you want to delete the Van Name <b>" + dataItem.VanAlias + '</b> ?', 'Delete', function (result) {
jConfirm(MANAGE_FLEET_MESSAGES.confirmReleaseDevice + " <b>" + VanAlias + '</b> ?', 'Release', function (result) {
if (result) {
for (var i = 0; i <= datasource.total() - 1; i++) {
var datasourceItem = datasource.at(i);
if (datasourceItem.VanId === VanId) {
console.log(datasourceItem.IsVanRelease);
datasourceItem.set("IsVanRelease", false);
console.log(datasourceItem.IsVanRelease);
}
}
}
console.log(datasource);
});
}
/**
* Function to show Dealer details.
* @method AddOrEditFleet
* @for ManageFleet_Detail
*/
var fueltype = "";
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) {
var apiUrl = url + "Api/Admin?get=s&fuel_type=tt";
$.ajax({
type: "Post",
url: apiUrl,
data: { Token: securityToken, dealerId: dealerID, fuelValue: 'dealer'},
success: function (data) {
// alert(data.substring(0, 2))
var arr = data.split('&');
// alert( arr[0] + "aa" + arr[1] );
fueltype = data;
}
});
$("#div_load").show();
activeRequest_UserDetails = $.ajax({
type: "POST",
url: "/Inventory/AddOrEditFleet/",
data: { sDealerId: dealerID },
success: function (data) {
var stateVal;
setTimeout(function () {
$("#divAddOrEditFleet").html('');
console.log('aa');
$("#divAddOrEditFleet").html(data);
setTimeout(function () {
$("#NewDealerId").attr('disabled','disabled');
$("#NewDealerId").addClass("disable_btn valid");
// $("#ddVehicleType").val(fueltype);
var combobox = $("#fueltypeComboboxDealer").data("kendoComboBox");//This "instantiates it"
if (fueltype.toLowerCase() == "electric") {
combobox.value("Electric");
}
else if (fueltype.toLowerCase() == "diesel,cng") {
combobox.value("Diesel/CNG");
}
else if (fueltype.toLowerCase() == "diesel,cng,electric") {
combobox.value("Diesel/CNG/Electric");
}
// $("#ddVehicleType").data("kendoAutoComplete").value(fueltype);
}, 1000);
}, 500);
LoadStateListRegionWise('ddOrganization', 'ddState', 'editDealer');
//setTimeout(function () {
//}, 1000);
vDealerContactNoOnFocus = $("#DealerContactNo").val();
HideDealerDetailMessage();
HideVanDetailMessage();
$("#btnSaveFleet").prop('value', 'Update');
ConfirmDealerName = $("#DealerDealerName").val();
$("#NewDealerId").prop('readonly', true).addClass("disable_btn");
},
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", 250);
$("#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();
openKendoWindowInCenter("#divShowDealerLocation");
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;
}