wip: Radicale extension (#574)

Enable search form + code refactoring.
This commit is contained in:
Antoine Nguyen
2014-06-23 22:50:02 +02:00
parent 15d4e53a5d
commit c77f390a04
9 changed files with 79 additions and 49 deletions
@@ -14,28 +14,9 @@ Admin.prototype = {
},
initialize: function(options) {
Listing.prototype.initialize.call(this, options);
this.options = $.extend({}, this.defaults, this.options);
this.options = $.extend({}, this.defaults, options);
this.options.defcallback = $.proxy(this.list_cb, this);
this.navobj = new History(this.options);
$("#searchquery").focus(function() {
$(this).val("");
}).blur($.proxy(function(e) {
var $this = $(e.target);
if ($this.val() === "") {
if (this.navobj.getparam("searchquery")) {
$this.val(this.navobj.getparam("searchquery"));
} else {
$this.val(gettext("Search"));
}
}
}, this));
if (this.navobj.getparam("searchquery") !== undefined) {
$("#searchquery").val(this.navobj.getparam("searchquery"));
}
Listing.prototype.initialize.call(this, this.options);
this.listen();
},
@@ -45,19 +26,10 @@ Admin.prototype = {
$("a.filter").click($.proxy(this.filter_by_tag, this));
},
/**
* Children must override this method.
*/
listen: function() {
$("#searchform").submit($.proxy(this.do_search, this));
},
do_search: function(e) {
e.preventDefault();
var squery = $("#searchquery").val();
if (squery !== "") {
this.navobj.setparam("searchquery", squery);
} else {
this.navobj.delparam("searchquery");
}
this.navobj.update();
},
importform_cb: function() {
+2 -2
View File
@@ -17,7 +17,7 @@ class ParametersForm(AdminParametersForm):
)
sep1 = SeparatorField(label=_("Messages releasing"))
released_msgs_cleanup = YesNoField(
label=_("Remove released messages"),
initial="no",
@@ -49,7 +49,7 @@ class ParametersForm(AdminParametersForm):
initial="/var/amavis/amavisd.sock",
help_text=_("Path to the PDP server socket (if unix mode)")
)
check_requests_interval = forms.IntegerField(
label=_("Check requests interval"),
initial=30,
@@ -10,11 +10,9 @@ Quarantine.prototype = {
},
initialize: function(options) {
Listing.prototype.initialize.call(this, options);
this.options = $.extend({}, this.defaults, this.options);
this.options = $.extend({}, this.defaults, options);
this.options.defcallback = $.proxy(this.listing_cb, this);
this.navobj = new History(this.options);
Listing.prototype.initialize.call(this, this.options);
this.register_navcallbacks();
this.listen();
this.set_msgtype();
@@ -1,13 +1,25 @@
from django.utils.translation import ugettext_lazy
from django import forms
from modoboa.lib.parameters import AdminParametersForm
from modoboa.lib.formutils import SeparatorField
class ParametersForm(AdminParametersForm):
app = "radicale"
rights_management_sep = SeparatorField(
label=ugettext_lazy("Rights management"))
rights_file_path = forms.CharField(
label=ugettext_lazy("Radicale rights file path"),
initial="/etc/radicale/rights",
help_text=ugettext_lazy("Path to file that contains rights definition")
)
allow_calendars_administration = forms.BooleanField(
label=ugettext_lazy("Allow calendars administration"),
initial=False,
help_text=ugettext_lazy(
"Allow domain administrators to manage user calendars (read an write)"
)
)
@@ -9,7 +9,7 @@ def top_menu(target, user):
if target == "top_menu":
return [
{"name": "radicale",
"label": _("Radicale"),
"label": _("Calendars"),
"url": reverse('modoboa.extensions.radicale.views.index')}
]
return []
@@ -14,10 +14,9 @@ Radicale.prototype = {
},
initialize: function(options) {
Listing.prototype.initialize.call(this, options);
this.options = $.extend({}, this.defaults, this.options);
this.options = $.extend({}, this.defaults, options);
this.options.defcallback = $.proxy(this.list_cb, this);
this.navobj = new History(this.options);
Listing.prototype.initialize.call(this, this.options);
this.register_tag_handler("cal", this.generic_tag_handler);
$(document).on(
"click", "a[name=delcalendar]", $.proxy(this.del_calendar, this)
+9 -1
View File
@@ -37,17 +37,25 @@ def calendars(request, tplname="radicale/calendar_list.html"):
"""
sort_order, sort_dir = get_sort_order(request.GET, "name")
calfilter = request.GET.get("calfilter", None)
searchquery = request.GET.get("searchquery", None)
if request.user.group == "SimpleUsers":
mbox = request.user.mailbox_set.all()[0]
cals = UserCalendar.objects.filter(mailbox=mbox).select_related().all()
cals = UserCalendar.objects.filter(mailbox=mbox)
if searchquery is not None:
cals = cals.filter(name__icontains=searchquery)
cals = cals.select_related().all()
with_owner = False
else:
ucals = []
if calfilter is None or calfilter == "user":
ucals = UserCalendar.objects.get_for_admin(request.user)
if searchquery is not None:
ucals = ucals.filter(name__icontains=searchquery)
scals = []
if calfilter is None or calfilter == "shared":
scals = SharedCalendar.objects.get_for_admin(request.user)
if searchquery is not None:
scals = scals.filter(name__icontains=searchquery)
cals = chain(ucals, scals)
with_owner = True
cals = sorted(
+43 -1
View File
@@ -8,16 +8,58 @@ Listing.prototype = {
listing_defaults: {
pbar_container: '#bottom-bar-right',
pbar_id: '#pagination_bar',
sortable_selector: '.sortable'
sortable_selector: '.sortable',
with_searchform: true
},
initialize: function(options) {
this.options = $.extend({}, this.listing_defaults, options);
this.tag_handlers = {};
this.navobj = new History(this.options);
$(document).on("click", this.options.pbar_container + " a",
$.proxy(this.load_page, this));
if (this.options.with_searchform) {
this.init_searchform();
}
},
/**
* Initialize the search form.
*/
init_searchform: function() {
$("#searchquery").focus(function() {
$(this).val("");
}).blur($.proxy(function(e) {
var $this = $(e.target);
if ($this.val() === "") {
if (this.navobj.getparam("searchquery")) {
$this.val(this.navobj.getparam("searchquery"));
} else {
$this.val(gettext("Search"));
}
}
}, this));
if (this.navobj.getparam("searchquery") !== undefined) {
$("#searchquery").val(this.navobj.getparam("searchquery"));
}
$("#searchform").submit($.proxy(this.do_search, this));
},
/**
* Apply the current search pattern.
*/
do_search: function(e) {
e.preventDefault();
var squery = $("#searchquery").val();
if (squery !== "") {
this.navobj.setparam("searchquery", squery);
} else {
this.navobj.delparam("searchquery");
}
this.navobj.update();
},
load_page: function(e) {
var $link = get_target(e, "a");
e.preventDefault();
+3 -4
View File
@@ -11,10 +11,9 @@ TwocolsNav.prototype = {
},
initialize: function(options) {
Listing.prototype.initialize.call(this, options);
this.options = $.extend({}, this.defaults, this.options);
this.options = $.extend({}, this.defaults, options);
this.options.defcallback = $.proxy(this.default_cb, this);
this.navobj = new History(this.options);
Listing.prototype.initialize.call(this, this.options);
this.listen();
},
@@ -130,4 +129,4 @@ TwocolsNav.prototype = {
}
};
TwocolsNav.prototype = $.extend({}, Listing.prototype, TwocolsNav.prototype);
TwocolsNav.prototype = $.extend({}, Listing.prototype, TwocolsNav.prototype);