Skip to content

Commit

Permalink
BO: Add confirmation modal in translation page
Browse files Browse the repository at this point in the history
  • Loading branch information
nihco2 authored and maximebiloe committed Jul 10, 2017
1 parent 9b116d6 commit 1023ada
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,16 @@
this.destHref = $(e.currentTarget).attr('href');
}
});
EventBus.$on('isEdited', (val) => {
console.log(val);
});
window.onbeforeunload = () => {
if (!this.leave && this.edited) {
if (!this.destHref && this.isEdited() && !this.leave) {
return true;
}
if (!this.leave && this.isEdited()) {
setTimeout(() => {
window.stop();
}, 500);
EventBus.$emit('showModal');
return null;
}
};
},
Expand All @@ -102,12 +103,16 @@
this.$store.currentDomain = '';
},
onSave() {

this.$refs.principal.saveTranslations();
EventBus.$emit('hideModal');
},
onLeave() {
this.leave = true;
window.location.href = this.destHref;
},
isEdited() {
return this.$refs.principal.edited();
},
},
data: () => ({
destHref: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@
@pageChanged="onPageChanged"
/>
</div>
<form class="col-xs-12" :action="saveAction" method="post" @submit.prevent="saveTranslations">
<form class="col-xs-12"
method="post"
:action="saveAction"
:isEdited="isEdited"
@submit.prevent="saveTranslations"
>
<div class="row">
<div class="col-xs-12 m-b-2">
<PSButton :primary="true" type="submit" class="pull-xs-right">
Expand All @@ -64,7 +69,7 @@
:translated="translation"
:label="translation.default"
:extraInfo="getDomain(translation.tree_domain)"
@isEdited="edited"
@editedAction="isEdited"
>
</TranslationInput>
<PSButton :primary="true" type="submit" class="pull-xs-right m-t-3">
Expand Down Expand Up @@ -149,6 +154,13 @@
},
},
methods: {
isEdited(input) {
if (this.editedInput.indexOf(input.id) === -1 && input.value) {
this.editedInput.push(input.id);
} else if (this.editedInput.indexOf(input.id) >= 0 && !input.value) {
this.editedInput.splice(this.editedInput.indexOf(input.id), 1);
}
},
onPageChanged(pageIndex) {
this.$store.dispatch('updatePageIndex', pageIndex);
this.fetch();
Expand Down Expand Up @@ -194,12 +206,15 @@

return this.modifiedTranslations;
},
edited() {
return this.editedInput.length > 0;
},
},
data: () => ({
translations: [],
originalTranslations: [],
modifiedTranslations: [],
edited: false,
editedInput: [],
}),
mounted() {
EventBus.$on('resetTranslation', (el) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

<script>
import PSButton from 'app/widgets/ps-button';
import { EventBus } from 'app/utils/event-bus';

export default {
name: 'TranslationInput',
Expand Down Expand Up @@ -65,7 +64,10 @@
modifiedTranslated.database = modifiedValue;
modifiedTranslated.edited = modifiedValue;
this.$emit('input', modifiedTranslated);
this.edited = modifiedValue !== '';
this.$emit('editedAction', {
value: modifiedValue !== '',
id: this.id,
});
},
},
isMissing() {
Expand All @@ -78,17 +80,6 @@
EventBus.$emit('resetTranslation', this.translated);
},
},
watch: {
edited(val) {
EventBus.$emit('isEdited', {
value: val,
id: this.id,
});
},
},
data: () => ({
edited: false,
}),
components: {
PSButton,
},
Expand Down
6 changes: 6 additions & 0 deletions admin-dev/themes/new-theme/js/app/widgets/ps-modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ export default {
EventBus.$on('showModal', () => {
this.showModal();
});
EventBus.$on('hideModal', () => {
this.hideModal();
});
},
methods: {
showModal() {
$(this.$el).modal('show');
},
hideModal() {
$(this.$el).modal('hide');
},
onSave() {
this.$emit('save');
},
Expand Down

0 comments on commit 1023ada

Please sign in to comment.