Correctly update images on selection
This commit is contained in:
parent
517d4cdf4a
commit
d774ddb154
1 changed files with 11 additions and 6 deletions
|
@ -114,17 +114,16 @@ class ListManager {
|
|||
return checkboxes;
|
||||
}
|
||||
|
||||
getFormData(defaultValues) {
|
||||
getFormData(defaultValues, index) {
|
||||
let formData = '<form id="popupForm" name="popupForm" method="post" enctype="multipart/form-data"><div class="form-group">';
|
||||
for (let i = 0; i < this.editableTypes.length; i++) {
|
||||
let inputId = this.editableTypes[i]['name'] + 'Input';
|
||||
let inputName = this.editableTypes[i]['name'];
|
||||
let inputType = this.editableTypes[i]['type'] === 'number' ? 'number' : 'text';
|
||||
let value = defaultValues[this.editableTypes[i]['name']] !== undefined ? defaultValues[this.editableTypes[i]['name']] : '';
|
||||
let icon = '';
|
||||
formData += '<label for="' + inputId + '">' + this.editableTypes[i]['description'] + ' :</label>';
|
||||
if (this.editableTypes[i]['type'] === 'image') {
|
||||
formData += this.getImagePicker(defaultValues['id']);
|
||||
formData += this.getImagePicker(defaultValues['id'], index);
|
||||
} else if (this.editableTypes[i]['type'] === 'checkboxes') {
|
||||
formData += this.getCategoryCheckboxes(defaultValues['id']);
|
||||
} else {
|
||||
|
@ -138,20 +137,26 @@ class ListManager {
|
|||
return formData;
|
||||
}
|
||||
|
||||
getImagePicker(id) {
|
||||
getImagePicker(id, index) {
|
||||
let imageSrc = $(this.displayedData[index].find("img")[0]).attr('src');
|
||||
return (
|
||||
'<img style="width: 50px; height: 50px" src="../uploaded_images/' + id + '.jpg" id="image_' + id + '"/>' +
|
||||
'<img style="width: 50px; height: 50px" src="' + imageSrc + '" id="image_' + id + '"/>' +
|
||||
'<div class="custom-file">\n' +
|
||||
'<input ' +
|
||||
'type="file" ' +
|
||||
'class="custom-file-input" ' +
|
||||
'id="fileInput"' +
|
||||
'accept="image/jpeg"' +
|
||||
'onchange="listManager.updatePickerImagePreview(this, \'image_' + id + '\')"' +
|
||||
'>\n' +
|
||||
'<label class="custom-file-label" for="customFile">Choose file</label>\n' +
|
||||
'</div>');
|
||||
}
|
||||
|
||||
updatePickerImagePreview(picker, previewId) {
|
||||
$("#" + previewId).attr('src', window.URL.createObjectURL(picker.files[0]));
|
||||
}
|
||||
|
||||
getFormValues(form) {
|
||||
let values = [];
|
||||
for (let i = 0; i < this.editableTypes.length; i++) {
|
||||
|
@ -232,7 +237,7 @@ class ListManager {
|
|||
defaultValues = this.currentData[index];
|
||||
title = "Modifier l'entrée";
|
||||
}
|
||||
let formData = this.getFormData(defaultValues);
|
||||
let formData = this.getFormData(defaultValues, index);
|
||||
let thisInstance = this;
|
||||
$.confirm({
|
||||
title: title,
|
||||
|
|
Loading…
Reference in a new issue