var baseUrl = "https://rms.rmto.ir"; // var baseUrl = "http://localhost:3000"; // Get announcements data $.ajax({ url: `${baseUrl}/events`, type: "GET", cache: false, contentType: false, processData: false, success: function (result) { //console.log(result); result = result.data; let rowNumber = 0; if (result.length < 1) { // No announcements available! $(".card-body-container").append( "

اطلاعیه ای جهت نمایش وجود ندارد.

" ); } else { // If we have 1 or 4 or ... announcements if (result.length % 3 == 1) { for (let index = 0; index < result.length; index++) { if (index == result.length - 1) { // Last element that is numebr 1 or 4 or ... rowNumber = index; $(".card-body-container").append( '\
\ \ ...\
\
عنوان: ' + result[index].title + '
\

\ ضرب العجل: ' + result[index].deadline + '

\

\ توضیحات: ' + result[index].description + '

\

' + showButtons( result[index].files, result[index].id, result[index].admin ) + "\

\
\
\ \ " ); $("#row" + rowNumber).append( '\ \ \ ' ); $("#row" + rowNumber).append( '\ \ \ ' ); } else { showCardBoxes(result, index); } } } // If we have 2 or 3 or ... announcements else { for (let index = 0; index < result.length; index++) { showCardBoxes(result, index); } } } }, error: function (error) { //console.log(error); }, }); function showCardBoxes(result, index) { if (index % 3 == 0) { rowNumber = index; $(".card-body-container").append( '\
\ \ ...\
\
عنوان: ' + result[index].title + '
\

\ ضرب العجل: ' + result[index].deadline + '

\

\ توضیحات: ' + result[index].description + '

\

' + showButtons( result[index].files, result[index].id, result[index].admin ) + "\

\
\
\ \ " ); } else { $("#row" + rowNumber).append( '\ \ ...\
\
عنوان: ' + result[index].title + '
\

\ ضرب العجل: ' + result[index].deadline + '

\

\ توضیحات: ' + result[index].description + '

\

' + showButtons( result[index].files, result[index].id, result[index].admin ) + "\

\
\ \ " ); } } function showButtons(files, id, admin) { let appendedButtons = ""; if (files != null) { //rms.rmto.ir/events/user/download/${id} https: appendedButtons = '\ '; } // else appendedButtons = ""; if (admin == 0) { // Towns appendedButtons += '\ \ '; } else if (admin == 1) { // The capital of the province appendedButtons += '\ \ \ '; } else if (admin == 2) { // Admin user (General Manager) appendedButtons += '\ \ \ \ \ '; } return appendedButtons; } function showConfirmBox(id) { let fileName = $("#upload-file" + id)[0].files[0].name; let filesize = $("#upload-file" + id)[0].files[0].size / 1000000 ; var formData = new FormData(); console.log(id); formData.append("files", $("#upload-file" + id)[0].files[0]); Swal.fire({ title: "آیا از ارسال این فایل مطمئن هستید؟", text: "نام فایل: " + fileName, icon: "warning", showCancelButton: true, confirmButtonColor: "#3085d6", cancelButtonColor: "#d33", cancelButtonText: "لغو عملیات", confirmButtonText: "ارسال فایل", showLoaderOnConfirm: true, preConfirm: () => { if (filesize <= 60){ return fetch(`https://rms.rmto.ir/events/user/upload/${id}`, { method: "POST", headers: { "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"), }, body: formData, }) .then((response) => { //console.log(response); if (!response.ok) { throw new Error(response.statusCode); } return response.json(); }) .catch((error) => { Swal.showValidationMessage( `ارسال فایل با خطا مواجه گردید. لطفا دوباره تلاش کنید.` ); }); } else { $("#upload-file").val(""); Swal.showValidationMessage( 'حجم فایل بیشتر از 60 مگابایت میباشد ' ); } }, }).then((result) => { //console.log(result); $("#upload-file").val(""); if (result.dismiss === Swal.DismissReason.cancel) { } else if (result.value.status == "succeed") { Swal.fire("فایل با موفقیت ارسال شد!", "", "success"); } else { Swal.fire( "ارسال فایل با خطا مواجه گردید. لطفا دوباره تلاش کنید.", "", "error" ); } }); } function deleteAnEvent(id) { Swal.fire({ title: "آیا از حذف این مورد مطمئن هستید؟", icon: "warning", showCancelButton: true, confirmButtonColor: "#3085d6", cancelButtonColor: "#d33", cancelButtonText: "لغو عملیات", confirmButtonText: "تایید و حذف", showLoaderOnConfirm: true, preConfirm: () => { return fetch(`https://rms.rmto.ir/events/delete/${id}`, { method: "POST", headers: { "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"), }, }) .then((response) => { //console.log(response); if (!response.ok) { throw new Error(response.statusCode); } return response.json(); }) .catch((error) => { Swal.showValidationMessage(`خطایی رخ داده است!`); }); }, }).then((result) => { //console.log(result); if (result.dismiss === Swal.DismissReason.cancel) { // } else if (result.value.status == "succeed") { window.open("/events/list", "_self"); } else { Swal.fire("خطایی رخ داده است!", "", "error"); } }); } function archive(id) { Swal.fire({ title: "آیا از آرشیو این مورد مطمئن هستید؟", icon: "warning", showCancelButton: true, confirmButtonColor: "#3085d6", cancelButtonColor: "#d33", cancelButtonText: "لغو عملیات", confirmButtonText: "تایید و حذف", showLoaderOnConfirm: true, preConfirm: () => { return fetch(`https://rms.rmto.ir/events/archive/${id}`, { method: "POST", headers: { "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"), }, }) .then((response) => { //console.log(response); if (!response.ok) { throw new Error(response.statusCode); } return response.json(); }) .catch((error) => { Swal.showValidationMessage(`خطایی رخ داده است!`); }); }, }).then((result) => { //console.log(result); if (result.dismiss === Swal.DismissReason.cancel) { // } else if (result.value.status == "succeed") { window.open("/events/list", "_self"); } else { Swal.fire("خطایی رخ داده است!", "", "error"); } }); }