From 14a026e2bf0b4b14189acb767949883eaf953482 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Fri, 8 Nov 2013 10:55:22 +0100 Subject: [PATCH] Properly display sieve filter errors. --- .../templates/sievefilters/index.html | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/modoboa/extensions/sievefilters/templates/sievefilters/index.html b/modoboa/extensions/sievefilters/templates/sievefilters/index.html index 817d6fd51..a8442ffab 100644 --- a/modoboa/extensions/sievefilters/templates/sievefilters/index.html +++ b/modoboa/extensions/sievefilters/templates/sievefilters/index.html @@ -14,6 +14,27 @@ var history = new History({ var cond_templates = null; var action_templates = null; +function display_form_errors(data) { + $.each(data.form_errors, function(id, value) { + var fullid = "id_" + (data.prefix ? data.prefix + "-" : "") + id; + var $widget = $("#" + formid + " #" + fullid); + var ulid = fullid + "-error"; + var $ul = $("#" + ulid); + + if (!$ul.length) { + $ul = $("", { + "class": "errors", + "id": ulid + }).append($("
  • ", { + html: value[0] + }); + $widget.after($ul); + } else { + $ul.find('li').html(value[0]); + } + }); +} + function filterform_cb() { cond_templates = fetch_templates("{% url 'modoboa.extensions.sievefilters.views.get_templates' 'condition' %}", cond_templates); action_templates = fetch_templates("{% url 'modoboa.extensions.sievefilters.views.get_templates' 'action' %}", action_templates); @@ -40,7 +61,8 @@ function filterform_cb() { simple_ajax_form_post(e, { formid: 'filterform', reload_mode: 'history', - extradata: counters + extradata: counters, + error_cb: display_filter_errors }); }); }