From c3fb86e391da83955916f155eedc8f26288d5647 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 4 Dec 2017 17:52:25 -0600 Subject: [PATCH] Refactor messages view to use master3 --- tailbone/forms2/core.py | 23 ++- tailbone/templates/messages/create.mako | 12 +- tailbone/templates/messages/view.mako | 2 +- tailbone/views/master3.py | 5 +- tailbone/views/messages.py | 232 +++++++++++------------- 5 files changed, 133 insertions(+), 141 deletions(-) diff --git a/tailbone/forms2/core.py b/tailbone/forms2/core.py index 65d63221..4631afce 100644 --- a/tailbone/forms2/core.py +++ b/tailbone/forms2/core.py @@ -331,13 +331,24 @@ class Form(object): return fields - def remove_field(self, key): - if key in self.fields: - self.fields.remove(key) + def insert_before(self, field, newfield): + self.fields.insert_before(field, newfield) - def remove_fields(self, *args): + def insert_after(self, field, newfield): + self.fields.insert_after(field, newfield) + + def remove(self, *args): for arg in args: - self.remove_field(arg) + if arg in self.fields: + self.fields.remove(arg) + + # TODO: deprecare / remove this + def remove_field(self, key): + self.remove(key) + + # TODO: deprecare / remove this + def remove_fields(self, *args): + self.remove(*args) def make_schema(self): if not self.model_class: @@ -538,7 +549,7 @@ class Form(object): label = HTML.tag('label', self.get_label(field_name), for_=field_name) field = self.render_field_value(field_name) or '' field_div = HTML.tag('div', class_='field', c=field) - return HTML.tag('div', class_='field-wrapper {}'.format(field), c=label + field_div) + return HTML.tag('div', class_='field-wrapper {}'.format(field_name), c=label + field_div) def render_field_value(self, field_name): record = self.model_instance diff --git a/tailbone/templates/messages/create.mako b/tailbone/templates/messages/create.mako index c434a194..11c711f0 100644 --- a/tailbone/templates/messages/create.mako +++ b/tailbone/templates/messages/create.mako @@ -15,17 +15,17 @@ // validate message before sending function validate_message_form() { - var form = $('#new-message'); + var form = $('#deform'); - if (! form.find('input[name="Message--recipients"]').val()) { + if (! form.find('input[name="recipients_"]').val()) { alert("You must specify some recipient(s) for the message."); - $('.recipients input').data('ui-tagit').tagInput.focus(); + $('.recipients_ input').data('ui-tagit').tagInput.focus(); return false; } - if (! form.find('input[name="Message--subject"]').val()) { + if (! form.find('input[name="subject"]').val()) { alert("You must provide a subject for the message."); - form.find('input[name="Message--subject"]').focus(); + form.find('input[name="subject"]').focus(); return false; } @@ -34,7 +34,7 @@ $(function() { - var recipients = $('.recipients input'); + var recipients = $('.recipients_ input'); recipients.tagit({ diff --git a/tailbone/templates/messages/view.mako b/tailbone/templates/messages/view.mako index 966961ee..2d14d4d8 100644 --- a/tailbone/templates/messages/view.mako +++ b/tailbone/templates/messages/view.mako @@ -26,7 +26,7 @@ <%def name="extra_styles()"> ${parent.extra_styles()}