$(document).ready(function () { loadSubjectList(); $('#btn-add').on('click', function (e) { e.preventDefault(); var subject = $("#NewSubject").val().trim(); if (subject != '') { $.ajax({ async: false, dataType: 'json', type: 'POST', url: CreateTaskSubjectAjax, headers: { "RequestVerificationToken": antiForgeryToken }, data: { subject: subject }, success: function (response) { if (response.isSuccess) { loadSubjectList(); $("#NewSubject").val(''); } }, error: function (err) { console.log(err); } }); } }); $('#NewSubject').on('keyup keypress', function (e) { if ($('#NewSubject').val() != '') { //کلید دمکه اینتر 13 var keyCode = e.keyCode || e.which; if (keyCode === 13) { $('#btn-add').click(); } } }); }); function loadSubjectList() { var htmlItem = ''; $.ajax({ url: listTaskSubjectAjax, type: 'GET', success: function (response) { var items = response.result; items.forEach(function (item) { htmlItem += `
${item.subject}
`; }); $('#loadSubjectList').html(htmlItem); }, error: function (xhr, status, error) { console.error(xhr.responseText); } }); } // $(".editSubject").on('keyup keypress', function (e) { // if (this.val() != '') { // //کلید دمکه اینتر 13 // var keyCode = e.keyCode || e.which; // if (keyCode === 13) { // editSubject(id); // } // } // }); function editSubject(id) { var subjectTitle = $("#editSubject_" + id).val(); if (subjectTitle.trim() != '') { $.ajax({ async: false, dataType: 'json', type: 'POST', url: editTaskSubjectAjax, headers: { "RequestVerificationToken": antiForgeryToken }, data: { id: Number(id), subject: subjectTitle }, success: function (response) { if (response.isSuccess) { loadSubjectList(); } }, error: function (err) { console.log(err); } }); } loadSubjectList(); } function removeSubject(id) { swal({ title: "آیا از حذف این عنوان اطمینان دارید؟", text: "", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "بله", cancelButtonText: "خیر", closeOnConfirm: true, closeOnCancel: true }, function (isConfirm) { if (isConfirm) { deleteSubject(id); } }); } function deleteSubject(id) { var ID = Number(id); $.ajax({ async: false, dataType: 'json', type: 'POST', url: RemoveTaskSubjectAjax, headers: { "RequestVerificationToken": antiForgeryToken }, data: {id: Number(ID) }, success: function (response) { console.log(response); if (response.isSuccess) { loadSubjectList(); } }, error: function (err) { console.log(err); } }); } function searchSubjectTask() { var input, filter, tbody, tr, a, i; input = document.getElementById("SearchSubject"); filter = input.value.toUpperCase(); tbody = document.getElementById("loadSubjectList"); tr = tbody.getElementsByClassName("items"); for (i = 0; i < tr.length; i++) { td = tr[i].getElementsByClassName("searchItem")[0]; if (td.innerHTML.toUpperCase().indexOf(filter) > -1) { tr[i].style.display = ""; } else { tr[i].style.display = "none"; } } } function editOperation(id) { $("#editOperation_" + id).css('display', 'none'); $("#editConfirm_" + id).css('display', 'flex'); var subjectTitleSpan = $("#editSubjectSpan_" + id); subjectTitleSpan.css('display', 'none'); var subjectTitle = $("#editSubject_" + id); subjectTitle.css('display', 'block'); subjectTitle.focus(); }