diff --git a/modoboa/extensions/sievefilters/__init__.py b/modoboa/extensions/sievefilters/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/modoboa/extensions/sievefilters/app_settings.py b/modoboa/extensions/sievefilters/app_settings.py deleted file mode 100644 index c3d1cbb4d..000000000 --- a/modoboa/extensions/sievefilters/app_settings.py +++ /dev/null @@ -1,65 +0,0 @@ -# coding: utf-8 -from django.utils.translation import ugettext_lazy as _ -from django import forms -from sievelib.managesieve import SUPPORTED_AUTH_MECHS -from modoboa.lib.parameters import AdminParametersForm, UserParametersForm -from modoboa.lib.form_utils import SeparatorField, YesNoField, InlineRadioSelect - - -def supported_auth_mechs(): - values = [('AUTO', 'auto')] - for m in SUPPORTED_AUTH_MECHS: - values += [(m, m.lower())] - return values - - -class ParametersForm(AdminParametersForm): - app = "sievefilters" - - sep1 = SeparatorField(label=_("ManageSieve settings")) - - server = forms.CharField( - label=_("Server address"), - initial="127.0.0.1", - help_text=_("Address of your MANAGESIEVE server"), - widget=forms.TextInput(attrs={"class": "form-control"}) - ) - - port = forms.IntegerField( - label=_("Server port"), - initial=4190, - help_text=_("Listening port of your MANAGESIEVE server"), - widget=forms.TextInput(attrs={"class": "form-control"}) - ) - - starttls = YesNoField( - label=_("Connect using STARTTLS"), - initial="no", - help_text=_("Use the STARTTLS extension") - ) - - authentication_mech = forms.ChoiceField( - label=_("Authentication mechanism"), - choices=supported_auth_mechs(), - initial="auto", - help_text=_("Prefered authentication mechanism"), - widget=forms.Select(attrs={"class": "form-control"}) - ) - - -class UserSettings(UserParametersForm): - app = "sievefilters" - - sep1 = SeparatorField(label=_("General")) - - editor_mode = forms.ChoiceField( - initial="gui", - label=_("Editor mode"), - choices=[("raw", "raw"), ("gui", "simplified")], - help_text=_("Select the mode you want the editor to work in"), - widget=InlineRadioSelect(attrs={"type": "checkbox"}) - ) - - @staticmethod - def has_access(user): - return user.mailbox_set.count() != 0 diff --git a/modoboa/extensions/sievefilters/forms.py b/modoboa/extensions/sievefilters/forms.py deleted file mode 100644 index 01e91e98c..000000000 --- a/modoboa/extensions/sievefilters/forms.py +++ /dev/null @@ -1,322 +0,0 @@ -"""Custom forms.""" - -from django import forms -from django.forms.widgets import RadioFieldRenderer, RadioSelect, RadioInput -from django.http import QueryDict -from django.utils.encoding import force_unicode -from django.utils.html import conditional_escape -from django.utils.safestring import mark_safe -from django.utils.translation import ugettext as _, ugettext_lazy - -from modoboa.extensions.admin.templatetags.admin_tags import gender - - -class FiltersSetForm(forms.Form): - name = forms.CharField( - widget=forms.TextInput(attrs={"class": "form-control"}) - ) - active = forms.BooleanField( - label=gender("Active", "m"), required=False, - initial=False, - help_text=ugettext_lazy("Check to activate this filters set") - ) - - -class CustomRadioInput(RadioInput): - - def __unicode__(self): - return self.render() - - def render(self, name=None, value=None, attrs=None, choices=()): - name = name or self.name - value = value or self.value - attrs = attrs or self.attrs - if 'id' in self.attrs: - label_for = ' for="%s_%s"' % (self.attrs['id'], self.index) - else: - label_for = '' - choice_label = conditional_escape(force_unicode(self.choice_label)) - return mark_safe( - u'' - % (label_for, self.tag(), choice_label) - ) - - -class CustomRadioFieldRenderer(RadioFieldRenderer): - - def __iter__(self): - for i, choice in enumerate(self.choices): - yield CustomRadioInput( - self.name, self.value, self.attrs.copy(), choice, i) - - def __getitem__(self, idx): - choice = self.choices[idx] - return CustomRadioInput( - self.name, self.value, self.attrs.copy(), choice, idx) - - def render(self): - return mark_safe(u'\n'.join([force_unicode(w) for w in self])) - - -class CustomRadioSelect(RadioSelect): - renderer = CustomRadioFieldRenderer - - -class FilterForm(forms.Form): - - def __init__(self, conditions, actions, request, *args, **kwargs): - super(FilterForm, self).__init__(*args, **kwargs) - - self.field_widths = { - "match_type": 8 - } - - self.fields["name"] = forms.CharField(label=_("Name")) - self.fields["match_type"] = forms.ChoiceField( - choices=[("allof", _("All of the following")), - ("anyof", _("Any of the following")), - ("all", _("All messages"))], - initial="anyof", - widget=CustomRadioSelect() - ) - - self.header_operators = [ - ("contains", _("contains"), "string"), - ("notcontains", _("does not contain"), "string"), - ("is", _("is"), "string"), - ("isnot", _("is not"), "string") - ] - - self.cond_templates = [ - {"name": "Subject", - "label": _("Subject"), - "operators": self.header_operators}, - {"name": "From", - "label": _("Sender"), - "operators": self.header_operators}, - {"name": "To", - "label": _("Recipient"), - "operators": self.header_operators}, - {"name": "Cc", - "label": _("Cc"), - "operators": self.header_operators}, - {"name": "size", "label": _("Size"), - "operators": [("over", _("is greater than"), "number"), - ("under", _("is less than"), "number")]}, - ] - - self.action_templates = [ - {"name": "fileinto", "label": _("Move message to"), - "args": [{"type": "list", "vloader": "userfolders"}]}, - {"name": "redirect", "label": _("Redirect message to"), - "args": [{"type": "string"}]}, - ] - - self.conds_cnt = 0 - for c in conditions: - getattr(self, "_build_%s_field" % c[0])(c[1], c[2]) - self.actions_cnt = 0 - for a in actions: - getattr(self, "_build_%s_field" % a[0])(request, a[1]) - - def clean_name(self): - """Check that name does not contain strange chars. - """ - if '#' in self.cleaned_data["name"]: - raise forms.ValidationError(_("Wrong filter name")) - return self.cleaned_data["name"] - - def _build_header_field(self, name, op, value): - targets = [] - ops = [] - vfield = None - for tpl in self.cond_templates: - targets += [(tpl["name"], tpl["label"]), ] - if tpl["name"] != name: - continue - for opdef in tpl["operators"]: - ops += [opdef[:2]] - if op != opdef[0]: - continue - if opdef[2] in ["string", "number"]: - vfield = forms.CharField(max_length=255, initial=value) - - self.fields["cond_target_%d" % self.conds_cnt] = \ - forms.ChoiceField(initial=name, choices=targets) - self.fields["cond_operator_%d" % self.conds_cnt] = \ - forms.ChoiceField(initial=op, choices=ops) - self.fields["cond_value_%d" % self.conds_cnt] = vfield - self.conds_cnt += 1 - - def _build_Subject_field(self, op, value): - self._build_header_field("Subject", op, value) - - def _build_To_field(self, op, value): - self._build_header_field("To", op, value) - - def _build_From_field(self, op, value): - self._build_header_field("From", op, value) - - def _build_Cc_field(self, op, value): - self._build_header_field("Cc", op, value) - - def _build_size_field(self, op, value): - self._build_header_field("size", op, value) - - def _build_action_field(self, request, name, value): - actions = [] - args = None - for tpl in self.action_templates: - actions += [(tpl["name"], tpl["label"]), ] - if name == tpl["name"]: - args = tpl["args"] - self.fields["action_name_%d" % self.actions_cnt] = \ - forms.ChoiceField(initial=name, choices=actions) - for cnt in xrange(0, len(args)): - arg = args[cnt] - aname = "action_arg_%d_%d" % (self.actions_cnt, cnt) - if arg["type"] == "string": - self.fields[aname] = forms.CharField( - max_length=255, - initial=value) - elif arg["type"] == "list": - choices = getattr(self, arg["vloader"])(request) - self.fields[aname] = forms.ChoiceField( - initial=value, - choices=choices) - self.actions_cnt += 1 - - def _build_redirect_field(self, request, value): - self._build_action_field(request, "redirect", value) - - def _build_fileinto_field(self, request, value): - self._build_action_field(request, "fileinto", value) - - def __build_folders_list(self, folders, user, imapc, parentmb=None): - ret = [] - for fd in folders: - value = fd["path"] if "path" in fd else fd["name"] - if parentmb: - ret += [ - (value, fd["name"].replace( - "%s%s" % (parentmb, imapc.hdelimiter), "")) - ] - else: - ret += [(value, fd["name"])] - if "sub" in fd: - submboxes = imapc.getmboxes(user, value, unseen_messages=False) - ret += self.__build_folders_list(submboxes, user, imapc, value) - return ret - - def userfolders(self, request): - from modoboa.extensions.webmail.lib import get_imapconnector - - mbc = get_imapconnector(request) - ret = mbc.getmboxes(request.user, unseen_messages=False) - - folders = self.__build_folders_list(ret, request.user, mbc) - return folders - - def tofilter(self): - conditions = [] - actions = [] - for cpt in xrange(0, self.conds_cnt): - conditions += [(self.cleaned_data["cond_target_%d" % cpt], - ":" + self.cleaned_data["cond_operator_%d" % cpt], - self.cleaned_data["cond_value_%d" % cpt])] - for cpt in xrange(0, self.actions_cnt): - naction = (self.cleaned_data["action_name_%d" % cpt],) - argcpt = 0 - while True: - try: - naction += ( - self.cleaned_data[ - "action_arg_%d_%d" % - (cpt, argcpt)],) - except KeyError: - break - argcpt += 1 - actions += [naction] - - return (conditions, actions) - - -def build_filter_form_from_qdict(request): - conditions = [] - actions = [] - qdict = QueryDict("", mutable=True) - qdict["name"] = request.POST["name"] - qdict["match_type"] = request.POST["match_type"] - cpt = 0 - i = 0 - if qdict["match_type"] != "all": - while True: - if cpt == int(request.POST["conds"]): - break - if "cond_target_%d" % i in request.POST: - qdict["cond_target_%d" % cpt] = ( - request.POST["cond_target_%d" % i] - ) - qdict["cond_operator_%d" % cpt] = ( - request.POST["cond_operator_%d" % i] - ) - qdict["cond_value_%d" % cpt] = request.POST["cond_value_%d" % i] - condtarget = request.POST["cond_target_%d" % i] - condop = request.POST["cond_operator_%d" % i] - condvalue = request.POST["cond_value_%d" % i] - conditions += [(condtarget, condop, condvalue)] - cpt += 1 - i += 1 - cpt = 0 - i = 0 - while True: - if cpt == int(request.POST["actions"]): - break - if "action_name_%d" % i in request.POST: - qdict["action_name_%d" % cpt] = request.POST["action_name_%d" % i] - action = request.POST["action_name_%d" % i] - argcpt = 0 - args = [] - while True: - try: - qdict["action_arg_%d_%d" % (cpt, argcpt)] = \ - request.POST["action_arg_%d_%d" % (i, argcpt)] - args += [request.POST["action_arg_%d_%d" % (i, argcpt)]] - except KeyError: - break - argcpt += 1 - args = [action] + args - actions += [args] - cpt += 1 - i += 1 - - return FilterForm(conditions, actions, request, qdict) - - -def build_filter_form_from_filter(request, name, fobj): - from sievelib.commands import SizeCommand, TrueCommand - - match_type = fobj["test"].name - conditions = [] - for t in fobj["test"]["tests"]: - if isinstance(t, TrueCommand): - match_type = "all" - conditions += [("Subject", "contains", "")] - break - elif isinstance(t, SizeCommand): - conditions += [("size", t["comparator"][1:], t["limit"])] - else: - conditions += [(t["header-names"].strip('"'), - t["match-type"][1:], - t["key-list"].strip('"'))] - actions = [] - for c in fobj.children: - action = (c.name,) - for arg in c.args_definition: - action += (c[arg["name"]].strip('"'),) - actions += [action] - - form = FilterForm(conditions, actions, request) - form.fields["name"].initial = name - form.fields["match_type"].initial = match_type - return form diff --git a/modoboa/extensions/sievefilters/general_callbacks.py b/modoboa/extensions/sievefilters/general_callbacks.py deleted file mode 100644 index c09b73fc4..000000000 --- a/modoboa/extensions/sievefilters/general_callbacks.py +++ /dev/null @@ -1,32 +0,0 @@ -from django.utils.translation import ugettext as _ -from django.core.urlresolvers import reverse -from modoboa.lib import events - - -@events.observe("UserMenuDisplay") -def menu(target, user): - if target != "options_menu": - return [] - if not user.mailbox_set.count(): - return [] - return [ - {"name": "sievefilters", - "label": _("Message filters"), - "url": reverse("sievefilters:index"), - "img": "fa fa-filter"} - ] - - -@events.observe("UserLogout") -def userlogout(request): - from .lib import SieveClient - - if not request.user.mailbox_set.count(): - return - try: - sc = SieveClient(user=request.user.username, - password=request.session["password"]) - except Exception: - pass - else: - sc.logout() diff --git a/modoboa/extensions/sievefilters/lib.py b/modoboa/extensions/sievefilters/lib.py deleted file mode 100644 index 26cf8a2d1..000000000 --- a/modoboa/extensions/sievefilters/lib.py +++ /dev/null @@ -1,107 +0,0 @@ -# coding: utf-8 - -"""Internal tools.""" - -from sievelib.factory import FiltersSet -from sievelib.managesieve import Client, Error -from sievelib.parser import Parser - -from django.utils.translation import ugettext as _ - -from modoboa.lib import parameters -from modoboa.lib.connections import ConnectionsManager, ConnectionError -from modoboa.lib.exceptions import ModoboaException - - -class SieveClientError(ModoboaException): - http_code = 424 - - -class SieveClient(object): - __metaclass__ = ConnectionsManager - - def __init__(self, user=None, password=None): - try: - ret, msg = self.login(user, password) - except Error as e: - raise ConnectionError(str(e)) - if not ret: - raise ConnectionError(msg) - - def login(self, user, password): - self.msc = Client(parameters.get_admin("SERVER"), - int(parameters.get_admin("PORT")), - debug=False) - use_starttls = True if parameters.get_admin("STARTTLS") == "yes" \ - else False - authmech = parameters.get_admin("AUTHENTICATION_MECH") - if authmech == "AUTO": - authmech = None - try: - ret = self.msc.connect(user, password, use_starttls, authmech) - except Error: - ret = False - if not ret: - return False, _( - "Connection to MANAGESIEVE server failed, check your " - "configuration" - ) - return True, None - - def logout(self): - self.msc.logout() - self.msc = None - - def refresh(self, user, password): - import ssl - - if self.msc is not None: - try: - self.msc.capability() - except Error as e: - pass - else: - return - try: - ret, msg = self.login(user, password) - except (Error, ssl.SSLError) as e: - raise ConnectionError(e) - if not ret: - raise ConnectionError(msg) - - def listscripts(self): - return self.msc.listscripts() - - def getscript(self, name, format="raw"): - content = self.msc.getscript(name) - if content is None: - raise SieveClientError(self.msc.errmsg) - if format == "raw": - return content - p = Parser() - if not p.parse(content): - print "Parse error????" - return None - fs = FiltersSet(name) - fs.from_parser_result(p) - return fs - - def pushscript(self, name, content, active=False): - if isinstance(content, unicode): - content = content.encode("utf-8") - if not self.msc.havespace(name, len(content)): - error = "%s (%s)" % ( - _("Not enough space on server"), self.msc.errmsg) - raise SieveClientError(error) - if not self.msc.putscript(name, content): - raise SieveClientError(self.msc.errmsg) - if active and not self.msc.setactive(name): - raise SieveClientError(self.msc.errmsg) - - def deletescript(self, name): - if not self.msc.deletescript(name): - raise SieveClientError(self.msc.errmsg) - - def activatescript(self, name): - if not self.msc.setactive(name): - raise SieveClientError(self.msc.errmsg) diff --git a/modoboa/extensions/sievefilters/modo_extension.py b/modoboa/extensions/sievefilters/modo_extension.py deleted file mode 100644 index 0b4fe46ba..000000000 --- a/modoboa/extensions/sievefilters/modo_extension.py +++ /dev/null @@ -1,24 +0,0 @@ -# coding: utf-8 -"""Declare and register the sievefilters extension.""" - -from django.utils.translation import ugettext_lazy - -from modoboa.core.extensions import ModoExtension, exts_pool -from modoboa.lib import parameters - - -class SieveFilters(ModoExtension): - name = "sievefilters" - label = "Sieve filters" - version = "1.0" - description = ugettext_lazy("Plugin to easily create server-side filters") - url = "sfilters" - available_for_topredirection = True - - def load(self): - from .app_settings import ParametersForm, UserSettings - parameters.register(ParametersForm, ugettext_lazy("Sieve filters")) - parameters.register(UserSettings, ugettext_lazy("Message filters")) - from modoboa.extensions.sievefilters import general_callbacks - -exts_pool.register_extension(SieveFilters) diff --git a/modoboa/extensions/sievefilters/static/sievefilters/css/style.css b/modoboa/extensions/sievefilters/static/sievefilters/css/style.css deleted file mode 100644 index 6ff656c85..000000000 --- a/modoboa/extensions/sievefilters/static/sievefilters/css/style.css +++ /dev/null @@ -1,134 +0,0 @@ -.fset_container { - padding: 0 15px; -} - -#set_content textarea { - width: 100%; - height: 500px; -} - -#set_content label { - margin: 5px; -} - -#filters_list { - border-left: 1px solid #CCC; - position: absolute; - padding-left: 5px; - left: 190px; - right: 10px; - top: 0px; - bottom: 0px; -} - -#id_content { - width: 95% !important; - height: 270px; -} - -/* Filter form */ -#filterform { - margin: 7px; -} - -#filterform h2 { - margin: 0; - padding: 0; - font-size: 1em; - margin-top: 20px; -} - -#submit_container { - width: 100%; - position: absolute; - bottom: 5px; - text-align: center; -} - -#error { - white-space: pre-line; -} - -#addfilterlist { - background-color: #FAFAFA; - border: 1px solid #CCCCCC; - border-radius: 26px 26px 26px 26px; - padding: 14px 5px 5px; -} - -#matchtype { - font-size: 0.9em; -} - - -div.item { - margin-bottom: 10px; - margin-left: 5px; - overflow: auto; -} - -ul.errors { - list-style: none; - display: inline; - margin: 0; - padding: 0; -} - -.errors li { - color: red; - font-weight: bold; - font-size: 0.9em; - display: inline; -} - -.leftbox { - width: 155px; -} - -.leftbox h1 { - float: none !important; - padding: 0; - margin: 0; - font-size: 1.1em; -} - -.leftbox ul { - list-style: none; - padding: 5px 0 0 0; - margin: 0; -} - -.leftbox li { - margin: 5px 0; -} - -.leftbox a, .leftbox a:visited { - color: black; - text-decoration: none; -} - -.leftbox a:hover { - color: #6AB0C5; - text-decoration: none; -} - -.leftbox li.selected { - background-color: #FFFF77; -} - -.leftbox img { - float: left; - margin-right: 5px; -} - -a.green { - text-decoration: none; - font-weight: bold; - color: green; -} - -a.red { - text-decoration: none; - font-weight: bold; - color: red; -} \ No newline at end of file diff --git a/modoboa/extensions/sievefilters/static/sievefilters/js/jquery.dynfields.js b/modoboa/extensions/sievefilters/static/sievefilters/js/jquery.dynfields.js deleted file mode 100644 index 1b6c8a253..000000000 --- a/modoboa/extensions/sievefilters/static/sievefilters/js/jquery.dynfields.js +++ /dev/null @@ -1,339 +0,0 @@ -(function($) { - var DynamicCondition = function(element, options) { - this.$element = $(element); - this.options = $.extend({}, $.fn.dyncondition.defaults, options); - this.fields_cnt = 1; - this.nextid = 1; - - var $addlink = $('', { - href: '#', - id: this.$element.attr("id") + '_rmbtn', - html: '' - }); - $("select[name*=cond_target_]").change($.proxy(this.target_change, this)); - $addlink.click($.proxy(this.addfields, this)); - this.$element.append($addlink); - - for (var cpt = 1; true; cpt++) { - var $div = $("#condition_" + cpt); - - if (!$div.length) { - break; - } - $div.append(this.newrmlink()); - this.nextid++; - this.fields_cnt++; - } - }; - - DynamicCondition.prototype = { - constructor: DynamicCondition, - - loadoperators: function($container, tpl) { - $container.empty(); - for (var ocpt = 0; ocpt < tpl.operators.length; ocpt++) { - var $opt = $("", { - value: tpl["operators"][ocpt][0], - html: tpl["operators"][ocpt][1] - }); - - $container.append($opt); - } - }, - - removefields: function(e) { - var $link = $(e.target).parent(); - var id = $link.attr("id"); - - e.preventDefault(); - $("#" + id.replace("_rmbtn", "")).remove(); - this.fields_cnt--; - }, - - newrmlink: function() { - return $('', { - href: '#', - id: 'condition_' + this.nextid + '_rmbtn', - html: '' - }).click($.proxy(this.removefields, this)); - }, - - addfields: function(e) { - e.preventDefault(); - var $div = $("
", { - id: "condition_" + this.nextid, 'class': "item" - }); - var $condtarget = $("", { - id: "id_cond_target_" + this.nextid, - name: "cond_target_" + this.nextid, - class: "form-control element-inline-block" - }).change($.proxy(this.target_change, this)); - var $condoperator = $("", { - id: "id_cond_operator_" + this.nextid, - name: "cond_operator_" + this.nextid, - class: "form-control element-inline-block" - }); - var $condvalue = $("", { - id: "id_cond_value_" + this.nextid, - name: "cond_value_" + this.nextid, - type: "text", - class: "form-control element-inline-block" - }); - var $rmlink = this.newrmlink(); - - for (var cpt = 0; cpt < this.options.templates.length; cpt++) { - var tpl = this.options.templates[cpt]; - var $opt = $("", { - value: tpl.name, - html: tpl.label - }); - - $condtarget.append($opt); - if (tpl.name != this.options.defaultcond) { - continue; - } - this.loadoperators($condoperator, tpl); - } - - $div.append($condtarget, $condoperator, $condvalue, $rmlink); - $condtarget.wrap(''); - $condoperator.wrap(''); - $condvalue.wrap(''); - this.$element.after($div); - this.nextid++; - this.fields_cnt++; - }, - - target_change: function(e) { - var $target = $(e.target); - var parts = $target.attr("name").split("_"); - var $container = $("#id_cond_operator_" + parts[2]); - - for (var cpt = 0; cpt < this.options.templates.length; cpt++) { - var tpl = this.options.templates[cpt]; - - if (tpl.name != $target.val()) { - continue; - } - this.loadoperators($container, tpl); - break; - } - }, - - counter: function() { - return this.fields_cnt; - } - }; - - $.fn.dyncondition = function(method) { - return this.each(function() { - var $this = $(this), - data = $this.data('dyncondition'), - options = typeof method === "object" && method; - - if (!data) { - $this.data('dyncondition', new DynamicCondition(this, options)); - } - if (typeof method === "string") { - data[method](); - } - }); - }; - - $.fn.dyncondition.defaults = { - defaultcond: "Subject", - templates: [] - }; - -})(jQuery); - -/* - * Dynamic actions class - */ -(function($) { - var DynamicAction = function(element, options) { - this.$element = $(element); - this.options = $.extend({}, $.fn.dynaction.defaults, options); - this.nextid = 1; - this.fields_cnt = 1; - - var $addlink = $('', { - href: '#', - id: this.$element.attr("id") + '_rmbtn', - html: '' - }); - $("select[name*=action_name_]").change($.proxy(this.name_change, this)); - $addlink.click($.proxy(this.addfields, this)); - this.$element.append($addlink); - - for (var cpt = 1; true; cpt++) { - var $div = $("#action_" + cpt); - - if (!$div.length) { - break; - } - $div.append(this.newrmlink()); - this.nextid++; - this.fields_cnt++; - } - - $("#id_action_arg_0_0").find("option").each(function() { - var $this = $(this), - cpt = 1, - start = 0, - value = $this.val(); - - while (true) { - var id = value.indexOf(options.hdelimiter, start); - if (id == -1) { - break; - } - $this.css("margin-left", (cpt * 20) + "px"); - cpt++; - start = id + 1; - } - }); - - this.$fdoptions = $("#id_action_arg_0_0").find("option"); - }; - - DynamicAction.prototype = { - constructor: DynamicAction, - - loadargs: function(id, tpl) { - var res = []; - - for (var acpt = 0; acpt < tpl.args.length; acpt++) { - var argname = "action_arg_" + id + "_" + acpt; - var $child = null; - - if (tpl.args[acpt].type == "list") { - $child = $("", {id: "id_" + argname, name: argname, class: "form-control"}); - if (tpl.args[acpt].vloader != undefined) { - this[tpl.args[acpt].vloader]($child); - } - } else if (tpl.args[acpt].type == "string") { - $child = $("", { - type: "text", - id: "id_" + argname, - name: argname, - class: "form-control" - }); - } - res.push($child); - } - return res; - }, - - deletePrevArgs: function(id) { - for (var cpt = 0; true; cpt++) { - var $arg = $("#id_action_arg_" + id + "_" + cpt); - if (!$arg.length) { - break; - } - $arg.remove(); - } - }, - - name_change: function(e) { - var $target = $(e.target); - var parts = $target.attr("name").split("_"); - var $pos = $("#action_" + parts[2] + "_rmbtn"); - - e.preventDefault(); - this.deletePrevArgs(parts[2]); - for (var cpt = 0; cpt < this.options.templates.length; cpt++) { - var tpl = this.options.templates[cpt]; - if (tpl.name != $target.val()) { - continue; - } - $.each(this.loadargs(parts[2], tpl), function(idx, arg) { - $pos.before(arg); - }); - } - }, - - newrmlink: function() { - return $('', { - href: '#', - id: 'action_' + this.nextid + '_rmbtn', - html: '' - }).click($.proxy(this.removefields, this)); - }, - - addfields: function(e) { - e.preventDefault(); - var $div = $("", {id: "action_" + this.nextid, "class": "item"}); - var $actioname = $("", { - id: "id_action_name_" + this.nextid, - name: "action_name_" + this.nextid, - class: "form-control element-inline-block" - }); - var $rmlink = this.newrmlink(); - var args = null; - - for (var cpt = 0; cpt < this.options.templates.length; cpt++) { - var tpl = this.options.templates[cpt]; - var $opt = $("", { - value: tpl.name, - html: tpl.label - }); - - $actioname.append($opt); - if (tpl.name != this.options.defaultaction) { - continue; - } - args = this.loadargs(this.nextid, tpl); - } - $div.append($actioname); - $actioname.change($.proxy(this.name_change, this)); - $.each(args, function(idx, element) { - $div.append(element); - element.wrap(''); - }); - - $actioname.wrap(''); - $div.append($rmlink); - this.$element.after($div); - this.nextid++; - this.fields_cnt++; - }, - - removefields: function(e) { - var $link = $(e.target).parent(); - var id = $link.attr("id"); - - e.preventDefault(); - $("#" + id.replace("_rmbtn", "")).remove(); - this.fields_cnt--; - }, - - userfolders: function($container) { - this.$fdoptions.each(function() { - $container.append($(this).clone()); - }); - } - - }; - - $.fn.dynaction = function(method) { - return this.each(function() { - var $this = $(this), - data = $this.data('dynaction'), - options = typeof method === "object" && method; - - if (!data) { - $this.data('dynaction', new DynamicAction(this, options)); - } - if (typeof method === "string") { - data[method](); - } - }); - }; - - $.fn.dynaction.defaults = { - defaultaction: "fileinto", - hdelimiter: '.', - templates: [] - }; -})(jQuery); \ No newline at end of file diff --git a/modoboa/extensions/sievefilters/static/sievefilters/js/lib.js b/modoboa/extensions/sievefilters/static/sievefilters/js/lib.js deleted file mode 100644 index 9edd81f62..000000000 --- a/modoboa/extensions/sievefilters/static/sievefilters/js/lib.js +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Plugin : "Sieve filters" - * - * Javascript utilities - */ -var curscript = null; - -/* - * Remove a filter from a filters set. - * - */ -function removefilter(evt) { - evt.preventDefault(); - if (!confirm(gettext("Remove this filter?"))) { - return; - } - var $this = $(this); - - $.ajax({ - url: $this.attr("href"), - dataType: 'json' - }).done(function(response) { - histomanager.update(true); - $("body").notify('success', response, 2000); - }); -} - -/* - * Handler listening for the "change" event on the filters sets list. - */ -function changefs(evt) { - evt.preventDefault(); - histomanager.baseurl($(this).val()).update(); -} - -/* - * Initializes buttons located inside the filters list - */ -function init_filters_list() { - $("a[name=togglestate]").click(toggle_filter_state); - $("a[name*=movefilter_]").click(move_filter); - $("a[name=removefilter]").click(removefilter); -} - -/* - * Function called just after a new filters set has been loaded. - * - * It updates the middle DIV and initializes the user interface. - */ -function loadfs(response) { - curscript = histomanager.getbaseurl(); - $("#curfset").val(curscript); - $("#set_content").html(response.content); - - if ($("#filters_list") != undefined) { - init_filters_list(); - } - if ($("#fsetmenu").length) { - $("#fsetmenu").remove(); - } - $("#menu").after($(response.menu)); - $("a[name=activatefs]").click(activatefs); - $("a[name=savefs]").click(savefs); - $("a[name=removefs]").click(removefs); -} - -/* - * Common function to send a command that manipulates a filters set. - * - * (remove, activate) - */ -function send_command(cmd, extracb) { - $.ajax({ - url: cmd, - dataType: 'json' - }).done(function(response) { - if (extracb != undefined) { - extracb(response); - } - if (!response.norefresh) { - histomanager.update(true); - } - $("body").notify('success', response.respmsg, 2000); - }); -} - -/* - * Common utility used by filters set manipulation functions to - * validate any new asked action. (activate, save, remove) - */ -function check_prereqs(evt, msg) { - evt.preventDefault(); - if (!curscript) { - return false; - } - if (msg != undefined && !confirm(msg)) { - return false; - } - return true; -} - -/* - * Save the current filters set by applying the modifications to the - * server. - */ -function savefs(evt) { - if (!check_prereqs(evt, gettext("Save changes?"))) { - return; - } - var $editor = $("#feditor"); - - $.ajax({ - url: $editor.attr("action"), - type: $editor.attr("method"), - dataType: 'json', - data: $editor.serialize() - }).done(function(response) { - $("body").notify('success', response.respmsg, 2000); - }); -} - -/* - * Remove the current filters set. - * - * On success, the user will be automatically redirected to the active - * filters set. - */ -function removefs(evt) { - if (!check_prereqs(evt, gettext("Remove filters set?"))) { - return; - } - send_command($(this).attr("href"), function(response) { - var $curfset = $("#curfset"); - - $curfset.find("option[value='" + curscript + "']").remove(); - histomanager.baseurl(response.newfs, 1); - }); -} - -/* - * Activate the current filters set. - */ -function activatefs(evt) { - var $this = $(this); - - if (!check_prereqs(evt, gettext("Activate this filters set?"))) { - return; - } - send_command($this.attr("href"), function(response) { - $("#curfset").find("option").each(function(index, element) { - var $element = $(element); - - ($element.val() == curscript) - ? $element.html(curscript + " (" + gettext("active") + ")") - : $element.html($element.val()); - }); - }); -} - -/* - * Enable/Disable a specific filter - */ -function toggle_filter_state(event) { - var $this = $(this); - - event.preventDefault(); - $.ajax({ - url: $this.attr("href"), - dataType: 'json' - }).done(function(response) { - $this.html(response.label); - $this.attr("class", ""); - $this.addClass(response.color); - }); -} - -function move_filter(event) { - var $this = $(this); - - event.preventDefault(); - $.ajax({ - url: $this.attr('href'), - dataType: 'json' - }).done(function(response) { - $("#set_content").html(response.content); - init_filters_list(); - }); -} - -function filterset_created(data) { - var name = data.url; - var option = $(''); - var curfset = $(parent.document).find("#curfset"); - - curfset.append(option); - curfset.val(name); - - if (data.active) { - curfset.find("option").each(function(index, element) { - var $element = $(element); - - if ($element.val() == name) { - $element.html(name + " (" + gettext("active") + ")"); - } else { - $element.html($element.val()); - } - }); - } - histomanager.baseurl(data.url, 1).update(1); -} - -function filtersetform_cb() { - $("#newfiltersset").find("input").keypress(function(e) { - if (e.which == 13) e.preventDefault(); - }); - $(".submit").on('click', function(e) { - simple_ajax_form_post(e, { - formid: "newfiltersset", - reload_on_success: false, - success_cb: filterset_created - }); - }); -} - -/* - * From here: specific functions used by the user-friendly form to - * create/edit filters. - */ -function fetch_templates(url, container) { - if (container) { - return container; - } - var result; - - $.ajax({ - url: url, - async: false, - dataType: 'json' - }).done(function(data) { - result = data; - }); - return result; -} diff --git a/modoboa/extensions/sievefilters/templates/sievefilters/filter.html b/modoboa/extensions/sievefilters/templates/sievefilters/filter.html deleted file mode 100644 index e0476c0b4..000000000 --- a/modoboa/extensions/sievefilters/templates/sievefilters/filter.html +++ /dev/null @@ -1,26 +0,0 @@ -{% extends "common/generic_modal_form.html" %} -{% load i18n form_tags sfilters_tags %} - -{% block modal_css_classes %}modal-lg{% endblock %} - -{% block formbody %} - {% if oldname %}{% endif %} - {% render_field form.name %} -| {% trans "Actions" %} | -{% trans "Name" %} | -{% trans "Active" %} | -
|---|---|---|
| {% filter_actions fs.name filter forloop.counter forloop.last %} | -{{ filter.name }} | -- - {{ filter.enabled|yesno }} - - | -