diff --git a/demo/__init__.py b/demo/__init__.py index a8be7ca30..db5549d52 100755 --- a/demo/__init__.py +++ b/demo/__init__.py @@ -6,6 +6,7 @@ from django.template.loader import render_to_string from modoboa.lib import events from modoboa.lib.webutils import static_url +@events.observe("UserMenuDisplay") def menu(target, user): import views @@ -31,16 +32,24 @@ def menu(target, user): } ] +@events.observe("GetAnnouncement") def announcement(target): if target == "loginpage": txt = render_to_string("demo/login_announcement.html") return [txt] return "" +@events.observe("PasswordChange") def password_change(user): return [user.id == 1] -if 'modoboa.demo' in settings.INSTALLED_APPS: - events.register("UserMenuDisplay", menu) - events.register("GetAnnouncement", announcement) - events.register("PasswordChange", password_change) +@events.observe("GetStaticContent") +def get_static_content(user): + if not user.has_mailbox: + return [] + return """""" diff --git a/extensions/amavis_quarantine/templates/amavis_quarantine/viewmail_selfservice.html b/extensions/amavis_quarantine/templates/amavis_quarantine/viewmail_selfservice.html index 8dbcacc86..fae1a3d41 100644 --- a/extensions/amavis_quarantine/templates/amavis_quarantine/viewmail_selfservice.html +++ b/extensions/amavis_quarantine/templates/amavis_quarantine/viewmail_selfservice.html @@ -1,6 +1,5 @@ - -{% load i18n libextras amextras %} - +{% load i18n libextras amextras %} + Modoboa @@ -10,17 +9,15 @@ - - + {% url django.views.i18n.javascript_catalog as catalog_url %} -
diff --git a/lib/events.py b/lib/events.py index 627dd9003..4df9cbda3 100644 --- a/lib/events.py +++ b/lib/events.py @@ -11,6 +11,7 @@ core application and additional components. from functools import wraps import inspect import re +from django.conf import settings events = [ "CanCreate", @@ -114,6 +115,9 @@ class observe(object): return [] if not ext.enabled: return [] + elif not modname in settings.INSTALLED_APPS: + return [] + return f(*args) map(lambda evt: register(evt, wrapped_f), self.evtnames) diff --git a/static/js/common.js b/static/js/common.js deleted file mode 100644 index 5bdfed32b..000000000 --- a/static/js/common.js +++ /dev/null @@ -1,226 +0,0 @@ -$(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); -}); - -var media_url = ""; - -/* - * A simple function to initialize the value of the global variable - * 'media_url' (corresponding to django's MEDIA_URL variable). - */ -function set_media_url(url) { - media_url = url; -} - -/* - * Shortcut function that construct an url from the media_url and the - * given value. - */ -function static_url(value) { - return media_url + value; -} - -/* - * Easy way to deactivate a link (ie. clicking on it does nothing) - */ -function disable_link(link) { - link.removeEvents("click") - .addEvent("click", function(evt) { - evt.stop(); - }); -} - -/* - * Easy way to re-activate a link that was previously disabled. An - * extra argument can be passed to specify a new "click" event - * callback. - */ -function enable_link(link, callback) { - link.removeEvents("click"); - if ($defined(callback)) { - link.addEvent("click", callback); - } -} - -function parse_menubar(id) { - var $menubar = $(id); - - if ($menubar == undefined) { - return; - } - $menubar.find('.dropdown-toggle').dropdown(); - $menubar.find('a[data-toggle="modal"]').click(function(e) { - console.log(this); - e.preventDefault(); - var href = $(this).attr('href'); - - if (href.indexOf('#') == 0) { - $(href).modal('open'); - } else { - $.get(href, function(data) { - $('').modal(); - }).success(function() { - $('input:text:visible:first').focus(); - }); - } - }); - - /*.each(function(elem){ - var list = elem.getElement('ul.links'); - var myFx = new Fx.Slide(list, { - duration: 200 - }); - - var coords = elem.getCoordinates(); - - myFx.wrapper.setStyles({ - position : "absolute", - left : coords['left'] - }); - myFx.hide(); - - elem.addEvents({ - 'mouseenter' : function(evt) { - myFx.cancel(); - myFx.slideIn(); - }, - 'mouseleave' : function() { - myFx.cancel(); - myFx.slideOut(); - } - }); - });*/ - /*SqueezeBox.assign($(id).getElements('a[class=boxed]'), { - parse: 'rel' - });*/ - -}; - -get_iframe_body = function(id) { - var saf = navigator.userAgent.match(/Safari/i); - var safver = (saf ? parseFloat(navigator.userAgent.match(/[\d\.]+Safari/i)) : 0); - var targetif = $(id); - var data; - - if (targetif.contentDocument && (!saf || (saf && safver >= 3))) { - // NS6 & Gecko & Opera & IE7+ - if (!saf || (saf && safver >= 3)) { - data = targetif.contentDocument.defaultView.document.body; - } else { - data = targetif.document.body; - } - } else if (targetif.contentWindow && !saf) { - // IE 5.5 & 6.x - data = targetif.contentWindow.document.body; - } - return (data); -}; - -setDivHeight = function(id, extrah, modulo) { - var contentsize = $(document.body).getSize().y - - $("topmenubar").getSize().y - - $("header").getSize().y - - $("footer").getSize().y - - extrah; - - if (modulo) { - contentsize -= contentsize % modulo; - } - $(id).setStyle("height", contentsize + "px"); -}; - -bindRows = function(rooturl, page) { - $$("tr").addEvent("dblclick", function(event) { - if (event.target.parentNode.id) { - var url = rooturl + "?domid=" + event.target.parentNode.id; - if (page != "") { - url += "?page=" + page; - } - event.target.parentNode.setStyle("background", "#ffffcc"); - location.href = url; - } - }); -}; - -toggleSelection = function(id, value) { - $$("input[name=" + id + "]").each(function(obj) { - obj.checked = value; - }); -}; - -checkTableSelection = function(text) { - if (!$$("tr[class*=table-tr-selected]").length) { - return false; - } - return confirm(text); -}; - -function searchbox_init() { - var myFx = new Fx.Slide($("searchparams")); - var $searchfield = $("searchfield"); - - myFx.hide(); - $("searchopts").addEvent("click", function(event) { - myFx.cancel(); - myFx.toggle(); - }); - $$("input[name=scriteria]").addEvent("click", function(event) { - myFx.cancel(); - myFx.toggle(); - }); - $searchfield.addEvent("change", function(event) { - var criteria = ""; - var pattern = this.get("value"); - - $$("input[name=scriteria]:checked").each(function(obj) { - criteria = obj.value; - }); - if (pattern != "") { - current_anchor.setparams({ - pattern: pattern, - criteria: criteria - }); - } else { - current_anchor.deleteParam("pattern"); - current_anchor.deleteParam("criteria"); - } - current_anchor.update(); - }); - $searchfield.addEvent("click", function(event) { - $searchfield.select(); - }); - - $searchfield.addEvent("blur", function(event) { - if ($searchfield.value == "") { - $searchfield.set("value", gettext("Search...")); - } - }); - $("searchbox").setStyle("float", "left"); - var frag = new URI(location.href).get("fragment"); - if (frag.indexOf('?') != -1) { - var params = frag.substring(frag.indexOf('?') + 1).parseQueryString(); - if ($defined(params.pattern)) { - $searchfield.set("value", params.pattern); - } - if ($defined(params.criteria)) { - $("crit_" + params.criteria).checked = true; - } - } -}; - -/*function saveparams(id, message) { - $("#update").click(function(evt) { - evt.preventDefault(); - var $form = $("form"); - - $.post($form.attr("action"), $form.serialize(), function(data) { - if (data.status == "ok") { - $("body").notify("success", message, 2000); - } - }); - }); -};*/ - diff --git a/static/js/utils.js b/static/js/global.js similarity index 87% rename from static/js/utils.js rename to static/js/global.js index ee5806efd..d6ed678e9 100644 --- a/static/js/utils.js +++ b/static/js/global.js @@ -1,7 +1,17 @@ /* - * Collection of functions that are accessible to every page. + * Global javascript utilities */ +var media_url = ""; + +/* + * A simple function to initialize the value of the global variable + * 'media_url' (corresponding to django's MEDIA_URL variable). + */ +function set_media_url(url) { + media_url = url; +} + function modalbox(e, css, defhref, defcb, defclosecb) { e.preventDefault(); var $this = $(this); @@ -47,20 +57,6 @@ function modalbox_autowidth(e) { }]); } -/* - * Simple function that redirect ajax requests to the login page if - * the status code received with a response is equal to 278. - */ -function ajax_login_redirect() { - if (this.status != 278) { - return; - } - var params = "?next=" + window.location.pathname; - - window.location.href = - this.xhr.getResponseHeader("Location").replace(/\?.*$/, params); -} - /* * Simple shorcut do create a bootstrap alert box (error mode) */ @@ -178,35 +174,6 @@ function get_target(e, tag) { return $target.parent(); } -/* - * Simple wrapper around Request.JSON. We just ensure that - * redirections are correctly catched. (on session timeout for - * example) - */ -// Request.JSON.mdb = new Class({ -// Extends: Request.JSON, - -// options: { -// format: "json", -// onComplete: ajax_login_redirect, -// onFailure: function(xhr) { -// $(document.body).setStyle("overflow", "auto"); -// $(document.body).set("html", xhr.responseText); -// } -// } -// }); - -/* - * 'Change password' form initialization. - */ -function chpasswordform_cb() { - $(".submit").one('click', function(e) { - simple_ajax_form_post(e, { - error_cb: chpasswordform_cb - }); - }); -} - /* * Send a simple AJAX request. */ @@ -224,4 +191,23 @@ function simple_ajax_request(e) { } } }); -} \ No newline at end of file +} + +/* + * Simple function that redirect ajax requests to the login page if + * the status code received with a response is equal to 278. + */ +function ajax_login_redirect() { + if (this.status != 278) { + return; + } + var params = "?next=" + window.location.pathname; + + window.location.href = + this.xhr.getResponseHeader("Location").replace(/\?.*$/, params); +} + +$(document).ready(function() { + $(document).on('click', 'a[data-toggle="ajaxmodal"]', modalbox); + $(document).on('click', 'a[data-toggle="ajaxmodal-autowidth"]', modalbox_autowidth); +}); \ No newline at end of file diff --git a/templates/nlayout.html b/templates/nlayout.html index d141af954..e171f75b8 100644 --- a/templates/nlayout.html +++ b/templates/nlayout.html @@ -11,8 +11,7 @@ - - + diff --git a/userprefs/__init__.py b/userprefs/__init__.py index cd6d003fc..ef66fcebd 100644 --- a/userprefs/__init__.py +++ b/userprefs/__init__.py @@ -1,7 +1,7 @@ # coding: utf-8 -from modoboa.lib import parameters -from django.utils.translation import ugettext as _ +from modoboa.lib import parameters, events +from django.utils.translation import ugettext_noop as _ parameters.register_user("LANG", type="list", deflt="en", label=_("Prefered language"), @@ -9,3 +9,16 @@ parameters.register_user("LANG", type="list", deflt="en", ("es", "español"), ("fr", "français")], help=_("Prefered language to display pages"), app="general") + +@events.observe("GetStaticContent") +def get_static_content(user): + return """"""