Improve/fix some views for Messages per Vue.js theme

This commit is contained in:
Lance Edgar 2019-10-31 19:00:42 -05:00
parent bcfb4f257d
commit 8af3d53a3c
5 changed files with 185 additions and 38 deletions

View file

@ -139,6 +139,9 @@ class MessagesView(MasterView):
return 'you'
return six.text_type(sender)
def render_subject_bold(self, message, field):
return HTML.tag('span', c=message.subject, style='font-weight: bold;')
def render_recipients(self, message, column_name):
recipients = message.recipients
if recipients:
@ -156,18 +159,44 @@ class MessagesView(MasterView):
recipients = message.recipients
if not recipients:
return ""
use_buefy = self.get_use_buefy()
# remove current user from displayed list, even if they're a recipient
recips = [r for r in recipients
if r.recipient is not self.request.user]
# sort recipients by display name
recips = sorted([r.recipient.display_name for r in recips])
# if we *did* remove current user from list, insert them at front of list
if len(recips) < len(recipients) and (
message.sender is not self.request.user or not recips):
recips.insert(0, 'you')
# we only want to show the first 5 recipients by default, with
# client-side JS allowing the user to view all if they want
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
if use_buefy:
basic = HTML.tag('span', c="{}, ".format(', '.join(recips[:max_display-1])))
more = tags.link_to("({} more)".format(len(recips[max_display-1:])), '#', **{
'v-show': '!showingAllRecipients',
'@click.prevent': 'showMoreRecipients()',
})
everyone = HTML.tag('span', c=', '.join(recips[max_display-1:]), **{
'v-show': 'showingAllRecipients',
'@click': 'hideMoreRecipients()',
'class_': 'everyone',
})
return HTML.tag('div', c=[basic, more, everyone])
else:
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
# show the full list if there are few enough recipients for that
return ', '.join(recips)
# TODO!!
@ -181,6 +210,7 @@ class MessagesView(MasterView):
def configure_form(self, f):
super(MessagesView, self).configure_form(f)
use_buefy = self.get_use_buefy()
# we have custom logic to disable submit button
f.auto_disable = False
@ -196,6 +226,9 @@ class MessagesView(MasterView):
f.set_renderer('recipients', self.render_recipients_full)
f.set_label('recipients', "To")
if use_buefy:
f.set_renderer('subject', self.render_subject_bold)
f.set_widget('body', dfwidget.TextAreaWidget(cols=50, rows=15))
if self.creating:
@ -317,8 +350,15 @@ class MessagesView(MasterView):
def template_kwargs_view(self, **kwargs):
message = kwargs['instance']
return {'message': message,
'recipient': self.get_recipient(message)}
recipient = self.get_recipient(message)
kwargs['message'] = message
kwargs['recipient'] = recipient
if recipient.status == self.enum.MESSAGE_STATUS_ARCHIVE:
kwargs['index_url'] = self.request.route_url('messages.archive')
return kwargs
def reply(self):
"""