From 36ed0449b49f64c27a3ae5afbca565252cf64695 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Wed, 4 Apr 2012 21:23:34 +0200 Subject: [PATCH] Fixed demo buttons. see #204 --- demo/views.py | 10 +++++----- static/js/common.js | 2 ++ static/js/utils.js | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/demo/views.py b/demo/views.py index 5b10f7f09..bd225a5b7 100755 --- a/demo/views.py +++ b/demo/views.py @@ -2,7 +2,7 @@ import os from django.conf import settings from django.contrib.auth.decorators import login_required -from modoboa.lib.webutils import ajax_response +from modoboa.lib.webutils import ajax_simple_response from modoboa.lib.emailutils import sendmail_simple, sendmail_fromfile from modoboa.lib.decorators import needs_mailbox @@ -13,8 +13,8 @@ def send_virus(request): os.path.join(settings.MODOBOA_DIR, "tmp/virus.msg")) if status: - return ajax_response(request) - return ajax_response(request, "ko", respmsg=error) + return ajax_simple_response(dict(status="ok", respmsg=_("Message sent"))) + return ajax_simple_response(dict(status="ko", respmsg=error)) @login_required @needs_mailbox() @@ -37,5 +37,5 @@ XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X You should send this test mail from an account outside of your network. """) if status: - return ajax_response(request) - return ajax_response(request, "ko", respmsg=error) + return ajax_simple_response(dict(status="ok", respmsg=_("Message sent")) + return ajax_simple_response(dict(status="ko", respmsg=error)) diff --git a/static/js/common.js b/static/js/common.js index 3f9c88ff7..6a7074e40 100644 --- a/static/js/common.js +++ b/static/js/common.js @@ -1,6 +1,8 @@ $(document).ready(function() { $(document).on('click', 'a[data-toggle="ajaxmodal"]', modalbox); $(document).on('click', 'a[data-toggle="ajaxmodal-autowidth"]', modalbox_autowidth); + $(document).on('click', 'a[name=sendspam]', simple_ajax_request); + $(document).on('click', 'a[name=sendvirus]', simple_ajax_request); //parse_menubar('#topmenubar'); //parse_menubar('#menubar'); diff --git a/static/js/utils.js b/static/js/utils.js index 9560a3ab4..89410b892 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -201,4 +201,23 @@ function chpasswordform_cb() { error_cb: chpasswordform_cb }); }); +} + +/* + * Send a simple AJAX request. + */ +function simple_ajax_request(e) { + var $this = $(this); + e.preventDefault(); + $.ajax({ + url: $this.attr("herf"), + dataType: 'json', + success: function(data) { + if (data.status == "ok") { + $("body").notify("success", data.respmsg, 2000); + } else { + $("body").notify("error", data.respmsg); + } + } + }); } \ No newline at end of file