2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 15:50:56 +00:00

Link Modal

- Reset modal state when it is hidden
- Reset link value if new doc was not created
- Set link value if new doc was created
This commit is contained in:
Faris Ansari 2018-07-09 15:48:09 +05:30
parent a8416dc4fe
commit 42320a39bf
2 changed files with 28 additions and 1 deletions

View File

@ -78,9 +78,19 @@ export default {
}); });
newDoc.on('afterInsert', (data) => { newDoc.on('afterInsert', (data) => {
// if new doc was created
// then set the name of the doc in input
this.handleChange(newDoc.name); this.handleChange(newDoc.name);
this.$modal.hide(); this.$modal.hide();
}); });
this.$modal.observable().on('modal.hide', () => {
// if new doc was not created
// then reset the input value
if (this.value === '__newItem') {
this.handleChange('');
}
})
} }
}) })
} }

View File

@ -14,6 +14,10 @@ export default {
hide() { hide() {
Bus.trigger('hideModal'); Bus.trigger('hideModal');
},
observable() {
return Bus;
} }
} }
@ -22,9 +26,21 @@ export default {
return { return {
registered: false, registered: false,
modalVisible: false, modalVisible: false,
modalOptions: {} modalOptions: {},
modalListeners: {}
} }
}, },
watch: {
modalVisible(value) {
if (value === true) {
Bus.trigger('modal.show');
} else {
Bus.trigger('modal.hide');
}
}
},
created: function () { created: function () {
if (this.registered) return; if (this.registered) return;
@ -35,6 +51,7 @@ export default {
Bus.on('hideModal', () => { Bus.on('hideModal', () => {
this.modalVisible = false; this.modalVisible = false;
this.modalOptions = {};
}); });
this.registered = true; this.registered = true;