Add auto-hide/show magic to message recipients field when viewing

This commit is contained in:
Lance Edgar 2016-05-01 14:57:41 -05:00
parent f3cab67aaf
commit 70a2f10c81
2 changed files with 29 additions and 0 deletions

View file

@ -4,6 +4,10 @@
<%def name="head_tags()"> <%def name="head_tags()">
${parent.head_tags()} ${parent.head_tags()}
<style type="text/css"> <style type="text/css">
.field-wrapper.recipients .everyone {
cursor: pointer;
display: none;
}
.message-tools { .message-tools {
margin-bottom: 15px; margin-bottom: 15px;
} }
@ -11,12 +15,31 @@
border-top: 1px solid black; border-top: 1px solid black;
border-bottom: 1px solid black; border-bottom: 1px solid black;
margin-bottom: 15px; margin-bottom: 15px;
padding: 0 5em;
white-space: pre-line; white-space: pre-line;
} }
.message-body p { .message-body p {
margin-bottom: 15px; margin-bottom: 15px;
} }
</style> </style>
<script type="text/javascript">
$(function() {
$('.field-wrapper.recipients .more').click(function() {
$(this).hide();
$(this).siblings('.everyone').css('display', 'inline-block');
return false;
});
$('.field-wrapper.recipients .everyone').click(function() {
$(this).hide();
$(this).siblings('.more').show();
});
});
</script>
</%def> </%def>
<%def name="context_menu_items()"> <%def name="context_menu_items()">

View file

@ -97,6 +97,12 @@ class RecipientsFieldRenderer(formalchemy.FieldRenderer):
recips = sorted([r.recipient.display_name for r in recips]) recips = sorted([r.recipient.display_name for r in recips])
if len(recips) < len(recipients): if len(recips) < len(recipients):
recips.insert(0, 'you') recips.insert(0, 'you')
max_display = 5
if len(recips) > max_display:
basic = HTML.literal("{}, ".format(', '.join(recips[:max_display-1])))
more = tags.link_to("({} more)".format(len(recips[max_display-1:])), '#', class_='more')
everyone = HTML.tag('span', class_='everyone', c=', '.join(recips[max_display-1:]))
return basic + more + everyone
return ', '.join(recips) return ', '.join(recips)