Add Buefy support for "delete w/ simple confirm" from index grid

This commit is contained in:
Lance Edgar 2019-06-10 21:58:36 -05:00
parent 3775c53df3
commit f727c87b56
6 changed files with 71 additions and 9 deletions

View file

@ -147,6 +147,12 @@ let TailboneGrid = {
this.applyFilters(params) this.applyFilters(params)
}, },
deleteObject(event) {
// we let parent component/app deal with this, in whatever way makes sense...
// TODO: should we ever provide anything besides the URL for this?
this.$emit('deleteActionClicked', event.target.href)
},
deleteResults(event) { deleteResults(event) {
// submit form if user confirms // submit form if user confirms
@ -166,3 +172,9 @@ let TailboneGrid = {
} }
} }
} }
let GridPage = {
template: '#grid-page-template',
methods: {}
}

View file

@ -145,7 +145,12 @@
% if grid.main_actions or grid.more_actions: % if grid.main_actions or grid.more_actions:
<b-table-column field="actions" label="Actions"> <b-table-column field="actions" label="Actions">
% for action in grid.main_actions: % for action in grid.main_actions:
<a :href="props.row._action_url_${action.key}"><i class="fas fa-${action.icon}"></i> <a :href="props.row._action_url_${action.key}"
% if action.click_handler:
@click.prevent="${action.click_handler}"
% endif
>
<i class="fas fa-${action.icon}"></i>
${action.label} ${action.label}
</a> </a>
&nbsp; &nbsp;
@ -224,7 +229,3 @@
} }
</script> </script>
<div id="tailbone-grid-app">
<tailbone-grid></tailbone-grid>
</div>

View file

@ -8,7 +8,7 @@
## note, the `ref` here is for buefy only ## note, the `ref` here is for buefy only
${h.form(action_url('delete', instance), ref='deleteObjectForm')} ${h.form(action_url('delete', instance), ref='deleteObjectForm')}
${h.csrf_token(request)} ${h.csrf_token(request)}
<a href="#" <a href="${action_url('delete', instance)}"
% if use_buefy: % if use_buefy:
@click.prevent="deleteObject" @click.prevent="deleteObject"
% else: % else:

View file

@ -224,9 +224,24 @@
Vue.component('tailbone-grid', TailboneGrid) Vue.component('tailbone-grid', TailboneGrid)
% if master.deletable and request.has_perm('{}.delete'.format(permission_prefix)) and master.delete_confirm == 'simple':
GridPage.methods.deleteObject = function(url) {
if (confirm("Are you sure you wish to delete this ${model_title}?")) {
let form = this.$refs.deleteObjectForm
form.action = url
form.submit()
}
}
% endif
Vue.component('grid-page', GridPage)
new Vue({ new Vue({
el: '#tailbone-grid-app' el: '#grid-page-app'
}); })
</script> </script>
</%def> </%def>
@ -235,6 +250,27 @@
% if use_buefy: % if use_buefy:
## TODO: stop using |n filter ## TODO: stop using |n filter
${grid.render_buefy(tools=capture(self.grid_tools).strip(), context_menu=capture(self.context_menu_items).strip())|n} ${grid.render_buefy(tools=capture(self.grid_tools).strip(), context_menu=capture(self.context_menu_items).strip())|n}
<script type="text/x-template" id="grid-page-template">
<div>
<tailbone-grid
% if master.deletable and request.has_perm('{}.delete'.format(permission_prefix)) and master.delete_confirm == 'simple':
@deleteActionClicked="deleteObject"
% endif
>
</tailbone-grid>
% if master.deletable and request.has_perm('{}.delete'.format(permission_prefix)) and master.delete_confirm == 'simple':
${h.form('#', ref='deleteObjectForm')}
${h.csrf_token(request)}
${h.end_form()}
% endif
</div>
</script>
<div id="grid-page-app">
<grid-page></grid-page>
</div>
${self.make_tailbone_grid_app()} ${self.make_tailbone_grid_app()}
% else: % else:

View file

@ -112,6 +112,11 @@ ${self.render_form_complete()}
<br /><br /> <br /><br />
## TODO: stop using |n filter ## TODO: stop using |n filter
${rows_grid.render_buefy(allow_save_defaults=False, tools=capture(self.render_row_grid_tools))|n} ${rows_grid.render_buefy(allow_save_defaults=False, tools=capture(self.render_row_grid_tools))|n}
<div id="tailbone-grid-app">
<tailbone-grid></tailbone-grid>
</div>
${self.make_tailbone_grid_app()} ${self.make_tailbone_grid_app()}
% else: % else:
## no buefy, so do the traditional thing ## no buefy, so do the traditional thing

View file

@ -2395,11 +2395,19 @@ class MasterView(View):
actions = [] actions = []
prefix = self.get_permission_prefix() prefix = self.get_permission_prefix()
use_buefy = self.get_use_buefy() use_buefy = self.get_use_buefy()
# Edit
if self.editable and self.request.has_perm('{}.edit'.format(prefix)): if self.editable and self.request.has_perm('{}.edit'.format(prefix)):
icon = 'edit' if use_buefy else 'pencil' icon = 'edit' if use_buefy else 'pencil'
actions.append(self.make_action('edit', icon=icon, url=self.default_edit_url)) actions.append(self.make_action('edit', icon=icon, url=self.default_edit_url))
# Delete
if self.deletable and self.request.has_perm('{}.delete'.format(prefix)): if self.deletable and self.request.has_perm('{}.delete'.format(prefix)):
actions.append(self.make_action('delete', icon='trash', url=self.default_delete_url)) kwargs = {}
if use_buefy and self.delete_confirm == 'simple':
kwargs['click_handler'] = 'deleteObject'
actions.append(self.make_action('delete', icon='trash', url=self.default_delete_url, **kwargs))
return actions return actions
def default_edit_url(self, row, i=None): def default_edit_url(self, row, i=None):