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;
|
return checkboxes;
|
||||||
}
|
}
|
||||||
|
|
||||||
getFormData(defaultValues) {
|
getFormData(defaultValues, index) {
|
||||||
let formData = '<form id="popupForm" name="popupForm" method="post" enctype="multipart/form-data"><div class="form-group">';
|
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++) {
|
for (let i = 0; i < this.editableTypes.length; i++) {
|
||||||
let inputId = this.editableTypes[i]['name'] + 'Input';
|
let inputId = this.editableTypes[i]['name'] + 'Input';
|
||||||
let inputName = this.editableTypes[i]['name'];
|
let inputName = this.editableTypes[i]['name'];
|
||||||
let inputType = this.editableTypes[i]['type'] === 'number' ? 'number' : 'text';
|
let inputType = this.editableTypes[i]['type'] === 'number' ? 'number' : 'text';
|
||||||
let value = defaultValues[this.editableTypes[i]['name']] !== undefined ? defaultValues[this.editableTypes[i]['name']] : '';
|
let value = defaultValues[this.editableTypes[i]['name']] !== undefined ? defaultValues[this.editableTypes[i]['name']] : '';
|
||||||
let icon = '';
|
|
||||||
formData += '<label for="' + inputId + '">' + this.editableTypes[i]['description'] + ' :</label>';
|
formData += '<label for="' + inputId + '">' + this.editableTypes[i]['description'] + ' :</label>';
|
||||||
if (this.editableTypes[i]['type'] === 'image') {
|
if (this.editableTypes[i]['type'] === 'image') {
|
||||||
formData += this.getImagePicker(defaultValues['id']);
|
formData += this.getImagePicker(defaultValues['id'], index);
|
||||||
} else if (this.editableTypes[i]['type'] === 'checkboxes') {
|
} else if (this.editableTypes[i]['type'] === 'checkboxes') {
|
||||||
formData += this.getCategoryCheckboxes(defaultValues['id']);
|
formData += this.getCategoryCheckboxes(defaultValues['id']);
|
||||||
} else {
|
} else {
|
||||||
|
@ -138,20 +137,26 @@ class ListManager {
|
||||||
return formData;
|
return formData;
|
||||||
}
|
}
|
||||||
|
|
||||||
getImagePicker(id) {
|
getImagePicker(id, index) {
|
||||||
|
let imageSrc = $(this.displayedData[index].find("img")[0]).attr('src');
|
||||||
return (
|
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' +
|
'<div class="custom-file">\n' +
|
||||||
'<input ' +
|
'<input ' +
|
||||||
'type="file" ' +
|
'type="file" ' +
|
||||||
'class="custom-file-input" ' +
|
'class="custom-file-input" ' +
|
||||||
'id="fileInput"' +
|
'id="fileInput"' +
|
||||||
'accept="image/jpeg"' +
|
'accept="image/jpeg"' +
|
||||||
|
'onchange="listManager.updatePickerImagePreview(this, \'image_' + id + '\')"' +
|
||||||
'>\n' +
|
'>\n' +
|
||||||
'<label class="custom-file-label" for="customFile">Choose file</label>\n' +
|
'<label class="custom-file-label" for="customFile">Choose file</label>\n' +
|
||||||
'</div>');
|
'</div>');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updatePickerImagePreview(picker, previewId) {
|
||||||
|
$("#" + previewId).attr('src', window.URL.createObjectURL(picker.files[0]));
|
||||||
|
}
|
||||||
|
|
||||||
getFormValues(form) {
|
getFormValues(form) {
|
||||||
let values = [];
|
let values = [];
|
||||||
for (let i = 0; i < this.editableTypes.length; i++) {
|
for (let i = 0; i < this.editableTypes.length; i++) {
|
||||||
|
@ -232,7 +237,7 @@ class ListManager {
|
||||||
defaultValues = this.currentData[index];
|
defaultValues = this.currentData[index];
|
||||||
title = "Modifier l'entrée";
|
title = "Modifier l'entrée";
|
||||||
}
|
}
|
||||||
let formData = this.getFormData(defaultValues);
|
let formData = this.getFormData(defaultValues, index);
|
||||||
let thisInstance = this;
|
let thisInstance = this;
|
||||||
$.confirm({
|
$.confirm({
|
||||||
title: title,
|
title: title,
|
||||||
|
|
Loading…
Reference in a new issue