Skip to content

Commit fa31bce

Browse files
author
pini-girit
committed
CLOUDINARY-127: Working on media-library implementation (IN PROGRESS)
1 parent 64b8625 commit fa31bce

File tree

2 files changed

+36
-26
lines changed

2 files changed

+36
-26
lines changed

app/design/adminhtml/default/default/template/cloudinary/catalog/product/gallery.phtml

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,29 @@
3737
</tr>
3838
</thead>
3939
<tbody id="media_gallery_content_list">
40-
<?php foreach ($this->getImages() as $image): ?>
41-
<tr>
42-
<td class="cell-image" id="cloudinary_preview_container_<?php echo $image->getValueId(); ?>">
43-
</td>
44-
<td class="cell-label"><?php echo $image->getLabel(); ?></td>
40+
<tr v-for="image in images">
41+
<td class="cell-image" v-bind:id="'cloudinary_preview_container_' + image.value_id"></td>
42+
<td class="cell-label">{{ image.label }}</td>
4543
<td>
4644
<input type="text"
47-
id="cloudinary_input_<?php echo $image->getValueId(); ?>"
48-
name="cloudinary_free[<?php echo $image->getValueId(); ?>]"
49-
value="<?php echo $image->getFreeTransformation(); ?>"
50-
style="width: 80%;" />
45+
v-bind:id="'cloudinary_input_' + image.value_id"
46+
v-bind:name="'cloudinary_free[' + image.value_id + ']'"
47+
v-bind:value="image.free_transformation"
48+
style="width: 80%;" />
5149
<input type="hidden"
52-
id="cloudinary_input_updated_<?php echo $image->getValueId(); ?>"
53-
name="cloudinary_free_updated[<?php echo $image->getValueId(); ?>]"
54-
value="" />
50+
v-bind:id="'cloudinary_input_updated_' + image.value_id"
51+
v-bind:name="'cloudinary_free_updated[' + image.value_id + ']'"
52+
v-bind:value="''" />
5553
</td>
5654
<td>
57-
<button id="cloudinary_preview_button_<?php echo $image->getValueId(); ?>"
58-
class="cloudinary_preview_button"
59-
type="button"
60-
data-file="<?php echo $image->getFile(); ?>"
61-
data-id="<?php echo $image->getValueId(); ?>">
55+
<button class="cloudinary_preview_button" type="button"
56+
v-bind:id="'cloudinary_preview_button_' + image.value_id"
57+
v-bind:data-id="image.value_id"
58+
v-bind:data-file="image.file">
6259
Preview
6360
</button>
6461
</td>
6562
</tr>
66-
<?php endforeach; ?>
6763
</tbody>
6864
</table>
6965
</div>
@@ -217,26 +213,34 @@
217213
var self = this,
218214
input = $('cloudinary_input_' + id);
219215

216+
220217
input.on('change', function() { self.setPreviewActiveState(id, true); });
221218
input.on('keydown', function() { self.setPreviewActiveState(id, true); });
222219
input.on('paste', function() { self.setPreviewActiveState(id, true); });
223220
input.on('input', function() { self.setPreviewActiveState(id, true); });
224221
},
225-
};
226222

227-
$$('.cloudinary_preview_button').each(function(button) {
228-
window.cloudinary.updatePreview(button.getAttribute('data-id'));
229-
window.cloudinary.addPreviewButtonListener(button);
230-
window.cloudinary.addTextChangeListener(button.getAttribute('data-id'));
231-
});
223+
init: function() {
224+
$$('.cloudinary_preview_button').each(function(button) {
225+
window.cloudinary.updatePreview(button.getAttribute('data-id'));
226+
window.cloudinary.addPreviewButtonListener(button);
227+
window.cloudinary.addTextChangeListener(button.getAttribute('data-id'));
228+
});
229+
}
230+
};
232231

233232
window.cloudinary_transformation_tab_images = <?php echo $jsonData; ?>;
234-
235233
window.cloudinaryTransformationTabApp = new Vue({
236234
el: '#cloudinary_transformation_tab',
237235
data: {
238236
images: window.cloudinary_transformation_tab_images
237+
},
238+
mounted: function () {
239+
window.cloudinary.init();
240+
},
241+
updated: function () {
242+
window.cloudinary.init();
239243
}
240-
})
244+
});
241245

242246
</script>

js/cloudinary/cloudinary-media-library.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
file.media_type = "image";
133133
file.label = asset.label = context.alt || context.caption || asset.public_id || "";
134134
if (widget.options.addTmpExtension && !/\.tmp$/.test(file.file)) {
135+
file.orig_file = file.file;
135136
file.file = file.file + '.tmp';
136137
}
137138
}
@@ -141,6 +142,11 @@
141142
file.cloudinary_asset = asset;
142143
//console.log(file);
143144
widget.successTrigger(file);
145+
146+
file.value_id = Math.random().toString(36).substr(2, 16);
147+
file.file = file.orig_file;
148+
window.window.cloudinary_transformation_tab_images.push(file);
149+
144150
} else {
145151
alert($.mage.__('An error occured during ' + asset.resource_type + ' insert!'));
146152
console.error(file);

0 commit comments

Comments
 (0)