Add Vue.js support for "enable / disable selected" grid feature
This commit is contained in:
parent
847136b69c
commit
ebc22d845a
|
@ -93,6 +93,13 @@ Vue.component('grid-filter', GridFilter)
|
||||||
let TailboneGrid = {
|
let TailboneGrid = {
|
||||||
template: '#tailbone-grid-template',
|
template: '#tailbone-grid-template',
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
// note, can use this with v-model for hidden 'uuids' fields
|
||||||
|
selected_uuids: function() {
|
||||||
|
return this.checkedRowUUIDs().join(',')
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
getRowClass(row, index) {
|
getRowClass(row, index) {
|
||||||
|
@ -232,8 +239,8 @@ let TailboneGrid = {
|
||||||
},
|
},
|
||||||
|
|
||||||
checkedRowUUIDs() {
|
checkedRowUUIDs() {
|
||||||
var uuids = [];
|
let uuids = []
|
||||||
for (var row of this.$data.checkedRows) {
|
for (let row of this.$data.checkedRows) {
|
||||||
uuids.push(row.uuid)
|
uuids.push(row.uuid)
|
||||||
}
|
}
|
||||||
return uuids
|
return uuids
|
||||||
|
|
|
@ -171,19 +171,42 @@
|
||||||
% endif
|
% endif
|
||||||
|
|
||||||
## enable / disable selected objects
|
## enable / disable selected objects
|
||||||
% if master.supports_set_enabled_toggle and request.has_perm('{}.enable_disable_set'.format(permission_prefix)):
|
% if master.supports_set_enabled_toggle and master.has_perm('enable_disable_set'):
|
||||||
|
|
||||||
|
% if use_buefy:
|
||||||
|
${h.form(url('{}.enable_set'.format(route_prefix)), class_='control', ref='enable_selected_form')}
|
||||||
|
${h.csrf_token(request)}
|
||||||
|
${h.hidden('uuids', v_model='selected_uuids')}
|
||||||
|
<b-button :disabled="enableSelectedDisabled"
|
||||||
|
@click="enableSelectedSubmit()">
|
||||||
|
{{ enableSelectedText }}
|
||||||
|
</b-button>
|
||||||
|
${h.end_form()}
|
||||||
|
% else:
|
||||||
${h.form(url('{}.enable_set'.format(route_prefix)), name='enable-set', class_='control')}
|
${h.form(url('{}.enable_set'.format(route_prefix)), name='enable-set', class_='control')}
|
||||||
${h.csrf_token(request)}
|
${h.csrf_token(request)}
|
||||||
${h.hidden('uuids')}
|
${h.hidden('uuids')}
|
||||||
<button type="button" class="button">Enable Selected</button>
|
<button type="button" class="button">Enable Selected</button>
|
||||||
${h.end_form()}
|
${h.end_form()}
|
||||||
|
% endif
|
||||||
|
|
||||||
|
% if use_buefy:
|
||||||
|
${h.form(url('{}.disable_set'.format(route_prefix)), class_='control', ref='disable_selected_form')}
|
||||||
|
${h.csrf_token(request)}
|
||||||
|
${h.hidden('uuids', v_model='selected_uuids')}
|
||||||
|
<b-button :disabled="disableSelectedDisabled"
|
||||||
|
@click="disableSelectedSubmit()">
|
||||||
|
{{ disableSelectedText }}
|
||||||
|
</b-button>
|
||||||
|
${h.end_form()}
|
||||||
|
% else:
|
||||||
${h.form(url('{}.disable_set'.format(route_prefix)), name='disable-set', class_='control')}
|
${h.form(url('{}.disable_set'.format(route_prefix)), name='disable-set', class_='control')}
|
||||||
${h.csrf_token(request)}
|
${h.csrf_token(request)}
|
||||||
${h.hidden('uuids')}
|
${h.hidden('uuids')}
|
||||||
<button type="button" class="button">Disable Selected</button>
|
<button type="button" class="button">Disable Selected</button>
|
||||||
${h.end_form()}
|
${h.end_form()}
|
||||||
% endif
|
% endif
|
||||||
|
% endif
|
||||||
|
|
||||||
## delete selected objects
|
## delete selected objects
|
||||||
% if master.set_deletable and request.has_perm('{}.delete_set'.format(permission_prefix)):
|
% if master.set_deletable and request.has_perm('{}.delete_set'.format(permission_prefix)):
|
||||||
|
@ -274,6 +297,72 @@
|
||||||
${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}
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
|
<%def name="modify_this_page_vars()">
|
||||||
|
${parent.modify_this_page_vars()}
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
% if master.supports_set_enabled_toggle and master.has_perm('enable_disable_set'):
|
||||||
|
|
||||||
|
TailboneGridData.enableSelectedSubmitting = false
|
||||||
|
TailboneGridData.enableSelectedText = "Enable Selected"
|
||||||
|
|
||||||
|
TailboneGrid.computed.enableSelectedDisabled = function() {
|
||||||
|
if (this.enableSelectedSubmitting) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if (!this.checkedRowUUIDs().length) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
TailboneGrid.methods.enableSelectedSubmit = function() {
|
||||||
|
let uuids = this.checkedRowUUIDs()
|
||||||
|
if (!uuids.length) {
|
||||||
|
alert("You must first select one or more objects to disable.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (! confirm("Are you sure you wish to ENABLE the " + uuids.length + " selected objects?")) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.enableSelectedSubmitting = true
|
||||||
|
this.enableSelectedText = "Working, please wait..."
|
||||||
|
this.$refs.enable_selected_form.submit()
|
||||||
|
}
|
||||||
|
|
||||||
|
TailboneGridData.disableSelectedSubmitting = false
|
||||||
|
TailboneGridData.disableSelectedText = "Disable Selected"
|
||||||
|
|
||||||
|
TailboneGrid.computed.disableSelectedDisabled = function() {
|
||||||
|
if (this.disableSelectedSubmitting) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if (!this.checkedRowUUIDs().length) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
TailboneGrid.methods.disableSelectedSubmit = function() {
|
||||||
|
let uuids = this.checkedRowUUIDs()
|
||||||
|
if (!uuids.length) {
|
||||||
|
alert("You must first select one or more objects to disable.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (! confirm("Are you sure you wish to DISABLE the " + uuids.length + " selected objects?")) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.disableSelectedSubmitting = true
|
||||||
|
this.disableSelectedText = "Working, please wait..."
|
||||||
|
this.$refs.disable_selected_form.submit()
|
||||||
|
}
|
||||||
|
|
||||||
|
% endif
|
||||||
|
</script>
|
||||||
|
</%def>
|
||||||
|
|
||||||
|
|
||||||
% if use_buefy:
|
% if use_buefy:
|
||||||
${parent.body()}
|
${parent.body()}
|
||||||
|
|
Loading…
Reference in a new issue