diff --git a/modoboa/extensions/admin/lib.py b/modoboa/extensions/admin/lib.py index d84a998d4..db945437e 100644 --- a/modoboa/extensions/admin/lib.py +++ b/modoboa/extensions/admin/lib.py @@ -2,11 +2,10 @@ from functools import wraps from itertools import chain from django.db.models import Q -from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.contrib.contenttypes.models import ContentType from django.utils.translation import ugettext as _ from modoboa.core.models import User -from modoboa.lib import parameters, events +from modoboa.lib import events from modoboa.lib.exceptions import PermDeniedException from modoboa.lib.emailutils import split_mailbox from modoboa.extensions.admin.models import ( @@ -30,46 +29,6 @@ def needs_mailbox(): return decorator -def get_sort_order(qdict, default, allowed_values=None): - """Return a sort order from a querydict object - - :param QueryDict qdict: the object to analyse - :param string default: the default sort order if no one is found - :param list allowed_values: an optional list of allowed values - :return: a 2uple of strings - """ - sort_order = qdict.get("sort_order", default) - if sort_order.startswith("-"): - sort_dir = "-" - sort_order = sort_order[1:] - else: - sort_dir = "" - if allowed_values is not None and not sort_order in allowed_values: - return (default, "") - return (sort_order, sort_dir) - - -def get_listing_page(objects, pagenum): - """Return specific a listing page. - - A page contains a limited number of elements (see - ITEMS_PER_PAGE). If the given page number is wrong, the first page - will be always returned. - - :param list objects: object list to paginate - :param int pagenum: page number - :return: a ``Page`` object - """ - paginator = Paginator( - objects, int(parameters.get_admin("ITEMS_PER_PAGE", app="core")) - ) - try: - page = paginator.page(int(pagenum)) - except (EmptyPage, PageNotAnInteger, ValueError): - page = paginator.page(paginator.num_pages) - return page - - def get_identities(user, searchquery=None, idtfilter=None, grpfilter=None): """Return all the identities owned by a user. diff --git a/modoboa/extensions/admin/static/admin/js/admin.js b/modoboa/extensions/admin/static/admin/js/admin.js index 04a89070e..60abd75ab 100644 --- a/modoboa/extensions/admin/static/admin/js/admin.js +++ b/modoboa/extensions/admin/static/admin/js/admin.js @@ -6,7 +6,7 @@ var Admin = function(options) { Listing.call(this, options); }; - + Admin.prototype = { defaults: { deflocation: "list/", @@ -17,7 +17,6 @@ Admin.prototype = { Listing.prototype.initialize.call(this, options); this.options = $.extend({}, this.defaults, this.options); this.options.defcallback = $.proxy(this.list_cb, this); - this.tag_handlers = {}; this.navobj = new History(this.options); @@ -50,54 +49,6 @@ Admin.prototype = { $("#searchform").submit($.proxy(this.do_search, this)); }, - register_tag_handler: function(name, handler) { - this.tag_handlers[name] = handler; - if (this.navobj.getparam(name + "filter") !== undefined) { - var text = this.navobj.getparam(name + "filter"); - $("#searchform").parent().after(this.make_tag(text, name)); - } - }, - - generic_tag_handler: function(tag, $link) { - if (this.navobj.getparam(tag + "filter") === undefined && $link.hasClass(tag)) { - var text = $link.attr("name"); - this.navobj.setparam(tag + "filter", text).update(); - $("#searchform").parent().after(this.make_tag(text, tag)); - return true; - } - return false; - }, - - make_tag: function(text, type) { - var $tag = $("", {"name": type, "class" : "btn btn-mini", "html": text}); - var $i = $("", {"class" : "icon-remove"}).prependTo($tag); - - $tag.click($.proxy(this.remove_tag, this)); - return $tag; - }, - - remove_tag: function(e) { - var $tag = $(e.target); - - if ($tag.is("i")) { - $tag = $tag.parent(); - } - e.preventDefault(); - this.navobj.delparam($tag.attr("name") + "filter").update(); - $tag.remove(); - }, - - filter_by_tag: function(e) { - var $link = $(e.target); - e.preventDefault(); - - for (var name in this.tag_handlers) { - if (this.tag_handlers[name].apply(this, [name, $link])) { - break; - } - } - }, - do_search: function(e) { e.preventDefault(); var squery = $("#searchquery").val(); diff --git a/modoboa/extensions/admin/views/domain.py b/modoboa/extensions/admin/views/domain.py index d7bd53ddb..d9afec638 100644 --- a/modoboa/extensions/admin/views/domain.py +++ b/modoboa/extensions/admin/views/domain.py @@ -16,7 +16,7 @@ from modoboa.lib.exceptions import ( PermDeniedException ) from modoboa.lib.templatetags.lib_tags import pagination_bar -from modoboa.extensions.admin.lib import get_sort_order, get_listing_page +from modoboa.lib.listing import get_sort_order, get_listing_page from modoboa.extensions.admin.models import Domain, Mailbox from modoboa.extensions.admin.forms import ( DomainForm diff --git a/modoboa/extensions/admin/views/identity.py b/modoboa/extensions/admin/views/identity.py index b97cf7e37..5ac0316b3 100644 --- a/modoboa/extensions/admin/views/identity.py +++ b/modoboa/extensions/admin/views/identity.py @@ -16,9 +16,10 @@ from modoboa.lib.webutils import ( from modoboa.lib.templatetags.lib_tags import pagination_bar from modoboa.core.models import User from modoboa.extensions.admin.models import Mailbox, Domain -from modoboa.extensions.admin.lib import ( - get_sort_order, get_listing_page, get_identities +from modoboa.lib.listing import ( + get_sort_order, get_listing_page ) +from modoboa.extensions.admin.lib import get_identities from modoboa.extensions.admin.forms import ( AccountForm ) diff --git a/modoboa/extensions/radicale/forms.py b/modoboa/extensions/radicale/forms.py index 51ee4fc21..a51a43ea4 100644 --- a/modoboa/extensions/radicale/forms.py +++ b/modoboa/extensions/radicale/forms.py @@ -6,7 +6,7 @@ from django.core.urlresolvers import reverse from django.utils.translation import ugettext as _, ugettext_lazy from modoboa.lib.webutils import render_to_json_response from modoboa.lib.formutils import WizardForm, TabForms, DynamicForm -from modoboa.extensions.admin.models import Domain +from modoboa.extensions.admin.models import Domain, Mailbox from modoboa.extensions.radicale.models import UserCalendar, SharedCalendar @@ -16,7 +16,24 @@ class UserCalendarForm(forms.ModelForm): """ class Meta: model = UserCalendar - fields = ('name', ) + fields = ('name', 'mailbox', ) + widgets = { + 'mailbox': forms.widgets.Select( + attrs={"class": "selectpicker", "data-live-search": "true"} + ) + } + + def __init__(self, user, *args, **kwargs): + """Custom constructor. + + We need the current user to filter the mailbox list. + """ + super(UserCalendarForm, self).__init__(*args, **kwargs) + if user.group == 'SimpleUsers': + del self.fields['mailbox'] + else: + self.fields['mailbox'].queryset = \ + Mailbox.objects.get_for_admin(user) class SharedCalendarForm(forms.ModelForm): @@ -25,6 +42,11 @@ class SharedCalendarForm(forms.ModelForm): """ class Meta: model = SharedCalendar + widgets = { + "domain": forms.widgets.Select( + attrs={"class": "selectpicker", "data-live-search": "true"} + ) + } def __init__(self, user, *args, **kwargs): """Custom constructor. @@ -127,9 +149,9 @@ class UserCalendarWizard(WizardForm): """ def __init__(self, request): super(UserCalendarWizard, self).__init__(request) - self.add_step(UserCalendarForm, _("General")) + self.add_step(UserCalendarForm, _("General"), new_args=[request.user]) self.add_step( - RightsForm, _("Rights"), formtpl="radicale/rightsform.html" + RightsForm, _("Rights"), formtpl="radicale/rightsform.html", ) def extra_context(self, context): @@ -141,7 +163,8 @@ class UserCalendarWizard(WizardForm): def done(self): calendar = self.first_step.form.save(commit=False) - calendar.mailbox = self.request.user.mailbox_set.all()[0] + if self.request.user.group == 'SimpleUsers': + calendar.mailbox = self.request.user.mailbox_set.all()[0] calendar.save() self.steps[1].form.calendar = calendar self.steps[1].form.save() @@ -151,13 +174,14 @@ class UserCalendarWizard(WizardForm): class UserCalendarEditionForm(TabForms): """User calendar edition form. """ - def __init__(self, *args, **kwargs): + def __init__(self, request, *args, **kwargs): self.forms = [] self.forms.append({ "id": "general", "title": _("General"), "cls": UserCalendarForm, - "mandatory": True + "mandatory": True, + "new_args": [request.user] }) self.forms.append({ "id": "rights", @@ -166,7 +190,7 @@ class UserCalendarEditionForm(TabForms): "formtpl": "radicale/rightsform.html", "mandatory": True }) - super(UserCalendarEditionForm, self).__init__(*args, **kwargs) + super(UserCalendarEditionForm, self).__init__(request, *args, **kwargs) def extra_context(self, context): calendar = self.instances["general"] diff --git a/modoboa/extensions/radicale/models.py b/modoboa/extensions/radicale/models.py index 2a6625de0..818c7b182 100644 --- a/modoboa/extensions/radicale/models.py +++ b/modoboa/extensions/radicale/models.py @@ -27,8 +27,8 @@ class Calendar(models.Model): raise NotImplementedError @property - def type(self): - """Return calendar type""" + def tags(self): + """Return calendar tags""" raise NotImplementedError @property @@ -72,8 +72,8 @@ class UserCalendar(Calendar): ) @property - def type(self): - return _("user") + def tags(self): + return [{"name": "user", "label": _("User"), "type": "cal"}] @property def owner(self): @@ -115,8 +115,9 @@ class SharedCalendar(Calendar): ) @property - def type(self): - return _("shared") + def tags(self): + return [{"name": "shared", "label": _("Shared"), "type": "cal"}] + @property def owner(self): diff --git a/modoboa/extensions/radicale/static/radicale/css/radicale.css b/modoboa/extensions/radicale/static/radicale/css/radicale.css index 000967846..d8daf5408 100644 --- a/modoboa/extensions/radicale/static/radicale/css/radicale.css +++ b/modoboa/extensions/radicale/static/radicale/css/radicale.css @@ -1,3 +1,7 @@ +#searchform { + margin-bottom: 10px; +} + #original_row { margin-left: 100px; } diff --git a/modoboa/extensions/radicale/static/radicale/js/radicale.js b/modoboa/extensions/radicale/static/radicale/js/radicale.js index c04595fdd..19c4fb157 100644 --- a/modoboa/extensions/radicale/static/radicale/js/radicale.js +++ b/modoboa/extensions/radicale/static/radicale/js/radicale.js @@ -18,6 +18,7 @@ Radicale.prototype = { this.options = $.extend({}, this.defaults, this.options); this.options.defcallback = $.proxy(this.list_cb, this); this.navobj = new History(this.options); + this.register_tag_handler("cal", this.generic_tag_handler); $(document).on( "click", "a[name=delcalendar]", $.proxy(this.del_calendar, this) ); diff --git a/modoboa/extensions/radicale/templates/radicale/calendar_list.html b/modoboa/extensions/radicale/templates/radicale/calendar_list.html index 219704a07..3d87ac0b6 100644 --- a/modoboa/extensions/radicale/templates/radicale/calendar_list.html +++ b/modoboa/extensions/radicale/templates/radicale/calendar_list.html @@ -3,8 +3,8 @@ {% trans "Name" %} - {% if with_owner %}{% trans "Owner" %}{% endif %} - {% trans "Type" %} + {% if with_owner %}{% trans "Owner" %}{% endif %} + {% trans "Tags" %} {% trans "Address" %} {% trans "Actions" %} @@ -14,9 +14,7 @@ {% calendar_modify_link cal %} {% if with_owner %}{{ cal.owner }}{% endif %} - - {{ cal.type }} - + {% render_tags cal.tags %} {{ cal.url }} {% calendar_actions cal %} diff --git a/modoboa/extensions/radicale/templates/radicale/calendars.html b/modoboa/extensions/radicale/templates/radicale/calendars.html index e554951cc..adf3a49cb 100644 --- a/modoboa/extensions/radicale/templates/radicale/calendars.html +++ b/modoboa/extensions/radicale/templates/radicale/calendars.html @@ -1,5 +1,6 @@ {% extends "twocols.html" %}{% load i18n radicale_tags %} {% block html_head %} + @@ -20,7 +21,6 @@ $(document).ready(function() { {% trans "Filter" %} {% include "admin/searchform.html" %} - {% trans "Actions" %} {% radicale_left_menu user %} diff --git a/modoboa/extensions/radicale/templates/radicale/user_calendar.html b/modoboa/extensions/radicale/templates/radicale/user_calendar.html deleted file mode 100644 index 834b93244..000000000 --- a/modoboa/extensions/radicale/templates/radicale/user_calendar.html +++ /dev/null @@ -1,4 +0,0 @@ -{% extends "common/generic_modal_form.html" %}{% load crispy_forms_tags %} -{% block formbody %} -{{ form|crispy }} -{% endblock %} diff --git a/modoboa/extensions/radicale/views.py b/modoboa/extensions/radicale/views.py index b97031814..0decb55e9 100644 --- a/modoboa/extensions/radicale/views.py +++ b/modoboa/extensions/radicale/views.py @@ -10,10 +10,12 @@ from django.contrib.auth.decorators import ( ) from django.utils.translation import ugettext as _ +from modoboa.lib.listing import get_sort_order from modoboa.lib.webutils import ( _render_to_string, render_to_json_response ) from modoboa.lib.exceptions import NotFound, PermDeniedException + from modoboa.extensions.radicale.forms import ( UserCalendarWizard, SharedCalendarForm, UserCalendarEditionForm ) @@ -33,16 +35,24 @@ def calendars(request, tplname="radicale/calendar_list.html"): The content depends on current user's role. """ + sort_order, sort_dir = get_sort_order(request.GET, "name") + calfilter = request.GET.get("calfilter", None) if request.user.group == "SimpleUsers": mbox = request.user.mailbox_set.all()[0] cals = UserCalendar.objects.filter(mailbox=mbox).select_related().all() with_owner = False else: - cals = chain( - UserCalendar.objects.get_for_admin(request.user), - SharedCalendar.objects.get_for_admin(request.user) - ) + ucals = [] + if calfilter is None or calfilter == "user": + ucals = UserCalendar.objects.get_for_admin(request.user) + scals = [] + if calfilter is None or calfilter == "shared": + scals = SharedCalendar.objects.get_for_admin(request.user) + cals = chain(ucals, scals) with_owner = True + cals = sorted( + cals, key=lambda c: getattr(c, sort_order), reverse=sort_dir == '-' + ) return render_to_json_response({ "table": _render_to_string(request, tplname, { "calendars": cals, "with_owner": with_owner diff --git a/modoboa/lib/listing.py b/modoboa/lib/listing.py index 9d1b0a38e..f8abb12dc 100644 --- a/modoboa/lib/listing.py +++ b/modoboa/lib/listing.py @@ -22,7 +22,19 @@ def get_sort_order(qdict, default, allowed_values=None): def get_listing_page(objects, pagenum): - paginator = Paginator(objects, int(parameters.get_admin("ITEMS_PER_PAGE", app="core"))) + """Return specific a listing page. + + A page contains a limited number of elements (see + ITEMS_PER_PAGE). If the given page number is wrong, the first page + will be always returned. + + :param list objects: object list to paginate + :param int pagenum: page number + :return: a ``Page`` object + """ + paginator = Paginator( + objects, int(parameters.get_admin("ITEMS_PER_PAGE", app="core")) + ) try: page = paginator.page(int(pagenum)) except (EmptyPage, PageNotAnInteger, ValueError): diff --git a/modoboa/static/css/bootstrap-select.min.css b/modoboa/static/css/bootstrap-select.min.css new file mode 100644 index 000000000..edb090cad --- /dev/null +++ b/modoboa/static/css/bootstrap-select.min.css @@ -0,0 +1,7 @@ +/*! + * bootstrap-select v1.5.4 + * http://silviomoreto.github.io/bootstrap-select/ + * + * Copyright 2013 bootstrap-select + * Licensed under the MIT license + */.bootstrap-select.btn-group:not(.input-group-btn),.bootstrap-select.btn-group[class*="span"]{float:none;display:inline-block;margin-bottom:10px;margin-left:0}.form-search .bootstrap-select.btn-group,.form-inline .bootstrap-select.btn-group,.form-horizontal .bootstrap-select.btn-group{margin-bottom:0}.bootstrap-select.form-control{margin-bottom:0;padding:0;border:0}.bootstrap-select.btn-group.pull-right,.bootstrap-select.btn-group[class*="span"].pull-right,.row-fluid .bootstrap-select.btn-group[class*="span"].pull-right{float:right}.input-append .bootstrap-select.btn-group{margin-left:-1px}.input-prepend .bootstrap-select.btn-group{margin-right:-1px}.bootstrap-select:not([class*="span"]):not([class*="col-"]):not([class*="form-control"]):not(.input-group-btn){width:220px}.bootstrap-select{width:220px\0}.bootstrap-select.form-control:not([class*="span"]){width:100%}.bootstrap-select>.btn{width:100%;padding-right:25px}.error .bootstrap-select .btn{border:1px solid #b94a48}.bootstrap-select.show-menu-arrow.open>.btn{z-index:2051}.bootstrap-select .btn:focus{outline:thin dotted #333 !important;outline:5px auto -webkit-focus-ring-color !important;outline-offset:-2px}.bootstrap-select.btn-group .btn .filter-option{display:inline-block;overflow:hidden;width:100%;float:left;text-align:left}.bootstrap-select.btn-group .btn .caret{position:absolute;top:50%;right:12px;margin-top:-2px;vertical-align:middle}.bootstrap-select.btn-group>.disabled,.bootstrap-select.btn-group .dropdown-menu li.disabled>a{cursor:not-allowed}.bootstrap-select.btn-group>.disabled:focus{outline:none !important}.bootstrap-select.btn-group[class*="span"] .btn{width:100%}.bootstrap-select.btn-group .dropdown-menu{min-width:100%;z-index:2000;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.bootstrap-select.btn-group .dropdown-menu.inner{position:static;border:0;padding:0;margin:0;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0;-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.bootstrap-select.btn-group .dropdown-menu dt{display:block;padding:3px 20px;cursor:default}.bootstrap-select.btn-group .div-contain{overflow:hidden}.bootstrap-select.btn-group .dropdown-menu li{position:relative}.bootstrap-select.btn-group .dropdown-menu li>a.opt{position:relative;padding-left:35px}.bootstrap-select.btn-group .dropdown-menu li>a{cursor:pointer}.bootstrap-select.btn-group .dropdown-menu li>dt small{font-weight:normal}.bootstrap-select.btn-group.show-tick .dropdown-menu li.selected a i.check-mark{position:absolute;display:inline-block;right:15px;margin-top:2.5px}.bootstrap-select.btn-group .dropdown-menu li a i.check-mark{display:none}.bootstrap-select.btn-group.show-tick .dropdown-menu li a span.text{margin-right:34px}.bootstrap-select.btn-group .dropdown-menu li small{padding-left:.5em}.bootstrap-select.btn-group .dropdown-menu li:not(.disabled)>a:hover small,.bootstrap-select.btn-group .dropdown-menu li:not(.disabled)>a:focus small,.bootstrap-select.btn-group .dropdown-menu li.active:not(.disabled)>a small{color:#64b1d8;color:rgba(255,255,255,0.4)}.bootstrap-select.btn-group .dropdown-menu li>dt small{font-weight:normal}.bootstrap-select.show-menu-arrow .dropdown-toggle:before{content:'';display:inline-block;border-left:7px solid transparent;border-right:7px solid transparent;border-bottom:7px solid #CCC;border-bottom-color:rgba(0,0,0,0.2);position:absolute;bottom:-4px;left:9px;display:none}.bootstrap-select.show-menu-arrow .dropdown-toggle:after{content:'';display:inline-block;border-left:6px solid transparent;border-right:6px solid transparent;border-bottom:6px solid white;position:absolute;bottom:-4px;left:10px;display:none}.bootstrap-select.show-menu-arrow.dropup .dropdown-toggle:before{bottom:auto;top:-3px;border-top:7px solid #ccc;border-bottom:0;border-top-color:rgba(0,0,0,0.2)}.bootstrap-select.show-menu-arrow.dropup .dropdown-toggle:after{bottom:auto;top:-3px;border-top:6px solid #fff;border-bottom:0}.bootstrap-select.show-menu-arrow.pull-right .dropdown-toggle:before{right:12px;left:auto}.bootstrap-select.show-menu-arrow.pull-right .dropdown-toggle:after{right:13px;left:auto}.bootstrap-select.show-menu-arrow.open>.dropdown-toggle:before,.bootstrap-select.show-menu-arrow.open>.dropdown-toggle:after{display:block}.bootstrap-select.btn-group .no-results{padding:3px;background:#f5f5f5;margin:0 5px}.bootstrap-select.btn-group .dropdown-menu .notify{position:absolute;bottom:5px;width:96%;margin:0 2%;min-height:26px;padding:3px 5px;background:#f5f5f5;border:1px solid #e3e3e3;box-shadow:inset 0 1px 1px rgba(0,0,0,0.05);pointer-events:none;opacity:.9;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.mobile-device{position:absolute;top:0;left:0;display:block !important;width:100%;height:100% !important;opacity:0}.bootstrap-select.fit-width{width:auto !important}.bootstrap-select.btn-group.fit-width .btn .filter-option{position:static}.bootstrap-select.btn-group.fit-width .btn .caret{position:static;top:auto;margin-top:-1px}.control-group.error .bootstrap-select .dropdown-toggle{border-color:#b94a48}.bootstrap-select-searchbox,.bootstrap-select .bs-actionsbox{padding:4px 8px}.bootstrap-select .bs-actionsbox{float:left;width:100%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.bootstrap-select-searchbox+.bs-actionsbox{padding:0 8px 4px}.bootstrap-select-searchbox input{margin-bottom:0}.bootstrap-select .bs-actionsbox .btn-group button{width:50%} \ No newline at end of file diff --git a/modoboa/static/js/bootstrap-select.min.js b/modoboa/static/js/bootstrap-select.min.js new file mode 100644 index 000000000..3cfa7862f --- /dev/null +++ b/modoboa/static/js/bootstrap-select.min.js @@ -0,0 +1,8 @@ +/*! + * bootstrap-select v1.5.4 + * http://silviomoreto.github.io/bootstrap-select/ + * + * Copyright 2013 bootstrap-select + * Licensed under the MIT license + */ +;!function(b){b.expr[":"].icontains=function(e,c,d){return b(e).text().toUpperCase().indexOf(d[3].toUpperCase())>=0};var a=function(d,c,f){if(f){f.stopPropagation();f.preventDefault()}this.$element=b(d);this.$newElement=null;this.$button=null;this.$menu=null;this.$lis=null;this.options=b.extend({},b.fn.selectpicker.defaults,this.$element.data(),typeof c=="object"&&c);if(this.options.title===null){this.options.title=this.$element.attr("title")}this.val=a.prototype.val;this.render=a.prototype.render;this.refresh=a.prototype.refresh;this.setStyle=a.prototype.setStyle;this.selectAll=a.prototype.selectAll;this.deselectAll=a.prototype.deselectAll;this.init()};a.prototype={constructor:a,init:function(){var c=this,d=this.$element.attr("id");this.$element.hide();this.multiple=this.$element.prop("multiple");this.autofocus=this.$element.prop("autofocus");this.$newElement=this.createView();this.$element.after(this.$newElement);this.$menu=this.$newElement.find("> .dropdown-menu");this.$button=this.$newElement.find("> button");this.$searchbox=this.$newElement.find("input");if(d!==undefined){this.$button.attr("data-id",d);b('label[for="'+d+'"]').click(function(f){f.preventDefault();c.$button.focus()})}this.checkDisabled();this.clickListener();if(this.options.liveSearch){this.liveSearchListener()}this.render();this.liHeight();this.setStyle();this.setWidth();if(this.options.container){this.selectPosition()}this.$menu.data("this",this);this.$newElement.data("this",this)},createDropdown:function(){var c=this.multiple?" show-tick":"";var d=this.$element.parent().hasClass("input-group")?" input-group-btn":"";var i=this.autofocus?" autofocus":"";var h=this.options.header?'×'+this.options.header+"":"";var g=this.options.liveSearch?'':"";var f=this.options.actionsBox?'Select AllDeselect All':"";var e=' '+h+g+f+'';return b(e)},createView:function(){var c=this.createDropdown();var d=this.createLi();c.find("ul").append(d);return c},reloadLi:function(){this.destroyLi();var c=this.createLi();this.$menu.find("ul").append(c)},destroyLi:function(){this.$menu.find("li").remove()},createLi:function(){var d=this,e=[],c="";this.$element.find("option").each(function(){var i=b(this);var g=i.attr("class")||"";var h=i.attr("style")||"";var m=i.data("content")?i.data("content"):i.html();var k=i.data("subtext")!==undefined?''+i.data("subtext")+"":"";var j=i.data("icon")!==undefined?' ':"";if(j!==""&&(i.is(":disabled")||i.parent().is(":disabled"))){j=""+j+""}if(!i.data("content")){m=j+''+m+k+""}if(d.options.hideDisabled&&(i.is(":disabled")||i.parent().is(":disabled"))){e.push('')}else{if(i.parent().is("optgroup")&&i.data("divider")!==true){if(i.index()===0){var l=i.parent().attr("label");var n=i.parent().data("subtext")!==undefined?''+i.parent().data("subtext")+"":"";var f=i.parent().data("icon")?' ':"";l=f+''+l+n+"";if(i[0].index!==0){e.push(''+l+""+d.createA(m,"opt "+g,h))}else{e.push(""+l+""+d.createA(m,"opt "+g,h))}}else{e.push(d.createA(m,"opt "+g,h))}}else{if(i.data("divider")===true){e.push('')}else{if(b(this).data("hidden")===true){e.push("")}else{e.push(d.createA(m,g,h))}}}}});b.each(e,function(g,h){var f=h===""?'class="hide is-hidden"':"";c+='"+h+""});if(!this.multiple&&this.$element.find("option:selected").length===0&&!this.options.title){this.$element.find("option").eq(0).prop("selected",true).attr("selected","selected")}return b(c)},createA:function(e,c,d){return''+e+''},render:function(e){var d=this;if(e!==false){this.$element.find("option").each(function(i){d.setDisabled(i,b(this).is(":disabled")||b(this).parent().is(":disabled"));d.setSelected(i,b(this).is(":selected"))})}this.tabIndex();var h=this.$element.find("option:selected").map(function(){var k=b(this);var j=k.data("icon")&&d.options.showIcon?' ':"";var i;if(d.options.showSubtext&&k.attr("data-subtext")&&!d.multiple){i=' '+k.data("subtext")+""}else{i=""}if(k.data("content")&&d.options.showContent){return k.data("content")}else{if(k.attr("title")!==undefined){return k.attr("title")}else{return j+k.html()+i}}}).toArray();var g=!this.multiple?h[0]:h.join(this.options.multipleSeparator);if(this.multiple&&this.options.selectedTextFormat.indexOf("count")>-1){var c=this.options.selectedTextFormat.split(">");var f=this.options.hideDisabled?":not([disabled])":"";if((c.length>1&&h.length>c[1])||(c.length==1&&h.length>=2)){g=this.options.countSelectedText.replace("{0}",h.length).replace("{1}",this.$element.find('option:not([data-divider="true"]):not([data-hidden="true"])'+f).length)}}this.options.title=this.$element.attr("title");if(!g){g=this.options.title!==undefined?this.options.title:this.options.noneSelectedText}this.$button.attr("title",b.trim(g));this.$newElement.find(".filter-option").html(g)},setStyle:function(e,d){if(this.$element.attr("class")){this.$newElement.addClass(this.$element.attr("class").replace(/selectpicker|mobile-device/gi,""))}var c=e?e:this.options.style;if(d=="add"){this.$button.addClass(c)}else{if(d=="remove"){this.$button.removeClass(c)}else{this.$button.removeClass(this.options.style);this.$button.addClass(c)}}},liHeight:function(){if(this.options.size===false){return}var f=this.$menu.parent().clone().find("> .dropdown-toggle").prop("autofocus",false).end().appendTo("body"),g=f.addClass("open").find("> .dropdown-menu"),e=g.find("li > a").outerHeight(),d=this.options.header?g.find(".popover-title").outerHeight():0,h=this.options.liveSearch?g.find(".bootstrap-select-searchbox").outerHeight():0,c=this.options.actionsBox?g.find(".bs-actionsbox").outerHeight():0;f.remove();this.$newElement.data("liHeight",e).data("headerHeight",d).data("searchHeight",h).data("actionsHeight",c)},setSize:function(){var i=this,d=this.$menu,j=d.find(".inner"),u=this.$newElement.outerHeight(),f=this.$newElement.data("liHeight"),s=this.$newElement.data("headerHeight"),m=this.$newElement.data("searchHeight"),h=this.$newElement.data("actionsHeight"),l=d.find("li .divider").outerHeight(true),r=parseInt(d.css("padding-top"))+parseInt(d.css("padding-bottom"))+parseInt(d.css("border-top-width"))+parseInt(d.css("border-bottom-width")),p=this.options.hideDisabled?":not(.disabled)":"",o=b(window),g=r+parseInt(d.css("margin-top"))+parseInt(d.css("margin-bottom"))+2,q,v,t,k=function(){v=i.$newElement.offset().top-o.scrollTop();t=o.height()-v-u};k();if(this.options.header){d.css("padding-top",0)}if(this.options.size=="auto"){var e=function(){var x,w=i.$lis.not(".hide");k();q=t-g;if(i.options.dropupAuto){i.$newElement.toggleClass("dropup",(v>t)&&((q-g)3){x=f*3+g-2}else{x=0}d.css({"max-height":q+"px",overflow:"hidden","min-height":x+s+m+h+"px"});j.css({"max-height":q-s-m-h-r+"px","overflow-y":"auto","min-height":Math.max(x-r,0)+"px"})};e();this.$searchbox.off("input.getSize propertychange.getSize").on("input.getSize propertychange.getSize",e);b(window).off("resize.getSize").on("resize.getSize",e);b(window).off("scroll.getSize").on("scroll.getSize",e)}else{if(this.options.size&&this.options.size!="auto"&&d.find("li"+p).length>this.options.size){var n=d.find("li"+p+" > *").filter(":not(.div-contain)").slice(0,this.options.size).last().parent().index();var c=d.find("li").slice(0,n+1).find(".div-contain").length;q=f*this.options.size+c*l+r;if(i.options.dropupAuto){this.$newElement.toggleClass("dropup",(v>t)&&(q .dropdown-menu").css("width");var d=e.css("width","auto").find("> button").css("width");e.remove();this.$newElement.css("width",Math.max(parseInt(c),parseInt(d))+"px")}else{if(this.options.width=="fit"){this.$menu.css("min-width","");this.$newElement.css("width","").addClass("fit-width")}else{if(this.options.width){this.$menu.css("min-width","");this.$newElement.css("width",this.options.width)}else{this.$menu.css("min-width","");this.$newElement.css("width","")}}}if(this.$newElement.hasClass("fit-width")&&this.options.width!=="fit"){this.$newElement.removeClass("fit-width")}},selectPosition:function(){var e=this,d="",f=b(d),h,g,c=function(i){f.addClass(i.attr("class").replace(/form-control/gi,"")).toggleClass("dropup",i.hasClass("dropup"));h=i.offset();g=i.hasClass("dropup")?0:i[0].offsetHeight;f.css({top:h.top+g,left:h.left,width:i[0].offsetWidth,position:"absolute"})};this.$newElement.on("click",function(){if(e.isDisabled()){return}c(b(this));f.appendTo(e.options.container);f.toggleClass("open",!b(this).hasClass("open"));f.append(e.$menu)});b(window).resize(function(){c(e.$newElement)});b(window).on("scroll",function(){c(e.$newElement)});b("html").on("click",function(i){if(b(i.target).closest(e.$newElement).length<1){f.removeClass("open")}})},mobile:function(){this.$element.addClass("mobile-device").appendTo(this.$newElement);if(this.options.container){this.$menu.hide()}},refresh:function(){this.$lis=null;this.reloadLi();this.render();this.setWidth();this.setStyle();this.checkDisabled();this.liHeight()},update:function(){this.reloadLi();this.setWidth();this.setStyle();this.checkDisabled();this.liHeight()},setSelected:function(c,d){if(this.$lis==null){this.$lis=this.$menu.find("li")}b(this.$lis[c]).toggleClass("selected",d)},setDisabled:function(c,d){if(this.$lis==null){this.$lis=this.$menu.find("li")}if(d){b(this.$lis[c]).addClass("disabled").find("a").attr("href","#").attr("tabindex",-1)}else{b(this.$lis[c]).removeClass("disabled").find("a").removeAttr("href").attr("tabindex",0)}},isDisabled:function(){return this.$element.is(":disabled")},checkDisabled:function(){var c=this;if(this.isDisabled()){this.$button.addClass("disabled").attr("tabindex",-1)}else{if(this.$button.hasClass("disabled")){this.$button.removeClass("disabled")}if(this.$button.attr("tabindex")==-1){if(!this.$element.data("tabindex")){this.$button.removeAttr("tabindex")}}}this.$button.click(function(){return !c.isDisabled()})},tabIndex:function(){if(this.$element.is("[tabindex]")){this.$element.data("tabindex",this.$element.attr("tabindex"));this.$button.attr("tabindex",this.$element.data("tabindex"))}},clickListener:function(){var c=this;b("body").on("touchstart.dropdown",".dropdown-menu",function(d){d.stopPropagation()});this.$newElement.on("click",function(){c.setSize();if(!c.options.liveSearch&&!c.multiple){setTimeout(function(){c.$menu.find(".selected a").focus()},10)}});this.$menu.on("click","li a",function(n){var t=b(this).parent().index(),m=c.$element.val(),i=c.$element.prop("selectedIndex");if(c.multiple){n.stopPropagation()}n.preventDefault();if(!c.isDisabled()&&!b(this).parent().hasClass("disabled")){var l=c.$element.find("option"),d=l.eq(t),f=d.prop("selected"),r=d.parent("optgroup"),p=c.options.maxOptions,h=r.data("maxOptions")||false;if(!c.multiple){l.prop("selected",false);d.prop("selected",true);c.$menu.find(".selected").removeClass("selected");c.setSelected(t,true)}else{d.prop("selected",!f);c.setSelected(t,!f);if((p!==false)||(h!==false)){var o=p');if((p&&o)||(h&&j)){if(s[2]){g=g.replace("{var}",s[2][p>1?0:1]);q=q.replace("{var}",s[2][h>1?0:1])}d.prop("selected",false);c.$menu.append(k);if(p&&o){k.append(b(""+g+""));c.$element.trigger("maxReached.bs.select")}if(h&&j){k.append(b(""+q+""));c.$element.trigger("maxReachedGrp.bs.select")}setTimeout(function(){c.setSelected(t,false)},10);k.delay(750).fadeOut(300,function(){b(this).remove()})}}}if(!c.multiple){c.$button.focus()}else{if(c.options.liveSearch){c.$searchbox.focus()}}if((m!=c.$element.val()&&c.multiple)||(i!=c.$element.prop("selectedIndex")&&!c.multiple)){c.$element.change()}}});this.$menu.on("click","li.disabled a, li dt, li .div-contain, .popover-title, .popover-title :not(.close)",function(d){if(d.target==this){d.preventDefault();d.stopPropagation();if(!c.options.liveSearch){c.$button.focus()}else{c.$searchbox.focus()}}});this.$menu.on("click",".popover-title .close",function(){c.$button.focus()});this.$searchbox.on("click",function(d){d.stopPropagation()});this.$menu.on("click",".actions-btn",function(d){if(c.options.liveSearch){c.$searchbox.focus()}else{c.$button.focus()}d.preventDefault();d.stopPropagation();if(b(this).is(".bs-select-all")){c.selectAll()}else{c.deselectAll()}c.$element.change()});this.$element.change(function(){c.render(false)})},liveSearchListener:function(){var d=this,c=b('');this.$newElement.on("click.dropdown.data-api",function(){d.$menu.find(".active").removeClass("active");if(!!d.$searchbox.val()){d.$searchbox.val("");d.$lis.not(".is-hidden").removeClass("hide");if(!!c.parent().length){c.remove()}}if(!d.multiple){d.$menu.find(".selected").addClass("active")}setTimeout(function(){d.$searchbox.focus()},10)});this.$searchbox.on("input propertychange",function(){if(d.$searchbox.val()){d.$lis.not(".is-hidden").removeClass("hide").find("a").not(":icontains("+d.$searchbox.val()+")").parent().addClass("hide");if(!d.$menu.find("li").filter(":visible:not(.no-results)").length){if(!!c.parent().length){c.remove()}c.html(d.options.noneResultsText+' "'+d.$searchbox.val()+'"').show();d.$menu.find("li").last().after(c)}else{if(!!c.parent().length){c.remove()}}}else{d.$lis.not(".is-hidden").removeClass("hide");if(!!c.parent().length){c.remove()}}d.$menu.find("li.active").removeClass("active");d.$menu.find("li").filter(":visible:not(.divider)").eq(0).addClass("active").find("a").focus();b(this).focus()});this.$menu.on("mouseenter","a",function(f){d.$menu.find(".active").removeClass("active");b(f.currentTarget).parent().not(".disabled").addClass("active")});this.$menu.on("mouseleave","a",function(){d.$menu.find(".active").removeClass("active")})},val:function(c){if(c!==undefined){this.$element.val(c);this.$element.change();return this.$element}else{return this.$element.val()}},selectAll:function(){if(this.$lis==null){this.$lis=this.$menu.find("li")}this.$element.find("option:enabled").prop("selected",true);b(this.$lis).filter(":not(.disabled)").addClass("selected");this.render(false)},deselectAll:function(){if(this.$lis==null){this.$lis=this.$menu.find("li")}this.$element.find("option:enabled").prop("selected",false);b(this.$lis).filter(":not(.disabled)").removeClass("selected");this.render(false)},keydown:function(p){var q,o,i,n,k,j,r,f,h,m,d,s,g={32:" ",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9"};q=b(this);i=q.parent();if(q.is("input")){i=q.parent().parent()}m=i.data("this");if(m.options.liveSearch){i=q.parent().parent()}if(m.options.container){i=m.$menu}o=b("[role=menu] li:not(.divider) a",i);s=m.$menu.parent().hasClass("open");if(!s&&/([0-9]|[A-z])/.test(String.fromCharCode(p.keyCode))){if(!m.options.container){m.setSize();m.$menu.parent().addClass("open");s=m.$menu.parent().hasClass("open")}else{m.$newElement.trigger("click")}m.$searchbox.focus()}if(m.options.liveSearch){if(/(^9$|27)/.test(p.keyCode)&&s&&m.$menu.find(".active").length===0){p.preventDefault();m.$menu.parent().removeClass("open");m.$button.focus()}o=b("[role=menu] li:not(.divider):visible",i);if(!q.val()&&!/(38|40)/.test(p.keyCode)){if(o.filter(".active").length===0){o=m.$newElement.find("li").filter(":icontains("+g[p.keyCode]+")")}}}if(!o.length){return}if(/(38|40)/.test(p.keyCode)){n=o.index(o.filter(":focus"));j=o.parent(":not(.disabled):visible").first().index();r=o.parent(":not(.disabled):visible").last().index();k=o.eq(n).parent().nextAll(":not(.disabled):visible").eq(0).index();f=o.eq(n).parent().prevAll(":not(.disabled):visible").eq(0).index();h=o.eq(k).parent().prevAll(":not(.disabled):visible").eq(0).index();if(m.options.liveSearch){o.each(function(e){if(b(this).is(":not(.disabled)")){b(this).data("index",e)}});n=o.index(o.filter(".active"));j=o.filter(":not(.disabled):visible").first().data("index");r=o.filter(":not(.disabled):visible").last().data("index");k=o.eq(n).nextAll(":not(.disabled):visible").eq(0).data("index");f=o.eq(n).prevAll(":not(.disabled):visible").eq(0).data("index");h=o.eq(k).prevAll(":not(.disabled):visible").eq(0).data("index")}d=q.data("prevIndex");if(p.keyCode==38){if(m.options.liveSearch){n-=1}if(n!=h&&n>f){n=f}if(nr){n=r}if(n==d){n=j}}q.data("prevIndex",n);if(!m.options.liveSearch){o.eq(n).focus()}else{p.preventDefault();if(!q.is(".dropdown-toggle")){o.removeClass("active");o.eq(n).addClass("active").find("a").focus();q.focus()}}}else{if(!q.is("input")){var c=[],l,t;o.each(function(){if(b(this).parent().is(":not(.disabled)")){if(b.trim(b(this).text().toLowerCase()).substring(0,1)==g[p.keyCode]){c.push(b(this).parent().index())}}});l=b(document).data("keycount");l++;b(document).data("keycount",l);t=b.trim(b(":focus").text().toLowerCase()).substring(0,1);if(t!=g[p.keyCode]){l=1;b(document).data("keycount",l)}else{if(l>=c.length){b(document).data("keycount",0);if(l>c.length){l=1}}}o.eq(c[l-1]).focus()}}if(/(13|32|^9$)/.test(p.keyCode)&&s){if(!/(32)/.test(p.keyCode)){p.preventDefault()}if(!m.options.liveSearch){b(":focus").click()}else{if(!/(32)/.test(p.keyCode)){m.$menu.find(".active a").click();q.focus()}}b(document).data("keycount",0)}if((/(^9$|27)/.test(p.keyCode)&&s&&(m.multiple||m.options.liveSearch))||(/(27)/.test(p.keyCode)&&!s)){m.$menu.parent().removeClass("open");m.$button.focus()}},hide:function(){this.$newElement.hide()},show:function(){this.$newElement.show()},destroy:function(){this.$newElement.remove();this.$element.remove()}};b.fn.selectpicker=function(e,f){var c=arguments;var g;var d=this.each(function(){if(b(this).is("select")){var m=b(this),l=m.data("selectpicker"),h=typeof e=="object"&&e;if(!l){m.data("selectpicker",(l=new a(this,h,f)))}else{if(h){for(var j in h){l.options[j]=h[j]}}}if(typeof e=="string"){var k=e;if(l[k] instanceof Function){[].shift.apply(c);g=l[k].apply(l,c)}else{g=l.options[k]}}}});if(g!==undefined){return g}else{return d}};b.fn.selectpicker.defaults={style:"btn-default",size:"auto",title:null,selectedTextFormat:"values",noneSelectedText:"Nothing selected",noneResultsText:"No results match",countSelectedText:"{0} of {1} selected",maxOptionsText:["Limit reached ({n} {var} max)","Group limit reached ({n} {var} max)",["items","item"]],width:false,container:false,hideDisabled:false,showSubtext:false,showIcon:true,showContent:true,dropupAuto:true,header:false,liveSearch:false,actionsBox:false,multipleSeparator:", ",iconBase:"glyphicon",tickIcon:"glyphicon-ok",maxOptions:false};b(document).data("keycount",0).on("keydown",".bootstrap-select [data-toggle=dropdown], .bootstrap-select [role=menu], .bootstrap-select-searchbox input",a.prototype.keydown).on("focusin.modal",".bootstrap-select [data-toggle=dropdown], .bootstrap-select [role=menu], .bootstrap-select-searchbox input",function(c){c.stopPropagation()})}(window.jQuery); \ No newline at end of file diff --git a/modoboa/static/js/global.js b/modoboa/static/js/global.js index 42c45a340..e5bdd4754 100644 --- a/modoboa/static/js/global.js +++ b/modoboa/static/js/global.js @@ -23,11 +23,11 @@ function get_static_url(value) { function modalbox(e, css, defhref, defcb, defclosecb) { e.preventDefault(); var $this = $(this); - var href = (defhref != undefined) ? defhref : $this.attr('href'); - var modalcb = (defcb != undefined) ? defcb : $this.attr('modalcb'); - var closecb = (defclosecb != undefined) ? defclosecb : $this.attr("closecb"); + var href = (defhref !== undefined) ? defhref : $this.attr('href'); + var modalcb = (defcb !== undefined) ? defcb : $this.attr('modalcb'); + var closecb = (defclosecb !== undefined) ? defclosecb : $this.attr("closecb"); - if (href.indexOf('#') == 0) { + if (href.indexOf('#') === 0) { $(href).modal('open'); return; } @@ -41,6 +41,9 @@ function modalbox(e, css, defhref, defcb, defclosecb) { $div.modal({show: false}); $div.one('shown', function() { + $(".selectpicker").selectpicker({ + container: 'body' + }); $(".help").popover({ container: "#modalbox", trigger: "hover" @@ -323,4 +326,4 @@ $(document).ready(function() { $(document).on('click', 'a[data-toggle="ajaxmodal-autowidth"]', modalbox_autowidth); $(document).on('click', '.activator', activate_widget); $(".help").popover({trigger: 'hover'}).click(function(e) {e.preventDefault();}); -}); \ No newline at end of file +}); diff --git a/modoboa/static/js/listing.js b/modoboa/static/js/listing.js index 8edc63e04..cf10d173b 100644 --- a/modoboa/static/js/listing.js +++ b/modoboa/static/js/listing.js @@ -13,6 +13,7 @@ Listing.prototype = { initialize: function(options) { this.options = $.extend({}, this.listing_defaults, options); + this.tag_handlers = {}; $(document).on("click", this.options.pbar_container + " a", $.proxy(this.load_page, this)); }, @@ -63,5 +64,53 @@ Listing.prototype = { sort_order = "-" + sort_order; } this.navobj.setparam("sort_order", sort_order).update(); + }, + + register_tag_handler: function(name, handler) { + this.tag_handlers[name] = handler; + if (this.navobj.getparam(name + "filter") !== undefined) { + var text = this.navobj.getparam(name + "filter"); + $("#searchform").parent().after(this.make_tag(text, name)); + } + }, + + generic_tag_handler: function(tag, $link) { + if (this.navobj.getparam(tag + "filter") === undefined && $link.hasClass(tag)) { + var text = $link.attr("name"); + this.navobj.setparam(tag + "filter", text).update(); + $("#searchform").parent().after(this.make_tag(text, tag)); + return true; + } + return false; + }, + + make_tag: function(text, type) { + var $tag = $("", {"name": type, "class" : "btn btn-mini", "html": text}); + var $i = $("", {"class" : "icon-remove"}).prependTo($tag); + + $tag.click($.proxy(this.remove_tag, this)); + return $tag; + }, + + remove_tag: function(e) { + var $tag = $(e.target); + + if ($tag.is("i")) { + $tag = $tag.parent(); + } + e.preventDefault(); + this.navobj.delparam($tag.attr("name") + "filter").update(); + $tag.remove(); + }, + + filter_by_tag: function(e) { + var $link = $(e.target); + e.preventDefault(); + + for (var name in this.tag_handlers) { + if (this.tag_handlers[name].apply(this, [name, $link])) { + break; + } + } } -}; \ No newline at end of file +}; diff --git a/modoboa/templates/common/generic_modal.html b/modoboa/templates/common/generic_modal.html index 8a63be2cf..146c2b54b 100644 --- a/modoboa/templates/common/generic_modal.html +++ b/modoboa/templates/common/generic_modal.html @@ -3,7 +3,7 @@ x {{ title }} - + {% block modalbody %}{% endblock %} - + {% csrf_token %} diff --git a/modoboa/templates/nlayout.html b/modoboa/templates/nlayout.html index bd6d9275e..f52204d42 100644 --- a/modoboa/templates/nlayout.html +++ b/modoboa/templates/nlayout.html @@ -8,10 +8,12 @@ + + {% if LANGUAGE_CODE != "en" %}{% endif %}