Browse Source

Correctly update images on selection

keplyx 4 years ago
parent
commit
d774ddb154
1 changed files with 11 additions and 6 deletions
  1. 11
    6
      assets/js/listManager.js

+ 11
- 6
assets/js/listManager.js View File

114
         return checkboxes;
114
         return checkboxes;
115
     }
115
     }
116
 
116
 
117
-    getFormData(defaultValues) {
117
+    getFormData(defaultValues, index) {
118
         let formData = '<form id="popupForm" name="popupForm" method="post" enctype="multipart/form-data"><div class="form-group">';
118
         let formData = '<form id="popupForm" name="popupForm" method="post" enctype="multipart/form-data"><div class="form-group">';
119
         for (let i = 0; i < this.editableTypes.length; i++) {
119
         for (let i = 0; i < this.editableTypes.length; i++) {
120
             let inputId = this.editableTypes[i]['name'] + 'Input';
120
             let inputId = this.editableTypes[i]['name'] + 'Input';
121
             let inputName = this.editableTypes[i]['name'];
121
             let inputName = this.editableTypes[i]['name'];
122
             let inputType = this.editableTypes[i]['type'] === 'number' ? 'number' : 'text';
122
             let inputType = this.editableTypes[i]['type'] === 'number' ? 'number' : 'text';
123
             let value = defaultValues[this.editableTypes[i]['name']] !== undefined ? defaultValues[this.editableTypes[i]['name']] : '';
123
             let value = defaultValues[this.editableTypes[i]['name']] !== undefined ? defaultValues[this.editableTypes[i]['name']] : '';
124
-            let icon = '';
125
             formData += '<label for="' + inputId + '">' + this.editableTypes[i]['description'] + ' :</label>';
124
             formData += '<label for="' + inputId + '">' + this.editableTypes[i]['description'] + ' :</label>';
126
             if (this.editableTypes[i]['type'] === 'image') {
125
             if (this.editableTypes[i]['type'] === 'image') {
127
-                formData += this.getImagePicker(defaultValues['id']);
126
+                formData += this.getImagePicker(defaultValues['id'], index);
128
             } else if (this.editableTypes[i]['type'] === 'checkboxes') {
127
             } else if (this.editableTypes[i]['type'] === 'checkboxes') {
129
                 formData += this.getCategoryCheckboxes(defaultValues['id']);
128
                 formData += this.getCategoryCheckboxes(defaultValues['id']);
130
             } else {
129
             } else {
138
         return formData;
137
         return formData;
139
     }
138
     }
140
 
139
 
141
-    getImagePicker(id) {
140
+    getImagePicker(id, index) {
141
+        let imageSrc = $(this.displayedData[index].find("img")[0]).attr('src');
142
         return (
142
         return (
143
-            '<img style="width: 50px; height: 50px" src="../uploaded_images/' + id + '.jpg" id="image_' + id + '"/>' +
143
+            '<img style="width: 50px; height: 50px" src="' + imageSrc + '" id="image_' + id + '"/>' +
144
             '<div class="custom-file">\n' +
144
             '<div class="custom-file">\n' +
145
             '<input ' +
145
             '<input ' +
146
             'type="file" ' +
146
             'type="file" ' +
147
             'class="custom-file-input" ' +
147
             'class="custom-file-input" ' +
148
             'id="fileInput"' +
148
             'id="fileInput"' +
149
             'accept="image/jpeg"' +
149
             'accept="image/jpeg"' +
150
+            'onchange="listManager.updatePickerImagePreview(this, \'image_' + id + '\')"' +
150
             '>\n' +
151
             '>\n' +
151
             '<label class="custom-file-label" for="customFile">Choose file</label>\n' +
152
             '<label class="custom-file-label" for="customFile">Choose file</label>\n' +
152
             '</div>');
153
             '</div>');
153
     }
154
     }
154
 
155
 
156
+    updatePickerImagePreview(picker, previewId) {
157
+        $("#" + previewId).attr('src', window.URL.createObjectURL(picker.files[0]));
158
+    }
159
+
155
     getFormValues(form) {
160
     getFormValues(form) {
156
         let values = [];
161
         let values = [];
157
         for (let i = 0; i < this.editableTypes.length; i++) {
162
         for (let i = 0; i < this.editableTypes.length; i++) {
232
             defaultValues = this.currentData[index];
237
             defaultValues = this.currentData[index];
233
             title = "Modifier l'entrée";
238
             title = "Modifier l'entrée";
234
         }
239
         }
235
-        let formData = this.getFormData(defaultValues);
240
+        let formData = this.getFormData(defaultValues, index);
236
         let thisInstance = this;
241
         let thisInstance = this;
237
         $.confirm({
242
         $.confirm({
238
             title: title,
243
             title: title,

Loading…
Cancel
Save