Merge pull request #457 from WDI-Ideas/sayli

Sayli
This commit is contained in:
Sayli Raut
2024-08-16 13:35:43 +05:30
committed by GitHub
4 changed files with 152 additions and 424 deletions

View File

@@ -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: {

View File

@@ -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');
}
});
}
});
});

View File

@@ -15,6 +15,11 @@ $('#zero-config').DataTable({
});
$(document).ready(function() {
$(' <button><a class="extra-btn width-max-content" data-toggle="modal" data-target="#add_location_modal" href="">Add</a></button>')
.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) {
}
},
});
});
});

View File

@@ -41,7 +41,7 @@
class="active_location" id="switch{{ $locations->id }}" value="1"
{{ $locations->is_active ? 'checked' : '' }} switch="bool" />
<label for="switch{{ $locations->id }}" data-on-label="Active"
data-off-label="Expired"></label>
data-off-label=" Deactivate"></label>
</div>
</td>
<td>
@@ -54,14 +54,14 @@
<ul>
<li>
<!-- <div class="switch-btn">
<input
type="checkbox" data-id = "{{ $locations->id }}"
class="active_location" id="switch{{ $locations->id }}" value="1"
{{ $locations->is_active ? 'checked' : '' }}
switch="bool" />
<label for="switch{{ $locations->id }}" data-on-label="Active"
data-off-label="Expired"></label>
</div> -->
<input
type="checkbox" data-id = "{{ $locations->id }}"
class="active_location" id="switch{{ $locations->id }}" value="1"
{{ $locations->is_active ? 'checked' : '' }}
switch="bool" />
<label for="switch{{ $locations->id }}" data-on-label="Active"
data-off-label="Expired"></label>
</div> -->
</li>
<li>
@@ -69,18 +69,16 @@
<a href="#"
data-toggle="modal"
data-target="#edit-location-modal"
class="edit_location_value"
data-location-id="{{ $locations->id }}"
data-location-name="{{ $locations->name }}"
data-location-timehours="{{ $locations->timeInterval->isNotEmpty() ? $locations->timeInterval->first()->time_hours : '' }}"
data-location-timeinterval="{{ $locations->timeInterval->isNotEmpty() ? $locations->timeInterval->first()->time_interval : '' }}"
data-location-quantity="{{ $locations->timeInterval->isNotEmpty() ? $locations->timeInterval->first()->quantity : '' }}">
<img src="{{ asset('public/assets/img/edit.svg') }}" />
<span>Edit</span>
</a>
<a href="#" data-toggle="modal"
data-target="#edit-location-modal" class="edit_location_value"
data-location-id="{{ $locations->id }}"
data-location-name="{{ $locations->name }}"
data-location-timehours="{{ $locations->timeInterval->isNotEmpty() ? $locations->timeInterval->first()->time_hours : '' }}"
data-location-timeinterval="{{ $locations->timeInterval->isNotEmpty() ? $locations->timeInterval->first()->time_interval : '' }}"
data-location-quantity="{{ $locations->timeInterval->isNotEmpty() ? $locations->timeInterval->first()->quantity : '' }}">
<img src="{{ asset('public/assets/img/edit.svg') }}" />
<span>Edit</span>
</a>
@@ -158,50 +156,52 @@
<div class="modal fade" id="edit-location-modal" tabindex="-1" role="dialog" aria-labelledby="editLocationModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form id="edit_location" enctype="multipart/form-data">
@csrf
<input class="form-control" name="id" type="hidden" id="location_id" value="">
<input class="form-control" name="manage_state_xid" type="hidden" id="manage_state_xid" value="">
<div class="modal-header">
<h5 class="modal-title" id="editLocationModalLabel">Edit Location</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label for="location-name">Location Name</label>
<input type="text" class="form-control" id="location-name" name="location_name">
</div>
<div class="form-group">
<label for="time-hours">Time in hours between redeeming two drinks</label>
<input type="number" class="form-control" id="time-hours" name="time_hours">
</div>
<div class="form-group">
<label for="time-interval">Maximum number of drinks</label>
<select class="form-control" id="time-interval" name="time_interval">
{{-- <option value="day">Day</option>
<div class="modal fade" id="edit-location-modal" tabindex="-1" role="dialog"
aria-labelledby="editLocationModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form id="edit_location" enctype="multipart/form-data">
@csrf
<input class="form-control" name="id" type="hidden" id="location_id" value="">
<input class="form-control" name="manage_state_xid" type="hidden" id="manage_state_xid"
value="">
<div class="modal-header">
<h5 class="modal-title" id="editLocationModalLabel">Edit Location</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label for="location-name">Location Name</label>
<input type="text" class="form-control" id="location-name" name="location_name">
</div>
<div class="form-group">
<label for="time-hours">Time in hours between redeeming two drinks</label>
<input type="number" class="form-control" id="time-hours" name="time_hours">
</div>
<div class="form-group">
<label for="time-interval">Maximum number of drinks</label>
<select class="form-control" id="time-interval" name="time_interval">
{{-- <option value="day">Day</option>
<option value="week">Week</option> --}}
<option value="month">Month</option>
</select>
</div>
<div class="form-group">
<label for="quantity">Quantity</label>
<input type="number" class="form-control" id="quantity" name="quantity">
</div>
<option value="month">Month</option>
</select>
</div>
<div class="form-group">
<label for="quantity">Quantity</label>
<input type="number" class="form-control" id="quantity" name="quantity">
</div>
</div>
<div class="modal-footer">
<button type="submit" id="update_location" class="download-btn-custom mt-4 mx-auto w-25">
<span>Save</span>
</button>
</div>
</form>
</div>
</div>
<div class="modal-footer">
<button type="submit" id="update_location" class="download-btn-custom mt-4 mx-auto w-25">
<span>Save</span>
</button>
</div>
</form>
</div>
</div>
</div>
@@ -235,111 +235,4 @@
<script src="{{ asset('public/assets/js/admin/manage_location/main.js') }}"></script>
<script src="{{ asset('public/assets/js/admin/manage_location/add_location.js') }}"></script>
<script src="{{ asset('public/assets/js/admin/manage_location/edit_location.js') }}"></script>
<script>
$(document).ready(function() {
$(' <button><a class="extra-btn width-max-content" data-toggle="modal" data-target="#add_location_modal" href="">Add</a></button>')
.insertBefore("#zero-config_filter label");
});
</script>
<script>
$(document).ready(function() {
$(document).on("click", ".edit_location_value", function (e) {
e.preventDefault(); // Prevent default action
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');
});
});
</script>
<script>
$(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');
}
});
}
});
});
</script>
@endsection