2
0
mirror of https://github.com/frappe/books.git synced 2024-11-14 09:24:04 +00:00
- pass arguments in an object
- add primaryAction prop
This commit is contained in:
Faris Ansari 2018-07-15 17:09:40 +05:30
parent 46a44976ef
commit 3a2ca34ac0
3 changed files with 32 additions and 13 deletions

View File

@ -10,10 +10,11 @@
</button> </button>
</div> </div>
<div class="modal-body modal-height"> <div class="modal-body modal-height">
<component :is="component" v-bind="props" v-on="events"/> <component ref="modalComponent" :is="component" v-bind="props" v-on="events"/>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<f-button secondary @click="closeModal">{{ _('Close') }}</f-button> <!-- <f-button secondary @click="closeModal">{{ _('Close') }}</f-button> -->
<f-button primary v-if="primaryAction" @click="onPrimaryAction">{{ primaryAction.label }}</f-button>
</div> </div>
</div> </div>
</div> </div>
@ -26,6 +27,10 @@ export default {
type: String, type: String,
default: "Modal Title" default: "Modal Title"
}, },
primaryAction: {
type: Object,
default: null
},
component: { component: {
type: Object type: Object
}, },
@ -39,6 +44,9 @@ export default {
methods: { methods: {
closeModal() { closeModal() {
this.$emit('close-modal'); this.$emit('close-modal');
},
onPrimaryAction() {
this.primaryAction.handler(this.$refs.modalComponent);
} }
} }
}; };

View File

@ -3,7 +3,7 @@
<modal <modal
:key="modal.id" :key="modal.id"
v-for="modal in modals" v-for="modal in modals"
v-bind="modal" v-bind="modal.modalProps"
@close-modal="onModalClose(modal.id)" @close-modal="onModalClose(modal.id)"
></modal> ></modal>
<div class="modal-backdrop show" v-show="modals.length"></div> <div class="modal-backdrop show" v-show="modals.length"></div>
@ -35,13 +35,15 @@ export default {
}); });
}, },
methods: { methods: {
add(component, props, events) { add({ component, props = {}, events = {}, modalProps = {} }) {
this.currentId++; this.currentId++;
this.modals.push({ this.modals.push({
id: this.currentId, id: this.currentId,
component, modalProps: Object.assign({}, modalProps, {
props, component,
events props,
events
})
}); });
return this.currentId; return this.currentId;
}, },
@ -55,7 +57,7 @@ export default {
onModalClose(id) { onModalClose(id) {
if (id) { if (id) {
const modal = this.modals.find(modal => modal.id === id); const modal = this.modals.find(modal => modal.id === id);
modal.props.onClose && modal.props.onClose(); modal.modalProps.events.onClose && modal.modalProps.events.onClose();
} }
this.removeModal(id); this.removeModal(id);
} }

View File

@ -1,3 +1,4 @@
import frappe from 'frappejs';
import Form from '../components/Form/Form'; import Form from '../components/Form/Form';
export default function installFormModal(Vue) { export default function installFormModal(Vue) {
@ -7,11 +8,19 @@ export default function installFormModal(Vue) {
$formModal() { $formModal() {
const open = (doc, options = {}) => { const open = (doc, options = {}) => {
const { defaultValues = null, onClose = null } = options; const { defaultValues = null, onClose = null } = options;
this.$modal.show(Form, { this.$modal.show({
doctype: doc.doctype, component: Form,
name: doc.name, props: {
defaultValues, doctype: doc.doctype,
onClose name: doc.name,
defaultValues,
},
events: {
onClose
},
modalProps: {
title: frappe._('Form Modal')
}
}); });
} }