diff options
Diffstat (limited to 'hyperkitty')
-rw-r--r-- | hyperkitty/static/css/hyperkitty-common.css | 21 | ||||
-rw-r--r-- | hyperkitty/static/js/hyperkitty-common.js | 28 | ||||
-rw-r--r-- | hyperkitty/views/forms.py | 30 |
3 files changed, 77 insertions, 2 deletions
diff --git a/hyperkitty/static/css/hyperkitty-common.css b/hyperkitty/static/css/hyperkitty-common.css index 1ff6e91..7b3190b 100644 --- a/hyperkitty/static/css/hyperkitty-common.css +++ b/hyperkitty/static/css/hyperkitty-common.css @@ -231,6 +231,9 @@ a.reply.disabled { .reply-form textarea { width: 95%; } +.reply-form p.buttons { + margin-top: 1em; +} .reply-result { text-align: center; } @@ -264,6 +267,24 @@ a.thread-new strong { .new-thread-form textarea { width: 90%; } +.new-thread-form p.buttons { + margin-top: 2em; +} + + +/* + * Attachments in replies or new threads + */ + +.attach-files-template { + display: none; +} +.attach-files-add { + display: none; +} +.attach-files span { + display: block; +} /* AJAX */ diff --git a/hyperkitty/static/js/hyperkitty-common.js b/hyperkitty/static/js/hyperkitty-common.js index 2d2ff16..b9fc897 100644 --- a/hyperkitty/static/js/hyperkitty-common.js +++ b/hyperkitty/static/js/hyperkitty-common.js @@ -74,6 +74,33 @@ function setup_vote(baseElem) { /* + * New messages (or replies) + */ + +function setup_attachments() { + function add_attach_form (e) { + e.preventDefault(); + var form = $(this).parents("form").first(); + form.find(".attach-files-template") + .clone().removeClass("attach-files-template") + .appendTo(form.find(".attach-files")); + form.find(".attach-files span a").click(function (e) { + e.preventDefault(); + $(this).parent().remove(); + if (form.find(".attach-files input").length === 0) { + form.find(".attach-files-add").hide(); + form.find(".attach-files-first").show(); + }; + }); + form.find(".attach-files-first").hide(); + form.find(".attach-files-add").show(); + } + $(".attach-files-add").click(add_attach_form); + $(".attach-files-first").click(add_attach_form); +} + + +/* * Misc. */ @@ -110,4 +137,5 @@ $(document).ready(function() { setup_months_list(); setup_disabled_tooltips(); setup_flash_messages(); + setup_attachments(); }); diff --git a/hyperkitty/views/forms.py b/hyperkitty/views/forms.py index 034b7d9..99f158f 100644 --- a/hyperkitty/views/forms.py +++ b/hyperkitty/views/forms.py @@ -17,12 +17,14 @@ # HyperKitty. If not, see <http://www.gnu.org/licenses/>. # # Author: Aamir Khan <syst3m.w0rm@gmail.com> +# Author: Aurélien Bompard <abompard@fedoraproject.org> # from django import forms from django.core import validators from django.contrib.auth.models import User from django.utils.safestring import mark_safe +from django.utils.translation import ugettext, ugettext_lazy from hyperkitty.models import UserProfile @@ -98,14 +100,38 @@ class AddTagForm(forms.Form): +class AttachmentFileInput(forms.FileInput): + attach_first_text = ugettext_lazy('Attach a file') + attach_another_text = ugettext_lazy('Attach another file') + rm_text = ugettext_lazy('Remove this file') + template = """ +<span class="attach-files-template"> + %(input)s <a href="#" title="%(rm_text)s">(-)</a> +</span> +<span class="attach-files"></span> +<a class="attach-files-first">%(attach_first_text)s</a> +<a class="attach-files-add">%(attach_another_text)s</a> +""" + + def render(self, name, value, attrs=None): + substitutions = { + 'attach_first_text': self.attach_first_text, + 'attach_another_text': self.attach_another_text, + 'rm_text': self.rm_text, + } + substitutions['input'] = super(AttachmentFileInput, self).render(name, value, attrs) + return mark_safe(self.template % substitutions) + + class ReplyForm(forms.Form): newthread = forms.BooleanField(label="", required=False) subject = forms.CharField(label="", required=False, widget=forms.TextInput(attrs={ 'placeholder': 'New subject'})) message = forms.CharField(label="", widget=forms.Textarea) - attachment = forms.FileField(required=False) + attachment = forms.FileField(required=False, widget=AttachmentFileInput) class PostForm(forms.Form): subject = forms.CharField() message = forms.CharField(widget=forms.Textarea) - attachment = forms.FileField(required=False) + attachment = forms.FileField(required=False, label="", + widget=AttachmentFileInput) |