Move "delete results" logic for master grid

should be easier to customize this way..?  previous way seemed to be broken
This commit is contained in:
Lance Edgar 2020-01-06 07:46:10 -06:00
parent 03c8d3409a
commit 4c5b01f287
2 changed files with 37 additions and 16 deletions

View file

@ -244,16 +244,6 @@ let TailboneGrid = {
this.$emit('deleteActionClicked', event.target.href) this.$emit('deleteActionClicked', event.target.href)
}, },
deleteResults(event) {
// submit form if user confirms
// TODO: how/where to get/show "plural model title" here?
// if (confirm("You are about to delete " + this.total + " ${grid.model_title_plural}.\n\nAre you sure?")) {
if (confirm("You are about to delete " + this.total.toLocaleString('en') + " objects.\n\nAre you sure?")) {
event.target.form.submit()
}
},
checkedRowUUIDs() { checkedRowUUIDs() {
let uuids = [] let uuids = []
for (let row of this.$data.checkedRows) { for (let row of this.$data.checkedRows) {

View file

@ -233,21 +233,24 @@
## delete search results ## delete search results
% if master.bulk_deletable and request.has_perm('{}.bulk_delete'.format(permission_prefix)): % if master.bulk_deletable and request.has_perm('{}.bulk_delete'.format(permission_prefix)):
${h.form(url('{}.bulk_delete'.format(route_prefix)), name='bulk-delete', class_='control')}
${h.csrf_token(request)}
% if use_buefy: % if use_buefy:
${h.form(url('{}.bulk_delete'.format(route_prefix)), ref='delete_results_form', class_='control')}
${h.csrf_token(request)}
<b-button type="is-danger" <b-button type="is-danger"
:disabled="! total" :disabled="deleteResultsDisabled"
:title="total ? null : 'There are no results to delete'" :title="total ? null : 'There are no results to delete'"
@click="deleteResults" @click="deleteResultsSubmit()"
icon-pack="fas" icon-pack="fas"
icon-left="trash"> icon-left="trash">
Delete Results {{ deleteResultsText }}
</b-button> </b-button>
% else:
<button type="button">Delete Results</button>
% endif
${h.end_form()} ${h.end_form()}
% else:
${h.form(url('{}.bulk_delete'.format(route_prefix)), name='bulk-delete', class_='control')}
${h.csrf_token(request)}
<button type="button">Delete Results</button>
${h.end_form()}
% endif
% endif % endif
</%def> </%def>
@ -396,6 +399,34 @@
} }
% endif % endif
% if master.bulk_deletable and master.has_perm('bulk_delete'):
TailboneGridData.deleteResultsSubmitting = false
TailboneGridData.deleteResultsText = "Delete Results"
TailboneGrid.computed.deleteResultsDisabled = function() {
if (this.deleteResultsSubmitting) {
return true
}
if (!this.total) {
return true
}
return false
}
TailboneGrid.methods.deleteResultsSubmit = function() {
// TODO: show "plural model title" here?
if (!confirm("You are about to delete " + this.total.toLocaleString('en') + " objects.\n\nAre you sure?")) {
return
}
this.deleteResultsSubmitting = true
this.deleteResultsText = "Working, please wait..."
this.$refs.delete_results_form.submit()
}
% endif
% if master.mergeable and master.has_perm('merge'): % if master.mergeable and master.has_perm('merge'):
TailboneGridData.mergeFormButtonText = "Merge 2 ${model_title_plural}" TailboneGridData.mergeFormButtonText = "Merge 2 ${model_title_plural}"