Refactor batch view/edit pages to share some "execution options" logic

This commit is contained in:
Lance Edgar 2016-08-22 15:46:16 -05:00
parent 53950931af
commit cdde848275
4 changed files with 67 additions and 43 deletions

View file

@ -0,0 +1,44 @@
/************************************************************
*
* tailbone.batch.js
*
* Common logic for view/edit batch pages
*
************************************************************/
$(function() {
$('.newgrid-wrapper').gridwrapper();
$('#execute-batch').click(function() {
if (has_execution_options) {
$('#execution-options-dialog').dialog({
title: "Execution Options",
width: 500,
height: 300,
modal: true,
buttons: [
{
text: "Execute",
click: function(event) {
$(event.target).button('option', 'label', "Executing, please wait...").button('disable');
$('form[name="batch-execution"]').submit();
}
},
{
text: "Cancel",
click: function() {
$(this).dialog('close');
}
}
]
});
} else {
$(this).button('option', 'label', "Executing, please wait...").button('disable');
$('form[name="batch-execution"]').submit();
}
});
});

View file

@ -4,10 +4,12 @@
<%def name="head_tags()"> <%def name="head_tags()">
${parent.head_tags()} ${parent.head_tags()}
${h.javascript_link(request.static_url('tailbone:static/js/jquery.ui.tailbone.js'))} ${h.javascript_link(request.static_url('tailbone:static/js/jquery.ui.tailbone.js'))}
${h.javascript_link(request.static_url('tailbone:static/js/tailbone.batch.js'))}
<script type="text/javascript"> <script type="text/javascript">
$(function() {
$('.newgrid-wrapper').gridwrapper(); var has_execution_options = ${'true' if master.has_execution_options else 'false'};
$(function() {
$('#save-refresh').click(function() { $('#save-refresh').click(function() {
var form = $(this).parents('form'); var form = $(this).parents('form');
@ -15,11 +17,6 @@
form.submit(); form.submit();
}); });
$('#execute-batch').click(function() {
$(this).button('option', 'label', "Executing, please wait...").button('disable');
location.href = '${url('{}.execute'.format(route_prefix), uuid=batch.uuid)}';
});
}); });
</script> </script>
<style type="text/css"> <style type="text/css">
@ -57,3 +54,13 @@
</div><!-- form-wrapper --> </div><!-- form-wrapper -->
${rows_grid.render_complete(allow_save_defaults=False, tools=capture(self.grid_tools))|n} ${rows_grid.render_complete(allow_save_defaults=False, tools=capture(self.grid_tools))|n}
<div id="execution-options-dialog" style="display: none;">
${h.form(url('{}.execute'.format(route_prefix), uuid=batch.uuid), name='batch-execution')}
% if master.has_execution_options:
${rendered_execution_options|n}
% endif
${h.end_form()}
</div>

View file

@ -4,41 +4,9 @@
<%def name="head_tags()"> <%def name="head_tags()">
${parent.head_tags()} ${parent.head_tags()}
${h.javascript_link(request.static_url('tailbone:static/js/jquery.ui.tailbone.js'))} ${h.javascript_link(request.static_url('tailbone:static/js/jquery.ui.tailbone.js'))}
${h.javascript_link(request.static_url('tailbone:static/js/tailbone.batch.js'))}
<script type="text/javascript"> <script type="text/javascript">
$(function() { var has_execution_options = ${'true' if master.has_execution_options else 'false'};
$('.newgrid-wrapper').gridwrapper();
$('#execute-batch').click(function() {
% if master.has_execution_options:
$('#execution-options-dialog').dialog({
title: "Execution Options",
width: 500,
height: 300,
modal: true,
buttons: [
{
text: "Execute",
click: function(event) {
$(event.target).button('option', 'label', "Executing, please wait...").button('disable');
$('form[name="batch-execution"]').submit();
}
},
{
text: "Cancel",
click: function() {
$(this).dialog('close');
}
}
]
});
% else:
$(this).button('option', 'label', "Executing, please wait...").button('disable');
$('form[name="batch-execution"]').submit();
% endif
});
});
</script> </script>
<style type="text/css"> <style type="text/css">

View file

@ -331,7 +331,7 @@ class BatchMasterView(MasterView):
self.get_model_title(), self.get_instance_title(batch))) self.get_model_title(), self.get_instance_title(batch)))
return self.redirect_after_edit(batch) return self.redirect_after_edit(batch)
return self.render_to_response('edit', { context = {
'instance': batch, 'instance': batch,
'instance_title': self.get_instance_title(batch), 'instance_title': self.get_instance_title(batch),
'instance_deletable': self.deletable_instance(batch), 'instance_deletable': self.deletable_instance(batch),
@ -340,7 +340,12 @@ class BatchMasterView(MasterView):
'rows_grid': grid, 'rows_grid': grid,
'execute_title': self.get_execute_title(batch), 'execute_title': self.get_execute_title(batch),
'execute_enabled': self.executable(batch), 'execute_enabled': self.executable(batch),
}) }
if context['execute_enabled'] and self.has_execution_options:
context['rendered_execution_options'] = self.render_execution_options()
return self.render_to_response('edit', context)
def redirect_after_edit(self, batch): def redirect_after_edit(self, batch):
""" """