Misc. fixes for model-crud, e.g. redirect to parent after deleting row

This commit is contained in:
Lance Edgar 2020-03-29 16:34:12 -05:00
parent d634143e84
commit 62d3c5fc05

View file

@ -6,7 +6,7 @@
<router-link :to="getModelPathPrefix() + '/'">{{ getModelIndexTitle() }}</router-link>
</li>
<li v-if="isRow">
<router-link :to="getModelPathPrefix() + '/' + record._parent_uuid">{{ renderParentHeaderLabel(record) }}</router-link>
<router-link :to="getParentUrl()">{{ renderParentHeaderLabel(record) }}</router-link>
<!-- &nbsp; {{ renderParentHeaderLabel(record) }} -->
</li>
<li v-if="mode == 'creating'">
@ -78,7 +78,6 @@
<slot name="quick-entry"></slot>
<div v-if="hasRows && mode == 'viewing'">
<br />
<div v-if="rowsTitle && shouldAllowCreateRow()"
style="display: flex;">
@ -366,6 +365,12 @@ export default {
return `${this.getModelPathPrefix()}/`
},
getParentUrl() {
if (this.isRow) {
return `${this.getModelPathPrefix()}/${this.record._parent_uuid}`
}
},
getViewURL() {
if (this.isRow) {
return `${this.getRowPathPrefix()}/${this.record.uuid}`
@ -394,7 +399,7 @@ export default {
return '/api/' + this.getModelSlug()
},
getApiObjectUrl() {
getApiObjectUrlBase() {
if (this.apiObjectUrl) {
return this.apiObjectUrl
}
@ -403,6 +408,14 @@ export default {
return url.slice(0, -1) + '/'
},
getApiObjectUrl(uuid) {
let url = this.getApiObjectUrlBase()
if (uuid) {
url += uuid
}
return url
},
getApiRowsUrl() {
return this.apiRowsUrl
},
@ -492,7 +505,7 @@ export default {
},
fetch(uuid) {
this.$http.get(this.getApiObjectUrl() + uuid).then(response => {
this.$http.get(this.getApiObjectUrl(uuid)).then(response => {
this.record = response.data.data
this.$emit('refresh', this.record)
if (this.hasRows) {
@ -605,27 +618,32 @@ export default {
if (this.mode == 'creating') {
url = this.getApiIndexUrl()
} else {
url = this.getApiObjectUrl() + this.record.uuid
url = this.getApiObjectUrl(this.record.uuid)
}
this.$emit('save', url)
},
confirmDelete() {
let modelTitle = this.getModelTitle()
this.$buefy.dialog.confirm({
title: "Delete Work Order",
message: "Are you sure you wish to delete this Work Order?",
title: `Delete ${modelTitle}`,
message: `Are you sure you wish to delete this ${modelTitle}?`,
hasIcon: true,
type: 'is-danger',
confirmText: "Delete Work Order",
confirmText: `Delete ${modelTitle}`,
cancelText: "Whoops, nevermind",
onConfirm: this.deleteObject,
})
},
deleteObject() {
let url = this.getApiObjectUrl() + this.record.uuid
let url = this.getApiObjectUrl(this.record.uuid)
this.$http.delete(url).then(response => {
this.$router.push(this.getIndexURL())
if (this.isRow) {
this.$router.push(this.getParentUrl())
} else {
this.$router.push(this.getIndexURL())
}
}, response => {
this.$buefy.toast.open({
message: "Failed to delete the record!",