608 lines
17 KiB
JavaScript
608 lines
17 KiB
JavaScript
/*================================================================================================================\
|
|
+
|
|
+ Project : GoData-VECV
|
|
+ Filename : vecvUserInventory.js
|
|
+ Module Name : VecvUserInventory
|
|
+ Purpose : For Eicher User Inventory
|
|
+ Coded By : Parul Gupta
|
|
+
|
|
+================================================================================================================*/
|
|
|
|
|
|
/**
|
|
* For user management
|
|
* @module UserManagement
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
* This class contains functionality of add vecv users.
|
|
* @class VecvUserManagement
|
|
* @constructor
|
|
*/
|
|
|
|
|
|
//Global variables
|
|
var activeRequest, activeRequest_City, activeRequest_del, activeRequest_UserDetails, activeRequest_export;
|
|
/**
|
|
* Close the kendo window.
|
|
* @method closeWindow
|
|
* @param divId : Id which we want to close kendowindo.
|
|
* @for VecvUserManagement
|
|
*/
|
|
function closeWindow(divId) {
|
|
$('#resetPasswordForm')[0].reset();
|
|
$("#resetPasswordForm").find(".field-validation-error").empty();
|
|
$(divId).data("kendoWindow").close();
|
|
}
|
|
|
|
/**
|
|
* Function to get vecv users list.
|
|
* @method getVecvUserList
|
|
* @for VecvUserManagement
|
|
*/
|
|
function getVecvUserList() {
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/UserInventory/ManageUserInventory_GetUserList/",
|
|
data: { userType: "user" },
|
|
success: function (data) {
|
|
|
|
//Bind html
|
|
$("#divVecvUserList").html(data);
|
|
},
|
|
error: function (data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
* Function to show vecv users details.
|
|
* @method showUserDetails
|
|
* @for VecvUserManagement
|
|
*/
|
|
function showUserDetails() {
|
|
|
|
//function call on click of user list table's row
|
|
$("#tableUserList tbody tr").click(function (e) {
|
|
|
|
var userName, $this;
|
|
$this = $(this);
|
|
userName = e.currentTarget.id;
|
|
|
|
//Add button hide show
|
|
$("#btnAdd").show();
|
|
$("#btnEdit").show();
|
|
//$("#btnDelete").show();
|
|
|
|
// add selected class on selected row
|
|
$('#tableUserList > tbody > tr').removeClass("SelectedRow");
|
|
$this.addClass("SelectedRow");
|
|
|
|
// ajax request to get user detail
|
|
if (activeRequest_UserDetails && activeRequest_UserDetails.readystate != 4) {
|
|
activeRequest_UserDetails.abort();
|
|
}
|
|
activeRequest_UserDetails = $.ajax({
|
|
type: "POST",
|
|
url: "/UserInventory/ManageUserInventory_GetUserDetails/",
|
|
data: { UserName: userName, ObjectId: null },
|
|
success: function (data) {
|
|
|
|
$("#divVecvUserDetailPanel").html('');
|
|
$("#divVecvUserDetailPanel").html(data);
|
|
|
|
if ($("#item_IsLocked").val() == "True") {
|
|
$("#btnUnlockUser").show();
|
|
}
|
|
else {
|
|
$("#btnUnlockUser").hide();
|
|
//$("#btnUnlockUser").prop("disabled", true);
|
|
}
|
|
},
|
|
error: function (data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
});
|
|
|
|
//Trigger click event on first row of user list table
|
|
$("#tableUserList tbody tr:first").trigger('click');
|
|
}
|
|
|
|
|
|
/**
|
|
* Function to add new vecv users.
|
|
* @method addUser
|
|
* @for VecvUserManagement
|
|
*/
|
|
function addUser() {
|
|
|
|
//send ajax report to add user
|
|
$.ajax({
|
|
|
|
type: "Get",
|
|
url: "/UserInventory/ManageUserInventory_AddVecvUser/",
|
|
success: function (data) {
|
|
$("#divVecvUserDetailPanel").html("");
|
|
$("#divVecvUserDetailPanel").html(data);
|
|
$("#btnAdd").hide();
|
|
$("#btnEdit").hide();
|
|
//$("#btnDelete").hide();
|
|
},
|
|
|
|
error: function (data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Function to add new vecv users.
|
|
* @method editUser
|
|
* @for VecvUserManagement
|
|
*/
|
|
function editUser() {
|
|
var userName = $('#tableUserList > tbody > tr.SelectedRow')[0].id;
|
|
var apiUrl = url + "Api/EPS?geteps=yes&seteps=yes&iseps=yes";
|
|
/*if (document.getElementById('rdoYesEPS').checked) {
|
|
iseps = 'yes';g , string seteps, string iseps
|
|
}
|
|
else if (document.getElementById('rdoNoEPS').checked) {
|
|
iseps = 'no';
|
|
}
|
|
else if (document.getElementById('rdobothEPS').checked) {
|
|
iseps = 'both';
|
|
}*/
|
|
var isval = "";
|
|
// alert(iseps);
|
|
$.ajax({
|
|
type: "Post",
|
|
url: apiUrl,
|
|
dataType: "json",
|
|
data: { Token: "teramatrix", AuthEngineId: userName },
|
|
success: function (data) {
|
|
|
|
isval = data;
|
|
|
|
}
|
|
});
|
|
//send ajax report to add user
|
|
$.ajax({
|
|
|
|
type: "Get",
|
|
url: "/UserInventory/ManageUserInventory_EditVecvUser/",
|
|
data: { UserName: userName, ObjectId: null },
|
|
success: function (data) {
|
|
|
|
$("#divVecvUserDetailPanel").html("");
|
|
$("#divVecvUserDetailPanel").html(data);
|
|
$("#btnAdd").hide();
|
|
$("#btnEdit").hide();
|
|
//$("#btnDelete").hide();
|
|
},
|
|
complete: function () {
|
|
setTimeout(function () {
|
|
// alert(isval);
|
|
if (isval.toLowerCase() == 'yes') {
|
|
$('#rdoYesEPS').prop('checked', true);
|
|
}
|
|
if (isval.toLowerCase() == 'no') {
|
|
$('#rdoNoEPS').prop('checked', true);
|
|
|
|
}
|
|
if (isval.toLowerCase() == 'both') {
|
|
$('#rdobothEPS').prop('checked', true);
|
|
|
|
}
|
|
}, 500);
|
|
|
|
|
|
},
|
|
error: function (data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
* Function to check if user already exist.
|
|
* @method checkIfUsernameIsExist
|
|
* @for VecvUserManagement
|
|
*/
|
|
function checkIfUsernameIsExist() {
|
|
|
|
//function call on blur of user name text box
|
|
$("#UserName").blur(function () {
|
|
var _userName = $("#UserName").val();
|
|
if (_userName != "") {
|
|
$.getJSON("/UserInventory/CheckUserIsExist/", { UserName: _userName }, function (data) {
|
|
//console.log(data);
|
|
if (data.result == false) {
|
|
|
|
//show validation message if username already exists
|
|
$("#spanUserName").show();
|
|
$("#UserName").val('').focus();
|
|
}
|
|
else {
|
|
$("#spanUserName").hide();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
* Function to check if email id exist.
|
|
* @method checkIfEmailidIsExist
|
|
* @for VecvUserManagement
|
|
*/
|
|
function checkIfEmailidIsExist() {
|
|
|
|
//function call on blur of user name text box
|
|
$("#EmailId").blur(function () {
|
|
var _emailId = $("#EmailId").val();
|
|
if (_emailId != "") {
|
|
$.getJSON("/UserInventory/CheckEmailIsExist/", { EmailId: _emailId }, function (data) {
|
|
//console.log(data);
|
|
if (data.result == false) {
|
|
|
|
//show validation message if username already exists
|
|
$("#spanEmail").show();
|
|
$("#EmailId").val('').focus();
|
|
}
|
|
else {
|
|
$("#spanEmail").hide();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
* Function to load city list state wise.
|
|
* @method LoadCityList
|
|
* @param {String} stateId selected state id
|
|
* @for VecvUserManagement
|
|
*/
|
|
function LoadCityList(stateId) {
|
|
|
|
var selectedState = $('#ddState').find('option:selected').text();
|
|
$("#stateName").val(selectedState);
|
|
//$("#stateName").val($('#ddState').find('option:selected').text());
|
|
|
|
var stateVal;
|
|
|
|
stateVal = $("#ddState").val();
|
|
if (stateVal != "-Select-") {
|
|
stateVal = $("#ddState").val();
|
|
|
|
// empty City dropdown
|
|
$("#ddCity").text("");
|
|
|
|
// by default add select text.
|
|
$("#ddCity").append($('<option></option>').val("").html("-Select-"));
|
|
}
|
|
else {
|
|
stateVal = 0;
|
|
}
|
|
if (stateVal != "") {
|
|
|
|
if (activeRequest_City && activeRequest_City.readystate != 4) {
|
|
activeRequest_City.abort();
|
|
}
|
|
|
|
activeRequest_City = $.ajax({
|
|
type: "GET",
|
|
url: "/UserInventory/showCityStateWise/",
|
|
data: { stateVal: stateVal },
|
|
success: function (data) {
|
|
|
|
// empty City dropdown
|
|
$("#ddCity").text("");
|
|
|
|
// by default add select text.
|
|
$("#ddCity").append($('<option></option>').val("").html("-Select-"));
|
|
|
|
// add data to dropdown.
|
|
if (data.list) {
|
|
for (var counter = 0; counter < data.list.length; counter++) {
|
|
$("#ddCity").append(
|
|
$('<option></option>').val(data.list[counter].Value).html(data.list[counter].Text));
|
|
}
|
|
}
|
|
},
|
|
error: function (data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Function call onclick of cancel button.
|
|
* @method btnCancelAddUser
|
|
* @for VecvUserManagement
|
|
*/
|
|
function btnCancelAddUser() {
|
|
//$("#tableUserList tbody tr.SelectedRow").trigger('click');
|
|
if (document.getElementById('tableUserList')) {
|
|
$("#tableUserList tbody tr.SelectedRow").trigger('click');
|
|
} else {
|
|
$("#divDealerUserDetailPanel").html("");
|
|
$("#btnAdd").show();
|
|
$("#btnEdit").show();
|
|
//$("#btnDelete").show();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Function call onsuccess of add vecv user.
|
|
* @method onSuccess
|
|
* @for VecvUserManagement
|
|
*/
|
|
function onSuccess(data) {
|
|
|
|
if (data.success == true) {
|
|
//console.log("user added");
|
|
getVecvUserList();
|
|
//jAlert('User added successfully.', 'Message', function () {
|
|
jAlert(USER_INVENTORY_MESSAGES.addUserSuccess, 'Add', function () {
|
|
$("#tableUserList tbody tr[data-userName='" + data.userAuthId + "']").trigger('click');
|
|
});
|
|
}
|
|
else {
|
|
jAlert(USER_INVENTORY_MESSAGES.addUserFailed + data.message, 'Add');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Function call onsuccess of add vecv user.
|
|
* @method onSuccess
|
|
* @for VecvUserManagement
|
|
*/
|
|
function onSuccessEdit(data) {
|
|
var iseps = "";
|
|
var apiUrl = url + "Api/EPS?seteps=yes&iseps=yes";
|
|
if (document.getElementById('rdoYesEPS').checked) {
|
|
iseps = 'yes';
|
|
}
|
|
else if (document.getElementById('rdoNoEPS').checked) {
|
|
iseps = 'no';
|
|
}
|
|
else if (document.getElementById('rdobothEPS').checked) {
|
|
iseps = 'both';
|
|
}
|
|
if (data.success == true) {
|
|
// alert(iseps);
|
|
$.ajax({
|
|
type: "Post",
|
|
url: apiUrl,
|
|
dataType: "json",
|
|
data: { Token: "teramatrix", AuthEngineId: data.userAuthId, Status: iseps },
|
|
success: function (data) {
|
|
}
|
|
});
|
|
//jAlert('User added successfully.', 'Message', function () {
|
|
jAlert(USER_INVENTORY_MESSAGES.editUserSuccess, 'Edit', function () {
|
|
|
|
$("#tableUserList tbody tr[data-userName='" + data.userAuthId + "']").trigger('click');
|
|
});
|
|
}
|
|
else {
|
|
jAlert(USER_INVENTORY_MESSAGES.editUserFailed + data.message, 'Edit');
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Function used to on key up to search data from list.
|
|
* @method initSearch
|
|
* @param {String} keyCode Input key code.
|
|
* @param {String} sValue text to be search.
|
|
* @for VecvUserManagement
|
|
*/
|
|
function initSearch(keyCode, sValue) {
|
|
var $rows = $('#tableUserList tbody tr');
|
|
var jThis;
|
|
if (keyCode != 8 && keyCode != 46) {
|
|
$rows.each(function () {
|
|
jThis = $(this);
|
|
console.log(jThis);
|
|
if (jThis.is(':visible')) {
|
|
var oLabel = jThis.find('label').text();
|
|
if (oLabel.length > 0) {
|
|
if (oLabel.toLowerCase().indexOf(sValue.toLowerCase()) >= 0) {
|
|
jThis.show();
|
|
} else {
|
|
jThis.hide();
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
$rows.each(function () {
|
|
jThis = $(this);
|
|
var oLabel = jThis.find('label').text();
|
|
if (oLabel.length > 0) {
|
|
if (oLabel.toLowerCase().indexOf(sValue.toLowerCase()) >= 0) {
|
|
jThis.show();
|
|
} else {
|
|
jThis.hide();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Function used to bind vehicle product variant list in drop down from js
|
|
* @method bindVehicleProductVariant
|
|
* @for VecvUserManagement
|
|
*/
|
|
function bindVehicleProductVariant() {
|
|
|
|
// by default add select text.
|
|
$("#VehicleTaggingList").append($('<option></option>').val("").html("-Select-"));
|
|
|
|
// add data to dropdown.
|
|
if (vehicleProductVariantList) {
|
|
|
|
for (var counter = 0; counter < vehicleProductVariantList.length; counter++) {
|
|
$("#VehicleTaggingList").append($('<option></option>').val(vehicleProductVariantList[counter].Value).html(vehicleProductVariantList[counter].Text));
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
function deleteUser() {
|
|
var userName = $('#tableUserList > tbody > tr.SelectedRow')[0].id;
|
|
var userOrganization = document.getElementById(userName).getAttribute('data-organizationId');
|
|
jConfirm("Are you sure that you want to delete '" + userName + "'?", 'Delete', function (result) {
|
|
if (result) {
|
|
var UserInventory = {};
|
|
UserInventory.UserName = userName;
|
|
UserInventory.IsDeleted = true;
|
|
UserInventory.OrganizationId = userOrganization;
|
|
|
|
//send ajax report to add user
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/UserInventory/ManageUserInventory_EditVecvUser/",
|
|
data: UserInventory,
|
|
success: function (data) {
|
|
getVecvUserList();
|
|
jAlert("'" + userName + "' is deleted successfully.", 'Delete', function () {
|
|
$("#tableUserList tbody tr:first").trigger('click');
|
|
});
|
|
},
|
|
|
|
error: function (data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
* Open the window for User reset pwd.
|
|
* @method resetUserPassword
|
|
* @for UserManagement
|
|
*/
|
|
function resetUserPassword() {
|
|
var userName = $('#tblUserInventory > tbody > tr');
|
|
var customerId = $(userName[1]).find("td:eq(3)").html();
|
|
if (customerId == undefined) {
|
|
customerId = $("#UserName").val();
|
|
}
|
|
|
|
$("#hiddenUserName").val(customerId);
|
|
$("#dealerResetPwdPopup_wnd_title").text("Reset Password - " + customerId);
|
|
$("#dealerResetPwdPopup").data("kendoWindow").open();
|
|
openKendoWindowInCenter("#dealerResetPwdPopup");
|
|
}
|
|
|
|
/**
|
|
* Called after dealer reset pwd.
|
|
* @method onSuccessResetPwd
|
|
* @for UserManagement
|
|
*/
|
|
function onSuccessResetPwd(result) {
|
|
$('#resetPasswordForm')[0].reset();
|
|
closeWindow("#dealerResetPwdPopup");
|
|
if (result.success == true) {
|
|
jAlert("Password successfully updated.", 'Message');
|
|
}
|
|
else {
|
|
jAlert("Reset Password failed.", 'Message');
|
|
}
|
|
}
|
|
/**
|
|
* Open the window for User reset pwd.
|
|
* @method resetUserPassword
|
|
* @for PrincipleDealerManagement
|
|
*/
|
|
function UnlockUser() {
|
|
var userName = $('#tblUserInventory > tbody > tr');
|
|
var customerId = $(userName[1]).find("td:eq(3)").html();
|
|
if (customerId == undefined) {
|
|
customerId = $("#UserName").val();
|
|
}
|
|
|
|
$("#hiddenUserNameUnlock").val(customerId);
|
|
$("#dealerUnlockPwdPopup_wnd_title").text("Unlock User - " + customerId);
|
|
$("#dealerUnlockPwdPopup").data("kendoWindow").open();
|
|
openKendoWindowInCenter("#dealerUnlockPwdPopup");
|
|
}
|
|
/**
|
|
* Called after dealer reset pwd.
|
|
* @method onSuccessResetPwd
|
|
* @for PrincipleDealerManagement
|
|
*/
|
|
function onSuccessUnlockUser(result) {
|
|
$('#UnlockUserForm')[0].reset();
|
|
closeWindow("#dealerUnlockPwdPopup");
|
|
if (result.success == true) {
|
|
jAlert("User successfully unlocked.", 'Message');
|
|
|
|
// ajax request to get user detail
|
|
if (activeRequest_UserDetails && activeRequest_UserDetails.readystate != 4) {
|
|
activeRequest_UserDetails.abort();
|
|
}
|
|
activeRequest_UserDetails = $.ajax({
|
|
type: "POST",
|
|
url: "/UserInventory/ManageUserInventory_GetUserDetails/",
|
|
data: { UserName: result.userName, ObjectId: null },
|
|
success: function (data) {
|
|
|
|
$("#divVecvUserDetailPanel").html('');
|
|
$("#divVecvUserDetailPanel").html(data);
|
|
|
|
if ($("#item_IsLocked").val() == "True") {
|
|
$("#btnUnlockUser").show();
|
|
}
|
|
else {
|
|
$("#btnUnlockUser").hide();
|
|
//$("#btnUnlockUser").prop("disabled", true);
|
|
}
|
|
},
|
|
error: function (data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
jAlert("Unlocked User failed.", 'Message');
|
|
}
|
|
}
|
|
/**
|
|
* Bind textbox keyup event for searching.
|
|
* @event keyup
|
|
* @for VecvUserManagement
|
|
*/
|
|
$('#txtSearchUserList').keyup(function (event) {
|
|
var sValue = $.trim($(this).val());
|
|
initSearch(event.keyCode, sValue);
|
|
}).keydown(function () { }).focus(function () { $(this).select(); });
|
|
|
|
//------------------------------------ document ready function --------------------------------------//
|
|
$(document).ready(function () {
|
|
getVecvUserList();
|
|
|
|
addKendoWindow("#dealerResetPwdPopup", "Reset Password", "500px", 150, 120);
|
|
addKendoWindow("#dealerUnlockPwdPopup", "Unlock User", "500px", 150, 120);
|
|
}); |