Only include "export invoice" logic if user has perm
This commit is contained in:
parent
75e720d679
commit
dda03fd655
|
@ -3,9 +3,10 @@
|
||||||
|
|
||||||
<%def name="grid_tools()">
|
<%def name="grid_tools()">
|
||||||
${parent.grid_tools()}
|
${parent.grid_tools()}
|
||||||
${h.form(url('{}.export'.format(route_prefix)), **{'@submit': 'exportingInvoices = true'})}
|
|
||||||
${h.csrf_token(request)}
|
|
||||||
% if master.has_perm('export'):
|
% if master.has_perm('export'):
|
||||||
|
${h.form(url('{}.export'.format(route_prefix)), **{'@submit': 'exportingInvoices = true'})}
|
||||||
|
${h.csrf_token(request)}
|
||||||
<b-button type="is-primary"
|
<b-button type="is-primary"
|
||||||
native-type="submit"
|
native-type="submit"
|
||||||
icon-pack="fas"
|
icon-pack="fas"
|
||||||
|
@ -13,75 +14,77 @@
|
||||||
:disabled="exportingInvoices || !exportingInvoicesCount">
|
:disabled="exportingInvoices || !exportingInvoicesCount">
|
||||||
{{ exportingInvoices ? "Working, please wait..." : `Export ${'$'}{this.exportingInvoicesCount} Invoices` }}
|
{{ exportingInvoices ? "Working, please wait..." : `Export ${'$'}{this.exportingInvoicesCount} Invoices` }}
|
||||||
</b-button>
|
</b-button>
|
||||||
|
${h.end_form()}
|
||||||
% endif
|
% endif
|
||||||
${h.end_form()}
|
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
<%def name="modify_this_page_vars()">
|
<%def name="modify_this_page_vars()">
|
||||||
${parent.modify_this_page_vars()}
|
${parent.modify_this_page_vars()}
|
||||||
<script type="text/javascript">
|
% if master.has_perm('export'):
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
${grid.component_studly}Data.exportingInvoices = false
|
${grid.component_studly}Data.exportingInvoices = false
|
||||||
${grid.component_studly}Data.exportingInvoicesCount = ${json.dumps(len(selected))|n}
|
${grid.component_studly}Data.exportingInvoicesCount = ${json.dumps(len(selected))|n}
|
||||||
|
|
||||||
${grid.component_studly}.methods.toggleRows = function(uuids, checked) {
|
${grid.component_studly}.methods.toggleRows = function(uuids, checked) {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
|
|
||||||
let url = checked ? '${url('{}.select'.format(route_prefix))}' : '${url('{}.deselect'.format(route_prefix))}'
|
let url = checked ? '${url('{}.select'.format(route_prefix))}' : '${url('{}.deselect'.format(route_prefix))}'
|
||||||
let params = {
|
let params = {
|
||||||
uuids: uuids.join(','),
|
uuids: uuids.join(','),
|
||||||
|
}
|
||||||
|
|
||||||
|
this.submitForm(url, params, response => {
|
||||||
|
this.exportingInvoicesCount = response.data.selected_count
|
||||||
|
this.loading = false
|
||||||
|
}, response => {
|
||||||
|
this.loading = false
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
this.submitForm(url, params, response => {
|
${grid.component_studly}.methods.rowChecked = function(checkedList, row) {
|
||||||
this.exportingInvoicesCount = response.data.selected_count
|
// skip this logic if triggered by header ("all") checkbox
|
||||||
this.loading = false
|
if (!row) {
|
||||||
}, response => {
|
return
|
||||||
this.loading = false
|
}
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
${grid.component_studly}.methods.rowChecked = function(checkedList, row) {
|
// are we toggling ON or OFF?
|
||||||
// skip this logic if triggered by header ("all") checkbox
|
let checked = checkedList.includes(row)
|
||||||
if (!row) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// are we toggling ON or OFF?
|
// collect all currently "checked" uuids
|
||||||
let checked = checkedList.includes(row)
|
let checkedUUIDs = []
|
||||||
|
for (row of checkedList) {
|
||||||
|
checkedUUIDs.push(row.uuid)
|
||||||
|
}
|
||||||
|
|
||||||
// collect all currently "checked" uuids
|
// even though we are given only the one row which was associated with
|
||||||
let checkedUUIDs = []
|
// the event, it is possible the user did a shift+click operation. and
|
||||||
for (row of checkedList) {
|
// since we cannot know for sure, we must assume so, which means we
|
||||||
checkedUUIDs.push(row.uuid)
|
// must send "all" relevant uuids as we are not given the specific
|
||||||
}
|
// range involved for shift+click
|
||||||
|
let uuids = []
|
||||||
// even though we are given only the one row which was associated with
|
if (checked) {
|
||||||
// the event, it is possible the user did a shift+click operation. and
|
// if toggling ON then we must send all "checked" rows
|
||||||
// since we cannot know for sure, we must assume so, which means we
|
uuids = checkedUUIDs
|
||||||
// must send "all" relevant uuids as we are not given the specific
|
} else {
|
||||||
// range involved for shift+click
|
// if toggling OFF then we must send all "unchecked" rows
|
||||||
let uuids = []
|
for (uuid of this.allRowUUIDs()) {
|
||||||
if (checked) {
|
if (!checkedUUIDs.includes(uuid)) {
|
||||||
// if toggling ON then we must send all "checked" rows
|
uuids.push(uuid)
|
||||||
uuids = checkedUUIDs
|
}
|
||||||
} else {
|
|
||||||
// if toggling OFF then we must send all "unchecked" rows
|
|
||||||
for (uuid of this.allRowUUIDs()) {
|
|
||||||
if (!checkedUUIDs.includes(uuid)) {
|
|
||||||
uuids.push(uuid)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.toggleRows(uuids, checked)
|
||||||
}
|
}
|
||||||
this.toggleRows(uuids, checked)
|
|
||||||
}
|
|
||||||
|
|
||||||
TailboneGrid.methods.allChecked = function(checkedList) {
|
TailboneGrid.methods.allChecked = function(checkedList) {
|
||||||
// (de-)select all visible invoices when header checkbox is clicked
|
// (de-)select all visible invoices when header checkbox is clicked
|
||||||
let checked = !!checkedList.length
|
let checked = !!checkedList.length
|
||||||
this.toggleRows(this.allRowUUIDs(), checked)
|
this.toggleRows(this.allRowUUIDs(), checked)
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
% endif
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue