Tweak form handling for sending a new message, for more customization
This commit is contained in:
parent
70e5915e51
commit
051b52bd4b
|
@ -3,8 +3,12 @@
|
|||
|
||||
<%def name="title()">New ${model_title}</%def>
|
||||
|
||||
<%def name="head_tags()">
|
||||
${parent.head_tags()}
|
||||
<%def name="extra_javascript()">
|
||||
${parent.extra_javascript()}
|
||||
${self.disable_button_js()}
|
||||
</%def>
|
||||
|
||||
<%def name="disable_button_js()">
|
||||
<script type="text/javascript">
|
||||
|
||||
$(function() {
|
||||
|
|
|
@ -13,6 +13,25 @@
|
|||
% endfor
|
||||
]);
|
||||
|
||||
// validate message before sending
|
||||
function validate_message_form() {
|
||||
var form = $('#new-message');
|
||||
|
||||
if (! form.find('input[name="Message--recipients"]').val()) {
|
||||
alert("You must specify some recipient(s) for the message.");
|
||||
$('.recipients input').data('ui-tagit').tagInput.focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! form.find('input[name="Message--subject"]').val()) {
|
||||
alert("You must provide a subject for the message.");
|
||||
form.find('input[name="Message--subject"]').focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$(function() {
|
||||
|
||||
var recipients = $('.recipients input');
|
||||
|
@ -57,26 +76,19 @@
|
|||
|
||||
// set focus to recipients field
|
||||
recipients.data('ui-tagit').tagInput.focus();
|
||||
});
|
||||
|
||||
// validate message before sending
|
||||
</script>
|
||||
${self.validate_message_js()}
|
||||
</%def>
|
||||
|
||||
<%def name="validate_message_js()">
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
$('#new-message').submit(function() {
|
||||
var form = $(this);
|
||||
|
||||
if (! form.find('input[name="Message--recipients"]').val()) {
|
||||
alert("You must specify some recipient(s) for the message.");
|
||||
recipients.data('ui-tagit').tagInput.focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! form.find('input[name="Message--subject"]').val()) {
|
||||
alert("You must provide a subject for the message.");
|
||||
form.find('input[name="Message--subject"]').focus();
|
||||
return false;
|
||||
}
|
||||
return validate_message_form();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
</%def>
|
||||
|
||||
|
|
|
@ -132,11 +132,14 @@ class MasterView(View):
|
|||
# let save_create_form() return alternate object if necessary
|
||||
obj = self.save_create_form(form) or form.fieldset.model
|
||||
self.after_create(obj)
|
||||
self.request.session.flash("{} has been created: {}".format(
|
||||
self.get_model_title(), self.get_instance_title(obj)))
|
||||
self.flash_after_create(obj)
|
||||
return self.redirect_after_create(obj)
|
||||
return self.render_to_response('create', {'form': form})
|
||||
|
||||
def flash_after_create(self, obj):
|
||||
self.request.session.flash("{} has been created: {}".format(
|
||||
self.get_model_title(), self.get_instance_title(obj)))
|
||||
|
||||
def save_create_form(self, form):
|
||||
self.before_create(form)
|
||||
form.save()
|
||||
|
|
|
@ -209,6 +209,7 @@ class MessagesView(MasterView):
|
|||
if self.creating:
|
||||
form.id = 'new-message'
|
||||
form.cancel_url = self.request.get_referrer(default=self.request.route_url('messages.inbox'))
|
||||
form.create_label = "Send Message"
|
||||
return form
|
||||
|
||||
def configure_fieldset(self, fs):
|
||||
|
@ -288,6 +289,10 @@ class MessagesView(MasterView):
|
|||
message = form.fieldset.model
|
||||
message.sender = self.request.user
|
||||
|
||||
def flash_after_create(self, obj):
|
||||
self.request.session.flash("Message has been sent: {}".format(
|
||||
self.get_instance_title(obj)))
|
||||
|
||||
def filter_reply_recipient(self, user):
|
||||
return user.active
|
||||
|
||||
|
|
Loading…
Reference in a new issue