2
0
mirror of https://github.com/frappe/books.git synced 2025-02-02 12:08:27 +00:00

Add link modal

This commit is contained in:
Suraj Shetty 2018-06-25 13:41:37 +05:30
parent 999cb583f3
commit 67d24bf128
7 changed files with 75 additions and 29 deletions

View File

@ -25,9 +25,8 @@ module.exports = {
'generator-star-spacing': 'off', 'generator-star-spacing': 'off',
// allow debugger during development // allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'semi': 'on', 'semi': 2,
'indent': 'off', 'indent': ["error", 2],
// 'indent': ["error", 4],
'space-before-function-paren': 'off' 'space-before-function-paren': 'off'
} }
} }

View File

@ -10,7 +10,6 @@ module.exports = {
"keywordFields": [ "keywordFields": [
"fullName" "fullName"
], ],
"titleField": "fullName",
"fields": [ "fields": [
{ {
"fieldname": "fullName", "fieldname": "fullName",

View File

@ -68,10 +68,8 @@ export default {
await this.doc.update(); await this.doc.update();
} }
if (this.doc.name !== this.$route.params.name) { this.$emit('save', this.doc);
this.$router.push(`/edit/${this.doctype}/${this.doc.name}`);
return;
}
} catch (e) { } catch (e) {
console.error(e); console.error(e);
return; return;
@ -95,7 +93,4 @@ export default {
}; };
</script> </script>
<style> <style>
.frappe-form {
height: calc(100vh - 50px);
}
</style> </style>

View File

@ -4,7 +4,7 @@
<frappe-list :doctype="doctype" :filters="filters" :key="doctype" /> <frappe-list :doctype="doctype" :filters="filters" :key="doctype" />
</div> </div>
<div class="col-8"> <div class="col-8">
<frappe-form v-if="name" :key="doctype + name" :doctype="doctype" :name="name" /> <frappe-form v-if="name" :key="doctype + name" :doctype="doctype" :name="name" @save="onSave" />
</div> </div>
</div> </div>
</template> </template>
@ -17,6 +17,13 @@ export default {
components: { components: {
FrappeList: List, FrappeList: List,
FrappeForm: Form FrappeForm: Form
},
methods: {
onSave(doc) {
if (doc.name !== this.$route.params.name) {
this.$router.push(`/edit/${doc.doctype}/${doc.name}`);
}
}
} }
} }
</script> </script>

View File

@ -1,8 +1,7 @@
<template> <template>
<div> <div>
<div :class="['modal fade', modalClasses]" :style="{display: show ? 'block' : ''}" id="frappe-modal" <div :class="['modal fade', modalClasses]" :style="{display: show ? 'block' : ''}" id="frappe-modal"
tabindex="-1" role="dialog" aria-labelledby="frappe-modal-label" aria-hidden="true" tabindex="-1" role="dialog" aria-labelledby="frappe-modal-label" aria-hidden="true">
>
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
@ -11,11 +10,11 @@
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
</div> </div>
<div class="modal-body"> <div class="modal-body modal-height">
<component :is="body" /> <component :is="bodyComponent" v-bind="bodyProps"/>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<component :is="footer" /> <component :is="footerComponent" v-bind="footerProps"/>
<button type="button" class="btn btn-secondary" @click="closeModal">Close</button> <button type="button" class="btn btn-secondary" @click="closeModal">Close</button>
</div> </div>
</div> </div>
@ -30,28 +29,42 @@ export default {
show: Boolean, show: Boolean,
title: { title: {
type: String, type: String,
default: 'Modal Title' default: "Modal Title"
}, },
body: { bodyComponent: {
type: Object, type: Object,
default: null default: null
}, },
footer: { bodyProps: {
type: Object, type: Object,
default: null default: null
} },
footerComponent: {
type: Object,
default: null
},
footerProps: {
type: Object,
default: null
},
}, },
computed: { computed: {
modalClasses() { modalClasses() {
return { return {
show: this.show show: this.show
} };
} }
}, },
methods: { methods: {
closeModal() { closeModal() {
this.$emit('closeModal'); this.$modal.hide();
} }
} }
} };
</script> </script>
<style scoped>
.modal-height {
max-height: 80vh;
overflow: auto;
}
</style>

View File

@ -21,7 +21,8 @@ export default {
this.awesomplete.list = await this.getList(e.target.value); this.awesomplete.list = await this.getList(e.target.value);
}, },
'awesomplete-select': e => { 'awesomplete-select': e => {
this.handleChange(e.text.value); const value = e.text.value;
this.handleChange(value);
} }
} }
}, },
@ -44,9 +45,14 @@ export default {
return li; return li;
} }
}); });
input.addEventListener('awesomplete-select', (e) => { console.log(e);this.$emit('awesomplete-select', e)} )
this.bindEvents();
},
bindEvents() {
}, },
sort() { sort() {
//
} }
} }
}; };
@ -59,7 +65,7 @@ export default {
padding: 0; padding: 0;
border: none; border: none;
&> ul { & > ul {
padding: $dropdown-padding-y 0; padding: $dropdown-padding-y 0;
} }

View File

@ -2,6 +2,8 @@
import frappe from 'frappejs'; import frappe from 'frappejs';
import feather from 'feather-icons'; import feather from 'feather-icons';
import Autocomplete from './Autocomplete'; import Autocomplete from './Autocomplete';
import Form from '../Form/Form';
import { _ } from 'frappejs/utils';
export default { export default {
extends: Autocomplete, extends: Autocomplete,
@ -42,6 +44,31 @@ export default {
} }
return a.value > b.value; return a.value > b.value;
} }
},
bindEvents() {
const input = this.$refs.input;
input.addEventListener('awesomplete-select', async (e) => {
// new item action
if (e.text && e.text.value === '__newItem') {
e.preventDefault();
const newDoc = await frappe.getNewDoc(this.getTarget());
this.$modal.show({
title: _('New {0}', _(newDoc.doctype)),
bodyComponent: Form,
bodyProps: {
doctype: newDoc.doctype,
name: newDoc.name,
},
});
newDoc.on('afterInsert', (data) => {
this.handleChange(newDoc.name);
this.$modal.hide();
});
}
})
} }
} }
} }