From 8af3d53a3c37d1f86126273da99ec36d8ca73027 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 31 Oct 2019 19:00:42 -0500 Subject: [PATCH] Improve/fix some views for Messages per Vue.js theme --- .../templates/messages/archive/index.mako | 10 +- tailbone/templates/messages/inbox/index.mako | 12 +-- tailbone/templates/messages/index.mako | 52 ++++++++++ tailbone/templates/messages/view.mako | 97 ++++++++++++++++--- tailbone/views/messages.py | 52 ++++++++-- 5 files changed, 185 insertions(+), 38 deletions(-) diff --git a/tailbone/templates/messages/archive/index.mako b/tailbone/templates/messages/archive/index.mako index 158780cf..002b9e90 100644 --- a/tailbone/templates/messages/archive/index.mako +++ b/tailbone/templates/messages/archive/index.mako @@ -5,9 +5,11 @@ <%def name="extra_javascript()"> ${parent.extra_javascript()} + % if not use_buefy: + % endif <%def name="context_menu_items()"> @@ -16,13 +18,5 @@
  • ${h.link_to("Go to my Sent Messages", url('messages.sent'))}
  • -<%def name="grid_tools()"> - ${h.form(url('messages.move_bulk'), name='move-selected')} - ${h.csrf_token(request)} - ${h.hidden('destination', value='inbox')} - ${h.hidden('uuids')} - - ${h.end_form()} - ${parent.body()} diff --git a/tailbone/templates/messages/inbox/index.mako b/tailbone/templates/messages/inbox/index.mako index 331f0456..f88010b0 100644 --- a/tailbone/templates/messages/inbox/index.mako +++ b/tailbone/templates/messages/inbox/index.mako @@ -1,13 +1,15 @@ -## -*- coding: utf-8 -*- +## -*- coding: utf-8; -*- <%inherit file="/messages/index.mako" /> <%def name="title()">Message Inbox <%def name="extra_javascript()"> ${parent.extra_javascript()} + % if not use_buefy: + % endif <%def name="context_menu_items()"> @@ -16,13 +18,5 @@
  • ${h.link_to("Go to my Sent Messages", url('messages.sent'))}
  • -<%def name="grid_tools()"> - ${h.form(url('messages.move_bulk'), name='move-selected')} - ${h.csrf_token(request)} - ${h.hidden('destination', value='archive')} - ${h.hidden('uuids')} - - ${h.end_form()} - ${parent.body()} diff --git a/tailbone/templates/messages/index.mako b/tailbone/templates/messages/index.mako index d948593d..4ded5571 100644 --- a/tailbone/templates/messages/index.mako +++ b/tailbone/templates/messages/index.mako @@ -3,6 +3,7 @@ <%def name="extra_javascript()"> ${parent.extra_javascript()} + % if not use_buefy: + % endif <%def name="context_menu_items()"> @@ -51,4 +53,54 @@ % endif +<%def name="grid_tools()"> + % if request.matched_route.name in ('messages.inbox', 'messages.archive'): + % if use_buefy: + ${h.form(url('messages.move_bulk'), **{'@submit': 'moveMessagesSubmit'})} + ${h.csrf_token(request)} + ${h.hidden('destination', value='archive' if request.matched_route.name == 'messages.inbox' else 'inbox')} + ${h.hidden('uuids', v_model='selected_uuids')} + + {{ moveMessagesTextCurrent }} + + ${h.end_form()} + % else: + ${h.form(url('messages.move_bulk'), name='move-selected')} + ${h.csrf_token(request)} + ${h.hidden('destination', value='archive' if request.matched_route.name == 'messages.inbox' else 'inbox')} + ${h.hidden('uuids')} + + ${h.end_form()} + % endif + % endif + + +<%def name="modify_this_page_vars()"> + ${parent.modify_this_page_vars()} + % if request.matched_route.name in ('messages.inbox', 'messages.archive'): + + % endif + + + ${parent.body()} diff --git a/tailbone/templates/messages/view.mako b/tailbone/templates/messages/view.mako index 5bab5a4b..a7bf449c 100644 --- a/tailbone/templates/messages/view.mako +++ b/tailbone/templates/messages/view.mako @@ -3,6 +3,7 @@ <%def name="extra_javascript()"> ${parent.extra_javascript()} + % if not use_buefy: + % endif <%def name="extra_styles()"> ${parent.extra_styles()} + % if use_buefy: + + % else: + % endif <%def name="context_menu_items()"> @@ -51,7 +67,7 @@
  • ${h.link_to("Send a new Message", url('messages.create'))}
  • % endif % if recipient: - % if recipient.status == rattail.enum.MESSAGE_STATUS_INBOX: + % if recipient.status == enum.MESSAGE_STATUS_INBOX:
  • ${h.link_to("Back to Message Inbox", url('messages.inbox'))}
  • ${h.link_to("Go to my Message Archive", url('messages.archive'))}
  • ${h.link_to("Go to my Sent Messages", url('messages.sent'))}
  • @@ -69,17 +85,43 @@ <%def name="message_tools()"> % if recipient: -
    - % if request.has_perm('messages.create'): - ${h.link_to("Reply", url('messages.reply', uuid=instance.uuid), class_='button')} - ${h.link_to("Reply to All", url('messages.reply_all', uuid=instance.uuid), class_='button')} - % endif - % if recipient.status == rattail.enum.MESSAGE_STATUS_INBOX: - ${h.link_to("Move to Archive", url('messages.move', uuid=instance.uuid) + '?dest=archive', class_='button')} + % if use_buefy: +
    + % if request.has_perm('messages.create'): + + + + + % endif + % if recipient.status == enum.MESSAGE_STATUS_INBOX: + + + % else: + + + % endif +
    % else: - ${h.link_to("Move to Inbox", url('messages.move', uuid=instance.uuid) + '?dest=inbox', class_='button')} +
    + % if request.has_perm('messages.create'): + ${h.link_to("Reply", url('messages.reply', uuid=instance.uuid), class_='button')} + ${h.link_to("Reply to All", url('messages.reply_all', uuid=instance.uuid), class_='button')} + % endif + % if recipient.status == enum.MESSAGE_STATUS_INBOX: + ${h.link_to("Move to Archive", url('messages.move', uuid=instance.uuid) + '?dest=archive', class_='button')} + % else: + ${h.link_to("Move to Inbox", url('messages.move', uuid=instance.uuid) + '?dest=inbox', class_='button')} + % endif +
    % endif -
    % endif @@ -89,14 +131,39 @@ <%def name="page_content()"> ${parent.page_content()} + % if use_buefy: +
    +
    + ${self.message_tools()} +
    + ${self.message_body()} +
    + ${self.message_tools()} +
    + % else: + ${self.message_tools()} +
    + ${self.message_body()} +
    + ${self.message_tools()} + % endif + - ${self.message_tools()} +<%def name="modify_this_page_vars()"> + ${parent.modify_this_page_vars()} + diff --git a/tailbone/views/messages.py b/tailbone/views/messages.py index ea9cd7d1..0d356d70 100644 --- a/tailbone/views/messages.py +++ b/tailbone/views/messages.py @@ -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): """