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