Файловый менеджер - Редактировать - /home/clickysoft/public_html/somni.clickysoft.net/public/js/calendar-init.js
Назад
async function fetchData() { try { const data = await $.ajax({ url: '/get-events', method: 'GET', dataType: 'json', }); // console.log(data); // Process the data as needed return data; } catch (error) { console.error('Error fetching data:', error); } } document.addEventListener('DOMContentLoaded', async function () { var calendarEl = document.getElementById('calendar'); let objectDate = new Date(); let month = objectDate.getMonth(); // console.log(month + 1); const today = new Date(); // Get the current date components const year = today.getFullYear(); const month_n = String(today.getMonth() + 1).padStart(2, '0'); // Months are zero-based const day = String(today.getDate()).padStart(2, '0'); // Format the date as "yyyy-mm-dd" const formattedDate = `${year}-${month_n}-${day}`; // console.log('This is formated Date',formattedDate); var event_ajax = await fetchData(); // console.log('This is inside: ',event_ajax); var calendar = new FullCalendar.Calendar(calendarEl, { // height:'auto', headerToolbar: { // left: 'prev,next today', // left: 'prev,next', right: 'customButton', center: 'prev title next', // right: 'dayGridMonth,timeGridWeek,timeGridDay', left: 'dayGridYear,timeGridWeek,dayGridMonth,timeGridDay', }, dateClick: function (info) { // Prevent the default behavior (the built-in event creation prompt) // info.jsEvent.preventDefault(); // // // Show your custom modal // $('#eventModal').modal('show'); // // // Clear the input fields in the modal // $('#eventTitle').val(''); // function saveEvent() { // var title = $('#eventTitle').val(); // calendar.addEvent({ // title: title, // start: info.dateStr,// Use the clicked date as the event's start date // }); // // Remove the event listener after it has been executed // $('#saveEvent')[0].removeEventListener('click', saveEvent); // // Close the modal // $('#eventModal').modal('hide'); // } // $('#saveEvent')[0].addEventListener('click', saveEvent); // // Handle saving the event data here (when the "Save Event" button is clicked) // $('#saveEvent').on('click', function () { // var eventTitle = $('#eventTitle').val(); // // Create a new event and add it to the calendar // calendar.addEvent({ // title: eventTitle, // start: info.dateStr // Use the clicked date as the event's start date // }); // }); }, customButtons: { customButton: { text: 'New Event', click: function () { $('#eventTitle').val(''); $("#eventModal").modal("show"); } } }, // initialDate: '2023-05-08', initialDate: formattedDate, initialView: 'timeGridWeek', // events: [ // { // title: 'Event 1', // start: '2023-05-16T10:00:00', // end: '2023-09-16T12:00:00', // }, // { // title: 'Event 2', // start: '2023-09-17T14:00:00', // end: '2023-09-17T16:00:00', // }, // // Add more events here // ], views: { timeGridWeek: { // name of view titleFormat: { month: 'short', day: '2-digit' } // other view-specific options here } }, dayHeaderFormat: { weekday: 'long', day: 'numeric', }, dayHeaderContent: (args) => { return moment(args.date).format('dddd D') // return 'abc' }, columnFormat: 'dddd', slotLabelInterval: { minutes: 30 }, // timeGrid: true, // timeFormat: 'HH:mm', scrollTime: '00:00:00', allDaySlot: false, navLinks: true, selectable: true, // slotWidth: 200, selectMirror: true, eventAfterRender: function (event, element, view) { // console.log('asd'); }, eventClick: async function (info) { var eventId = info.event.id; showLoading(); await $.ajax({ url: '/landlord/get_single_event/'+eventId, type: 'get', success: function(response){ if(response.code == 200 || response.code == 400){ var event = response.event; $('.event_edit_modal :input').prop('disabled', true); if ($('#event_edit_btn').length === 0) { // Button does not exist, so create and append it var editButton = $('<button>', { type: 'button', class: 'event-create-btn', id: 'event_edit_btn', text: 'Edit' }); // Append the button to the div with class edit_btn_event_container $('.edit_btn_event_container').append(editButton); } if ($('#event_archive_btn').length === 0) { // Button does not exist, so create and append it var editButton = $('<button>', { type: 'button', class: 'event-create-btn', id: 'event_archive_btn', text: 'Archive', 'data-archive': event.id }); // Append the button to the div with class edit_btn_event_container $('.archive_btn_event_container').append(editButton); }else{ $('#event_archive_btn').attr('data-archive',event.id); } var capitalizedType = response.event.type; capitalizedType = capitalizedType.replace(/_/g, ' ').split(' ').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' '); // $('#eventModal .task_name').val(response.event.task); // $('#eventModal input[name="type"]').val(response.event.type); // $('#eventModal .select-selected').attr('data-value',response.event.type); // Set the title input $('#openhouseModal input[name="title"]').val(event.task); // Set the type input (assuming you want to set the type of event) $('#openhouseModal input[name="type"]').val(event.type); $('#openhouseModal .select-selected').html(capitalizedType); // Set the select for property_id $('#openhouseModal select[name="property_id"]').val(event.property_id); // Set the date input $('#openhouseModal input[name="date"]').val(event.date); // Set the time inputs $('#openhouseModal input[name="edit_from_time"]').val(event.from_time); $('#openhouseModal input[name="edit_to_time"]').val(event.to_time); // Set the email input $('#openhouseModal input[name="edit_email"]').val(event.email); // Set the note input $('#openhouseModal input[name="edit_note"]').val(event.note); $('#openhouseModal input[name="event_id"]').val(event.id); var propertiesSelect = $('#openhouseModal select[name="property_id"]'); propertiesSelect.empty(); // Remove previous options $.each(response.properties, function(index, property) { var option = $('<option>', { value: property.id, text: property.name }); if (property.id === event.event_property.id) { option.attr('selected', 'selected'); // Select the matching option } propertiesSelect.append(option); }); var unitSelect = $('#openhouseModal select[name="unit_id"]'); unitSelect.empty(); // Remove previous options $.each(response.units, function(index, unit) { var option = $('<option>', { value: unit.id, text: unit.number }); if (unit.id === event.unit.id) { option.attr('selected', 'selected'); // Select the matching option } unitSelect.append(option); }); var categorySelect = $('#openhouseModal .category_container select'); categorySelect.empty(); $.each(response.categories, function(index, category) { var option = $('<option>', { value: category.id, text: category.name }); if(event.type == "maintenance"){ if (category.id === event.category_id) { option.attr('selected', 'selected'); // Select the matching option } } categorySelect.append(option); }); if(event.type == 'maintenance'){ $('#openhouseModal .category_container').removeClass('dsk-none'); categorySelect.attr('disabled',true); } $('#datepickerEdit').datepicker('update', event.date); $('#datepickerEdit #date').val(event.date); $('#datepickerEdit #date').attr('disabled',true); $('#openhouseModal form').attr('action', '/update/event/' + event.id); if(response.code == 400){ $('#event_edit_btn').remove(); } if(event.is_archive == 1){ $('#event_archive_btn').remove(); } }else{ TopEndPopUp('warning','No Records') } swal.close(); // console.log(response); }, error: function(XMLHttpRequest, textStatus, errorThrown) { swal.close() TopEndPopUp('warning',errorThrown) } }); $('#openhouseModal').modal('show'); // if (confirm('Are you sure you want to delete this event?')) { // const data = await $.ajax({ // url: '/delete-events?event_id='+eventId, // method: 'GET', // // dataType: 'json', // }); // if(data){ // info.event.remove(); // toastr.options = { // "closeButton": true, // "debug": false, // "newestOnTop": false, // "progressBar": false, // "positionClass": "toast-top-right", // "preventDuplicates": false, // "onclick": null, // "showDuration": "300", // "hideDuration": "1000", // "timeOut": "5000", // "extendedTimeOut": "1000", // "showEasing": "swing", // "hideEasing": "linear", // "showMethod": "fadeIn", // "hideMethod": "fadeOut" // } // toastr.success('Event Deleted'); // }else{ // toastr.options = { // "closeButton": true, // "debug": false, // "newestOnTop": false, // "progressBar": false, // "positionClass": "toast-top-right", // "preventDuplicates": false, // "onclick": null, // "showDuration": "300", // "hideDuration": "1000", // "timeOut": "5000", // "extendedTimeOut": "1000", // "showEasing": "swing", // "hideEasing": "linear", // "showMethod": "fadeIn", // "hideMethod": "fadeOut" // } // toastr.error('Error Deleting Event'); // } // } // console.log('Clicked event ID:', eventId); }, editable: true, dayMaxEvents: true, events: event_ajax, // eventDidMount: function (info) { // // console.log(info); // // {description: "Lecture", department: "BioChemistry"} // }, eventDidMount: function (info) { // Access and log the event information // console.log(info.event.extendedProps); const userDisplay = info.event?.extendedProps?.userDisplay ?? false; if (userDisplay) { var adjustedEndTime = moment(info.event.end).subtract(30, 'minutes'); var adjustedStartTime = moment(info.event.start).format('h:mm A'); var formattedEndTime = adjustedEndTime.format('h:mm A'); var currentTime = '<div class="fc-event-time">'+adjustedStartTime+' - '+formattedEndTime+'</div>'; // console.log(currentTime); var existingElement = info.el.querySelector('.fc-event-time'); existingElement.innerHTML = currentTime; // console.log($(info.el).closest('.all-events')) const parentElement = $(info.el).closest('.all-events'); let newDiv = `<div class="custom-div">`; // Replace with your HTML content const users = info.event?.extendedProps?.users ?? []; for (let index = 0; index < users.length; index++) { const user = users[index]; newDiv += `<span class="user-display">${user[0]}</span>`; } newDiv += `</div>` parentElement.append(newDiv); } // var $successParent = $(info.el).closest('.success'); // if ($successParent.length > 0) { // // Create an HTML div element with your desired content // var newDiv = '<div class="custom-div">Custom Content</div>'; // Replace with your HTML content // // Append the new div to the success parent element using jQuery // $successParent.append(newDiv); // } }, }); calendar.render(); }); $('#new_unit_modal_form').submit(function(e) { var selectedValue = $('#customSelect .select-selected').attr('data-value'); // console.log('This is selected Value: ',selectedValue); $('#customSelect-error').css('display','none'); if (!selectedValue) { // If the custom select is not selected, prevent form submission e.preventDefault(); // Add red shadow or any other styling to indicate the error $('#customSelect .select-selected').addClass('error-shadow'); $('#customSelect-error').css('display','block'); // console.log('Null Found'); }else{ $('#new_unit_modal_form').submit(); // console.log('form submitted'); } // e.preventDefault(); return; }); // custom select ds-calendar // custom select function toggleSelectOptions($customSelect) { const $options = $customSelect.find(".select-options"); // Close all other select options except the current one $(".custom-select").not($customSelect).find(".select-options").slideUp(); if (!$options.is(":animated")) { $options.slideToggle(); } } // Handle click on select items // Function to close all select options function closeSelectOptions() { $(".select-options").slideUp(); $('.select-arrow').removeClass('active') } $(".select-selected, .select-arrow").on("click", function (e) { e.stopPropagation(); const $customSelect = $(this).closest(".custom-select"); const $selectOptions = $customSelect.find(".select-options"); $(this).next('.select-arrow').toggleClass('active'); // Toggle the options panel with a slide animation $selectOptions.slideToggle(); }); $('#eventModal select[name="property_id"],#openhouseModal select[name="property_id"]').on('change', async function(){ var property_id = $(this).val(); showLoading(); await $.ajax({ url: '/landlord/get_single_unit/'+property_id, type: 'get', success: function(response){ var selectElement = $('#eventModal select[name="unit_id"]'); var selectElementEdit = $('#openhouseModal select[name="unit_id"]'); // Remove existing options selectElement.empty(); selectElementEdit.empty(); selectElement.append('<option value="">Please Select Unit</option>'); // Append new options based on the received data $.each(response.units, function(index, unit) { selectElement.append('<option value="' + unit.id + '">' + unit.number + '</option>'); selectElementEdit.append('<option value="' + unit.id + '">' + unit.number + '</option>'); }); swal.close(); // console.log(response.units); }, error: function(XMLHttpRequest, textStatus, errorThrown) { swal.close() TopEndPopUp('warning',errorThrown) } }); }); $(".select-option").on("click", function () { const value = $(this).data("value"); const text = $(this).text(); const $customSelect = $(this).closest(".custom-select"); const isMultiple = $customSelect.data("multiple"); if (isMultiple) { $(this).toggleClass("selected"); const selectedOptions = $customSelect .find(".select-option.selected") .map(function () { return $(this).data("value"); }) .get(); $customSelect.find(".select-selected").text(selectedOptions.join(", ")); $customSelect.find(".select-selected").attr("data-value", selectedOptions.join(", ")); // selectValidation();//IF NULL } else { $customSelect.find(".select-selected").text(text); $customSelect.find(".select-selected").attr("data-value", value); toggleCategory(value) $('input[name="type"]').val(value); $ ('#hidden_option').val(value); closeSelectOptions(); // Close the options panel // selectValidation(); // You can customize the behavior when an option is selected here // console.log("Selected Value:", value); } }); // Close the dropdowns when clicking outside $(document).on("click", function () { closeSelectOptions(); }); // Prevent clicks inside the dropdown from closing it $(".select-options").on("click", function (e) { e.stopPropagation(); }); $(document).ready(function(){ $('#datepicker,#datepickerEdit').datepicker({ startDate: "0", format: 'yyyy-mm-dd', autoclose: true, }); $(document).on('click','#event_edit_btn',function(){ document.getElementById('event_edit_btn').disabled = true; $('#event_edit_btn').addClass('disabled'); // Enable all fields inside the form (assuming the form has an id openhouseForm) $('#openhouseModal form :input').prop('disabled', false); $('.select-selected').removeClass('disable_custom_select'); }); // $('#event_edit_btn').on('click', function() { // // Disable the button // // $('#event_edit_btn').attr('disabled', 'disabled'); // document.getElementById('event_edit_btn').disabled = true; // $('#event_edit_btn').addClass('disabled'); // // Enable all fields inside the form (assuming the form has an id openhouseForm) // $('#openhouseModal form :input').prop('disabled', false); // }); }); $(document).on('click','#event_archive_btn',async function(){ var eventId = $('#event_archive_btn').attr('data-archive'); // console.log(eventId); if (confirm('Are you sure you want to archive this event?')) { showLoading(); const data = await $.ajax({ url: '/archive-events?event_id='+eventId, method: 'GET', // dataType: 'json', }); swal.close(); if(data){ // info.event.remove(); toastr.options = { "closeButton": true, "debug": false, "newestOnTop": false, "progressBar": false, "positionClass": "toast-top-right", "preventDuplicates": false, "onclick": null, "showDuration": "300", "hideDuration": "1000", "timeOut": "5000", "extendedTimeOut": "1000", "showEasing": "swing", "hideEasing": "linear", "showMethod": "fadeIn", "hideMethod": "fadeOut" } toastr.success('Event Archived'); $('.modal').modal('hide'); }else{ toastr.options = { "closeButton": true, "debug": false, "newestOnTop": false, "progressBar": false, "positionClass": "toast-top-right", "preventDuplicates": false, "onclick": null, "showDuration": "300", "hideDuration": "1000", "timeOut": "5000", "extendedTimeOut": "1000", "showEasing": "swing", "hideEasing": "linear", "showMethod": "fadeIn", "hideMethod": "fadeOut" } toastr.error('Error Archiving Event'); } } // console.log('Clicked event ID:', eventId); }); function toggleCategory(event_type){ if(event_type == "Maintenance" || event_type == "maintenance"){ $('#category_container').removeClass('dsk-none'); $('#category_container select').prop('required', true); }else{ $('#category_container').addClass('dsk-none'); $('#category_container select').prop('required', false); } } // custom select ds-calendar
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка