';
- var title_patten = '
{1}
';
-
- if (body !== "") {
- content += title_patten.format("modal-header", question);
- content += '
{0}
'.format(body);
- } else {
- content += title_patten.format("modal-body", question);
- }
- content += ''.format(gettext("Cancel"));
-
- box.append($(content));
-
- box.find(".btn-primary").click(function(evt) {
- evt.preventDefault();
- box.data('result', true);
- box.modal('hide');
- });
-
- box.find(".btn-default").click(function(evt) {
- evt.preventDefault();
- box.modal('hide');
- });
-
- return box;
- },
-
- hidden_callback: function() {
- if (this.box.data('result') === undefined) {
- return;
- }
- var params = "";
-
- $('input[type=checkbox]:checked').each(function() {
- if (params !== "") {
- params += "&";
- }
- params += $(this).attr("name") + "=true";
- });
- $.ajax({
- cache: false,
- type: this.options.method,
- data: params,
- url: this.$element.attr('href')
- }).done($.proxy(function(data) {
- if (this.options.success_cb !== undefined) {
- this.options.success_cb(data);
- return;
- }
- window.location.reload();
- }, this));
- this.box.remove();
- }
- };
-
- $.fn.confirm = function(method) {
- return this.each(function() {
- var $this = $(this),
- data = $this.data('confirm'),
- options = typeof method === "object" && method;
-
- if (!data) {
- $this.data('confirm', new Confirm(this, options));
- }
- if (typeof method === "string") {
- data[method]();
- }
- });
- };
-
- $.fn.confirm.defaults = {
- question: "",
- method: "GET",
- warning: null,
- checkboxes: null
- };
-
-})(jQuery);
diff --git a/modoboa/static/js/creation_wizard.js b/modoboa/static/js/creation_wizard.js
deleted file mode 100644
index 20a1a8ab9..000000000
--- a/modoboa/static/js/creation_wizard.js
+++ /dev/null
@@ -1,129 +0,0 @@
-(function($) {
- var Cwizard = function(element, options) {
- this.initialize(element, options);
- };
-
- Cwizard.prototype = {
- constructor: Cwizard,
-
- initialize: function(element, options) {
- this.$element = $(element);
- this.options = $.extend({}, $.fn.cwizard.defaults, options);
- this.$element.carousel({pause: true});
- this.$element.carousel("pause");
- this.listen();
- this.titles = {};
- $('input:text:visible:first').focus();
- },
-
- listen: function() {
- $(".next").on("click", $.proxy(this.next, this));
- $(".prev").on("click", $.proxy(this.prev, this));
- $(".submit").on("click", $.proxy(this.submit, this));
- },
-
- get_current_step_id: function() {
- return $(".item.active").attr("id");
- },
-
- get_current_title: function() {
- return $(".modal-header").find("small").html();
- },
-
- set_current_title: function(title) {
- $(".modal-header").find("small").html(title);
- },
-
- post: function(last, target) {
- var $form = (this.options.formid) ? $('#' + this.options.formid) : $('form');
- var data = $form.serialize() + "&stepid=" + this.get_current_step_id() + "&target=" + target;
-
- $.ajax({
- type: 'POST', url: $form.attr("action"), data: data, global: false
- }).done($.proxy(function(resp) {
- if (!last) {
- $('input:text:visible:first').focus();
- this.set_current_title(resp.title);
- if (this.options.transition_callbacks[resp.id] !== undefined) {
- this.options.transition_callbacks[resp.id]();
- }
- $(".carousel-inner").css("overflow", "hidden");
- this.$element.carousel(resp.stepid);
- } else {
- $("#modalbox").modal('hide');
- if (this.options.success_callback !== undefined) {
- this.options.success_callback(resp);
- } else {
- window.location.reload();
- }
- }
- }, this)).fail($.proxy(function(jqxhr) {
- var resp = $.parseJSON(jqxhr.responseText);
- if (resp.stepid !== undefined) {
- var stepid = resp.stepid;
- display_form_errors("step" + stepid, resp);
- if (this.options.error_callbacks[stepid] !== undefined) {
- this.options.error_callbacks[stepid]();
- }
- $('input:text:visible:first').focus();
- if (resp.respmsg) {
- $(".modal-body").prepend(build_error_alert(resp.respmsg));
- }
- return;
- }
- $(".modal-body").prepend(build_error_alert(resp));
- }, this));
- },
-
- update_buttons: function() {
- $(".carousel-inner").css("overflow", "visible");
- $('.bset.active').removeClass("active");
- $("#" + $(".item.active").attr("id") + "_buttons").addClass("active");
- },
-
- next: function(evt) {
- evt.preventDefault();
- var step_id = this.get_current_step_id();
- this.titles[step_id] = this.get_current_title();
- this.$element.on('slid.bs.carousel', this.update_buttons);
- this.post(false, "next");
- },
-
- /**
- * Go back to the previous step.
- */
- prev: function(evt) {
- var stepid = this.get_current_step_id();
-
- evt.preventDefault();
- this.$element.on('slid.bs.carousel', this.update_buttons);
- this.post(false, "prev", stepid);
- },
-
- submit: function(evt) {
- evt.preventDefault();
- this.post(true, "next");
- }
- };
-
- $.fn.cwizard = function(method) {
- return this.each(function() {
- var $this = $(this),
- data = $this.data('cwizard'),
- options = typeof method === "object" && method;
-
- if (!data) {
- $this.data('cwizard', new Cwizard(this, options));
- }
- if (typeof method === "string") {
- data[method]();
- }
- });
- };
-
- $.fn.cwizard.defaults = {
- transition_callbacks: {},
- error_callbacks: {}
- };
-
-})(jQuery);
diff --git a/modoboa/static/js/csrf.js b/modoboa/static/js/csrf.js
deleted file mode 100644
index 9835b64ed..000000000
--- a/modoboa/static/js/csrf.js
+++ /dev/null
@@ -1,47 +0,0 @@
-function getCookie(name) {
- var cookieValue = null;
- if (document.cookie && document.cookie != '') {
- var cookies = document.cookie.split(';');
- for (var i = 0; i < cookies.length; i++) {
- var cookie = jQuery.trim(cookies[i]);
- // Does this cookie string begin with the name we want?
- if (cookie.substring(0, name.length + 1) == (name + '=')) {
- cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
- break;
- }
- }
- }
- return cookieValue;
-}
-
-function csrfSafeMethod(method) {
- // these HTTP methods do not require CSRF protection
- return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
-}
-
-function sameOrigin(url) {
- // test that a given url is a same-origin URL
- // url could be relative or scheme relative or absolute
- var host = document.location.host; // host + port
- var protocol = document.location.protocol;
- var sr_origin = '//' + host;
- var origin = protocol + sr_origin;
- // Allow absolute or scheme relative URLs to same origin
- return (url == origin || url.slice(0, origin.length + 1) == origin + '/') ||
- (url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') ||
- // or any other URL that isn't scheme relative or absolute i.e relative.
- !(/^(\/\/|http:|https:).*/.test(url));
-}
-
-$.ajaxSetup({
- beforeSend: function(xhr, settings) {
- var csrftoken = getCookie("csrftoken");
-
- if (csrftoken && !csrfSafeMethod(settings.type) && sameOrigin(settings.url)) {
- // Send the token to same-origin, relative URLs only.
- // Send the token only if the method warrants CSRF protection
- // Using the CSRFToken value acquired earlier
- xhr.setRequestHeader("X-CSRFToken", csrftoken);
- }
- }
-});
diff --git a/modoboa/static/js/dynamic_input.js b/modoboa/static/js/dynamic_input.js
deleted file mode 100644
index da5a62f9b..000000000
--- a/modoboa/static/js/dynamic_input.js
+++ /dev/null
@@ -1,160 +0,0 @@
-(function($) {
-
- /**
- * Creates an instance of DynamicInput.
- *
- * @constructor
- * @this DynamicInput
- * @param {Object} element -
- * @param {Object} options -
- */
- var DynamicInput = function(element, options) {
- this.$element = $(element);
- this.$input = (this.$element.is("input")) ?
- this.$element : this.$element.find("input");
- this.options = $.extend({}, $.fn.dynamic_input.defaults, options);
- this.nextid = 1;
- this.baseid = this.$input.attr("id");
- this.basename = this.$input.attr("name").split("_")[0];
-
- this.$input.keyup($.proxy(this.checknotempty, this));
-
- for (var cpt = 1; true; cpt++) {
- var $input = $("#" + this.baseid + "_" + cpt);
-
- if (!$input.length) {
- break;
- }
- $input.parent().after(this.addrmlink($input));
- $input.focusout(this.checkempty);
- this.nextid++;
- }
- };
-
- DynamicInput.prototype = {
- constructor: DynamicInput,
-
- /**
- * Add a remove link right to an input.
- *
- * @this DynamicInput
- * @param {Object} input - target input
- * @return {Object} - created link
- */
- addrmlink: function(input) {
- var $rmlink = $(
- "
".format(input.attr("id")) +
- ""
- );
-
- $rmlink.click($.proxy(this.removeinput, this));
- return $rmlink;
- },
-
- /**
- * Add a new input.
- *
- * @this DynamicInput
- */
- addinput: function() {
- var $clone = this.$element.clone();
- var id = this.baseid + '_' + this.nextid;
- var name = this.basename + '_' + this.nextid;
-
- $clone.insertAfter(this.$element);
-
- var $ninput = $clone.find("input").attr("id", id).attr("name", name);
- var $rmlink = this.addrmlink($ninput);
-
- $clone.append($rmlink);
- $ninput.focusout(this.checkempty);
- $ninput.val(this.$input.val());
- this.$input.val(this.options.emptylabel);
- this.nextid++;
-
- if (this.options.input_added) {
- this.options.input_added($clone);
- }
- },
-
- /**
- * Click event. Remove an input.
- *
- * @this DynamicInput
- * @param {Object} evt - event object
- * @param {boolean} force - force the removal if true
- */
- removeinput: function(evt, force) {
- evt.preventDefault();
-
- var $link = get_target(evt, "a");
- var id = "#" + $link.attr("id").replace("_rmbtn", "");
- var $input = $(id);
-
- if ($input.val() === "" && (force === undefined || !force)) {
- return;
- }
- if (this.options.input_removed && this.options.input_removed($input)) {
- return;
- }
- $input.remove();
- $link.remove();
- },
-
- /**
- * Check if input's value is not empty before adding a new input.
- *
- * @this DynamicInput
- * @param {Object} evt - event object
- */
- checknotempty: function(evt) {
- if (evt.keyCode != 13) {
- return;
- }
- if (this.$input.val() === "") {
- return;
- }
- this.addinput();
- },
-
- /**
- * Focus out event : remove the input if it's value is empty.
- *
- * @param {Object} evt - event object
- */
- checkempty: function(evt) {
- var $input = $(evt.target);
-
- if ($input.val() === "") {
- $("#" + $input.attr("id") + "_rmbtn").trigger("click", true);
- }
- }
- };
-
- $.fn.dynamic_input = function(method) {
- return this.each(function() {
- var $this = $(this),
- data = $this.data('dynamic_input'),
- options = typeof method === "object" && method;
-
- if (!data) {
- $this.data('dynamic_input', new DynamicInput(this, options));
- }
- if (typeof method === "string") {
- data[method]();
- }
- });
- };
-
- /*
- * Allow an external access to the constructor (for inheritance)
- */
- $.fn.dynamic_input.Constructor = DynamicInput;
-
- $.fn.dynamic_input.defaults = {
- emptylabel: "",
- input_added: null,
- input_removed: null
- };
-
-})(jQuery);
diff --git a/modoboa/static/js/global.js b/modoboa/static/js/global.js
deleted file mode 100644
index 0e6dbc5d1..000000000
--- a/modoboa/static/js/global.js
+++ /dev/null
@@ -1,380 +0,0 @@
-/*
- * Global javascript utilities
- */
-
-/* global $ */
-
-var static_url = "";
-
-/*
- * A simple function to initialize the value of the global variable
- * 'media_url' (corresponding to django's MEDIA_URL variable).
- */
-function set_static_url(url) {
- static_url = url;
-}
-
-/*
- * Shortcut function that construct an url from the media_url and the
- * given value.
- */
-function get_static_url(value) {
- return static_url + value;
-}
-
-/**
- * Open a modal box and load its content using an AJAX request.
- *
- * @param {Object} e - event object
- */
-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");
-
- if (href.indexOf('#') === 0) {
- $(href).modal('open');
- return;
- }
- if ($("#modalbox").length) {
- return;
- }
- $.ajax({
- type: "GET",
- url: href
- }).done(function(data) {
- var $div = $('
', {
- id: "modalbox", 'class': "modal fade", role: "modal",
- html: data, 'aria-hidden': true
- });
-
- $div.modal({show: false});
- $div.one('shown.bs.modal', function() {
- if ($(".selectpicker").length) {
- $(".selectpicker").selectize();
- }
- $(".help").popover({
- container: "#modalbox",
- trigger: "hover"
- }).click(function(e) {e.preventDefault();});
- if (modalcb !== undefined) {
- if (typeof modalcb === "function") modalcb(); else eval(modalcb + '()');
- }
- }).on('hidden.bs.modal', function(e) {
- var $target = $(e.target);
-
- if (!$target.is($(this))) {
- return;
- }
- $("#modalbox").remove();
- if (closecb !== undefined) {
- if (typeof closecb === "function") closecb(); else eval(closecb + '()');
- }
- });
- $div.modal('show');
-
- if (css !== undefined) {
- $div.css(css);
- }
- });
-}
-
-function modalbox_autowidth(e) {
- modalbox.apply(this, [e]);
-}
-
-/*
- * Simple shorcut do create a bootstrap alert box (error mode)
- */
-function build_alert_box(msg, level) {
- return $('
");
-}
-
-function build_error_alert(msg) {
- return build_alert_box(msg, 'danger');
-}
-
-function build_success_alert(msg) {
- return build_alert_box(msg, 'success');
-}
-
-
-/*
- * '.keys()' method support for old browsers :p
- */
-if (!Object.keys) {
- Object.keys = function (obj) {
- var keys = [],
- k;
- for (k in obj) {
- if (Object.prototype.hasOwnProperty.call(obj, k)) {
- keys.push(k);
- }
- }
- return keys;
- };
-}
-
-/*
- * Clean all errors in a given form.
- */
-function clean_form_errors(formid) {
- $("#" + formid + " div.has-error").removeClass("has-error");
- $("#" + formid + " span.help-block").remove();
-}
-
-function display_field_error($field, error) {
- var spanid = $field.attr('id') + "-error";
- var $span = $("#" + spanid);
-
- if (!$field.parents(".form-group").hasClass("has-error")) {
- $field.parents(".form-group").addClass("has-error");
- }
- if (!$span.length) {
- $span = $("
", {
- class: "help-block",
- html: error,
- id: spanid
- });
- $field.parents(".form-group").append($span);
- } else {
- $span.html(error);
- }
-}
-
-/*
- * Display validation errors for a given form.
- */
-function display_form_errors(formid, data) {
- clean_form_errors(formid);
- $.each(data.form_errors, function(id, value) {
- var fullid = "id_" + (data.prefix ? data.prefix + "-" : "") + id;
- var $widget = $("#" + formid + " #" + fullid);
- var error = value.join(' ');
-
- display_field_error($widget, error);
- });
-}
-
-/*
- * Simple function that sends a form using an 'ajax' post request.
- *
- * The function is intended to be used in a modal environment.
- */
-function simple_ajax_form_post(e, options) {
- e.preventDefault();
- var $form = (options.formid !== undefined) ? $("#" + options.formid) : $("form");
- var defaults = {reload_on_success: true, reload_mode: 'full', modal: true};
- var opts = $.extend({}, defaults, options);
- var args = $form.serialize();
-
- if (options.extradata !== undefined) {
- args += "&" + options.extradata;
- }
- $.ajax({
- type: "POST",
- global: false,
- url: $form.attr("action"),
- data: args
- }).done(function(data) {
- if (opts.modal) {
- $("#modalbox").modal('hide');
- }
- if (opts.success_cb !== undefined) {
- opts.success_cb(data);
- return;
- }
- if (opts.reload_on_success) {
- if (opts.reload_mode === 'full') {
- window.location.reload();
- } else {
- histomanager.update(true);
- }
- }
- if (data && data.message) {
- $("body").notify('success', data.message, 2000);
- }
- }).fail(function(jqxhr) {
- var data = $.parseJSON(jqxhr.responseText);
- if (data.form_errors) {
- display_form_errors(options.formid, data);
- } else {
- if (opts.modal) {
- $('.modal-body').prepend(build_error_alert(data));
- } else {
- $('body').notify('error', data);
- }
- }
- if (opts.error_cb) {
- opts.error_cb(data);
- }
- });
-}
-
-/*
- * The following code prevents a bug under IE7 because fullpath is
- * returned instead of a relative one. (even if mootools uses
- * getAttribute("href", 2), this is not working for AJAX requests)
- */
-function gethref(obj) {
- var url = $(obj).attr("href");
- var re = new RegExp("^(https?):");
- var scheme = re.exec(url);
-
- if (scheme !== null) {
- var baseurl = scheme[0] + "://" + location.host + location.pathname;
- return url.replace(baseurl, "");
- }
- return url;
-}
-
-/*
- * Extract the current URL parameters into a dictionnary.
- *
- * Ref:
- * http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript
- */
-function parse_qs(raw) {
- if (raw === "") { return {}; }
- var res = {};
-
- for (var i = 0; i < raw.length; i++) {
- var p = raw[i].split('=');
-
- if (p.length !== 2) { continue; }
- res[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
- }
- return res;
-}
-
-/*
- * Extract a specific URL parameter using its name.
- *
- * Ref: http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript
- */
-function get_parameter_by_name(url, name, dont_replace_plus) {
- name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
- var regex = new RegExp("[\\?&]" + name + "=([^]*)"),
- results = regex.exec(url);
-
- if (results === null) {
- return "";
- }
-
- var result = results[1];
- if (dont_replace_plus === undefined || !dont_replace_plus) {
- result = result.replace("/\+/g", "");
- }
- return decodeURIComponent(result);
-}
-
-/**
- * Return the target associated to an event object. You will generally
- * use this function within a click event handler configured on a
- * tag containg an image. (because e.target will often point to the
- * image...)
- *
- * @param {Object} e - event object
- * @param {string} tag - desired tag
- */
-function get_target(e, tag) {
- var $target = $(e.target);
-
- if (tag === undefined || $target.is(tag)) {
- return $target;
- }
- return $target.parent();
-}
-
-/**
- * Send a simple AJAX request.
- */
-function simple_ajax_request(e, uoptions) {
- var $this = $(this);
- var defaults = {};
- var options = $.extend({}, defaults, uoptions);
-
- if (e !== undefined) { e.preventDefault(); }
- $.ajax({
- url: $this.attr("href"),
- dataType: 'json'
- }).done(function(data) {
- if (options.ok_cb) { options.ok_cb(data); }
- if (data) {
- $("body").notify("success", data, 2000);
- }
- });
-}
-
-/*
- * 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(xhr) {
- if (xhr.status !== 278) {
- return;
- }
- var params = "?next=" + window.location.pathname;
-
- window.location.href =
- xhr.getResponseHeader("Location").replace(/\?.*$/, params);
-}
-
-function activate_widget(e) {
- var $this = $(this);
- var widget_id = $this.attr("id").substr(0, $this.attr("id").length - 4);
- var $widget = $('#' + widget_id);
-
- if ($this.prop("checked")) {
- $widget.attr('disabled', true);
- } else {
- $widget.attr('disabled', false);
- }
-}
-
-/*
- * Default error handler for AJAX requests.
- */
-function defaultAjaxErrorHandler(event, jqxhr, settings) {
- var data;
-
- try {
- data = $.parseJSON(jqxhr.responseText);
- } catch (x) {
- data = gettext("Internal error");
- }
- $('body').notify('error', htmlEncode(data));
-}
-
-/**
- * An equivalent of python .format() method.
- */
-String.prototype.format = function() {
- var args = arguments;
- return this.replace(/\{\{|\}\}|\{(\d+)\}/g, function (m, n) {
- if (m === "{{") { return "{"; }
- if (m === "}}") { return "}"; }
- return args[n];
- });
-};
-
-/**
- * Simple HTML escape function
- */
-function htmlEncode(str) {
- return String(str).replace(/[^\w. ]/gi, function(c) {
- return ''+c.charCodeAt(0)+';';
- });
-}
-
-$(document).ready(function() {
- $(document).ajaxSuccess(function(e, xhr, settings) { ajax_login_redirect(xhr); });
- $(document).ajaxError(defaultAjaxErrorHandler);
- $(document).on('click', 'a[data-toggle="ajaxmodal"]', modalbox);
- $(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(); });
-});
diff --git a/modoboa/static/js/history.js b/modoboa/static/js/history.js
deleted file mode 100644
index 84556f477..000000000
--- a/modoboa/static/js/history.js
+++ /dev/null
@@ -1,285 +0,0 @@
-/**
- * Creates an instance of History.
- *
- * @constructor
- * @this {History}
- * @param {dictionary} options - instance options
- */
-var History = function(options) {
- this.options = $.extend({}, this.defaults, options);
- this.callbacks = {};
- this.base = '';
- this.serialized = null;
- this.updatenext = true;
- this.load_params();
- if (this.options.defcallback) {
- this.register_callback("default", this.options.defcallback);
- this.check_id =
- setInterval($.proxy(this.check, this), this.options.checkinterval);
- }
-};
-
-History.prototype = {
- constructor: History,
-
- defaults: {
- checkinterval: 300,
- deflocation: null,
- defcallback: null
- },
-
- /**
- * Return the encoded hash part of the URL (some browsers like FF
- * automatically decode the location.hash variable).
- */
- get_raw_hash: function() {
- var parts = window.location.href.split('#');
- if (parts.length > 1) {
- return parts[1];
- }
- return "";
- },
-
- load_params: function() {
- var rawqs = this.get_raw_hash();
-
- if (!rawqs || rawqs.indexOf('?') == -1) {
- this.params = {};
- return;
- }
- var tmp = rawqs.split('?');
-
- rawqs = (tmp.length == 1) ? tmp[0] : tmp[1];
- this.params = parse_qs(rawqs.split('&'));
- },
-
- paramslength: function() {
- return Object.keys(this.params).length;
- },
-
- reset: function() {
- this.base = "";
- this.params = {};
- return this;
- },
-
- parse_string: function(value, reset) {
- var splits = (value.charAt(0) == '#') ?
- value.substring(1).split('?') : value.split('?');
-
- if (splits.length === 0) {
- this.base = this.options.deflocation;
- return this;
- }
- if (reset === undefined) {
- reset = false;
- }
- if (reset) {
- this.reset();
- }
-
- if ((this.base = splits[0]) !== "") {
- var re = new RegExp("/$");
- if (!this.base.match(re)) {
- this.base += '/';
- }
- }
- if (splits.length > 1) {
- var params = splits[1].split('&');
- for (var i = 0; i < params.length; i++) {
- var tmp = params[i].split('=');
- this.setparam(tmp[0], tmp[1], false);
- }
- }
- return this;
- },
-
- from_string: function(value, reset) {
- this.parse_string(value);
- this.serialized = value;
- return this;
- },
-
- serialize: function() {
- var res = this.base;
- var args = "";
-
- if (this.paramslength() !== 0) {
- args += "?";
- $.each(this.params, function(key, value) {
- if (args != "?") {
- args += "&";
- }
- args += key + "=" + value;
- });
- }
- return res + args;
- },
-
- /**
- * Update the current location.
- *
- * @param {boolean} force - force the update
- * @param {boolean} noupdate - disable the next update
- */
- update: function(force, noupdate) {
- location.hash = this.serialize();
-
- if (noupdate === undefined) {
- noupdate = false;
- }
- if (!noupdate) {
- if (force) {
- this.force = force;
- }
- } else {
- this.updatenext = false;
- }
- },
-
- /**
- * Check if a parameter is present.
- *
- * @param {string} name - name of the parameter
- * @return {boolean} true if parameter is present, false otherwise
- */
- hasparam: function(name) {
- return this.params[name] !== undefined;
- },
-
- /**
- * Retrieve a parameter.
- *
- * @param {string} name - name of the parameter
- * @return {string} the parameter's value (URI decoded)
- */
- getparam: function(name, defvalue) {
- if (this.params[name] === undefined) {
- return (defvalue !== undefined) ? defvalue : undefined;
- }
- return decodeURIComponent(this.params[name]);
- },
-
- /**
- * Set a parameter.
- *
- * @param {string} name - name of the parameter
- * @param {string} value - parameter's value
- * @param {boolean} encode - URI encode the parameter if true
- * @return {History}
- */
- setparam: function(name, value, encode) {
- if (encode === undefined || encode) {
- this.params[name] = encodeURIComponent(value);
- } else {
- this.params[name] = value;
- }
- return this;
- },
-
- /**
- * Set several parameters.
- *
- * @param {Object} params - a dictionary of parameters
- * @return {Object} - History instance
- */
- setparams: function(params) {
- $.each(params, $.proxy(this.setparam, this));
- return this;
- },
-
- updateparams: function(str) {
- if (str.charAt(0) == '?') {
- str = str.substring(1);
- }
- var elems = str.split('&');
- for (var i = 0; i < elems.length; i++) {
- var pdef = elems[i].split('=');
- this.setparam(pdef[0], pdef[1]);
- }
- return this;
- },
-
- /**
- * Delete a parameter.
- *
- * @param {string} name - name of the parameter
- * @return {History}
- */
- delparam: function(name) {
- if (this.params[name] === undefined) {
- return this;
- }
- delete(this.params[name]);
- return this;
- },
-
- baseurl: function(value, noreset) {
- if (noreset === undefined || noreset === 0) {
- this.reset();
- }
- this.base = value;
- var re = new RegExp("/$");
- if (!this.base.match(re)) {
- this.base += '/';
- }
- return this;
- },
-
- addbaseurl: function(value) {
- var newbase = this.base + value;
- return this.baseurl(newbase);
- },
-
- getbaseurl: function() {
- return decodeURIComponent(this.base.substr(0, this.base.length - 1));
- },
-
- register_callback: function(name, callback) {
- this.callbacks[name] = callback;
- },
-
- get_callback: function(name) {
- return this.callbacks[name];
- },
-
- set_default_callback: function(callback) {
- this.register_callback("default", callback);
- if (this.ca_id === undefined) {
- this.ca_id =
- setInterval($.proxy(this.check, this), this.options.checkinterval);
- }
- },
-
- check: function() {
- var rawhash = this.get_raw_hash();
-
- if (this.serialized === rawhash && this.force === undefined) {
- return;
- }
- delete this.force;
- this.from_string(rawhash);
-
- if (!this.serialized) {
- window.location.hash = this.options.deflocation;
- return;
- }
- if (!this.updatenext) {
- this.updatenext = true;
- return;
- }
-
- $.ajax({
- url: this.serialized,
- cache: false,
- dataType: 'json'
- }).done($.proxy(function(resp) {
- var callback = (resp.callback !== undefined) ? resp.callback : "default";
-
- this.callbacks[callback](resp);
- if (resp.respmsg) {
- $("body").notify("success", resp.respmsg, 2000);
- }
- }, this));
- }
-};
diff --git a/modoboa/static/js/jquery.htmltable.js b/modoboa/static/js/jquery.htmltable.js
deleted file mode 100644
index 25737c089..000000000
--- a/modoboa/static/js/jquery.htmltable.js
+++ /dev/null
@@ -1,217 +0,0 @@
-(function($) {
- var HtmlTable = function(element, options) {
- this.initialize(element, options);
- };
-
- HtmlTable.prototype = {
- constructor: HtmlTable,
-
- initialize: function(element, options) {
- this.$element = $(element);
- this.options = $.extend({}, $.fn.htmltable.defaults, options);
- this.shift_pressed = false;
- this.ctrl_pressed = false;
- this.last_selection = null;
- this.listen();
-
- this.$element.css({
- "-moz-user-select": "-moz-none",
- "-khtml-user-select": "none",
- "-webkit-user-select": "none",
- "-ms-user-select": "none",
- "user-select": "none"
- });
- this.$element.attr("unselectable", "on");
- },
-
- listen: function() {
- this.$element
- .off("change", "input[type=checkbox]")
- .on("change", "input[type=checkbox]",
- $.proxy(this.toggle_select, this));
- $(document).on("keydown", "body", $.proxy(this.keydown, this));
- $(document).on("keyup", "body", $.proxy(this.keyup, this));
- },
-
- /**
- * Effective change of a row's state.
- */
- _toggle_select: function($row) {
- var $input = $row.find(this.options.input_selector);
-
- if ($row.hasClass(this.options.row_selected_class)) {
- $input.prop('checked', false);
- $row.removeClass(this.options.row_selected_class);
- if (this.options.row_unselected_event !== undefined) {
- this.options.row_unselected_event($row);
- }
- } else {
- $input.prop('checked', true);
- $row.addClass(this.options.row_selected_class);
- if (this.options.row_selected_event !== undefined) {
- this.options.row_selected_event($row);
- }
- }
- },
-
- /**
- * Set the row's state, cancel the change if the current state
- * and the new state are identical
- */
- _set_select: function($row, selected) {
- var $input = $row.find(this.options.input_selector);
-
- if (this.is_selected($row) == selected)
- return;
- $input.prop('checked', selected);
- if (selected) {
- $row.addClass(this.options.row_selected_class);
- if (this.options.row_unselected_event !== undefined) {
- this.options.row_unselected_event($row);
- }
- } else {
- $row.removeClass(this.options.row_selected_class);
- if (this.options.row_selected_event !== undefined) {
- this.options.row_selected_event($row);
- }
- }
- },
-
- /**
- * Change the selection state of a given row.
- *
- * Holding the shift key between two selections let users
- * select all rows between those two locations.
- *
- * Holding the ctrl key between two selections let users make
- * an additive selection.
- */
- toggle_select: function(e) {
- var $row = $(e.target).parents(this.options.row_selector);
-
- if (this.shift_pressed && this.last_selection) {
- var select = !this.is_selected($row);
- var itfunc = ($row.index() >= this.last_selection.index()) ?
- "next" : "prev";
- var $cur_row;
-
- for ($cur_row = this.last_selection;
- $cur_row.length;
- $cur_row = $cur_row[itfunc](this.options.row_selector)) {
- this._set_select($cur_row, select);
- if ($row.attr("id") == $cur_row.attr("id")) {
- break;
- }
- }
- this.last_selection = $row;
- return;
- } else if (!this.options.keep_selection && !this.ctrl_pressed &&
- (!this.last_selection || !this.last_selection.is($row))) {
- this.clear_selection();
- }
- this.last_selection = $row;
- this._toggle_select($row);
- },
-
- /**
- * Change the selection state of all rows.
- */
- toggleSelectAll: function(value) {
- if (!value) {
- this.clear_selection();
- } else {
- $(this.options.row_selector).each((index, row) => {
- this._set_select($(row), true);
- });
- }
- },
-
- /**
- * Check if $row is selected or not.
- */
- is_selected: function($row) {
- return $row.hasClass(this.options.row_selected_class);
- },
-
- /**
- * Return the current selection. (jQuery object)
- */
- current_selection: function() {
- return this.$element.find("." + this.options.row_selected_class);
- },
-
- /**
- * Cancel the current selection.
- */
- clear_selection: function() {
- this.last_selection = null;
- this.current_selection().removeClass(this.options.row_selected_class);
- this.$element.find(this.options.input_selector).prop('checked', false);
- if (this.options.row_unselected_event !== undefined) {
- this.options.row_unselected_event();
- }
- },
-
- /**
- * Manually select a row.
- */
- select_row: function($row) {
- if (!this.last_selection) {
- this.last_selection = $row;
- }
- $row.addClass(this.options.row_selected_class);
- if (this.options.row_selected_event !== undefined) {
- this.options.row_selected_event($row);
- }
- },
-
- keydown: function(e) {
- switch (e.which) {
- case 16:
- e.preventDefault();
- this.shift_pressed = true;
- break;
- case 17:
- this.ctrl_pressed = true;
- break;
- }
- },
-
- keyup: function(e) {
- switch (e.which) {
- case 16:
- e.preventDefault();
- this.shift_pressed = false;
- break;
- case 17:
- this.ctrl_pressed = false;
- break;
- }
- }
- };
-
- $.fn.htmltable = function(method) {
- var args = arguments;
-
- return this.each(function() {
- var $this = $(this),
- data = $this.data('htmltable'),
- options = typeof method === "object" && method;
-
- if (!data) {
- $this.data('htmltable', new HtmlTable(this, options));
- data = $this.data('htmltable');
- }
- if (typeof method === "string") {
- data[method].apply(data, Array.prototype.slice.call(args, 1));
- }
- });
- };
-
- $.fn.htmltable.defaults = {
- row_selector: 'tr',
- input_selector: "input[type=checkbox]",
- row_selected_class: 'tr-selected',
- keep_selection: false
- };
-})(jQuery);
diff --git a/modoboa/static/js/jquery.infinitescroll.js b/modoboa/static/js/jquery.infinitescroll.js
deleted file mode 100644
index 814e766f4..000000000
--- a/modoboa/static/js/jquery.infinitescroll.js
+++ /dev/null
@@ -1,199 +0,0 @@
-/**
- * Infinite scroll plugin for jQuery.
- *
- * @author {Antoine Nguyen}
- */
-!function($) {
- 'use strict';
-
- /**
- * Creates an instance of InfiniteScroll.
- *
- * @constructor
- * @this InfiniteScroll
- * @param {object} element
- * @param {dictionary} options - instance options
- */
- var InfiniteScroll = function(element, options) {
- this.$element = $(element);
- this.$data = $(element).data();
- this.$options = options;
- this.executing = false;
- this.end_of_results = false;
- if (this.$options.initial_pages !== undefined &&
- this.$options.initial_pages.length > 0) {
- this.current_page = this.$options.initial_pages[0];
- this.loaded_pages = this.$options.initial_pages;
- } else {
- this.current_page = 1;
- this.loaded_pages = [this.current_page];
- }
- this.resume();
- };
-
- InfiniteScroll.prototype = {
- constructor: InfiniteScroll,
-
- /**
- * Scroll event handler.
- *
- * @this InfiniteScroll
- */
- on_scroll: function() {
- var bottom = this.$options.calculate_bottom(this.$element);
-
- if (bottom === undefined || bottom < 0) {
- return;
- }
- if (this.$element.scrollTop() >= bottom) {
- this.load_next_page();
- } else if (this.$element.scrollTop() === 0) {
- this.load_previous_page();
- }
- },
-
- /**
- * Load the previous page from the server.
- *
- * @private
- * @this InfiniteScroll
- */
- load_previous_page: function() {
- var $this = this;
-
- if ($this.executing || $.inArray(1, $this.loaded_pages) != -1) {
- return;
- }
-
- while ($this.current_page > 0) {
- $this.current_page -= 1;
- if ($.inArray($this.current_page, $this.loaded_pages) == -1) {
- break;
- }
- }
- if ($this.current_page === 0) {
- $this.current_page = 1;
- return;
- }
- this.load_page("up");
- },
-
- /**
- * Load the next page from the server.
- *
- * @this InfiniteScroll
- */
- load_next_page: function() {
- var $this = this;
-
- if ($this.executing || $this.end_of_results) {
- return;
- }
- while (true) {
- $this.current_page += 1;
- if ($.inArray($this.current_page, $this.loaded_pages) == -1) {
- break;
- }
- }
- this.load_page("down");
- },
-
- /**
- * Load a page's content.
- *
- * @private
- * @this InfiniteScroll
- * @param {string} direction - direction of the scroll (up or down)
- */
- load_page: function(direction) {
- var args = (this.$options.get_args) ? this.$options.get_args() : {};
- var $this = this;
-
- this.executing = true;
- args.page = this.current_page;
- $.ajax({
- contentType: 'application/json; charset=UTF-8',
- data: args,
- url: $this.$options.url,
- type: 'GET',
- success: function(data) {
- $this.$options.process_results(data, direction);
- if (data.length === 0) {
- $this.end_of_results = true;
- $this.$options.end_of_list_reached($this.$element);
- }
- $this.executing = false;
- $this.loaded_pages.push($this.current_page);
- }
- });
- },
-
- /**
- * Reset the loaded pages cache.
- *
- * @this InfiniteScroll
- * @param {Array} new_pages - the new loaded pages
- */
- reset_loaded_pages: function(new_pages) {
- if (new_pages !== undefined) {
- this.current_page = new_pages[0];
- this.loaded_pages = new_pages;
- } else {
- this.current_page = this.$options.initial_page;
- this.loaded_pages = [this.$options.initial_pages];
- }
- this.end_of_results = false;
- },
-
- /**
- * Suspend the "infinite scroll" mode.
- *
- * @this InfiniteScroll
- */
- pause: function() {
- this.$element.unbind("scroll");
- },
-
- /**
- * Resume the "infinite scroll" mode.
- *
- * @this InfiniteScroll
- */
- resume: function() {
- this.$element.scroll($.proxy(this.on_scroll, this));
- }
- };
-
- $.fn.infinite_scroll = function (option) {
- var args = arguments;
-
- return this.each(function () {
- var $this = $(this),
- data = $this.data('infinite-scroll'),
- options = $.extend(
- {}, $.fn.infinite_scroll.defaults,
- typeof option == 'object' && option
- );
-
- if (!data) {
- $this.data('infinite-scroll', (
- data = new InfiniteScroll(this, options))
- );
- }
- if (typeof option == 'string') {
- data[option].apply(data, Array.prototype.slice.call(args, 1));
- }
- });
- };
-
- $.fn.infinite_scroll.defaults = {
- initial_page: 1,
- calculate_bottom: null,
- get_data: null,
- process_results: null,
- end_of_list_reached: null,
- url: ''
- };
-
- $.fn.infinite_scroll.Constructor = InfiniteScroll;
-}(window.jQuery);
diff --git a/modoboa/static/js/jquery.sortable.js b/modoboa/static/js/jquery.sortable.js
deleted file mode 100644
index 1690ea203..000000000
--- a/modoboa/static/js/jquery.sortable.js
+++ /dev/null
@@ -1,95 +0,0 @@
-(function($) {
- /**
- * Return an instance of Sortable.
- *
- * @constructor
- * @param {Object} element -
- * @param {Object} options - instance options
- */
- var Sortable = function(element, options) {
- this.initialize(element, options);
- };
-
- Sortable.prototype = {
- constructor: Sortable,
-
- initialize: function(element, options) {
- this.$element = $(element);
- this.options = $.extend({}, $.fn.sortable.defaults, options);
- this.$element.addClass('sort-header');
- this.listen();
- },
-
- listen: function() {
- this.$element.click($.proxy(this.sort, this));
- },
-
- change_sort_order: function(e, new_sort_order) {
- if (new_sort_order != this.$element.attr('data-sort_order')) {
- this.$element.removeClass('sort-header-desc sort-header-asc');
- }
- },
-
- sort: function(e) {
- e.preventDefault();
- var dir = this.select();
-
- if (this.options.onSortOrderChange) {
- this.options.onSortOrderChange(this.$element.attr('data-sort_order'), dir);
- }
- },
-
- /**
- * Mark a column as the one used to sort content.
- *
- * @this Sortable
- * @param {string} dir - optional sort direction (up or down)
- * @return {string} - new sort direction
- */
- select: function(dir) {
- $("span.sort-selection").remove();
- if (dir !== undefined) {
- this.$element.removeClass("sort-header-" + ((dir == "asc") ? "desc" : "asc"));
- this.$element.addClass("sort-header-" + dir);
- } else {
- if (this.$element.hasClass("sort-header-desc")) {
- this.$element
- .removeClass("sort-header-desc")
- .addClass("sort-header-asc");
- dir = "asc";
- } else {
- this.$element
- .removeClass("sort-header-asc")
- .addClass("sort-header-desc");
- dir = "desc";
- }
- }
- this.$element.append($("
", {
- "class": "sort-selection fa fa-chevron-" + ((dir == 'asc') ? 'up' : 'down')
- }));
- return dir;
- }
- };
-
- $.fn.sortable = function(method) {
- var args = arguments;
-
- return this.each(function() {
- var $this = $(this),
- data = $this.data('sortable'),
- options = typeof method === "object" && method;
-
- if (!data) {
- $this.data('sortable', new Sortable(this, options));
- data = $this.data('sortable');
- }
- if (typeof method === "string") {
- data[method].apply(data, Array.prototype.slice.call(args, 1));
- }
- });
- };
-
- $.fn.sortable.defaults = {
- onSortOrderChange: null
- };
-})(jQuery);
diff --git a/modoboa/static/js/listing.js b/modoboa/static/js/listing.js
deleted file mode 100644
index 2fc96fbae..000000000
--- a/modoboa/static/js/listing.js
+++ /dev/null
@@ -1,299 +0,0 @@
-/**
- * Return an instance of Listing.
- *
- * @constructor
- * @param {Object} options - instance options
- */
-var Listing = function(options) {
- this.initialize(options);
-};
-
-Listing.prototype = {
- constructor: Listing,
-
- listing_defaults: {
- sortable_selector: '.sortable',
- with_searchform: true,
- load_page_url: null,
- navigation_params: ["sort_order", "searchquery"],
- scroll_container: null,
- main_table_id: "objects_table",
- eor_message: gettext("No more entry to show")
- },
-
- initialize: function(options) {
- this.options = $.extend({}, this.listing_defaults, options);
- this.tag_handlers = {};
- this.navobj = new History(this.options);
- $(document).on("click", "a.filter", $.proxy(this.filter_by_tag, 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();
- this.navobj.updateparams($link.attr("href")).update();
- },
-
- /**
- * Return extra arguments used to fetch a page.
- *
- * @this Listing
- */
- get_load_page_args: function() {
- var $this = this;
- var args = {};
-
- $.each(this.options.navigation_params, function(pos, param) {
- if ($this.navobj.hasparam(param)) {
- args[param] = $this.navobj.getparam(param);
- }
- });
- return args;
- },
-
- /**
- * Calculate the bottom position of the scroll container.
- *
- * @param {Object} $element - scroll container object
- */
- calculate_bottom: function($element) {
- var $last_row = $("#" + this.options.main_table_id)
- .find("tr").last();
- return $last_row.offset().top - $element.height();
- },
-
- /**
- * A new page has been received, inject it.
- *
- * @param {Object} data - page content
- * @param {string} direction - scroll direction (up or down)
- */
- add_new_page: function(data, direction) {
- var $container = $("#{0} tbody".format(this.options.main_table_id));
-
- if (direction == "down") {
- $container.html(function(pos, oldhtml) {
- return oldhtml + data.rows;
- });
- } else {
- $container.html(function(pos, oldhtml) {
- return data.rows + oldhtml;
- });
- }
- },
-
- /**
- * Callback called when no more page can be loaded.
- *
- * @this Listing
- */
- end_of_list_reached: function(element) {
- $("#" + this.options.main_table_id).after(
- $("
{0}
".format(
- this.options.eor_message
- ))
- );
- },
-
- /**
- * Update the listing with the received data.
- *
- * @this Listing
- * @param {Object} data - new content
- */
- update_listing: function(data, with_infinite_scroll) {
- var $this = this;
- var $scroll_container = (this.options.scroll_container) ?
- $(this.options.scroll_container) : $(window);
-
- $scroll_container.scrollTop(0);
- if (with_infinite_scroll || with_infinite_scroll === undefined) {
- if ($scroll_container.data("infinite-scroll") !== undefined) {
- $scroll_container.infinite_scroll("reset_loaded_pages", data.pages);
- $scroll_container.infinite_scroll("resume");
- $("#eor_message").remove();
- } else {
- $scroll_container.infinite_scroll({
- initial_pages: data.pages,
- url: this.options.load_page_url,
- get_args: $.proxy(this.get_load_page_args, this),
- calculate_bottom: $.proxy(this.calculate_bottom, this),
- process_results: $.proxy(this.add_new_page, this),
- end_of_list_reached: $.proxy(this.end_of_list_reached, this)
- });
- }
- } else if ($scroll_container.data("infinite-scroll") !== undefined) {
- $scroll_container.infinite_scroll("pause");
- }
-
- var $sortables = $(this.options.sortable_selector);
- if ($sortables.length) {
- $(this.options.sortable_selector).sortable({
- onSortOrderChange: $.proxy(this.change_sort_order, this)
- });
- this.set_sort_order();
- }
- },
-
- /**
- * Set current sort order.
- *
- * @this Listing
- */
- set_sort_order: function() {
- var sort_order = this.navobj.getparam("sort_order");
- var sort_dir;
-
- if (!sort_order) {
- return;
- }
- if (sort_order[0] == '-') {
- sort_dir = "desc";
- sort_order = sort_order.substr(1);
- } else {
- sort_dir = 'asc';
- }
- $("th[data-sort_order=" + sort_order + "]").sortable('select', sort_dir);
- },
-
- /**
- * Change current sort order.
- *
- * @this Listing
- */
- change_sort_order: function(sort_order, dir) {
- if (dir == "desc") {
- sort_order = "-" + sort_order;
- }
- this.navobj.setparam("sort_order", sort_order).update();
- },
-
- /**
- * Register a new tag handler.
- *
- * @this Listing
- * @param {string} name - name of the tag
- * @param {function} handler - reference to a function (optional)
- */
- register_tag_handler: function(name, handler) {
- if (handler === undefined) {
- handler = this.generic_tag_handler;
- }
- this.tag_handlers[name] = handler;
- if (this.navobj.getparam(name + "filter") !== undefined) {
- var text = this.navobj.getparam(name + "filter");
- $("#taglist").append(this.make_tag(text, name));
- }
- },
-
- /**
- * Default tag handler.
- *
- * @this Listing
- * @param {string} tag - name of the tag
- * @param {Object} $link - tag that was clicked
- * @return {boolean} - return true if handler has been executed
- */
- 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();
- $("#taglist").append(this.make_tag(text, tag));
- return true;
- }
- return false;
- },
-
- /**
- * Build a button to remove a specific filter.
- *
- * @this Listing
- * @param {string} text - text of the button
- * @param {string} type - tag type
- * @return {Object} - new button object
- */
- make_tag: function(text, type) {
- var $tag = $("
", {
- "name": type, "class" : "btn btn-default btn-xs",
- "html": " " + htmlEncode(text)
- });
-
- $("
", {"class" : "fa fa-remove"}).prependTo($tag);
- $tag.click($.proxy(this.remove_tag, this));
- return $tag;
- },
-
- /**
- * Click event : remove a tag button.
- *
- * @this Listing
- * @param {Object} e - event object
- */
- 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();
- },
-
- /**
- * Click event: filter the listing when a tag is clicked.
- *
- * @this Listing
- * @param {Object} e - event object
- */
- 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;
- }
- }
- }
-};
diff --git a/modoboa/static/js/notify.js b/modoboa/static/js/notify.js
deleted file mode 100644
index 8694671ab..000000000
--- a/modoboa/static/js/notify.js
+++ /dev/null
@@ -1,104 +0,0 @@
-(function($) {
- var Notify = function(element, options) {
- this.$element = $(element);
- this.options = $.extend({}, $.fn.notify.defaults, options);
- };
-
- Notify.prototype = {
- constructor: Notify,
-
- build_box: function(bid) {
- if (bid === undefined) {
- bid = "notifybox";
- }
- var div = $("
", {
- id: bid,
- click: $.proxy(this.destroy_box, this)
- }).css({
- position: "fixed"
- });
-
- return div;
- },
-
- destroy_box: function(evt) {
- evt.preventDefault();
- this.$element.hide().remove();
- },
-
- set_position: function(box) {
- box.css({
- 'z-index': 100,
- top: this.options.top_position,
- left: "50%",
- 'margin-left': -box.outerWidth(true) / 2
- });
- },
-
- set_message: function(box, value) {
- var content = '
' + value;
-
- box.html(content);
- },
-
- show: function(klass, message, timer) {
- var nbox = this.build_box();
-
- if (klass != "normal") {
- nbox.addClass("alert-" + klass);
- }
- this.set_message(nbox, message);
- this.$element.append(nbox);
- this.set_position(nbox);
- if (timer !== undefined) {
- window.setTimeout(function() {
- nbox.alert('close');
- }, timer);
- }
- return this;
- },
-
- success: function(message, timer) {
- return this.show.apply(this, ["success", message, timer]);
- },
-
- info: function(message, timer) {
- return this.show.apply(this, ["info", message, timer]);
- },
-
- error: function(message, timer) {
- return this.show.apply(this, ["danger", message, timer]);
- },
-
- warning: function(message, timer) {
- return this.show.apply(this, ["warning", message, timer]);
- },
-
- hide: function() {
-
- }
- };
-
- $.fn.notify = function(method) {
- var args = arguments;
-
- return this.each(function() {
- var $this = $(this),
- data = $this.data('notify'),
- options = typeof method === "object" && method;
-
- if (!data) {
- $this.data('notify', new Notify(this, options));
- data = $this.data('notify');
- }
- if (typeof method === "string") {
- data[method].apply(data, Array.prototype.slice.call(args, 1));
- }
- });
- };
-
- $.fn.notify.defaults = {
- top_position: 50
- };
-
-})(jQuery);
diff --git a/modoboa/static/js/poller.js b/modoboa/static/js/poller.js
deleted file mode 100644
index acca1c4e5..000000000
--- a/modoboa/static/js/poller.js
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Simple poller plugin.
- *
- * Sends a request at a given frequency.
- */
-var Poller = function(url, options) {
- this.initialize(url, options);
-};
-
-Poller.prototype = {
- constructor: Poller,
-
- defaults: {
- interval: 2000,
- success_cb: null,
- error_cb: null
- },
-
- initialize: function(url, options) {
- this.url = url;
- this.options = $.extend({}, this.defaults, options);
- this.running_request = false;
- this.paused = false;
- this.reset();
- },
-
- reset: function() {
- if (!this.paused) {
- this.tid = setTimeout($.proxy(this.send_request, this), this.options.interval);
- }
- },
-
- pause: function() {
- this.paused = true;
- if (!this.tid) {
- return;
- }
- clearTimeout(this.tid);
- },
-
- resume: function() {
- if (!this.paused) {
- return;
- }
- this.paused = false;
- this.reset();
- },
-
- send_request: function() {
- var poller = this;
- var args = "";
-
- if (this.options.args != undefined) {
- args = "?";
- if (typeof this.options.args === "function") {
- args += this.options.args();
- } else {
- args += this.options.args;
- }
- }
- this.running_request = true;
- $.ajax({
- url: this.url + args,
- dataType: 'json',
- global: false
- }).done(function(data) {
- poller.running_request = false;
- if (poller.options.success_cb) {
- poller.options.success_cb(data);
- }
- poller.reset();
- }).fail(function(jqxhr) {
- var data = $.parseJSON(jqxhr.responseText);
- $("body").notify("error", data);
- if (poller.options.error_cb) {
- poller.options.error_cb(data);
- }
- });
- }
-};
\ No newline at end of file
diff --git a/modoboa/static/js/searchbar.js b/modoboa/static/js/searchbar.js
deleted file mode 100644
index 10d163337..000000000
--- a/modoboa/static/js/searchbar.js
+++ /dev/null
@@ -1,86 +0,0 @@
-(function($) {
-
- /**
- * Return an instance of SearchBar.
- *
- * @constructor
- * @param {Object} element -
- * @param {Object} options - instance options
- */
- var SearchBar = function(element, options) {
- this.initialize(element, options);
- };
-
- SearchBar.prototype = {
- constructor: SearchBar,
-
- initialize: function(element, options) {
- this.$element = $(element);
- this.options = $.extend({}, $.fn.searchbar.defaults, options);
-
- this.$element.change($.proxy(this.pattern_change, this));
- this.$element.click(function(e) {
- $(this).select();
- });
- this.$element.blur(function(e) {
- var $this = $(this);
- if ($this.val() === "") {
- $this.val(gettext("Search..."));
- }
- });
- if (this.options.navobj.params.pattern !== undefined) {
- this.$element.val(this.options.navobj.getparam("pattern"));
- }
- if (this.options.navobj.params.criteria !== undefined) {
- $("#crit_" + this.options.navobj.params.criteria).attr("checked", "checked");
- }
- },
-
- /**
- * Change event: apply search criterion.
- *
- * @this SearchBar
- * @param {Object} e - event object
- */
- pattern_change: function(e) {
- var $input = $(e.target);
- var criteria = $("input[name=scriteria]:checked").val();
- var pattern = $input.val();
-
- if (pattern !== "") {
- this.options.navobj.setparams({
- pattern: pattern,
- criteria: criteria
- });
- } else {
- this.options.navobj.delparam("pattern");
- this.options.navobj.delparam("criteria");
- this.options.navobj.delparam("page");
- }
- if (this.options.pattern_changed) {
- this.options.pattern_changed(this.options.navobj);
- }
- this.options.navobj.update();
- }
- };
-
- $.fn.searchbar = function(method) {
- return this.each(function() {
- var $this = $(this),
- data = $this.data('searchbar'),
- options = typeof method === "object" && method;
-
- if (!data) {
- $this.data('searchbar', new SearchBar(this, options));
- }
- if (typeof method === "string") {
- data[method]();
- }
- });
- };
-
- $.fn.searchbar.defaults = {
- navobj: null,
- pattern_changed: null
- };
-})(jQuery);
diff --git a/modoboa/static/js/top_notifications.js b/modoboa/static/js/top_notifications.js
deleted file mode 100644
index 3e29911f4..000000000
--- a/modoboa/static/js/top_notifications.js
+++ /dev/null
@@ -1,101 +0,0 @@
-/**
- * Top notifications poller.
- */
-
-var TopNotifications = function(options) {
- this.initialize(options);
-};
-
-TopNotifications.prototype = {
- constructor: TopNotifications,
-
- defaults: {
- container_id: "#top_notifications",
- global_counter_id: "#alerts-counter",
- url: null,
- interval: 1000
- },
-
- /**
- * Constructor.
- */
- initialize: function(options) {
- this.options = $.extend({}, this.defaults, options);
- this.poller = new Poller(this.options.url, {
- interval: this.options.interval,
- success_cb: $.proxy(this.update, this)
- });
- this.$container = $(this.options.container_id);
- },
-
- /**
- * Build a notification entry content.
- */
- build_link_content: function(data) {
- var content = "";
-
- if (data.counter) {
- content = "
" + data.counter + " " +
- data.text;
- } else {
- content = "
" + data.text;
- }
- return content;
- },
-
- /**
- * Append an entry to the notification list.
- */
- append_entry: function(data) {
- if ((data.counter !== undefined && data.counter === 0) ||
- (data.counter === undefined && data.text === undefined)) {
- return;
- }
-
- var $li = $("
");
-
- $li.append(
- $("
", {
- id: data.id, href: data.url,
- html: this.build_link_content(data)
- })
- );
- this.$container.find(".dropdown-menu").append($li);
- },
-
- /**
- * Update an existing entry in the notification list.
- */
- update_entry: function(data) {
- var $link = $("#" + data.id);
-
- if ((data.counter !== undefined && data.counter === 0) ||
- (data.counter === undefined && data.text === undefined)) {
- $link.parent().remove();
- return;
- }
- $link.html(this.build_link_content(data));
- },
-
- /**
- * Poller callback.
- */
- update: function(data) {
- for (var cpt = 0; cpt < data.length; cpt++) {
- var $link = $("#" + data[cpt].id);
- if (!$link.length) {
- this.append_entry(data[cpt]);
- } else {
- this.update_entry(data[cpt]);
- }
- }
- var $entries = this.$container.find(".dropdown-menu li");
- if ($entries.length) {
- this.$container.removeClass("hidden");
- $(this.options.global_counter_id).html($entries.length);
- } else {
- this.$container.addClass("hidden");
- }
- }
-};
diff --git a/modoboa/static/js/twocols_nav.js b/modoboa/static/js/twocols_nav.js
deleted file mode 100644
index f862a50d7..000000000
--- a/modoboa/static/js/twocols_nav.js
+++ /dev/null
@@ -1,202 +0,0 @@
-/**
- * Return an instance of TwocolsNav.
- *
- * @constructor
- */
-
-/* global Listing */
-
-var TwocolsNav = function(options) {
- Listing.call(this, options);
-};
-
-TwocolsNav.prototype = {
- defaults: {
- deflocation: null,
- formid: "#form",
- divid: "#content",
- reload_exceptions: null
- },
-
- initialize: function(options) {
- this.options = $.extend({}, this.defaults, options);
- this.options.defcallback = $.proxy(this.default_cb, this);
- Listing.prototype.initialize.call(this, this.options);
- this.listen();
- this.navobj.register_callback(
- "security", $.proxy(this.security_callback, this));
- },
-
- listen: function() {
- $("a.ajaxnav").click($.proxy(this.load_section, this));
- $(document).on("click", "#update", $.proxy(function(e) {
- var $form = $(e.target).closest("form");
- simple_ajax_form_post(e, {
- formid: $form.attr("id"),
- modal: false,
- reload_on_success: false,
- success_cb: $.proxy(this.save_cb, this)
- });
- }, this));
- var formId = 'parameters_form';
- $(document).on('submit', '#' + formId, $.proxy(function(evt) {
- simple_ajax_form_post(evt, {
- formid: formId,
- modal: false,
- reload_on_success: false,
- success_cb: $.proxy(this.save_cb, this),
- error_cb: function(data) {
- window.scrollTo(0, 0);
- $('a[data-app="' + data.prefix + '"]').tab('show');
- }
- });
- }, this));
- },
-
- update_content: function(data) {
- if (data.content) {
- $('#' + this.options.divid).html(data.content);
- }
- this.update_listing(data, false);
- if (data.onload_cb) {
- eval(data.onload_cb + '()');
- }
- if (data.respmsg) {
- $("body").notify("error", data.respmsg);
- }
- $('#' + this.options.divid + ' select').change($.proxy(this.select_change, this));
- $('#' + this.options.divid + ' input[type=radio]').click($.proxy(this.radio_clicked, this));
- $(".help").popover({
- placement: 'bottom',
- trigger: 'hover'
- }).click(function(e) {e.preventDefault();});
- $('#' + this.options.divid + ' select').change();
- $('#' + this.options.divid + ' input[type=radio]:checked').click();
- },
-
- propagate_change: function($node) {
- var $select = $node.find("select");
- var $radio = $node.find("input[type=radio]");
- if ($select.length) {
- $select.change();
- }
- if ($radio.length) {
- $radio.click();
- }
- },
-
- toggle_field_visibility: function($field, $parent, value) {
- if ($parent.attr("disabled") === undefined &&
- $field.attr("data-visibility-value") === value) {
- $field.attr("disabled", null);
- $field.show();
- this.propagate_change($field);
- } else {
- $field.hide();
- $field.attr("disabled", "disabled");
- this.propagate_change($field);
- }
- },
-
- select_change: function(e) {
- var instance = this;
- var $target = $(e.target);
- var $parent = $target.parents("div.form-group");
-
- $('div[data-visibility-field="' + $target.attr("id") + '"]').each(function(idx) {
- instance.toggle_field_visibility($(this), $parent, $target.val());
- });
- $('h5[data-visibility-field="' + $target.attr("id") + '"]').each(function(idx) {
- instance.toggle_field_visibility($(this), $parent, $target.val());
- });
- },
-
- radio_clicked: function(e) {
- var instance = this;
- var $target = $(e.target);
- var $parent = $target.parents("div.form-group");
- var realid = $target.attr("id");
-
- realid = realid.substr(0, realid.length - 2);
- $('div[data-visibility-field="' + realid + '"]').each(function(idx) {
- instance.toggle_field_visibility($(this), $parent, $target.val());
- });
- $('h5[data-visibility-field="' + realid + '"]').each(function(idx) {
- instance.toggle_field_visibility($(this), $parent, $target.val());
- });
- },
-
- save_cb: function(data) {
- clean_form_errors(this.options.formid);
- if (this.options.reload_exceptions) {
- for (var i = 0; i < this.options.reload_exceptions.length; i++) {
- if (this.navobj.getbaseurl() == this.options.reload_exceptions[i]) {
- window.location.reload();
- break;
- }
- }
- }
- $("body").notify("success", data, 2000);
- },
-
- load_section: function(e) {
- var $link = get_target(e);
- e.preventDefault();
- this.navobj.parse_string($link.attr("href"), true).update();
- },
-
- /**
- * Select an entry in the left menu based on current url.
- */
- select_left_menu: function() {
- $("a.ajaxnav").parent().removeClass("active");
- $("a[name=" + this.navobj.getbaseurl() + "]").parent().addClass("active");
- },
-
- default_cb: function(data) {
- this.select_left_menu();
- this.update_content(data);
- },
-
- /**
- * Navigation callback: security.
- */
- security_callback: function (data) {
- this.select_left_menu();
- this.update_content(data);
- $('#start-tfa-setup').click(this.startTFASetup);
- $('#finalize-tfa-setup').click(this.finalizeTFASetup);
- },
-
- startTFASetup: function (evt) {
- evt.preventDefault();
- $.ajax({
- url: window.root_url + '/api/v1/account/tfa/setup/',
- type: 'post',
- contentType: 'application/json'
- }).done(function (resp) {
- window.location.reload();
- });
- },
-
- finalizeTFASetup: function (evt) {
- evt.preventDefault();
- var data = {
- pin_code: $('#pin-code').val()
- };
- $.ajax({
- url: window.root_url + '/api/v1/account/tfa/setup/check/',
- type: 'post',
- global: false,
- data: JSON.stringify(data),
- contentType: 'application/json'
- }).done(function (resp) {
- window.location.reload();
- }).fail(function (jqxhr) {
- var errors = JSON.parse(jqxhr.responseText);
- display_field_error($('#pin-code'), errors.pin_code.join(' '));
- });
- }
-};
-
-TwocolsNav.prototype = $.extend({}, Listing.prototype, TwocolsNav.prototype);
diff --git a/modoboa/static/pics/answered.png b/modoboa/static/pics/answered.png
deleted file mode 100644
index 9d31e533f..000000000
Binary files a/modoboa/static/pics/answered.png and /dev/null differ
diff --git a/modoboa/static/pics/attachment.png b/modoboa/static/pics/attachment.png
deleted file mode 100644
index 529bb7f55..000000000
Binary files a/modoboa/static/pics/attachment.png and /dev/null differ
diff --git a/modoboa/static/pics/collapsed.png b/modoboa/static/pics/collapsed.png
deleted file mode 100644
index 07cc1ec7d..000000000
Binary files a/modoboa/static/pics/collapsed.png and /dev/null differ
diff --git a/modoboa/static/pics/expanded.png b/modoboa/static/pics/expanded.png
deleted file mode 100644
index 1db079b79..000000000
Binary files a/modoboa/static/pics/expanded.png and /dev/null differ
diff --git a/modoboa/static/pics/forwarded.png b/modoboa/static/pics/forwarded.png
deleted file mode 100644
index 56d7d48ba..000000000
Binary files a/modoboa/static/pics/forwarded.png and /dev/null differ
diff --git a/modoboa/static/pics/grippy.png b/modoboa/static/pics/grippy.png
deleted file mode 100644
index 4aced88ff..000000000
Binary files a/modoboa/static/pics/grippy.png and /dev/null differ
diff --git a/modoboa/static/pics/release.png b/modoboa/static/pics/release.png
deleted file mode 100644
index 8b0fef9a8..000000000
Binary files a/modoboa/static/pics/release.png and /dev/null differ
diff --git a/modoboa/static/pics/transparent.png b/modoboa/static/pics/transparent.png
deleted file mode 100644
index 398ea4d8a..000000000
Binary files a/modoboa/static/pics/transparent.png and /dev/null differ