$(document).ready(function () {
BindCreateSizePopup();
BindSizeGridsEvents();
});
var sizeNameAlreadyExist = false;
var sizeCodeAlreadyExist = false;
function BindCreateSizePopup() {
$('#AddNewSize').click(function () {
showLoader(true);
$.get("/Size/_Create", function (data) {
showLoader(false);
bootbox.dialog({
message: data,
title: "Size"
});
});
});
}
function BindSizeGridsEvents() {
$('#CountryPagination div ul li a').click(function () {
var URL = $(this).attr('href');
if (URL.trim() != "") {
showLoader(true);
$.get(URL, function (data) {
$('#SizeGridPlaceHolder').html(data);
showLoader(false);
BindSizeGridsEvents();
});
}
return false;
});
$('.EditSize').click(function () {
var URL = $(this).attr('href');
showLoader(true);
$.get(URL, function (data) {
showLoader(false);
bootbox.dialog({
message: data,
title: "Size"
});
});
return false;
});
$('.DeleteSize').click(function () {
var URL = $(this).attr('href');
bootbox.dialog({
message: "Are you sure you want to delete this Country?",
title: "Confirm",
buttons: {
ok: {
label: "Ok",
className: "btn btn-primary",
callback: function () {
showLoader(true);
$.post(URL, function (data) {
LoadCountryGrid();
$(".bootbox").modal("hide");
showLoader(false);
successBox("Size deleted successfully.", "Success");
}).fail(function () {
showLoader(false);
dangerBox("Cannot remove this record as this might be referenced in some other data.", "Error");
});
}
},
cancel: {
label: "Cancel",
className: "btn btn-light-grey",
callback: function () {
$(".bootbox").modal("hide");
showLoader(false);
}
}
}
});
$('.modal-content').attr('class', 'modal-content alert-danger');
return false;
});
}
function LoadSizeGrid() {
$.get("/Size/_Index", function (data) {
$('#SizeGridPlaceHolder').html(data);
BindCountryGridsEvents();
});
}
function ChecksizeAlreadExist() {
if ($('#size').val().trim() == '')
return;
showLoader(true);
$.ajax({
url: "/size/issizeExist",
type: "POST",
data: { id: $('#ID').val(), name: $('#countryName').val().trim() },
traditional: true,
success: function (html) {
if (html.trim() == 'True') {
countryNameAlreadyExist = true;
$('#countryNameAlreadyExistError').show();
}
else {
countryNameAlreadyExist = false;
$('#countryNameAlreadyExistError').hide();
}
showLoader(false);
}
});
}
function CheckcountryCodeAlreadExist() {
if ($('#countryCode').val().trim() == '')
return;
showLoader(true);
$.ajax({
url: "/country/iscountryCodeExist",
type: "POST",
data: { id: $('#ID').val(), code: $('#countryCode').val().trim() },
traditional: true,
success: function (html) {
if (html.trim() == 'True') {
countryCodeAlreadyExist = true;
$('#countryCodeAlreadyExistError').show();
}
else {
countryCodeAlreadyExist = false;
$('#countryCodeAlreadyExistError').hide();
}
showLoader(false);
}
});
}
function BindcountryNameEvent() {
$("#countryName").focusout(function () {
CheckcountryNameAlreadExist();
});
}
function bindLnaguageCodeEvent() {
$("#CountryCode").focusout(function () {
CheckcountryCodeAlreadExist();
});
}
function validateCountryForm() {
if (countryCodeAlreadyExist == false && countryNameAlreadyExist == false)
return true;
else
return false;
}