diff --git a/tailbone/static/js/tailbone.buefy.grid.js b/tailbone/static/js/tailbone.buefy.grid.js index 17da854d..45f6581d 100644 --- a/tailbone/static/js/tailbone.buefy.grid.js +++ b/tailbone/static/js/tailbone.buefy.grid.js @@ -244,16 +244,6 @@ let TailboneGrid = { 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() { let uuids = [] for (let row of this.$data.checkedRows) { diff --git a/tailbone/templates/master/index.mako b/tailbone/templates/master/index.mako index 6889ac44..cd785bad 100644 --- a/tailbone/templates/master/index.mako +++ b/tailbone/templates/master/index.mako @@ -233,21 +233,24 @@ ## delete search results % 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: + ${h.form(url('{}.bulk_delete'.format(route_prefix)), ref='delete_results_form', class_='control')} + ${h.csrf_token(request)} - Delete Results + {{ deleteResultsText }} + ${h.end_form()} % else: + ${h.form(url('{}.bulk_delete'.format(route_prefix)), name='bulk-delete', class_='control')} + ${h.csrf_token(request)} + ${h.end_form()} % endif - ${h.end_form()} % endif @@ -396,6 +399,34 @@ } % 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'): TailboneGridData.mergeFormButtonText = "Merge 2 ${model_title_plural}"