Skip to content

Commit

Permalink
Fixing the browse media modal
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Jul 31, 2017
1 parent 18b6eed commit 99bf61d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
16 changes: 11 additions & 5 deletions resources/assets/js/MediaBrowser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,27 @@
data() {
return {
modalId: '',
url: ''
}
},
mounted() {
this.modalId = 'browse-modal-'+Math.random().toString(16).slice(2);
this.url = this.value;
window.eventHub.$on(events.MEDIA_MODAL_BROWSER_SELECT, (url) => {
this.url = url;
window.eventHub.$on(events.MEDIA_MODAL_BROWSER_SELECT, (data) => {
if (this.modalId === data.modalId) {
this.url = data.url;
}
});
},
methods: {
openBrowserModal() {
window.eventHub.$emit(events.MEDIA_MODAL_BROWSER_OPEN);
window.eventHub.$emit(events.MEDIA_MODAL_BROWSER_OPEN, {
modalId: this.modalId
});
}
}
}
Expand All @@ -81,12 +87,12 @@
:placeholder="placeholder" :disabled="disabled" :readonly="readonly" :required="required">

<span class="input-group-btn">
<button class="btn btn-default" type="button" @click.prevent="openBrowserModal">
<button class="btn btn-default" type="button" @click.prevent="openBrowserModal()">
<slot>{{ lang.get('actions.browse') }}</slot>
</button>
</span>
</div>

<browse-media-modal></browse-media-modal>
<browse-media-modal :id="modalId"></browse-media-modal>
</div>
</template>
34 changes: 23 additions & 11 deletions resources/assets/js/Modals/BrowseMediaModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
export default {
name: 'media-browser-modal',
props: ['id'],
mixins: [translator],
components: {
Expand All @@ -21,18 +23,24 @@
},
mounted() {
this.modal = $('div#media-browser-modal');
const that = this;
this.modal.on('hidden.bs.modal', () => {
this.modalOpened = false;
});
$(() => {
that.modal = $(that.$el);
window.eventHub.$on(events.MEDIA_MODAL_BROWSER_OPEN, () => {
this.openModal();
});
that.modal.on('hidden.bs.modal', () => {
that.modalOpened = false;
});
window.eventHub.$on(events.MEDIA_ITEM_SELECTED, (media) => {
this.selected = (media && media.isFile()) ? media : null;
window.eventHub.$on(events.MEDIA_MODAL_BROWSER_OPEN, (data) => {
if (that.id === data.modalId) {
that.openModal();
}
});
window.eventHub.$on(events.MEDIA_ITEM_SELECTED, (media) => {
that.selected = (media && media.isFile()) ? media : null;
});
});
},
Expand All @@ -58,14 +66,18 @@
selectMedia() {
this.closeModal();
window.eventHub.$emit(events.MEDIA_MODAL_BROWSER_SELECT, this.selected.url);
window.eventHub.$emit(events.MEDIA_MODAL_BROWSER_SELECT, {
url: this.selected.url,
modalId: this.id
});
}
}
}
</script>

<template>
<div id="media-browser-modal" class="modal fade">
<div class="media-browser-modal modal fade">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
Expand Down

0 comments on commit 99bf61d

Please sign in to comment.