diff --git a/app/Http/Controllers/Admin/ManageNotificationsController.php b/app/Http/Controllers/Admin/ManageNotificationsController.php index 7751806..b811608 100644 --- a/app/Http/Controllers/Admin/ManageNotificationsController.php +++ b/app/Http/Controllers/Admin/ManageNotificationsController.php @@ -34,6 +34,8 @@ class ManageNotificationsController extends Controller ->latest() ->take(12) ->get(); + // return $notifications; + } else if ($activeQuery == 3) { // for restaurant $notifications = NotificationDetails::with('Notification') ->where('is_active', 1) @@ -44,8 +46,6 @@ class ManageNotificationsController extends Controller ->latest() ->take(12) ->get(); - - // return $notifications; } else { $notificationsOfType3 = NotificationDetails::with('Notification') ->where('is_active', 1) @@ -68,8 +68,8 @@ class ManageNotificationsController extends Controller ->get(); $notifications = $notificationsOfType3->merge($notificationsOfType4); - $scheduledNotifications = NotificationDetails::where('is_schedule', 1)->where('is_active', 1)->orderByDesc('id')->get(); } + $scheduledNotifications = NotificationDetails::where('is_schedule', 1)->where('is_active', 1)->orderByDesc('id')->get(); return view('Admin.pages.manage_notification.manage_notification', compact('notifications', 'scheduledNotifications')); } @@ -287,7 +287,6 @@ class ManageNotificationsController extends Controller $notification->state_ids = json_encode($request->state_ids); $notification->save(); return jsonResponseWithSuccessMessage(__('success.save_data_scheduled')); - } catch (Exception $e) { DB::rollBack(); Log::error("Notification update Failed " . $e->getMessage()); @@ -300,5 +299,4 @@ class ManageNotificationsController extends Controller $data = NotificationDetails::find($id)->delete(); return redirect()->back()->with('success', ''); } - } diff --git a/public/assets/js/admin/manage_notification/add.js b/public/assets/js/admin/manage_notification/add.js new file mode 100644 index 0000000..e21265f --- /dev/null +++ b/public/assets/js/admin/manage_notification/add.js @@ -0,0 +1,206 @@ +$(document).ready(function() { + // Custom validator for checking state checkboxes + $.validator.addMethod('stateRequired', function(value, element) { + let selectedUserType = $('input[name="user_type"]:checked').val(); + if (selectedUserType) { + let dropdownId = `dropdown-${selectedUserType}`; + return $(`#${dropdownId} .state-checkbox:checked`).length > 0; + } + return true; + }, 'Please select at least one state.'); + + // Validate the form + $('#send_notification_form').validate({ + ignore: [], + debug: false, + rules: { + title: { + required: true + }, + description: { + required: true + }, + image: { + required: true + }, + user_type: { + required: true + }, + schedule_radio1: { + required: true + }, + schedule_date: { + required: function() { + return $('#push_schedule_radi02').is(':checked'); + } + }, + 'states[]': { + stateRequired: true + } + }, + messages: { + title: { + required: 'Please enter this field' + }, + description: { + required: 'Please enter this field' + }, + image: { + required: 'Please upload an image file' + }, + user_type: { + required: 'Please select at least one category' + }, + schedule_radio1: { + required: 'Please select a delivery schedule' + }, + schedule_date: { + required: 'Please select a specific time' + }, + 'states[]': { + stateRequired: 'Please select at least one state.' + } + }, + errorClass: 'error-message', + errorPlacement: function(error, element) { + if (element.attr("name") == "user_type") { + error.appendTo("#user_type_error").addClass('error-message'); + } else if (element.attr("name") == "schedule_radio1") { + error.insertAfter("#push_schedule_radi02").addClass('error-message'); + } else if (element.attr("name") == "states[]") { + error.insertAfter(`#dropdown-${$('input[name="user_type"]:checked').val()}`) + error.appendTo("#user_type_error").addClass('error-message'); + } else { + error.insertAfter(element).addClass('error-message'); + } + }, + submitHandler: function(form) { + var formData = new FormData(form); + let base_url = url_path; + $.ajaxSetup({ + headers: { + 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') + } + }); + $.ajax({ + url: base_url + '/insert_notification', + type: 'POST', + data: formData, + beforeSend: function() { + $('#store_notification_btn').html('Please wait...'); + $('#store_notification_btn').attr('disabled', true); + }, + processData: false, + contentType: false, + success: function(result) { + if (result.status_code == 200) { + toastr.success(result.message); + setTimeout(function() { + window.location.href = base_url + + "/manage-notification"; + }, 2000); + } else if (result.status_code == 422) { + // Display validation errors using toastr + $.each(result.errors, function(key, value) { + toastr.error(value); + setTimeout(function() { + window.location.href = base_url + + "/manage-notification"; + }, 2000); + }); + } else { + toastr.error('Something Went Wrong'); + setTimeout(function() { + window.location.href = base_url + + "/manage-notification"; + }, 2000); + } + $('#store_notification_btn').attr('disabled', false); + $('#store_notification_btn').text('Submit'); + }, + }); + } + }); + + // Hide date and time input by default + $('.checkbox-btsss').hide(); + + // Show/hide date and time input based on radio button selection + $('#push_schedule_radi01').click(function() { + $('.checkbox-btsss').hide(); + $('input[name="schedule_date"]').val(''); // Clear date and time input + }); + + $('#push_schedule_radi02').click(function() { + $('.checkbox-btsss').show(); + }); + +}); + + + +document.addEventListener('DOMContentLoaded', function() { + function handleUserTypeChange() { + var dropdowns = [ + document.getElementById('dropdown-1'), + document.getElementById('dropdown-2'), + document.getElementById('dropdown-3') + ]; + + dropdowns.forEach(function(dropdown, index) { + if (index + 1 == this.value) { + dropdown.style.display = 'block'; + toggleCheckboxes(dropdown, false); + } else { + dropdown.style.display = 'none'; + toggleCheckboxes(dropdown, true); + } + }, this); + } + + function toggleCheckboxes(dropdown, disable) { + var checkboxes = dropdown.querySelectorAll('.form-check-input'); + for (var i = 0; i < checkboxes.length; i++) { + checkboxes[i].disabled = disable; + } + } + + var userTypeRadios = document.getElementsByName('user_type'); + for (var i = 0; i < userTypeRadios.length; i++) { + userTypeRadios[i].addEventListener('change', handleUserTypeChange); + } + + var checkedRadio = document.querySelector('input[name="user_type"]:checked'); + if (checkedRadio) { + handleUserTypeChange.call(checkedRadio); + } + + function handleSelectAllChange() { + var dropdown = this.closest('div[id^="dropdown-"]'); + var checkboxes = dropdown.querySelectorAll('.state-checkbox'); + for (var i = 0; i < checkboxes.length; i++) { + checkboxes[i].checked = this.checked; + } + } + + var selectAllCheckboxes = document.querySelectorAll('.select-all-checkbox'); + for (var i = 0; i < selectAllCheckboxes.length; i++) { + selectAllCheckboxes[i].addEventListener('change', handleSelectAllChange); + } +}); + + +function previewImage(event) { + var input = event.target; + var reader = new FileReader(); + + reader.onload = function() { + var preview = document.getElementById('preview'); + preview.src = reader.result; + preview.style.display = 'block'; + }; + + if (input.files && input.files[0]) { + reader.readAsDataURL(input.files[0]); + } +} diff --git a/public/assets/js/admin/manage_notification/edit.js b/public/assets/js/admin/manage_notification/edit.js new file mode 100644 index 0000000..4d741a2 --- /dev/null +++ b/public/assets/js/admin/manage_notification/edit.js @@ -0,0 +1,139 @@ +$(document).ready(function () { + $('#editNotificationForm').validate({ + ignore: [], + debug: false, + rules: { + type: { + required: true + }, + description: { + required: true + }, + delivery_schedule: { + required: true, + } + }, + messages: { + type: { + required: 'Please enter the notification title' + }, + description: { + required: 'Please enter the description' + }, + delivery_schedule: { + required: 'Please select a delivery schedule', + } + }, + errorClass: 'error-message', + submitHandler: function (form) { + var formData = new FormData(form); + + $('#update_notification').text('Please wait...'); + $('#update_notification').attr('disabled', true); + let base_url = url_path; + + + $.ajaxSetup({ + headers: { + 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') + } + }); + + $.ajax({ + + url: base_url + '/manage_update_notifications/', + type: 'POST', + data: formData, + processData: false, + contentType: false, + success: function (result) { + if (result.status_code == 200) { + toastr.success('Notification Updated Successfully'); + setTimeout(function () { + window.location.href = + "{{ route('manage.notification') }}"; + }, 2000); + } else { + toastr.error('Something Went Wrong'); + setTimeout(function () { + window.location.href = + "{{ route('manage.notification') }}"; + }, 2000); + } + $('#update_notification').attr('disabled', false); + $('#update_notification').text('Submit'); + }, + error: function (xhr) { + toastr.error('An error occurred: ' + xhr.responseText); + $('#update_notification').attr('disabled', false); + $('#update_notification').text('Submit'); + } + }); + } + }); +}); + + +$(document).ready(function () { + $('input[name="user_type"]').change(function () { + var selectedValue = $(this).val(); + + $('.dropdown-container').hide(); + + // Disable all checkboxes + $('.dropdown-container input[type="checkbox"]').prop('disabled', true); + + // Enable and show the checkboxes for the selected radio button + $('#dropdown-' + selectedValue + '-edit').show(); + $('#dropdown-' + selectedValue + '-edit input[type="checkbox"]').prop('disabled', false); + }); + + // Trigger the change event on page load to set the initial state + $('input[name="user_type"]:checked').trigger('change'); + + // Select All functionality + $('.select-all-checkbox').change(function () { + var groupNumber = $(this).data('group'); + var isChecked = $(this).is(':checked'); + $('.state-group-' + groupNumber + '-checkbox').prop('checked', isChecked); + }); + + // Check if all checkboxes are checked when loading the form + $('.select-all-checkbox').each(function () { + var groupNumber = $(this).data('group'); + var allChecked = $('.state-group-' + groupNumber + '-checkbox').length === $( + '.state-group-' + groupNumber + '-checkbox:checked').length; + $(this).prop('checked', allChecked); + }); + + // Update "Select All" checkbox when any state checkbox is changed + $('.state-checkbox').change(function () { + var groupNumber = $(this).closest('.dropdown-container').find('.select-all-checkbox').data( + 'group'); + var allChecked = $('.state-group-' + groupNumber + '-checkbox').length === $( + '.state-group-' + groupNumber + '-checkbox:checked').length; + $('#select-all-' + groupNumber + '-edit').prop('checked', allChecked); + }); +}); + + +const imageInputEdit = document.getElementById('imageInputNormal'); +const imagePreviewEdit = document.getElementById('imageInputPreviewNormal'); + +imageInputEdit.addEventListener('change', function () { + const file = this.files[0]; + if (file) { + const reader = new FileReader(); + reader.onload = function (event) { + const img = document.createElement('img'); + img.src = event.target.result; + img.style.maxWidth = '60px'; + img.style.maxHeight = '60px'; + imagePreviewEdit.innerHTML = ''; + imagePreviewEdit.appendChild(img); + }; + reader.readAsDataURL(file); + } else { + imagePreviewEdit.innerHTML = ''; + } +}); diff --git a/public/assets/js/admin/manage_notification/main.js b/public/assets/js/admin/manage_notification/main.js new file mode 100644 index 0000000..590fd55 --- /dev/null +++ b/public/assets/js/admin/manage_notification/main.js @@ -0,0 +1,88 @@ +$(document).ready(function () { + $('#zero-config').DataTable({ + "dom": "<'dt--top-section'<'row'<'col-12 col-sm-6 d-flex justify-content-sm-start justify-content-center'l><'col-12 col-sm-6 d-flex justify-content-sm-end justify-content-center mt-sm-0 mt-3'f>>>" + + "<'table-responsive'tr>" + + "<'dt--bottom-section d-sm-flex justify-content-sm-between text-center'<'dt--pages-count mb-sm-0 mb-3'i><'dt--pagination'p>>", + "oLanguage": { + "oPaginate": { + "sPrevious": '', + "sNext": '' + }, + "sInfo": "Showing page _PAGE_ of _PAGES_", + "sSearch": '', + "sSearchPlaceholder": "Search...", + "sLengthMenu": "Results : _MENU_", + }, + "stripeClasses": [], + "lengthMenu": [7, 10, 20, 50], + "pageLength": 10 + }); + + $('#zero-config-scheduled').DataTable({ + "dom": "<'dt--top-section'<'row'<'col-12 col-sm-6 d-flex justify-content-sm-start justify-content-center'l><'col-12 col-sm-6 d-flex justify-content-sm-end justify-content-center mt-sm-0 mt-3'f>>>" + + "<'table-responsive'tr>" + + "<'dt--bottom-section d-sm-flex justify-content-sm-between text-center'<'dt--pages-count mb-sm-0 mb-3'i><'dt--pagination'p>>", + "oLanguage": { + "oPaginate": { + "sPrevious": '', + "sNext": '' + }, + "sInfo": "Showing page _PAGE_ of _PAGES_", + "sSearch": '', + "sSearchPlaceholder": "Search...", + "sLengthMenu": "Results : _MENU_", + }, + "stripeClasses": [], + "lengthMenu": [7, 10, 20, 50], + "pageLength": 10 + }); +}); + + + +function toggleDropdown(event) { + event.stopPropagation(); + const dropdownMenu = event.currentTarget.nextElementSibling; + const isVisible = dropdownMenu.style.display === 'block'; + document.querySelectorAll('.dropdown-menu').forEach(menu => menu.style.display = 'none'); + dropdownMenu.style.display = isVisible ? 'none' : 'block'; +} + +document.addEventListener('click', () => { + document.querySelectorAll('.dropdown-menu').forEach(menu => menu.style.display = 'none'); +}); + +document.querySelectorAll('.dropdown-menu').forEach(menu => { + menu.addEventListener('click', (event) => { + event.stopPropagation(); + }); +}); + +$(document).ready(function() { + $('.admin_delete_btn').on('click', function() { + var id = $(this).data('id'); + $('#sub_admin_delete').val(id); + }); + + + let base_url = url_path; + + + $('.admin_delete').on('click', function() { + var id = $('#sub_admin_delete').val(); + $.ajax({ + url: base_url + '/manage_delete_notifications/' + id, + + type: 'POST', + data: { + _token: '{{ csrf_token() }}' + }, + success: function(result) { + location.reload(); + }, + error: function(xhr) { + alert('An error occurred: ' + xhr.responseText); + } + }); + }); +}); diff --git a/resources/views/Admin/pages/manage_notification/manage_notification.blade.php b/resources/views/Admin/pages/manage_notification/manage_notification.blade.php index 2195163..7ad0a27 100644 --- a/resources/views/Admin/pages/manage_notification/manage_notification.blade.php +++ b/resources/views/Admin/pages/manage_notification/manage_notification.blade.php @@ -209,70 +209,8 @@ @section('section_script') - - - + - - - @endsection diff --git a/resources/views/Admin/pages/manage_notification/manage_notification_edit.blade.php b/resources/views/Admin/pages/manage_notification/manage_notification_edit.blade.php index 4a69c0a..4657e41 100644 --- a/resources/views/Admin/pages/manage_notification/manage_notification_edit.blade.php +++ b/resources/views/Admin/pages/manage_notification/manage_notification_edit.blade.php @@ -210,146 +210,5 @@ @endsection @section('section_script') - - - + @endsection diff --git a/resources/views/Admin/pages/manage_notification/manage_notifications_add.blade.php b/resources/views/Admin/pages/manage_notification/manage_notifications_add.blade.php index ce9b4fd..32e4118 100644 --- a/resources/views/Admin/pages/manage_notification/manage_notifications_add.blade.php +++ b/resources/views/Admin/pages/manage_notification/manage_notifications_add.blade.php @@ -189,212 +189,5 @@ @endsection @section('section_script') - - - - + @endsection