Add Buefy support for "execute results" from core batch grid view

This commit is contained in:
Lance Edgar 2019-06-16 15:50:40 -05:00
parent 0e67c62c86
commit 26137ec81e
2 changed files with 93 additions and 1 deletions

View file

@ -3,6 +3,7 @@
<%def name="extra_javascript()">
${parent.extra_javascript()}
% if not use_buefy:
% if master.results_executable and request.has_perm('{}.execute_multiple'.format(permission_prefix)):
<script type="text/javascript">
@ -59,16 +60,105 @@
</script>
% endif
% endif
</%def>
<%def name="grid_tools()">
% if master.results_executable and request.has_perm('{}.execute_multiple'.format(permission_prefix)):
% if use_buefy:
<b-button type="is-primary"
@click="executeResults()"
:disabled="!total">
Execute Results
</b-button>
<b-modal has-modal-card
:active.sync="showExecutionOptions">
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Execution Options</p>
</header>
<section class="modal-card-body">
<p>
Please be advised, you are about to execute {{ total }} batches!
</p>
<br />
<tailbone-form ref="executeResultsForm"></tailbone-form>
</section>
<footer class="modal-card-foot">
<b-button @click="showExecutionOptions = false">
Cancel
</b-button>
<once-button type="is-primary"
@click="submitExecuteResults()"
text="Execute">
</once-button>
</footer>
</div>
</b-modal>
% else:
<button type="button" id="execute-results-button">Execute Results</button>
% endif
% endif
</%def>
<%def name="modify_tailbone_grid()">
${parent.modify_tailbone_grid()}
% if master.results_executable and request.has_perm('{}.execute_multiple'.format(permission_prefix)):
<script type="text/javascript">
TailboneForm.data = function() { return TailboneFormData }
TailboneForm.methods.submit = function() {
this.$refs.actualForm.submit()
}
Vue.component('tailbone-form', TailboneForm)
TailboneGridData.hasExecutionOptions = ${json.dumps(master.has_execution_options(batch))|n}
TailboneGridData.showExecutionOptions = false
TailboneGrid.methods.executeResults = function() {
// this should never happen since we disable the button when there are no results
if (!this.total) {
alert("There are no batch results to execute.")
return
}
if (this.hasExecutionOptions) {
// show execution options modal, user can submit form from there
this.showExecutionOptions = true
} else {
// no execution options, but this still warrants a basic confirmation
if (confirm("Are you sure you wish to execute all " + this.total.toLocaleString('en') + " batches?")) {
alert('TODO: ok then you asked for it')
}
}
}
TailboneGrid.methods.submitExecuteResults = function() {
this.$refs.executeResultsForm.submit()
}
</script>
% endif
</%def>
% if use_buefy:
${execute_form.render_deform(form_kwargs={'ref': 'actualForm'}, buttons=False)|n}
% endif
${parent.body()}
% if not use_buefy:
% if master.results_executable and request.has_perm('{}.execute_multiple'.format(permission_prefix)):
<div id="execution-options-dialog" style="display: none;">
<br />
@ -79,3 +169,4 @@ ${parent.body()}
${execute_form.render_deform(form_kwargs={'name': 'execute-results'}, buttons=False)|n}
</div>
% endif
% endif

View file

@ -801,6 +801,7 @@ class BatchMasterView(MasterView):
else:
schema = colander.Schema()
kwargs['use_buefy'] = self.get_use_buefy()
return forms.Form(schema=schema, request=self.request, defaults=defaults, **kwargs)
def get_execute_title(self, batch):