var urlPathname = location.pathname; $(document).ready(function () { $('.loading').hide(); $(".modal-xxl").css('max-width', '460px'); $(".select2Option").select2({ language: "fa", dir: "rtl", dropdownParent: $('#MainModal'), templateResult: function (data, container) { if (data.element) { $(container).addClass($(data.element).attr("class")); } return data.text; } }); $('#Amount').keyup(function () { var amount = $(this).val(); var amountRials = wordifyRials(amount); var amountTomans = wordifyRialsInTomans(amount); $('#amountRials').text(amountRials); $('#amountTomans').text(amountTomans); }); $('.form-control-number').on('keydown', function (e) { const allowedKeys = [ 'Backspace', 'Tab', 'Escape', 'Enter', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Delete', 'Home', 'End' ]; if (allowedKeys.includes(e.key) || (e.key === 'a' && (e.ctrlKey || e.metaKey))) { return; } if (!/^\d$/.test(e.key)) { e.preventDefault(); } }); $(".form-control-currency").each(function () { let element = $(this); element.on('input', function () { let value = convertPersianNumbersToEnglish(element.val()); element.val(value); }); new Cleave(this, { numeral: true, numeralThousandsGroupStyle: 'thousand' }); }); $(".form-control-date").each(function () { let element = $(this); element.on('input', function () { let value = convertPersianNumbersToEnglish(element.val()); element.val(value); }); new Cleave(this, { date: true, delimiter: '/', datePattern: ['Y', 'm', 'd'] }); }); updateDateInput(0); ajaxPersonals(); }); function updateDateInput(daysToAdd) { var today = new Date(); today.setDate(today.getDate() + daysToAdd); var jalaaliDate = jalaali.toJalaali(today); var formattedDate = jalaaliDate.jy + '/' + (jalaaliDate.jm < 10 ? '0' + jalaaliDate.jm : jalaaliDate.jm) + '/' + (jalaaliDate.jd < 10 ? '0' + jalaaliDate.jd : jalaaliDate.jd); $('.dateTime').val(formattedDate); } function ajaxPersonals() { $.ajax({ url: employeeListAjax, type: 'GET', success: function (response) { if (response.success) { var employees = response.data; var employeeOptionsHtml = ''; employees.forEach(function (employee) { employeeOptionsHtml += ``; }); $('#employeeSelect').html(employeeOptionsHtml); } else { $('.alert-msg').show(); $('.alert-msg p').text(response.message); setTimeout(function () { $('.alert-msg').hide(); $('.alert-msg p').text(''); }, 3500); } }, error: function (xhr, status, error) { console.error(xhr.responseText); } }); } $('#createData').on('click', SaveDataAjax); function SaveDataAjax() { var loading = $('#createData .spinner-loading'); var employeeSelect = $('#employeeSelect').val(); var Amount = $('#Amount '); var Description = $('#Description'); var GrantDate = $('#GrantDate'); if (employeeSelect.length === 0) { $('.alert-msg').show(); $('.alert-msg p').text('لطفا اسامی پرسنل را کلیک و مشخص نمائید'); $('.select-alert').addClass('errored'); setTimeout(function () { $('.alert-msg').hide(); $('.alert-msg p').text(''); $('.select-alert').removeClass('errored'); }, 3500); return; } if (!Amount.val() || Amount.val() === "0") { Amount.addClass('errored'); $('.alert-msg').show(); $('.alert-msg p').text('لطفا مبلغ را وارد نمائید'); setTimeout(function () { $('.alert-msg').hide(); $('.alert-msg p').text(''); Amount.removeClass('errored'); }, 3500); return; } if (!GrantDate.val()) { GrantDate.addClass('errored'); $('.alert-msg').show(); $('.alert-msg p').text('لطفا تاریخ را وارد نمائید'); setTimeout(function () { $('.alert-msg').hide(); $('.alert-msg p').text(''); GrantDate.removeClass('errored'); }, 3500); return; } if (!Description.val()) { Description.addClass('errored'); $('.alert-msg').show(); $('.alert-msg p').text('لطفا علت توضیحات را وارد نمائید'); setTimeout(function () { $('.alert-msg').hide(); $('.alert-msg p').text(''); Description.removeClass('errored'); }, 3500); return; } $('#createData').addClass('disable'); var data = $('#create-form').serialize(); $.ajax({ async: false, dataType: 'json', type: 'POST', url: saveNewRewardAjax, headers: { "RequestVerificationToken": antiForgeryToken }, data: data, success: function (response) { if (response.success) { loading.show(); $('.alert-success-msg').show(); $('.alert-success-msg p').text(response.message); setTimeout(function () { $('.alert-success-msg').hide(); $('.alert-success-msg p').text(''); }, 2000); if (urlPathname.indexOf('/Client/Company/Reward') > -1) { $('#rewardListAjax').html(''); $('#PageIndex').val(0); pageIndexJs = 0; loadRewardList(); } loading.hide(); $('#MainModal').modal('hide'); } else { $('.alert-msg').show(); $('.alert-msg p').text(response.message); setTimeout(function () { $('.alert-msg').hide(); $('.alert-msg p').text(''); }, 3500); loading.hide(); $('#createData').removeClass('disable'); } }, error: function (err) { loading.hide(); $('#createData').removeClass('disable'); console.log(err); } }); }