1530 lines
48 KiB
JavaScript
1530 lines
48 KiB
JavaScript
|
||
|
||
document.getElementById("MainModal").style.visibility = "visible";
|
||
var isHoliday = false;
|
||
|
||
|
||
$(document).on('keydown', '#EndTaskDate', function () {
|
||
$("input[name='btnradio']").prop('checked', false);
|
||
});
|
||
|
||
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);
|
||
$('#EndTaskDate').val(formattedDate);
|
||
//computeDays();
|
||
}
|
||
|
||
|
||
$(document).ready(function () {
|
||
// textarea <br> replace
|
||
var currentDescription = $('#EditTask_Description').val();
|
||
var formattedText = currentDescription.replace(/<br\s*\/?>/gi, "\n");
|
||
formattedText = formattedText.replace(/\n+/g, "\n");
|
||
$('#EditTask_Description').val(formattedText);
|
||
|
||
//updateDateInput(0);
|
||
|
||
$(document).on('click', '#today', function () {
|
||
$("#EndTaskDate").css('color', '#797979');
|
||
$("#HolidayError").hide();
|
||
updateDateInput(0);
|
||
$("#today").prop('checked', true);
|
||
CheckHoliday();
|
||
});
|
||
|
||
$(document).on('click', '#tommorow', function () {
|
||
$("#EndTaskDate").css('color', '#797979');
|
||
$("#HolidayError").hide();
|
||
updateDateInput(1);
|
||
$("#tommorow").prop('checked', true);
|
||
CheckHoliday();
|
||
});
|
||
|
||
$(document).on('click', '#two-day-later', function () {
|
||
$("#EndTaskDate").css('color', '#797979');
|
||
$("#HolidayError").hide();
|
||
updateDateInput(2);
|
||
$("#two-day-later").prop('checked', true);
|
||
CheckHoliday();
|
||
});
|
||
|
||
|
||
$('.select2Member').select2({
|
||
placeholder: {
|
||
id: '-1', // the value of the option
|
||
text: "نوع ارسال را انتخاب کنید"
|
||
}
|
||
});
|
||
|
||
$('.select2Group').select2({
|
||
placeholder: {
|
||
id: '-1', // the value of the option
|
||
text: "انتخاب گروهی ..."
|
||
}
|
||
});
|
||
|
||
|
||
$(document).on('click', '#memberSelect', function () {
|
||
|
||
$('.select2Member').select2({
|
||
placeholder: {
|
||
id: '-1', // the value of the option
|
||
text: "انتخاب اعضاء..."
|
||
}
|
||
});
|
||
|
||
$('#select2MemberList').show();
|
||
$('#select2GroupList').hide();
|
||
if ($('#memberSelect').is(':checked')) {
|
||
$('#EditTask_PositionId').val(null).trigger('change');
|
||
}
|
||
$('.select2Member').removeClass('disable');
|
||
$('.select2Member').prop('disabled', false);
|
||
$('.select2Group').removeClass('disable');
|
||
$('.select2Group').prop('disabled', false);
|
||
});
|
||
|
||
$(document).on('click', '#groupSelect', function () {
|
||
$('#select2MemberList').hide();
|
||
$('#select2GroupList').show();
|
||
if ($('#groupSelect').is(':checked')) {
|
||
$('#EditTask_ReceiverId').val(null).trigger('change');
|
||
}
|
||
$('.select2Member').removeClass('disable');
|
||
$('.select2Member').prop('disabled', false);
|
||
$('.select2Group').removeClass('disable');
|
||
$('.select2Group').prop('disabled', false);
|
||
});
|
||
|
||
$('#editSave').on('click', function (e) {
|
||
e.preventDefault();
|
||
|
||
//var member = $('.select2Member').select2('data');
|
||
//var group = $('.select2Group').select2('data');
|
||
|
||
//if (!$('#memberSelect').is(':checked') && !$('#groupSelect').is(':checked')) {
|
||
// $('.selectRadioBox').addClass('errored');
|
||
// $('.alert-msg').show();
|
||
// $('.alert-msg p').text('لطفا انتخاب اعضاء یا گروهی را مشخص نمائید.');
|
||
// setTimeout(function () {
|
||
// $('.alert-msg').hide();
|
||
// $('.alert-msg p').text('');
|
||
// $('.selectRadioBox').removeClass('errored');
|
||
// }, 3500);
|
||
// return;
|
||
//}
|
||
|
||
//if ($('#memberSelect').is(':checked')) {
|
||
// if (member.length == 0) {
|
||
// $('#select2MemberList').addClass('errored');
|
||
// $('.alert-msg').show();
|
||
// $('.alert-msg p').text('لطفا انتخاب اعضاء را مشخص نمائید.');
|
||
// setTimeout(function () {
|
||
// $('.alert-msg').hide();
|
||
// $('.alert-msg p').text('');
|
||
// $('#select2MemberList').removeClass('errored');
|
||
// }, 3500);
|
||
// return;
|
||
// }
|
||
//}
|
||
|
||
//if ($('#groupSelect').is(':checked')) {
|
||
// if (group.length == 0) {
|
||
// $('#select2GroupList').addClass('errored');
|
||
// $('.alert-msg').show();
|
||
// $('.alert-msg p').text('لطفا انتخاب گروهی را مشخص نمائید.');
|
||
// setTimeout(function () {
|
||
// $('.alert-msg').hide();
|
||
// $('.alert-msg p').text('');
|
||
// $('#select2GroupList').removeClass('errored');
|
||
// }, 3500);
|
||
// return;
|
||
// }
|
||
//}
|
||
|
||
if (isHoliday) {
|
||
swal.fire({
|
||
title: "اخطار",
|
||
text: "تاریخ وظیفه مورد نظر در روز تعطیل میباشد؛ آیا میخواهید ادامه دهید؟",
|
||
icon: "warning",
|
||
showCancelButton: true,
|
||
confirmButtonText: "بله",
|
||
cancelButtonText: "خیر",
|
||
confirmButtonColor: '#84cc16',
|
||
reverseButtons: true
|
||
}).then((result) => {
|
||
if (result.isConfirmed) {
|
||
submitForm();
|
||
} else {
|
||
return;
|
||
}
|
||
});
|
||
}
|
||
else {
|
||
submitForm();
|
||
}
|
||
});
|
||
|
||
function submitForm() {
|
||
var button = $('#editSave');
|
||
var loadingDiv = button.find('.loading');
|
||
loadingDiv.show();
|
||
button.prop('disabled', true);
|
||
|
||
var textArea = $('#EditTask_Description');
|
||
var content = textArea.val();
|
||
//content = content.replace(/\n/g, '<br>');
|
||
textArea.val(content);
|
||
|
||
var data = new FormData(button.closest('form')[0]);
|
||
|
||
$.ajax({
|
||
async: false,
|
||
dataType: 'json',
|
||
type: 'POST',
|
||
processData: false,
|
||
contentType: false,
|
||
url: editSaveTask,
|
||
headers: { "RequestVerificationToken": antiForgeryToken },
|
||
data: data,
|
||
success: function (response) {
|
||
if (response.isSuccess) {
|
||
$('.alert-success-msg').show();
|
||
$('.alert-success-msg p').text(response.message);
|
||
setTimeout(function () {
|
||
$('.alert-success-msg').hide();
|
||
$('.alert-success-msg p').text('');
|
||
window.location.replace('/AdminNew/Company/Task');
|
||
}, 1500);
|
||
} else {
|
||
console.log(response.message);
|
||
if (response.message == 'لطفا عنوان وظیفه خود را وارد کنید') {
|
||
$('#EditTask_Title').addClass('errored');
|
||
$('.alert-msg p').text('لطفا انتخاب گروهی را مشخص نمائید.');
|
||
setTimeout(function () {
|
||
$('#EditTask_Title').removeClass('errored');
|
||
}, 3500);
|
||
}
|
||
|
||
if (response.message == 'لطفا طرف حساب خود را وارد کنید') {
|
||
$('#partyNameSearch').addClass('errored');
|
||
$('.alert-msg p').text('لطفا انتخاب گروهی را مشخص نمائید.');
|
||
setTimeout(function () {
|
||
$('#partyNameSearch').removeClass('errored');
|
||
}, 3500);
|
||
}
|
||
|
||
if (response.message == 'لطفا تاریخ انجام وظیفه را وارد کنید') {
|
||
$('#EditTask_EndTaskDate').addClass('errored');
|
||
$('.alert-msg p').text('لطفا انتخاب گروهی را مشخص نمائید.');
|
||
setTimeout(function () {
|
||
$('#EditTask_EndTaskDate').removeClass('errored');
|
||
}, 3500);
|
||
}
|
||
|
||
$('.alert-msg').show();
|
||
$('.alert-msg p').text(response.message);
|
||
setTimeout(function () {
|
||
$('.alert-msg').hide();
|
||
$('.alert-msg p').text('');
|
||
}, 3500);
|
||
|
||
button.prop('disabled', false);
|
||
loadingDiv.hide();
|
||
}
|
||
},
|
||
error: function (err) {
|
||
console.log(err);
|
||
button.prop('disabled', false);
|
||
loadingDiv.hide();
|
||
}
|
||
});
|
||
}
|
||
// loadingDiv.hide();
|
||
|
||
// if ($('.errored').length < 1) {
|
||
// console.log('hello')
|
||
// $('#editSaveFinaly').click();
|
||
// } else {
|
||
// $('.alert-msg').show();
|
||
// $('.alert-msg p').text('لطفا خطاها را برطرف کنید.');
|
||
// setTimeout(function () {
|
||
// $('.alert-msg').hide();
|
||
// $('.alert-msg p').text('');
|
||
// }, 3500);
|
||
// }
|
||
});
|
||
|
||
|
||
//$(".date").mask("0000/00/00");
|
||
$(".date").on('input', function () {
|
||
var value = $(this).val();
|
||
$(this).val(convertPersianNumbersToEnglish(value));
|
||
}).mask("0000/00/00");
|
||
|
||
$(".date").keyup(function () {
|
||
let value = $(this).val();
|
||
let lengthValue = value.length;
|
||
if (lengthValue == 10) {
|
||
if (!dateValidcheck(this)) {
|
||
$(this).addClass("errored");
|
||
} else {
|
||
$(this).removeClass("errored");
|
||
}
|
||
} else if (lengthValue == 0) {
|
||
$(this).removeClass("errored");
|
||
}
|
||
});
|
||
|
||
function dateValidcheck(inputField1) {
|
||
|
||
let persianNumbers = [/۰/g, /۱/g, /۲/g, /۳/g, /۴/g, /۵/g, /۶/g, /۷/g, /۸/g, /۹/g],
|
||
arabicNumbers = [/٠/g, /١/g, /٢/g, /٣/g, /٤/g, /٥/g, /٦/g, /٧/g, /٨/g, /٩/g],
|
||
fixNumbers = function (str) {
|
||
if (typeof str === 'string') {
|
||
for (var i = 0; i < 10; i++) {
|
||
str = str.replace(persianNumbers[i], i).replace(arabicNumbers[i], i);
|
||
}
|
||
}
|
||
return str;
|
||
};
|
||
let getdate = inputField1.value;
|
||
|
||
let m1, m2;
|
||
let y1, y2, y3, y4;
|
||
let d1, d2;
|
||
let s1, s2;
|
||
for (var i = 0; i < getdate.length; i++) {
|
||
if (i === 0) {
|
||
y1 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 1) {
|
||
y2 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 2) {
|
||
y3 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 3) {
|
||
y4 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 4) {
|
||
s1 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 5) {
|
||
m1 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 6) {
|
||
m2 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 7) {
|
||
s2 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 8) {
|
||
d1 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 9) {
|
||
d2 = fixNumbers(getdate[i]);
|
||
}
|
||
|
||
}
|
||
let yRes = y1 + y2 + y3 + y4;
|
||
let year = parseInt(yRes);
|
||
let mRes = m1 + m2;
|
||
let month = parseInt(mRes);
|
||
let dRes = d1 + d2;
|
||
let day = parseInt(dRes);
|
||
let fixResult = yRes + s1 + mRes + s2 + dRes;
|
||
let test1 = checkEnValid(inputField1.value);
|
||
|
||
let isValid = /^([1][3-4][0-9][0-9][/])([0][1-9]|[1][0-2])([/])([0][1-9]|[1-2][0-9]|[3][0-1])$/.test(fixResult);
|
||
|
||
|
||
if (isValid && test1) {
|
||
// inputField1.style.backgroundColor = '#a6e9a6';
|
||
start1valid = true;
|
||
|
||
|
||
} else {
|
||
|
||
if (inputField1.value != "") {
|
||
// inputField1.style.backgroundColor = '#f94c4c';
|
||
$.Notification.autoHideNotify('error', 'top center', 'پیام سیستم ', "لطفا تاریخ را بصورت صحیح وارد کنید");
|
||
start1valid = false;
|
||
}
|
||
|
||
|
||
}
|
||
return start1valid;
|
||
|
||
}
|
||
|
||
function checkEnValid(fixDate1) {
|
||
|
||
let persianNumbers = [/۰/g, /۱/g, /۲/g, /۳/g, /۴/g, /۵/g, /۶/g, /۷/g, /۸/g, /۹/g],
|
||
arabicNumbers = [/٠/g, /١/g, /٢/g, /٣/g, /٤/g, /٥/g, /٦/g, /٧/g, /٨/g, /٩/g],
|
||
fixNumbers = function (str) {
|
||
if (typeof str === 'string') {
|
||
for (var i = 0; i < 10; i++) {
|
||
str = str.replace(persianNumbers[i], i).replace(arabicNumbers[i], i);
|
||
}
|
||
}
|
||
return str;
|
||
};
|
||
let getdate = fixDate1;
|
||
|
||
let m1, m2;
|
||
let y1, y2, y3, y4;
|
||
let d1, d2;
|
||
for (let i = 0; i < getdate.length; i++) {
|
||
if (i === 0) {
|
||
y1 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 1) {
|
||
y2 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 2) {
|
||
y3 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 3) {
|
||
y4 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 5) {
|
||
m1 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 6) {
|
||
m2 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 8) {
|
||
d1 = fixNumbers(getdate[i]);
|
||
}
|
||
if (i === 9) {
|
||
d2 = fixNumbers(getdate[i]);
|
||
}
|
||
}
|
||
let yRes = y1 + y2 + y3 + y4;
|
||
let year = parseInt(yRes);
|
||
let mRes = m1 + m2;
|
||
let month = parseInt(mRes);
|
||
let dRes = d1 + d2;
|
||
let day = parseInt(dRes);
|
||
let kabiseh = false;
|
||
if (month <= 6 && day > 31) {
|
||
return false;
|
||
} else if (month > 6 && month < 12 && day > 30) {
|
||
return false;
|
||
} else if (month === 12) {
|
||
|
||
switch (year) {
|
||
case 1346:
|
||
kabiseh = true;
|
||
break;
|
||
case 1350:
|
||
kabiseh = true;
|
||
break;
|
||
case 1354:
|
||
kabiseh = true;
|
||
break;
|
||
case 1358:
|
||
kabiseh = true;
|
||
break;
|
||
case 1362:
|
||
kabiseh = true;
|
||
break;
|
||
case 1366:
|
||
kabiseh = true;
|
||
break;
|
||
case 1370:
|
||
kabiseh = true;
|
||
break;
|
||
case 1375:
|
||
kabiseh = true;
|
||
break;
|
||
case 1379:
|
||
kabiseh = true;
|
||
break;
|
||
case 1383:
|
||
kabiseh = true;
|
||
break;
|
||
case 1387:
|
||
kabiseh = true;
|
||
break;
|
||
case 1391:
|
||
kabiseh = true;
|
||
break;
|
||
case 1395:
|
||
kabiseh = true;
|
||
break;
|
||
case 1399:
|
||
kabiseh = true;
|
||
break;
|
||
case 1403:
|
||
kabiseh = true;
|
||
break;
|
||
case 1408:
|
||
kabiseh = true;
|
||
break;
|
||
case 1412:
|
||
kabiseh = true;
|
||
break;
|
||
case 1416:
|
||
kabiseh = true;
|
||
break;
|
||
case 1420:
|
||
kabiseh = true;
|
||
break;
|
||
case 1424:
|
||
kabiseh = true;
|
||
break;
|
||
case 1428:
|
||
kabiseh = true;
|
||
break;
|
||
case 1432:
|
||
kabiseh = true;
|
||
break;
|
||
case 1436:
|
||
kabiseh = true;
|
||
break;
|
||
case 1441:
|
||
kabiseh = true;
|
||
break;
|
||
case 1445:
|
||
kabiseh = true;
|
||
break;
|
||
default:
|
||
kabiseh = false;
|
||
|
||
}
|
||
if (kabiseh == true && day > 30) {
|
||
return false;
|
||
} else if (kabiseh == false && day > 29) {
|
||
return false;
|
||
} else {
|
||
return true;
|
||
}
|
||
} else {
|
||
return true;
|
||
}
|
||
}
|
||
$('#EndTaskTime').on("keyup",
|
||
function () {
|
||
var isValid = /^([2][0-3]|[1][0-9]|[0-9]|[0][0-9])([:][0-5][0-9])$/.test($(this).val());
|
||
if (isValid) {
|
||
$(this).addClass("validTime");
|
||
$(this).removeClass("invalidTime");
|
||
// if ($('#EndTaskTime').val() != null) {
|
||
// computeDays();
|
||
// }
|
||
} else {
|
||
$(this).removeClass("validTime");
|
||
$(this).addClass("invalidTime");
|
||
}
|
||
}
|
||
);
|
||
|
||
|
||
|
||
$(document).ready(function () {
|
||
$(document).on('click', '#upload-doc', function (event) {
|
||
event.preventDefault();
|
||
|
||
for (let i = 1; i <= 6; i++) {
|
||
let fileInput = document.getElementById(`EditTask_Document${i}`);
|
||
if (fileInput && fileInput.type === 'file' && fileInput.files.length === 0) {
|
||
attachFileChangeHandler(fileInput, i);
|
||
fileInput.click();
|
||
return;
|
||
}
|
||
}
|
||
});
|
||
});
|
||
|
||
|
||
function attachFileChangeHandler(fileInput, index) {
|
||
$(fileInput).off('change').on('change', function () {
|
||
let file = fileInput.files[0];
|
||
|
||
if (file.size > 5000000) {
|
||
showAlertMessage('.alert-msg', 'لطفا فایل حجم کمتر از 5 مگابایت را انتخاب کنید.', 3500);
|
||
$(`#EditTask_Document${index}`).val('');
|
||
return;
|
||
}
|
||
|
||
if (file) {
|
||
uploadFile(file, index, `.inBox${index}`);
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
var indexCount = 0;
|
||
var activeUploads = 0;
|
||
var indexDeleteCount = 0;
|
||
function uploadFile(file, id, boxClass) {
|
||
const formData = new FormData();
|
||
formData.append('media', file);
|
||
|
||
activeUploads++;
|
||
$('#editSave').prop('disabled', true).addClass('disable');
|
||
|
||
const extension = file.name.slice(file.name.lastIndexOf('.'));
|
||
const nameWithoutExtension = file.name.slice(0, file.name.lastIndexOf('.'));
|
||
const maxLength = 20 - extension.length;
|
||
const start = nameWithoutExtension.slice(0, Math.floor((maxLength - 3) / 2));
|
||
const end = nameWithoutExtension.slice(-Math.floor((maxLength - 3) / 2));
|
||
|
||
const deleteBtn = `
|
||
<div class="bRe${id}" style="cursor: pointer;">
|
||
<svg width="22" height="22" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||
<path d="M3.07812 9.09567L8.56833 3.60547M3.07812 3.60547L8.56833 9.09567" stroke="#B4B4B4" stroke-linecap="round" stroke-linejoin="round"/>
|
||
</svg>
|
||
</div>`;
|
||
|
||
const htmlUploadBox = `
|
||
<div class="p-0 b${id}">
|
||
<div class="upload-box overflow-hidden empty inBox${id}">
|
||
${deleteBtn}
|
||
<span class="file-name">
|
||
<span class="end">${end}${extension}</span>
|
||
<span class="ellipsis">...</span>
|
||
<span class="start">${start}</span>
|
||
</span>
|
||
<div id="imageFileUpload_${id}"></div>
|
||
<div class="spinner-loading-progress loading" style="display: none">
|
||
</div>
|
||
</div>
|
||
</div>`;
|
||
|
||
$('#upload-container-doc').append(htmlUploadBox);
|
||
|
||
const loading = $(boxClass).find('.spinner-loading-progress').show();
|
||
const reader = new FileReader();
|
||
reader.onload = function (e) {
|
||
|
||
const fileExtensions = [
|
||
".ai", ".avi", ".bmp", ".crd", ".csv", ".dll", ".doc", ".docx", ".dwg",
|
||
".eps", ".exe", ".flv", ".gif", ".html", ".iso", ".java", ".jpg", ".mdb",
|
||
".mid", ".mov", ".mp3", ".mp4", ".mpeg", ".pdf", ".png", ".ppt", ".ps",
|
||
".psd", ".pub", ".rar", ".raw", ".rss", ".svg", ".tiff", ".txt", ".wav",
|
||
".wma", ".xml", ".xsl", ".zip"
|
||
];
|
||
|
||
let svgName = extension.slice(1);
|
||
let img;
|
||
|
||
if (file.type.startsWith("image/")) {
|
||
img = `<img class="uploaded-file b${id}" src="${e.target.result}">`;
|
||
} else {
|
||
if (fileExtensions.includes(extension)) {
|
||
img = `<img class="uploaded-file" src="/common/filesvg/${svgName}.svg" style="width: 23px;" />`;
|
||
} else {
|
||
img = `<img class="uploaded-file" src="/common/filesvg/unknown.svg" style="width: 23px;" />`;
|
||
}
|
||
}
|
||
|
||
$(`#imageFileUpload_${id}`).append(img);
|
||
};
|
||
reader.readAsDataURL(file);
|
||
|
||
var xhr = new XMLHttpRequest();
|
||
xhr.open('POST', uploadFileAjax, true);
|
||
xhr.setRequestHeader('RequestVerificationToken', antiForgeryToken);
|
||
|
||
xhr.upload.addEventListener('progress', function (e) {
|
||
if (e.lengthComputable) {
|
||
var percentComplete = (e.loaded / e.total) * 100;
|
||
//$('#progressBar').text(Math.round(percentComplete) + '%');
|
||
let h = Math.round(percentComplete);
|
||
loading.css('width', `${h}%`);
|
||
}
|
||
});
|
||
|
||
xhr.onload = function () {
|
||
setTimeout(function () {
|
||
const response = JSON.parse(xhr.responseText);
|
||
if (xhr.status === 200 && response.isSuccedded) {
|
||
$(`.bRe${id}`).attr('onclick', `remove(${id}, ${response.id})`);
|
||
$(boxClass).css('background-color', '#f2fff1');
|
||
$('#fileItems').append(`<input type="hidden" value="${response.id}" name="EditTask.UploadedMedia[${indexCount}]"/>`);
|
||
indexCount++;
|
||
} else {
|
||
showAlertMessage('.alert-msg', response.message || 'Error uploading file', 3500);
|
||
$(`#EditTask_Document${id}`).val('');
|
||
$('.b' + id).remove();
|
||
}
|
||
handleActiveUploads();
|
||
loading.hide();
|
||
}, 1000);
|
||
};
|
||
|
||
xhr.onerror = function () {
|
||
showAlertMessage('.alert-msg', 'مشکلی در آپلود فایل به وجود آمد.', 3500);
|
||
$(`#EditTask_Document${id}`).val('');
|
||
$('.b' + id).remove();
|
||
handleActiveUploads();
|
||
loading.hide();
|
||
};
|
||
|
||
xhr.send(formData);
|
||
|
||
}
|
||
|
||
function handleActiveUploads() {
|
||
activeUploads--;
|
||
if (activeUploads === 0) {
|
||
$('#editSave').prop('disabled', false).removeClass('disable');
|
||
}
|
||
}
|
||
|
||
function remove(id, resId) {
|
||
var loading = $('.inBox' + id + ' .spinner-loading-progress');
|
||
loading.show();
|
||
$('#EditTask_Document' + id).val('');
|
||
$('.b' + id).remove();
|
||
|
||
var input = `<input type="file" class="d-none" name="EditTask.Document${id}" id="EditTask_Document${id}" accept=".pdf,.doc,.docx,.txt, image/*">`;
|
||
var inputDelete = `<input type="hidden" value="${resId}" name="EditTask.DeletedFileIds[${indexDeleteCount}]"/>`;
|
||
|
||
$('#deletedItems').append(inputDelete);
|
||
indexDeleteCount++;
|
||
|
||
// Remove from hidden inputs
|
||
$(`#fileItems input[value='${resId}']`).remove();
|
||
indexCount--;
|
||
|
||
activeUploads++;
|
||
$('#editSave').prop('disabled', true);
|
||
$('#editSave').addClass('disable');
|
||
|
||
var formData = new FormData();
|
||
formData.append('mediaId', resId);
|
||
|
||
$.ajax({
|
||
dataType: 'json',
|
||
type: 'POST',
|
||
processData: false,
|
||
contentType: false,
|
||
url: deleteFileAjax,
|
||
data: formData,
|
||
headers: { "RequestVerificationToken": antiForgeryToken },
|
||
success: function (response) {
|
||
if (response.isSuccedded) {
|
||
// showAlertMessage('.alert-success-msg', response.message, 1500);
|
||
} else {
|
||
showAlertMessage('.alert-msg', response.message, 3500);
|
||
}
|
||
loading.hide();
|
||
handleActiveUploads();
|
||
},
|
||
error: function (err) {
|
||
console.log(err);
|
||
loading.hide();
|
||
handleActiveUploads();
|
||
}
|
||
});
|
||
}
|
||
|
||
$('.cancelAndRefresh').on('click', function () {
|
||
$.ajax({
|
||
dataType: 'json',
|
||
type: 'POST',
|
||
processData: false,
|
||
contentType: false,
|
||
url: deleteAllFilesAjax,
|
||
headers: { "RequestVerificationToken": antiForgeryToken },
|
||
success: function (response) {
|
||
if (response.isSuccedded) {
|
||
// showAlertMessage('.alert-success-msg', response.message, 1500);
|
||
//$('#MainModal').modal('toggle');
|
||
window.location.replace('/AdminNew/Company/Task');
|
||
} else {
|
||
showAlertMessage('.alert-msg', response.message, 3500);
|
||
}
|
||
},
|
||
error: function (err) {
|
||
console.log(err);
|
||
loading.hide();
|
||
}
|
||
});
|
||
});
|
||
|
||
|
||
function showAlertMessage(selector, message, timeout) {
|
||
$(selector).show();
|
||
$(selector + ' p').text(message);
|
||
setTimeout(function () {
|
||
$(selector).hide();
|
||
$(selector + ' p').text('');
|
||
}, timeout);
|
||
}
|
||
|
||
|
||
function removeVoiceHandle(id) {
|
||
$('#EditTask_Voice').val('');
|
||
|
||
|
||
//$('#NewVoice').removeClass('d-none');
|
||
//$('#NewVoice').addClass('d-block d-md-flex');
|
||
//$('#OldVoice').addClass('d-none');
|
||
//$('#OldVoice').removeClass('d-block d-md-flex');
|
||
|
||
// var inputDelete = `<input type="hidden" value="${id}" name="EditTask.DeletedFileVoice"/>"`;
|
||
|
||
var inputDelete = `<input type="hidden" value="${id}" name="EditTask.DeletedFileIds[${indexDeleteCount}]"/>`;
|
||
$('#deletedItems').append(inputDelete);
|
||
indexDeleteCount++;
|
||
|
||
|
||
$('.upload-voice-container').removeClass('d-flex');
|
||
$('.upload-voice-container').hide();
|
||
$('#EditTask_Description').show();
|
||
$('#EditTask_Description').css('display','block');
|
||
}
|
||
|
||
|
||
// صدا
|
||
var msg_box = document.getElementById('msg_box'),
|
||
button = document.getElementById('upload-voice'),
|
||
rec = document.getElementById('upload-voice-recording'),
|
||
canvas = document.getElementById('canvas'),
|
||
lang = {
|
||
'mic_error': 'خطا! به میکروفون دسترسی ندارد.',
|
||
'press_to_start': 'برای ضبط صدا، پیام صوتی را کلیک نمائید',
|
||
'recording': 'در حال ضبط پیام صوتی ...',
|
||
'play': 'پخش',
|
||
'stop': 'متوقف',
|
||
'download': 'دانلود',
|
||
'use_https': 'This application in not working over insecure connection. Try to use HTTPS'
|
||
},
|
||
time;
|
||
|
||
msg_box.innerHTML = lang.press_to_start;
|
||
|
||
if (navigator.mediaDevices === undefined) {
|
||
navigator.mediaDevices = {};
|
||
}
|
||
|
||
if (navigator.mediaDevices.getUserMedia === undefined) {
|
||
navigator.mediaDevices.getUserMedia = function (constrains) {
|
||
var getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia
|
||
if (!getUserMedia) {
|
||
return Promise.reject(new Error('getUserMedia is not implemented in this browser'));
|
||
}
|
||
|
||
return new Promise(function (resolve, reject) {
|
||
getUserMedia.call(navigator, constrains, resolve, reject);
|
||
});
|
||
}
|
||
}
|
||
|
||
if (navigator.mediaDevices.getUserMedia) {
|
||
var btn_status = 'inactive',
|
||
mediaRecorder,
|
||
chunks = [],
|
||
audio = new Audio(),
|
||
mediaStream,
|
||
audioSrc,
|
||
type = {
|
||
'type': 'audio/ogg,codecs=opus'
|
||
},
|
||
ctx,
|
||
analys,
|
||
blob;
|
||
|
||
button.onclick = function () {
|
||
if (btn_status == 'inactive') {
|
||
|
||
if ($('#EditTask_Description').val() != '') {
|
||
swal.fire({
|
||
title: "اخطار",
|
||
text: "توضیحات مربوط به تسک وجود دارد، بعد از ضبط صدا تمامی توضیحات پاک خواهد شد، آیا میخواهید ادامه دهید؟",
|
||
icon: "warning",
|
||
showCancelButton: true,
|
||
confirmButtonText: "بله",
|
||
cancelButtonText: "خیر",
|
||
confirmButtonColor: '#84cc16',
|
||
reverseButtons: true
|
||
}).then((result) => {
|
||
if (result.isConfirmed) {
|
||
start();
|
||
} else {
|
||
return;
|
||
}
|
||
});
|
||
}
|
||
else {
|
||
start();
|
||
}
|
||
|
||
} else if (btn_status == 'recording') {
|
||
stop();
|
||
}
|
||
}
|
||
|
||
function parseTime(sec) {
|
||
var h = parseInt(sec / 3600);
|
||
var m = parseInt(sec / 60);
|
||
var sec = sec - (h * 3600 + m * 60);
|
||
|
||
h = h == 0 ? '' : h + ':';
|
||
sec = sec < 10 ? '0' + sec : sec;
|
||
|
||
return h + m + ':' + sec;
|
||
}
|
||
|
||
function start() {
|
||
$("#waveArea").hide();
|
||
$('#EditTask_Description').val('');
|
||
$('#EditTask_Description').hide();
|
||
$('.upload-voice-container').show();
|
||
$('.upload-voice-container').addClass('d-flex');
|
||
$('#upload-voice-recording').show();
|
||
$('#msg_box').hide();
|
||
$('#editSave').addClass('disable');
|
||
$('#editSave').prop('disabled', true);
|
||
|
||
//button.style.backgroundColor = '#32292C';
|
||
//button.style.color = '#FFFFFF';
|
||
//button.innerHTML = '<span>توقف</span>';
|
||
button.classList.add('recording-active');
|
||
|
||
|
||
if ($("#stop-voice-span").length) {
|
||
$("#stop-voice-span").remove(); // Remove the span if it exists
|
||
} else {
|
||
$('<span id="stop-voice-span">توقف</span>').appendTo(button); // Create and append the span
|
||
}
|
||
//$('#upload-voice').css('background-color', '#32292C');
|
||
|
||
navigator.mediaDevices.getUserMedia({ 'audio': true }).then(function (stream) {
|
||
mediaRecorder = new MediaRecorder(stream);
|
||
mediaRecorder.start();
|
||
|
||
rec.classList.add('recording');
|
||
|
||
btn_status = 'recording';
|
||
|
||
msg_box.innerHTML = lang.recording;
|
||
|
||
if (navigator.vibrate) navigator.vibrate(150);
|
||
|
||
time = Math.ceil(new Date().getTime() / 1000);
|
||
|
||
mediaRecorder.ondataavailable = function (event) {
|
||
chunks.push(event.data);
|
||
}
|
||
|
||
mediaRecorder.onstop = function () {
|
||
stream.getTracks().forEach(function (track) { track.stop() });
|
||
|
||
blob = new Blob(chunks, type);
|
||
audioSrc = window.URL.createObjectURL(blob);
|
||
|
||
audio.src = audioSrc;
|
||
|
||
chunks = [];
|
||
|
||
// Save the Blob to the input element
|
||
saveToInput(blob);
|
||
}
|
||
|
||
}).catch(function (error) {
|
||
console.log(132);
|
||
if (location.protocol != 'https:') {
|
||
msg_box.innerHTML = lang.mic_error + '<br>' + lang.use_https;
|
||
} else {
|
||
msg_box.innerHTML = lang.mic_error;
|
||
}
|
||
button.disabled = true;
|
||
});
|
||
}
|
||
|
||
function stop() {
|
||
$("#waveArea").show();
|
||
//$('.upload-voice-container').show();
|
||
//$('.upload-voice-container').addClass('d-flex');
|
||
$('#upload-voice-recording').hide();
|
||
$('#msg_box').hide();
|
||
$('#editSave').removeClass('disable');
|
||
$('#editSave').prop('disabled', false);
|
||
button.classList.remove('recording-active');
|
||
|
||
mediaRecorder.stop();
|
||
rec.classList.remove('recording');
|
||
if ($("#stop-voice-span").length) {
|
||
$("#stop-voice-span").remove();
|
||
}
|
||
btn_status = 'inactive';
|
||
console.log(123);
|
||
|
||
if (navigator.vibrate) navigator.vibrate([200, 100, 200]);
|
||
|
||
var now = Math.ceil(new Date().getTime() / 1000);
|
||
var t = parseTime(now - time);
|
||
|
||
msg_box.innerHTML = '<a href="#" onclick="play(); return false;" class="txt_btn">' + lang.play + ' (' + t + 's)</a><br>' +
|
||
'<a href="#" id="saveToInput" onclick="save(); return false;" class="txt_btn">' + lang.download + '</a>';
|
||
|
||
|
||
}
|
||
|
||
function play() {
|
||
audio.play();
|
||
msg_box.innerHTML = '<a href="#" onclick="pause(); return false;" class="txt_btn">' + lang.stop + '</a><br>' +
|
||
'<a href="#" onclick="save(); return false;" class="txt_btn">' + lang.download + '</a>';
|
||
}
|
||
|
||
function pause() {
|
||
audio.pause();
|
||
audio.currentTime = 0;
|
||
msg_box.innerHTML = '<a href="#" onclick="play(); return false;" class="txt_btn">' + lang.play + '</a><br>' +
|
||
'<a href="#" onclick="save(); return false;" class="txt_btn">' + lang.download + '</a>'
|
||
}
|
||
|
||
function roundedRect(ctx, x, y, width, height, radius, fill) {
|
||
ctx.beginPath();
|
||
ctx.moveTo(x, y + radius);
|
||
ctx.lineTo(x, y + height - radius);
|
||
ctx.quadraticCurveTo(x, y + height, x + radius, y + height);
|
||
ctx.lineTo(x + width - radius, y + height);
|
||
ctx.quadraticCurveTo(x + width, y + height, x + width, y + height - radius);
|
||
ctx.lineTo(x + width, y + radius);
|
||
ctx.quadraticCurveTo(x + width, y, x + width - radius, y);
|
||
ctx.lineTo(x + radius, y);
|
||
ctx.quadraticCurveTo(x, y, x, y + radius);
|
||
|
||
ctx.fillStyle = fill;
|
||
ctx.fill();
|
||
}
|
||
|
||
function saveToInput(blob) {
|
||
// Create the File object with the actual Blob data
|
||
const myFile = new File([blob], 'record.ogg', {
|
||
type: 'audio/ogg',
|
||
lastModified: new Date()
|
||
});
|
||
|
||
let fileVoice = document.getElementById("EditTask_Voice");
|
||
let playAudio = document.getElementById("playAudio");
|
||
const dataTransfer = new DataTransfer();
|
||
dataTransfer.items.add(myFile);
|
||
fileVoice.files = dataTransfer.files;
|
||
let voiceSrc = URL.createObjectURL(dataTransfer.files[0]);
|
||
|
||
|
||
var formData = new FormData();
|
||
formData.append('media', myFile);
|
||
|
||
var loading = $('.upload-box-voice').find('.spinner-loading');
|
||
loading.show();
|
||
|
||
$.ajax({
|
||
dataType: 'json',
|
||
type: 'POST',
|
||
processData: false,
|
||
contentType: false,
|
||
url: uploadFileAjax,
|
||
headers: { "RequestVerificationToken": antiForgeryToken },
|
||
data: formData,
|
||
success: function (response) {
|
||
if (response.isSuccedded) {
|
||
|
||
var inputVoice = `<input type="hidden" value="${response.id}" name="EditTask.UploadedVoiceMedia" />"`;
|
||
$('#voiceItem').append(inputVoice);
|
||
|
||
//showAlertMessage('.alert-success-msg', response.message, 1500);
|
||
console.log('voice uploaded');
|
||
} else {
|
||
showAlertMessage('.alert-msg', response.message, 3500);
|
||
$('#EditTask_Voice').val('');
|
||
}
|
||
loading.hide();
|
||
waveVoice(voiceSrc);
|
||
},
|
||
error: function (err) {
|
||
console.log(err);
|
||
loading.hide();
|
||
}
|
||
});
|
||
}
|
||
|
||
function save() {
|
||
console.log(audioSrc);
|
||
var a = document.createElement('a');
|
||
a.download = 'record.ogg';
|
||
a.href = audioSrc;
|
||
document.body.appendChild(a);
|
||
a.click();
|
||
|
||
document.body.removeChild(a);
|
||
}
|
||
|
||
} else {
|
||
if (location.protocol != 'https:') {
|
||
msg_box.innerHTML = lang.mic_error + '<br>' + lang.use_https;
|
||
} else {
|
||
msg_box.innerHTML = lang.mic_error;
|
||
}
|
||
button.disabled = true;
|
||
}
|
||
|
||
|
||
var wavesurfer = null;
|
||
|
||
if ($('#EditTask_Voice').val() !== '') {
|
||
const dataTransfer = new DataTransfer();
|
||
dataTransfer.items.add(myFile);
|
||
let voiceSrc = URL.createObjectURL(dataTransfer.files[0]);
|
||
}
|
||
|
||
if (voiceSrc) {
|
||
waveVoice(voiceSrc);
|
||
}
|
||
|
||
function waveVoice(voiceSrc) {
|
||
// Ensure identifiers are only declared once
|
||
var playPauseButton = $('#play-pause');
|
||
var currentTimeEl = $('#current-time');
|
||
var durationEl = $('#duration');
|
||
var voiceSource = decodeURIComponent(voiceSrc.replace(/&/g, '&'));
|
||
|
||
// If a wavesurfer instance already exists, destroy it
|
||
if (wavesurfer) {
|
||
wavesurfer.destroy();
|
||
}
|
||
|
||
// Initialize Wavesurfer
|
||
wavesurfer = WaveSurfer.create({
|
||
container: '#waveform',
|
||
waveColor: '#e0e0e0',
|
||
progressColor: '#23a9a9',
|
||
cursorWidth: 2,
|
||
cursorColor: '#23a9a9',
|
||
height: 40,
|
||
barWidth: 2,
|
||
responsive: true
|
||
});
|
||
|
||
// Load the audio file
|
||
wavesurfer.load(`${voiceSource}`);
|
||
$("#waveArea").show();
|
||
|
||
// Play/pause functionality
|
||
playPauseButton.off('click'); // Remove previous event handlers
|
||
playPauseButton.on('click', function () {
|
||
if (wavesurfer.isPlaying()) {
|
||
wavesurfer.pause();
|
||
playPauseButton.removeClass('pause').addClass('play');
|
||
} else {
|
||
wavesurfer.play();
|
||
playPauseButton.removeClass('play').addClass('pause');
|
||
}
|
||
});
|
||
|
||
// Update time and progress
|
||
wavesurfer.on('audioprocess', function () {
|
||
currentTimeEl.text(formatTime(wavesurfer.getCurrentTime()));
|
||
});
|
||
|
||
// Set duration once ready
|
||
wavesurfer.on('ready', function () {
|
||
durationEl.text(formatTime(wavesurfer.getDuration()));
|
||
});
|
||
|
||
// Format time function
|
||
function formatTime(seconds) {
|
||
var minutes = Math.floor(seconds / 60);
|
||
seconds = Math.floor(seconds % 60);
|
||
return minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
|
||
}
|
||
}
|
||
|
||
|
||
// صدا
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// نمایش اسامی کارگاه
|
||
var container = $('#partyName');
|
||
var searchBox = $('#partyNameSearch');
|
||
var searchResul = $('.searchResult');
|
||
var mixContainerAndSerchResult = $('#partyName , .searchResult');
|
||
|
||
container.hide();
|
||
var liList;
|
||
var liPointer;
|
||
var count = 0;
|
||
|
||
//close search Employee when click on body
|
||
$(document).on('click', function (event) {
|
||
if (!$(event.target).closest(container).length) {
|
||
container.hide();
|
||
}
|
||
});
|
||
//select option by mouse
|
||
function selectItem(employeeFullName) {
|
||
searchBox.val(employeeFullName);
|
||
container.hide();
|
||
};
|
||
|
||
|
||
$(document).on('click', '#partyNameSearch', function () {
|
||
searchResul.html('');
|
||
let searchText = $(this).val();
|
||
|
||
|
||
$.ajax({
|
||
contentType: 'charset=utf-8',
|
||
dataType: 'json',
|
||
type: 'GET',
|
||
url: searchContractingPartiesAjax,
|
||
data: { "searchName": searchText },
|
||
headers: { "RequestVerificationToken": antiForgeryToken },
|
||
success: function (response) {
|
||
$(".opt").remove();
|
||
if (response.list.length > 0) {
|
||
$(".noResult").remove();
|
||
container.show();
|
||
$.each(response.list,
|
||
function (i, item) {
|
||
let li = `<li data-employeeId="0" onclick="selectItem('${item}');" >${item}</li>`;
|
||
searchResul.append(li);
|
||
});
|
||
} else {
|
||
$(".noResult").remove();
|
||
container.show();
|
||
let noResult = `<li class="noResult">نتیجه ای یافت نشد!</li>`;
|
||
searchResul.append(noResult);
|
||
}
|
||
}
|
||
});
|
||
});
|
||
|
||
|
||
|
||
function searchPartyNameTask() {
|
||
var input, filter, tbody, tr, i, td, containerResult;
|
||
input = document.getElementById("partyNameSearch");
|
||
filter = input.value.toUpperCase();
|
||
tbody = document.getElementById("searchResult");
|
||
tr = tbody.getElementsByTagName("li");
|
||
|
||
var hasVisibleResults = false;
|
||
|
||
for (i = 0; i < tr.length; i++) {
|
||
td = tr[i];
|
||
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
|
||
tr[i].style.display = "";
|
||
hasVisibleResults = true;
|
||
} else {
|
||
tr[i].style.display = "none";
|
||
}
|
||
}
|
||
|
||
containerResult = document.getElementById("partyName");
|
||
if (hasVisibleResults) {
|
||
containerResult.style.display = "block";
|
||
} else {
|
||
containerResult.style.display = "none";
|
||
}
|
||
}
|
||
|
||
|
||
|
||
//search by Ajax
|
||
//searchBox.on('keyup keypress',
|
||
// function (e) {
|
||
// searchResul.html('');
|
||
|
||
// //stop submit form with enter
|
||
// var keyCode = e.keyCode || e.which;
|
||
// if (keyCode === 13) {
|
||
// e.preventDefault();
|
||
// if (count > 0 && count <= liList.length) {
|
||
// liPointer.click();
|
||
// }
|
||
// return false;
|
||
// }
|
||
|
||
// let searchText = $(this).val();
|
||
|
||
// if (searchText.length > 1) {
|
||
|
||
// $.ajax({
|
||
// async: false,
|
||
// contentType: 'charset=utf-8',
|
||
// dataType: 'json',
|
||
// type: 'GET',
|
||
// url: searchContractingPartiesAjax,
|
||
// data: { "searchName": searchText },
|
||
// headers: { "RequestVerificationToken": antiForgeryToken },
|
||
|
||
// success: function (response) {
|
||
// $(".opt").remove();
|
||
// if (response.list.length > 0) {
|
||
// $(".noResult").remove();
|
||
// container.show();
|
||
// $.each(response.list,
|
||
// function (i, item) {
|
||
// let li = `<li data-employeeId="${item.id}" onclick="selectItem('${item.fullName}');" >${item.fullName}</li>`;
|
||
// searchResul.append(li);
|
||
// });
|
||
// } else {
|
||
// $(".noResult").remove();
|
||
// container.show();
|
||
// let noResult = `<li class="noResult">نتیجه ای یافت نشد!</li>`;
|
||
// searchResul.append(noResult);
|
||
// }
|
||
// }// endOfSuccess
|
||
|
||
// }); //endOfAjax
|
||
|
||
// } else {
|
||
// container.hide();
|
||
// count = 0;
|
||
// }
|
||
// });
|
||
// نمایش اسامی کارگاه
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// نمایش عنوان دلبخواه
|
||
var containerTitle = $('#TaskTitle');
|
||
var searchBoxTitle = $('.TaskTitleSearch');
|
||
var searchResulTitle = $('.searchTitleResult');
|
||
var mixContainerAndSerchResultTitle = $('#TaskTitle , .searchTitleResult');
|
||
|
||
containerTitle.hide();
|
||
var liListTitle;
|
||
var liPointerTitle;
|
||
var countTitle = 0;
|
||
|
||
//close search Employee when click on body
|
||
$(document).on('click', function (event) {
|
||
if (!$(event.target).closest(container).length) {
|
||
containerTitle.hide();
|
||
}
|
||
});
|
||
|
||
$(document).on('keydown', function (event) {
|
||
if (event.keyCode === 9) {
|
||
$('#partyName').hide();
|
||
$('#TaskTitle').hide();
|
||
}
|
||
});
|
||
|
||
//select option by mouse
|
||
function selectItemTitle(subject) {
|
||
searchBoxTitle.val(subject);
|
||
containerTitle.hide();
|
||
};
|
||
|
||
|
||
$(document).on('click', '.TaskTitleSearch', function () {
|
||
|
||
searchResulTitle.html('');
|
||
|
||
//stop submit form with enter
|
||
//var keyCode = e.keyCode || e.which;
|
||
//if (keyCode === 13) {
|
||
// e.preventDefault();
|
||
// if (countTitle > 0 && countTitle <= liListTitle.length) {
|
||
// liPointerTitle.click();
|
||
// }
|
||
// return false;
|
||
//}
|
||
|
||
let searchTextTitle = $(this).val();
|
||
|
||
$.ajax({
|
||
contentType: 'charset=utf-8',
|
||
dataType: 'json',
|
||
type: 'GET',
|
||
url: searchTaskSubject,
|
||
data: { "searchSubject": searchTextTitle },
|
||
headers: { "RequestVerificationToken": antiForgeryToken },
|
||
success: function (response) {
|
||
if (response.list.length > 0) {
|
||
containerTitle.show();
|
||
$.each(response.list,
|
||
function (i, item) {
|
||
let li = `<li class="li-subject" onclick="selectItemTitle('${item.subject}');">${item.subject}</li>`;
|
||
searchResulTitle.append(li);
|
||
});
|
||
} else {
|
||
containerTitle.hide();
|
||
}
|
||
}
|
||
|
||
});
|
||
});
|
||
|
||
|
||
function searchSubjectTask() {
|
||
var input, filter, tbody, tr, i, td, containerResult;
|
||
input = document.getElementById("EditTask_Title");
|
||
filter = input.value.toUpperCase();
|
||
tbody = document.getElementById("searchTitleResult");
|
||
tr = tbody.getElementsByClassName("li-subject");
|
||
|
||
var hasVisibleResults = false;
|
||
|
||
for (i = 0; i < tr.length; i++) {
|
||
td = tr[i];
|
||
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
|
||
tr[i].style.display = "";
|
||
hasVisibleResults = true;
|
||
} else {
|
||
tr[i].style.display = "none";
|
||
}
|
||
}
|
||
|
||
containerResult = document.getElementById("TaskTitle");
|
||
if (hasVisibleResults) {
|
||
containerResult.style.display = "block";
|
||
} else {
|
||
containerResult.style.display = "none";
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
//search by Ajax
|
||
//searchBoxTitle.on('keyup keypress',
|
||
// function (e) {
|
||
// searchResulTitle.html('');
|
||
|
||
// //stop submit form with enter
|
||
// var keyCode = e.keyCode || e.which;
|
||
// if (keyCode === 13) {
|
||
// e.preventDefault();
|
||
// if (countTitle > 0 && countTitle <= liListTitle.length) {
|
||
// liPointerTitle.click();
|
||
// }
|
||
// return false;
|
||
// }
|
||
|
||
// let searchTextTitle = $(this).val();
|
||
|
||
// if (searchTextTitle.length > 0) {
|
||
|
||
// $.ajax({
|
||
// async: false,
|
||
// contentType: 'charset=utf-8',
|
||
// dataType: 'json',
|
||
// type: 'GET',
|
||
// url: searchTaskSubject,
|
||
// data: { "searchSubject": searchTextTitle },
|
||
// headers: { "RequestVerificationToken": antiForgeryToken },
|
||
// success: function (response) {
|
||
// if (response.list.length > 0) {
|
||
// //$(".noResultTitle").remove();
|
||
// containerTitle.show();
|
||
// $.each(response.list,
|
||
// function (i, item) {
|
||
// let li = `<li onclick="selectItemTitle('${item.subject}');" >${item.subject}</li>`;
|
||
// searchResulTitle.append(li);
|
||
// });
|
||
// } else {
|
||
// //$(".noResult").remove();
|
||
// containerTitle.hide();
|
||
// //let noResultTitle = `<li class="noResult">نتیجه ای یافت نشد!</li>`;
|
||
// //searchResulTitle.append(noResultTitle);
|
||
// }
|
||
// }// endOfSuccess
|
||
|
||
// }); //endOfAjax
|
||
|
||
// } else {
|
||
// container.hide();
|
||
// count = 0;
|
||
// }
|
||
// });
|
||
// نمایش عنوان دلبخواه
|
||
|
||
|
||
|
||
|
||
// برای محاسبه تاریخ و ساعت به صورت داینامیک
|
||
// function computeDays() {
|
||
// $('.resultDays').remove();
|
||
// $.ajax({
|
||
// /* contentType: 'charset=utf-8',*/
|
||
// async: false,
|
||
// dataType: 'json',
|
||
// type: 'GET',
|
||
// url: '@Url.Page("/Company/Task/Create", "ComputeDay")',
|
||
// headers: { "RequestVerificationToken": $('input[name="__RequestVerificationToken"]').val() },
|
||
// data: { "date": $('#EndTaskDate').val(), "time": $('#EndTaskTime').val() },
|
||
// success: function (response) {
|
||
// if (response.status == false) {
|
||
// $('.sumDays').addClass("note");
|
||
// } else {
|
||
// $('.sumDays').removeClass("note");
|
||
// }
|
||
// let res = `<span class="resultDays">${response.res}</span>`;
|
||
// $('.sumDays').append(res);
|
||
// },
|
||
// failure: function (response) {
|
||
// console.log(5, response);
|
||
// }
|
||
// });
|
||
// }
|
||
|
||
|
||
function taskSubjectModal() {
|
||
var goTo = `#showmodal=${taskSubjectModal}`;
|
||
window.location.href = goTo;
|
||
}
|
||
|
||
|
||
|
||
function CheckHoliday() {
|
||
|
||
var timeChecked = $("#EndTaskDate").val();
|
||
if (timeChecked.length === 10) {
|
||
$.ajax({
|
||
contentType: 'charset=utf-8',
|
||
dataType: 'json',
|
||
type: 'GET',
|
||
url: checkIsHolidayModalAjax,
|
||
data: { time: timeChecked },
|
||
headers: { "RequestVerificationToken": antiForgeryToken },
|
||
success: function (response) {
|
||
if (response.isSuccedded) {
|
||
if (response.isHoliday) {
|
||
$("#EndTaskDate").css('color', 'red');
|
||
$("#HolidayError").show();
|
||
isHoliday = response.isHoliday;
|
||
}
|
||
else {
|
||
isHoliday = response.isHoliday;
|
||
}
|
||
|
||
}
|
||
else {
|
||
$('.alert-msg p').text(response.message);
|
||
setTimeout(function () {
|
||
}, 3500);
|
||
}
|
||
}
|
||
});
|
||
}
|
||
else {
|
||
$("#EndTaskDate").css('color', '#797979');
|
||
$("#HolidayError").hide();
|
||
}
|
||
}
|