Misc. improvements for "delete" support in model-crud
This commit is contained in:
parent
f68db3c97c
commit
bc148f910a
|
@ -36,18 +36,18 @@
|
||||||
|
|
||||||
<div v-if="showButtons"
|
<div v-if="showButtons"
|
||||||
class="buttons">
|
class="buttons">
|
||||||
<b-button type="is-primary"
|
<b-button :type="getSaveButtonType()"
|
||||||
:icon-left="saveButtonIcon"
|
:icon-left="getSaveButtonIcon()"
|
||||||
:disabled="saveDisabled"
|
:disabled="saveDisabled"
|
||||||
@click="save()">
|
@click="save()">
|
||||||
{{ saveButtonText }}
|
{{ getSaveButtonText() }}
|
||||||
</b-button>
|
</b-button>
|
||||||
<b-button v-if="mode == 'creating'"
|
<b-button v-if="mode == 'creating'"
|
||||||
tag="router-link"
|
tag="router-link"
|
||||||
:to="getModelPathPrefix() + '/'">
|
:to="getModelPathPrefix() + '/'">
|
||||||
Cancel
|
Cancel
|
||||||
</b-button>
|
</b-button>
|
||||||
<b-button v-if="mode == 'editing'"
|
<b-button v-if="mode == 'editing' || mode == 'deleting'"
|
||||||
tag="router-link"
|
tag="router-link"
|
||||||
:to="getViewURL()">
|
:to="getViewURL()">
|
||||||
Cancel
|
Cancel
|
||||||
|
@ -188,11 +188,11 @@ export default {
|
||||||
},
|
},
|
||||||
saveButtonText: {
|
saveButtonText: {
|
||||||
type: String,
|
type: String,
|
||||||
default: "Save Data",
|
default: null,
|
||||||
},
|
},
|
||||||
saveButtonIcon: {
|
saveButtonIcon: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'save',
|
default: null,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
data: function() {
|
data: function() {
|
||||||
|
@ -214,6 +214,9 @@ export default {
|
||||||
if (this.mode == 'editing') {
|
if (this.mode == 'editing') {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
if (this.mode == 'deleting') {
|
||||||
|
return true
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -226,7 +229,6 @@ export default {
|
||||||
this.$buefy.toast.open({
|
this.$buefy.toast.open({
|
||||||
message: "You do not have permission to access that page.",
|
message: "You do not have permission to access that page.",
|
||||||
type: 'is-danger',
|
type: 'is-danger',
|
||||||
position: 'is-bottom',
|
|
||||||
})
|
})
|
||||||
this.$router.push(this.getModelPathPrefix() + '/')
|
this.$router.push(this.getModelPathPrefix() + '/')
|
||||||
}
|
}
|
||||||
|
@ -261,7 +263,6 @@ export default {
|
||||||
// this.$buefy.toast.open({
|
// this.$buefy.toast.open({
|
||||||
// message: "You do not have permission to access that page.",
|
// message: "You do not have permission to access that page.",
|
||||||
// type: 'is-danger',
|
// type: 'is-danger',
|
||||||
// position: 'is-bottom',
|
|
||||||
// })
|
// })
|
||||||
// this.$router.push(this.getModelPathPrefix() + '/')
|
// this.$router.push(this.getModelPathPrefix() + '/')
|
||||||
// return
|
// return
|
||||||
|
@ -324,6 +325,10 @@ export default {
|
||||||
return '/' + this.getModelSlug() + '/rows'
|
return '/' + this.getModelSlug() + '/rows'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getIndexURL() {
|
||||||
|
return `${this.getModelPathPrefix()}/`
|
||||||
|
},
|
||||||
|
|
||||||
getViewURL() {
|
getViewURL() {
|
||||||
if (this.isRow) {
|
if (this.isRow) {
|
||||||
return `${this.getRowPathPrefix()}/${this.record.uuid}`
|
return `${this.getRowPathPrefix()}/${this.record.uuid}`
|
||||||
|
@ -372,6 +377,7 @@ export default {
|
||||||
return this.getModelSlug()
|
return this.getModelSlug()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// TODO: should use this.$hasPerm()
|
||||||
hasPerm(perm) {
|
hasPerm(perm) {
|
||||||
|
|
||||||
// if user is root then assume permission
|
// if user is root then assume permission
|
||||||
|
@ -418,6 +424,36 @@ export default {
|
||||||
return row._str
|
return row._str
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getSaveButtonIcon() {
|
||||||
|
if (this.saveButtonIcon) {
|
||||||
|
return this.saveButtonIcon
|
||||||
|
}
|
||||||
|
if (this.mode == 'deleting') {
|
||||||
|
return 'trash'
|
||||||
|
}
|
||||||
|
return 'save'
|
||||||
|
},
|
||||||
|
|
||||||
|
getSaveButtonText() {
|
||||||
|
if (this.saveButtonText) {
|
||||||
|
return this.saveButtonText
|
||||||
|
}
|
||||||
|
if (this.mode == 'deleting') {
|
||||||
|
return "Delete This Forever!"
|
||||||
|
}
|
||||||
|
if (this.mode == 'creating') {
|
||||||
|
return `Create ${this.getModelTitle()}`
|
||||||
|
}
|
||||||
|
return "Save Data"
|
||||||
|
},
|
||||||
|
|
||||||
|
getSaveButtonType() {
|
||||||
|
if (this.mode == 'deleting') {
|
||||||
|
return 'is-danger'
|
||||||
|
}
|
||||||
|
return 'is-primary'
|
||||||
|
},
|
||||||
|
|
||||||
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
|
||||||
|
@ -430,14 +466,12 @@ export default {
|
||||||
this.$buefy.toast.open({
|
this.$buefy.toast.open({
|
||||||
message: "You do not have permission to access that page.",
|
message: "You do not have permission to access that page.",
|
||||||
type: 'is-danger',
|
type: 'is-danger',
|
||||||
position: 'is-bottom',
|
|
||||||
})
|
})
|
||||||
this.$router.push(this.getModelPathPrefix() + '/')
|
this.$router.push(this.getModelPathPrefix() + '/')
|
||||||
} else {
|
} else {
|
||||||
this.$buefy.toast.open({
|
this.$buefy.toast.open({
|
||||||
message: "Failed to fetch page data!",
|
message: "Failed to fetch page data!",
|
||||||
type: 'is-danger',
|
type: 'is-danger',
|
||||||
position: 'is-bottom',
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -505,7 +539,7 @@ export default {
|
||||||
if (!this.allowDelete) {
|
if (!this.allowDelete) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (this.mode == 'creating' || this.mode == 'deleting') {
|
if (this.mode != 'viewing') {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (!this.hasModelPerm('delete')) {
|
if (!this.hasModelPerm('delete')) {
|
||||||
|
@ -515,12 +549,43 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
save() {
|
save() {
|
||||||
let url = this.getApiIndexUrl()
|
if (this.mode == 'deleting') {
|
||||||
if (this.mode != 'creating') {
|
this.confirmDelete()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let url
|
||||||
|
if (this.mode == 'creating') {
|
||||||
|
url = this.getApiIndexUrl()
|
||||||
|
} else {
|
||||||
url = this.getApiObjectUrl() + this.record.uuid
|
url = this.getApiObjectUrl() + this.record.uuid
|
||||||
}
|
}
|
||||||
this.$emit('save', url)
|
this.$emit('save', url)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
confirmDelete() {
|
||||||
|
this.$buefy.dialog.confirm({
|
||||||
|
title: "Delete Work Order",
|
||||||
|
message: "Are you sure you wish to delete this Work Order?",
|
||||||
|
hasIcon: true,
|
||||||
|
type: 'is-danger',
|
||||||
|
confirmText: "Delete Work Order",
|
||||||
|
cancelText: "Whoops, nevermind",
|
||||||
|
onConfirm: this.deleteObject,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
deleteObject() {
|
||||||
|
let url = this.getApiObjectUrl() + this.record.uuid
|
||||||
|
this.$http.delete(url).then(response => {
|
||||||
|
this.$router.push(this.getIndexURL())
|
||||||
|
}, response => {
|
||||||
|
this.$buefy.toast.open({
|
||||||
|
message: "Failed to delete the record!",
|
||||||
|
type: 'is-danger',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue