home/autoph/public_html/connectv1/dist/js/customer/ltms.js 0000644 00000012630 15027733406 0017744 0 ustar 00 var upload_image_name = [];
var myDropzone;
function photoDropzoneListener() {
Dropzone.autoDiscover = false; // Disable auto-discovery
// Initialize Dropzone
myDropzone = new Dropzone("#upload-ltms-photo", {
url: "api/upload/upload_image_ltms.php", // Ensure the URL is correct
autoProcessQueue: false, // Disable auto-upload
acceptedFiles: '.png,.jpg,.jpeg',
maxFilesize: 40, // Max file size in MB
maxFiles: 10, // Max number of files
clickable: true,
addRemoveLinks: true,
dictCancelUpload: 'Cancel',
parallelUploads: 10, // Allow multiple files to be uploaded in parallel
renameFile: function (file) {
var extension = file.name.substr((file.name.lastIndexOf('.') + 1)).toLowerCase();
let newName = uniqImgId() + '.' + extension;
upload_image_name.push(newName);
return newName;
},
init: function () {
this.on("maxfilesexceeded", function (file) {
alert('Only 10 images allowed.');
this.removeFile(file);
return;
});
this.on("error", function (file, response) {
alert(response || 'Error uploading file.');
});
this.on("success", function (file, response) {
sweetAlertSimple('success', 'Nice...',"Successfully uploaded!");
console.log("Success:", response); // Log the success response
});
this.on('sending', function (file, xhr, formData) {
formData.append("cuid", customer_record_id);
formData.append("did", $('#did').val());
});
this.on('complete', function (file) {
// Check if all files are uploaded
// sweetAlertSimple('success', 'Nice...',"Successfully uploaded!");
if (myDropzone.getQueuedFiles().length === 0 && myDropzone.getUploadingFiles().length === 0) {
$('#loading-indicator').hide();
setTimeout(() => {
// Refresh the page or update the UI
window.location.reload();
}, "1000");
}
});
}
});
// Handle form submit button click
$('#ltms-submit').on('click', function (e) {
e.preventDefault(); // Prevent default form submission
if (myDropzone.getQueuedFiles().length > 0) {
$('#loading-indicator').show(); // Show loading indicator
myDropzone.processQueue(); // Upload files if there are any
} else {
alert('No files to upload.');
}
});
}
$("#btn-upload-ltms").on('click',function(){
$("#ltms-container").show();
$(this).hide();
$("#customer-ltms-image-data").hide();
});
$("#ltms-submit-cancel").on('click',function(){
// window.location.reload();
$("#ltms-container").hide();
$("#btn-upload-ltms").show();
$("#customer-ltms-image-data").show();
});
function uniqImgId() {
var id = Math.round(new Date().getTime() + (Math.random() * 100));
return id;
}
function removeImage(id) {
// alert(id);
Swal.fire({
icon: 'warning',
html: 'Do you want to remove this image?',
showDenyButton: false,
showCancelButton: true,
confirmButtonText: `Confirm`,
denyButtonText: `Don't Confirm`,
}).then((result) => {
if (result.isConfirmed) {
// toastr.remove();
$.ajax({
url: "api/upload/upload_image_ltms.php",
method: "POST",
data: {
apiKey: '9434631886897744',
id: id
},
cache: false,
beforeSend: function() {
sweetAlertSimple('info', 'Oops...', 'Removing image...');
},
success: function(data) {
// fetchVehicleInfo(vehicle_record_id, customer_record_id)
// readVehicleImage(vehicle_record_id);
readLtmsUpload();
sweetAlertSimple('success', 'Oops...', 'Image remove successfully.');
// setTimeout(() => {
// // Refresh the page or update the UI
// window.location.reload();
// }, "1000");
}
})
} else if (result.isDenied) {
// Swal.fire('', 'Changes are not saved', 'info')
}
})
}
function readLtmsUpload() {
$.ajax({
url: "api/upload/upload_image_ltms.php",
type: "POST",
dataType: 'json',
data: {
apiKey: '1164288154587287',
cuid:customer_record_id
},
beforeSend: function() {},
success: function(result) {
// result.total
$('#customer-ltms-image-data').html('');
$('#customer-ltms-image-data').append(result.vehicle_image);
}
});
}
readLtmsUpload();
photoDropzoneListener();