Refactor batch view/edit pages to share some "execution options" logic
This commit is contained in:
parent
53950931af
commit
cdde848275
44
tailbone/static/js/tailbone.batch.js
Normal file
44
tailbone/static/js/tailbone.batch.js
Normal 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();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
|
@ -4,10 +4,12 @@
|
|||
<%def name="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/tailbone.batch.js'))}
|
||||
<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() {
|
||||
var form = $(this).parents('form');
|
||||
|
@ -15,11 +17,6 @@
|
|||
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>
|
||||
<style type="text/css">
|
||||
|
@ -57,3 +54,13 @@
|
|||
</div><!-- form-wrapper -->
|
||||
|
||||
${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>
|
||||
|
|
|
@ -4,41 +4,9 @@
|
|||
<%def name="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/tailbone.batch.js'))}
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
|
||||
$('.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
|
||||
});
|
||||
|
||||
});
|
||||
var has_execution_options = ${'true' if master.has_execution_options else 'false'};
|
||||
</script>
|
||||
<style type="text/css">
|
||||
|
||||
|
|
|
@ -331,7 +331,7 @@ class BatchMasterView(MasterView):
|
|||
self.get_model_title(), self.get_instance_title(batch)))
|
||||
return self.redirect_after_edit(batch)
|
||||
|
||||
return self.render_to_response('edit', {
|
||||
context = {
|
||||
'instance': batch,
|
||||
'instance_title': self.get_instance_title(batch),
|
||||
'instance_deletable': self.deletable_instance(batch),
|
||||
|
@ -340,7 +340,12 @@ class BatchMasterView(MasterView):
|
|||
'rows_grid': grid,
|
||||
'execute_title': self.get_execute_title(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):
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue