526 lines
16 KiB
JavaScript
526 lines
16 KiB
JavaScript
/*================================================================================================================\
|
|
+
|
|
+ Project : GoData-Eicher
|
|
+ Filename : principleDealerInventory.js
|
|
+ Module Name : DealerUserInventory
|
|
+ Purpose : For Principal Dealer Inventory
|
|
+ Coded By : Parul Gupta
|
|
+
|
|
+================================================================================================================*/
|
|
|
|
|
|
/**
|
|
* For user management
|
|
* @module UserManagement
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
* This class contains functionality of add principal dealer users.
|
|
* @class PrincipleDealerManagement
|
|
* @constructor
|
|
*/
|
|
|
|
|
|
|
|
//Global variables
|
|
var activeRequest, activeRequest_City, activeRequest_del, activeRequest_UserDetails, activeRequest_export;
|
|
|
|
|
|
/**
|
|
* Function to get non-vecv users list.
|
|
* @method getPrincipleDealerUserList
|
|
* @for PrincipleDealerManagement
|
|
*/
|
|
function getPrincipleDealerUserList() {
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/UserInventory/ManageUserInventory_GetUserList/",
|
|
data: { userType: "principleDealer" },
|
|
success: function (data) {
|
|
|
|
//Bind html
|
|
$("#divPrincipleDealerUserList").html(data);
|
|
},
|
|
error: function (data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
* Function to show non-vecv users details.
|
|
* @method showUserDetails
|
|
* @for PrincipleDealerManagement
|
|
*/
|
|
function showUserDetails() {
|
|
|
|
//function call on click of user list table's row
|
|
$("#tableUserList tbody tr").click(function (e) {
|
|
|
|
var userName, $this, objectId;
|
|
$this = $(this);
|
|
userName = e.currentTarget.id;
|
|
objectId = document.getElementById(userName).getAttribute('data-objectId');
|
|
//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 non-vecv 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: objectId },
|
|
success: function (data) {
|
|
|
|
$("#divPrincipleDealerUserDetailPanel").html('');
|
|
$("#divPrincipleDealerUserDetailPanel").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 Dealer Principal user list table
|
|
$("#tableUserList tbody tr:first").trigger('click');
|
|
}
|
|
|
|
|
|
/**
|
|
* Function to add new non-vecv users.
|
|
* @method addPrincipleDealer
|
|
* @for PrincipleDealerManagement
|
|
*/
|
|
function addPrincipleDealer() {
|
|
|
|
//send ajax report to add Dealer Principal user
|
|
$.ajax({
|
|
|
|
type: "Get",
|
|
url: "/UserInventory/ManagePrincipleDealerInventory_AddPrincipleDealer/",
|
|
success: function (data) {
|
|
$("#divPrincipleDealerUserDetailPanel").html('');
|
|
$("#divPrincipleDealerUserDetailPanel").html(data);
|
|
$("#btnAdd").hide();
|
|
$("#btnEdit").hide();
|
|
//$("#btnDelete").hide();
|
|
},
|
|
|
|
error: function (data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
* Function to check if user already exist.
|
|
* @method checkIfUsernameIsExist
|
|
* @for PrincipleDealerManagement
|
|
*/
|
|
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 PrincipleDealerManagement
|
|
*/
|
|
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 PrincipleDealerManagement
|
|
*/
|
|
function LoadCityList(stateId) {
|
|
|
|
var selectedState = $('#ddState').find('option:selected').text();
|
|
$("#stateName").val(selectedState);
|
|
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 PrincipleDealerManagement
|
|
*/
|
|
function btnCancelAddUser() {
|
|
if (document.getElementById('tableUserList')) {
|
|
$("#tableUserList tbody tr.SelectedRow").trigger('click');
|
|
} else {
|
|
$("#divPrincipleDealerUserDetailPanel").html("");
|
|
$("#btnAdd").show();
|
|
$("#btnEdit").show();
|
|
//$("#btnDelete").show();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Function call onsuccess of add non-vecv user.
|
|
* @method onSuccessAddPrincipleDealer
|
|
* @for PrincipleDealerManagement
|
|
*/
|
|
function onSuccessAddPrincipleDealer(data) {
|
|
|
|
if (data.success == true) {
|
|
//console.log("user added");
|
|
getPrincipleDealerUserList();
|
|
//jAlert('User added successfully.', 'Message', function () {
|
|
jAlert(USER_INVENTORY_MESSAGES.addUserSuccess, 'Message', function () {
|
|
$("#tableUserList tbody tr[data-userName='" + data.userAuthId + "']").trigger('click');
|
|
});
|
|
}
|
|
else {
|
|
//jAlert('Add User failed !!' + data.message, 'Message');
|
|
jAlert(USER_INVENTORY_MESSAGES.addUserFailed + data.message, 'Message');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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 PrincipleDealerManagement
|
|
*/
|
|
function initSearch(keyCode, sValue) {
|
|
var $rows = $('#tableUserList tbody tr');
|
|
var jThis;
|
|
if (keyCode != 8 && keyCode != 46) {
|
|
$rows.each(function () {
|
|
jThis = $(this);
|
|
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 to add new non-vecv users.
|
|
* @method editPrincipleDealer
|
|
* @for PrincipleDealerManagement
|
|
*/
|
|
function editPrincipleDealer() {
|
|
var userName = $('#tableUserList > tbody > tr.SelectedRow')[0].id;
|
|
var userObjectId = document.getElementById(userName).getAttribute('data-objectid');
|
|
//send ajax report to add Dealer Principal user
|
|
$.ajax({
|
|
|
|
type: "Get",
|
|
url: "/UserInventory/ManagePrincipleDealerInventory_EditPrincipleDealer/",
|
|
data: { UserName: userName, ObjectId: userObjectId },
|
|
success: function (data) {
|
|
$("#divPrincipleDealerUserDetailPanel").html('');
|
|
$("#divPrincipleDealerUserDetailPanel").html(data);
|
|
$("#btnAdd").hide();
|
|
$("#btnEdit").hide();
|
|
//$("#btnDelete").hide();
|
|
},
|
|
|
|
error: function (data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
* Function call onsuccess of add non-vecv user.
|
|
* @method onSuccessEditPrincipleDealer
|
|
* @for PrincipleDealerManagement
|
|
*/
|
|
function onSuccessEditPrincipleDealer(data) {
|
|
|
|
if (data.success == true) {
|
|
jAlert(USER_INVENTORY_MESSAGES.editUserSuccess, 'Message', function () {
|
|
$("#tableUserList tbody tr[data-userName='" + data.userAuthId + "']").trigger('click');
|
|
});
|
|
}
|
|
else {
|
|
jAlert(USER_INVENTORY_MESSAGES.editUserFailed + data.message, 'Message');
|
|
}
|
|
}
|
|
|
|
function deletePrincipleDealer() {
|
|
var userName = $('#tableUserList > tbody > tr.SelectedRow')[0].id;
|
|
var userOrganization = document.getElementById(userName).getAttribute('data-organizationId');
|
|
var userObjectId = document.getElementById(userName).getAttribute('data-objectid');
|
|
var childDealers = $("#hdnChildDealers").val();
|
|
|
|
console.log(childDealers);
|
|
|
|
jConfirm("Are you sure that you want to delete '" + userName + "'?", 'Delete', function (result) {
|
|
if (result) {
|
|
var UserInventory = {};
|
|
UserInventory.UserName = userName;
|
|
UserInventory.ObjectId = userObjectId;
|
|
UserInventory.IsDealerDeleted = true;
|
|
UserInventory.OrganizationId = userOrganization;
|
|
UserInventory.DealerChildList = childDealers;
|
|
|
|
//send ajax report to add user
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/UserInventory/ManagePrincipleDealerInventory_EditPrincipleDealer/",
|
|
data: UserInventory,
|
|
success: function (data) {
|
|
getPrincipleDealerUserList();
|
|
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 PrincipleDealerManagement
|
|
*/
|
|
function resetUserPassword() {
|
|
var userName = $('#tblDealerPrincipalInventory > tbody > tr');
|
|
var customerId = $(userName[0]).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 PrincipleDealerManagement
|
|
*/
|
|
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 = $('#tblDealerPrincipalInventory > tbody > tr');
|
|
var customerId = $(userName[0]).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');
|
|
var objectId = document.getElementById(result.userName).getAttribute('data-objectId');
|
|
// ajax request to get non-vecv 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: objectId },
|
|
success: function (data) {
|
|
|
|
$("#divPrincipleDealerUserDetailPanel").html('');
|
|
$("#divPrincipleDealerUserDetailPanel").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');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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();
|
|
}
|
|
|
|
/**
|
|
* Bind textbox keyup event for searching.
|
|
* @event keyup
|
|
* @for PrincipleDealerManagement
|
|
*/
|
|
$('#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 () {
|
|
|
|
getPrincipleDealerUserList();
|
|
|
|
addKendoWindow("#dealerResetPwdPopup", "Reset Password", "500px", 150, 120);
|
|
|
|
addKendoWindow("#dealerUnlockPwdPopup", "Unlock User", "500px", 150, 120);
|
|
|
|
}); |