Add basic merge feature to MasterView

This commit is contained in:
Lance Edgar 2016-10-28 10:26:37 -05:00
parent a398a0a710
commit 06b0b13992
3 changed files with 251 additions and 4 deletions

View file

@ -15,7 +15,34 @@
${h.javascript_link(request.static_url('tailbone:static/js/jquery.ui.tailbone.js'))}
<script type="text/javascript">
$(function() {
$('.newgrid-wrapper').gridwrapper();
% if master.mergeable and request.has_perm('{}.merge'.format(permission_prefix)):
$('form[name="merge-things"] button').button('option', 'disabled', $('.newgrid tbody td.checkbox input:checked').length != 2);
$('.newgrid-wrapper').on('click', 'tbody td.checkbox input', function() {
$('form[name="merge-things"] button').button('option', 'disabled', $('.newgrid tbody td.checkbox input:checked').length != 2);
});
$('form[name="merge-things"]').submit(function() {
var uuids = [];
$('.newgrid tbody td.checkbox input:checked').each(function() {
uuids.push($(this).parents('tr:first').data('uuid'));
});
if (uuids.length != 2) {
return false;
}
$(this).find('[name="uuids"]').val(uuids.toString());
$(this).find('button')
.button('option', 'label', "Preparing to Merge...")
.button('disable');
});
% endif
});
</script>
</%def>
@ -26,6 +53,13 @@
% endif
</%def>
<%def name="grid_tools()"></%def>
<%def name="grid_tools()">
% if master.mergeable and request.has_perm('{}.merge'.format(permission_prefix)):
${h.form(url('{}.merge'.format(route_prefix)), name='merge-things')}
${h.hidden('uuids')}
<button type="submit">Merge 2 ${model_title_plural}</button>
${h.end_form()}
% endif
</%def>
${grid.render_complete(tools=capture(self.grid_tools).strip(), context_menu=capture(self.context_menu_items).strip())|n}

View file

@ -0,0 +1,135 @@
## -*- coding: utf-8 -*-
<%inherit file="/base.mako" />
<%def name="title()">Merge 2 ${model_title_plural}</%def>
<%def name="head_tags()">
${parent.head_tags()}
<script type="text/javascript">
$(function() {
$('button.swap').click(function() {
$(this).button('disable').button('option', 'label', "Swapping, please wait...");
var form = $(this).parents('form');
var input = form.find('input[name="uuids"]');
var uuids = input.val().split(',');
uuids.reverse();
input.val(uuids.join(','));
form.submit();
});
$('form.merge input[type="submit"]').click(function() {
$(this).button('disable').button('option', 'label', "Merging, please wait...");
var form = $(this).parents('form');
form.append($('<input type="hidden" name="commit-merge" value="yes" />'));
form.submit();
});
});
</script>
<style type="text/css">
p {
margin: 20px auto;
}
p.warning {
color: red;
}
a.merge-object {
font-weight: bold;
}
table {
border-collapse: collapse;
border-left: 1px solid black;
border-top: 1px solid black;
font-size: 11pt;
margin-left: 50px;
min-width: 80%;
}
table th,
table td {
border-bottom: 1px solid black;
border-right: 1px solid black;
}
table td {
padding: 5px 10px;
}
table td.value {
font-family: monospace;
white-space: pre;
}
table.diff tr.diff td.keep-value {
background-color: #cfc;
}
table.diff tr.diff td.remove-value {
background-color: #fcc;
}
table.diff td.result-value.diff {
background-color: #fe8;
}
div.buttons {
margin-top: 20px;
}
</style>
</%def>
<%def name="context_menu_items()">
<li>${h.link_to("Back to {}".format(model_title_plural), url(route_prefix))}</li>
</%def>
<ul id="context-menu">
${self.context_menu_items()}
</ul>
<p class="warning">
You are about to <strong>merge</strong> two ${model_title} records,
(possibly) along with various related data.&nbsp; The tool you are using now
is somewhat generic and is not able to give you the full picture of the
implications of this merge.&nbsp; You are urged to proceed with caution!
</p>
<p>
The ${h.link_to("{} on the right".format(model_title), view_url(object_to_keep), target='_blank', class_='merge-object')}
will be <strong>kept</strong>
and the ${h.link_to("{} on the left".format(model_title), view_url(object_to_remove), target='_blank', class_='merge-object')}
will be <strong>deleted</strong>.&nbsp; The one which is to be kept may also
be updated to reflect certain aspects of the one being deleted; however again
the details are up to the app logic for this type of merge and aren't fully
known to the generic tool which you're using now.
</p>
<table class="diff">
<thead>
<tr>
<th>field name</th>
<th>deleting ${model_title}</th>
<th>keeping ${model_title}</th>
<th>resulting ${model_title}</th>
</tr>
</thead>
<tbody>
% for field in sorted(merge_fields):
<tr${' class="diff"' if keep_data[field] != remove_data[field] else ''|n}>
<td class="field">${field}</td>
<td class="value remove-value">${repr(remove_data[field])}</td>
<td class="value keep-value">${repr(keep_data[field])}</td>
<td class="value result-value${' diff' if resulting_data[field] != keep_data[field] else ''}">${repr(resulting_data[field])}</td>
</tr>
% endfor
</tbody>
</table>
${h.form(request.current_route_url(), class_='merge')}
<div class="buttons">
${h.hidden('uuids', value='{},{}'.format(object_to_remove.uuid, object_to_keep.uuid))}
<a class="button" href="${index_url}">Whoops, nevermind</a>
<button type="button" class="swap">Swap which ${model_title} is kept/removed</button>
${h.submit('merge', "Yes, perform this merge")}
</div>
${h.end_form()}