diff --git a/public/assets/js/admin/manage_location/add_location.js b/public/assets/js/admin/manage_location/add_location.js index 98f2d64..8129c60 100644 --- a/public/assets/js/admin/manage_location/add_location.js +++ b/public/assets/js/admin/manage_location/add_location.js @@ -1,45 +1,3 @@ -// $(document).on("click", "#submit_location", function (e) { -// $('#store_location').validate({ -// rules: { -// location_name: { -// required: true, -// } -// }, -// messages: { -// location_name: { -// required: "Please enter the state.", -// } -// }, -// errorClass: 'error-message', -// submitHandler: function (form) { -// e.preventDefault(); -// let base_url = url_path; -// var formData = new FormData(form); -// $.ajaxSetup({ -// headers: { -// "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"), -// }, -// }); -// $.ajax({ -// url: base_url + '/insert_location', -// type: 'POST', -// data: formData, -// processData: false, -// contentType: false, -// success: function (response) { -// if (response.status == 200) { -// toastr.success('Location added successfully'); -// setTimeout(function () { -// window.location.href = base_url + "/manage_location"; -// }, 1000); -// } else { -// toastr.error("Something went wrong"); -// } -// }, -// }); -// } -// }); -// }); $(document).on("click", "#submit_location", function (e) { $('#store_location').validate({ rules: { diff --git a/public/assets/js/admin/manage_location/edit_location.js b/public/assets/js/admin/manage_location/edit_location.js index cb559e0..ef1f751 100644 --- a/public/assets/js/admin/manage_location/edit_location.js +++ b/public/assets/js/admin/manage_location/edit_location.js @@ -1,217 +1,87 @@ -// $(document).on("click", ".edit_location_value", function (e) { -// var edit_id = $(this).data('location-id'); -// var edit_country = $(this).data('location-name'); -// console.log(edit_country); -// var edit_timeInterval = $(this).data('location-time_interval'); -// console.log(edit_timeInterval); +$(document).ready(function() { + $(document).on("click", ".edit_location_value", function (e) { + e.preventDefault(); // Prevent default action -// var edit_timeHours = $(this).data('location-timehours'); -// // console.log(edit_timeHours); -// var edit_Quantity = $(this).data('location-quantity'); + var locationId = $(this).data('location-id'); + var locationName = $(this).data('location-name'); + var timeHours = $(this).data('location-timehours'); + var timeInterval = $(this).data('location-timeinterval'); + var quantity = $(this).data('location-quantity'); + + console.log('Location ID:', locationId); + console.log('Location Name:', locationName); + console.log('Time Hours:', timeHours); + console.log('Time Interval:', timeInterval); + console.log('Quantity:', quantity); + + $('#location_id').val(locationId); + $('#location-name').val(locationName); + $('#time-hours').val(timeHours); + $('#time-interval').val(timeInterval); + $('#quantity').val(quantity); + + $('#edit-location-modal').modal('show'); + }); +}); -// $('#location_id').val(edit_id); -// $('#name').val(edit_country); -// $('#timeHours').val(edit_timeHours); - -// $('#timeInterval').val(edit_timeInterval); - -// $('#timeQuantity').val(edit_Quantity); - -// $('').val() - -// }); - - - - - -// $('#edit_location').validate({ -// rules: { -// location_name: { -// required: true, -// } -// }, -// messages: { -// location_name: { -// required: "Please enter the state.", -// } -// }, -// errorClass: 'error-message', -// submitHandler: function (form) { -// var formData = new FormData(form); -// $('#update_passport_btn').text('Please wait...'); -// $('#update_passport_btn').attr('disabled', true); -// let base_url = url_path; -// $.ajax({ -// url: base_url + '/update_location', -// type: 'POST', -// data: formData, -// processData: false, -// contentType: false, -// success: function(result) { -// if (result.status === 200) { -// toastr.success('Location Updated successfully'); -// setTimeout(function() { -// window.location.href = base_url + "/manage_location"; -// }, 2000); -// } -// else if (result.status === 422 && result.error === 'Location name already exists') { -// toastr.error('Location name already exists'); -// } -// else { -// toastr.error('Something Went Wrong'); -// setTimeout(function() { -// window.location.href = base_url + "/manage_location"; -// }, 2000); -// } -// $('#update_passport_btn').attr('disabled', false); -// $('#update_passport_btn').text('Submit'); -// }, -// error: function(xhr, status, error) { -// toastr.error('Something Went Wrong'); -// $('#update_passport_btn').attr('disabled', false); -// $('#update_passport_btn').text('Submit'); -// } -// }); -// } -// }); -// $('#edit_location').validate({ -// rules: { -// location_name: { -// required: true, -// }, -// time_hours: { -// required: true, -// digits: true // Ensure time_hours is a valid number -// }, -// quantity: { -// required: true, -// digits: true // Ensure quantity is a valid number -// }, -// time_interval: { -// required: true -// } -// }, -// messages: { -// location_name: { -// required: "Please enter the location name." -// }, -// time_hours: { -// required: "Please enter time hours.", -// digits: "Please enter a valid number for time hours." -// }, -// quantity: { -// required: "Please enter quantity.", -// digits: "Please enter a valid number for quantity." -// }, -// time_interval: { -// required: "Please select a time interval." -// } -// }, -// errorClass: 'error-message', -// submitHandler: function(form) { -// var formData = new FormData(form); -// formData.append('id', $('#location-id').val()); / -// $('#update_location').text('Please wait...'); -// $('#update_location').attr('disabled', true); -// let base_url = url_path; -// $.ajax({ -// url: base_url + '/update_location', -// type: 'POST', -// data: formData, -// processData: false, -// contentType: false, -// success: function(result) { -// if (result.success) { -// toastr.success('Location updated successfully'); -// setTimeout(function() { -// window.location.href = base_url + "/manage_location"; -// }, 2000); -// } else { -// toastr.error(result.error || 'Something went wrong'); -// setTimeout(function() { -// window.location.href = base_url + "/manage_location"; -// }, 2000); -// } -// $('#update_location').attr('disabled', false); -// $('#update_location').text('Save'); -// }, -// error: function(xhr, status, error) { -// toastr.error('Something went wrong'); -// $('#update_location').attr('disabled', false); -// $('#update_location').text('Save'); -// } -// }); -// } -// }); -// $('#edit_location').validate({ -// rules: { -// location_name: { -// required: true, -// }, -// time_hours: { -// required: true, -// digits: true // Ensure time_hours is a valid number -// }, -// quantity: { -// required: true, -// digits: true // Ensure quantity is a valid number -// }, -// time_interval: { -// required: true -// } -// }, -// messages: { -// location_name: { -// required: "Please enter the location name." -// }, -// time_hours: { -// required: "Please enter time hours.", -// digits: "Please enter a valid number for time hours." -// }, -// quantity: { -// required: "Please enter quantity.", -// digits: "Please enter a valid number for quantity." -// }, -// time_interval: { -// required: "Please select a time interval." -// } -// }, -// errorClass: 'error-message', -// submitHandler: function(form) { -// var formData = new FormData(form); -// formData.append('id', $('#location_id').val()); - -// $('#update_location').text('Please wait...'); -// $('#update_location').attr('disabled', true); -// let base_url = url_path; -// $.ajax({ -// url: base_url + '/update_location', -// type: 'POST', -// data: formData, -// processData: false, -// contentType: false, -// success: function(result) { -// if (result.success) { -// toastr.success('Location updated successfully'); -// setTimeout(function() { -// window.location.href = base_url + "/manage_location"; -// }, 2000); -// } else { -// toastr.error(result.error || 'Something went wrong'); -// } -// $('#update_location').attr('disabled', false); -// $('#update_location').text('Save'); -// }, -// error: function(xhr, status, error) { -// toastr.error('Something went wrong'); -// $('#update_location').attr('disabled', false); -// $('#update_location').text('Save'); -// } -// }); -// } -// }); - +$(document).ready(function() { + // Assuming you have a mechanism to set manage_state_xid in the modal + $('#edit-location-modal').on('show.bs.modal', function(event) { + var button = $(event.relatedTarget); // Button that triggered the modal + var locationId = button.data('location-id'); // Extract info from data-* attributes + var manageStateXid = button.data('manage-state-xid'); + // If necessary, you could initiate an AJAX request here (and then do the updating in a callback). + // Update the modal's content. + var modal = $(this); + modal.find('#location_id').val(locationId); + modal.find('#manage_state_xid').val(manageStateXid); + }); + $('#edit_location').validate({ + rules: { + location_name: { required: true }, + time_hours: { required: true, digits: true }, + quantity: { required: true, digits: true }, + time_interval: { required: true } + }, + messages: { + location_name: { required: "Please enter the location name." }, + time_hours: { required: "Please enter time hours.", digits: "Please enter a valid number for time hours." }, + quantity: { required: "Please enter quantity.", digits: "Please enter a valid number for quantity." }, + time_interval: { required: "Please select a time interval." } + }, + errorClass: 'error-message', + submitHandler: function(form) { + var formData = new FormData(form); + let base_url = url_path; + $('#update_location').text('Please wait...'); + $('#update_location').attr('disabled', true); + $.ajax({ + url: base_url + '/update_location', + type: 'POST', + data: formData, + processData: false, + contentType: false, + success: function(result) { + if (result.success) { + toastr.success('Location updated successfully'); + setTimeout(function() { + window.location.href = base_url + "/manage_location"; + }, 2000); + } else { + toastr.error(result.error || 'Something went wrong'); + } + $('#update_location').attr('disabled', false); + $('#update_location').text('Save'); + }, + error: function(xhr, status, error) { + toastr.error('Something went wrong'); + $('#update_location').attr('disabled', false); + $('#update_location').text('Save'); + } + }); + } + }); +}); diff --git a/public/assets/js/admin/manage_location/main.js b/public/assets/js/admin/manage_location/main.js index 1e3c0da..c49b9b1 100644 --- a/public/assets/js/admin/manage_location/main.js +++ b/public/assets/js/admin/manage_location/main.js @@ -15,6 +15,11 @@ $('#zero-config').DataTable({ }); +$(document).ready(function() { + $(' ') + .insertBefore("#zero-config_filter label"); +}); + $(".location_table").on("change", ".active_location", function () { let base_url = url_path; var status = $(this).prop("checked") == true ? 1 : 0; @@ -68,4 +73,6 @@ $(document).on("click", ".delete_location_button", function (e) { } }, }); -}); \ No newline at end of file +}); + + diff --git a/resources/views/Admin/pages/manage_states/manage_states.blade.php b/resources/views/Admin/pages/manage_states/manage_states.blade.php index 3f8e671..49f0f9d 100644 --- a/resources/views/Admin/pages/manage_states/manage_states.blade.php +++ b/resources/views/Admin/pages/manage_states/manage_states.blade.php @@ -41,7 +41,7 @@ class="active_location" id="switch{{ $locations->id }}" value="1" {{ $locations->is_active ? 'checked' : '' }} switch="bool" /> + data-off-label=" Deactivate"> @@ -54,14 +54,14 @@