mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-11-19 10:04:05 +01:00
wip: UI refactoring
* When creating a simple user, the email field is automatically filled with the username see #204
This commit is contained in:
+42
-3
@@ -21,23 +21,62 @@ function domainform_cb() {
|
||||
});
|
||||
}
|
||||
|
||||
function accountform_init() {
|
||||
function generalform_init() {
|
||||
$("#id_role").change(function(e) {
|
||||
if ($(this).attr("value") == "SimpleUsers") {
|
||||
$("#id_username").autocompleter({
|
||||
from_character: "@",
|
||||
choices: get_domains_list
|
||||
});
|
||||
$("#id_email").addClass("disabled")
|
||||
.attr("readonly", "")
|
||||
.autocompleter("unbind");
|
||||
} else {
|
||||
$("#id_email").removeClass("disabled")
|
||||
.attr("readonly", null)
|
||||
.autocompleter("listen");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function mailform_init() {
|
||||
$("#id_aliases").dynamic_input();
|
||||
$("#id_email").autocompleter({
|
||||
from_character: "@",
|
||||
choices: get_domains_list
|
||||
});
|
||||
$("#id_role").trigger("change");
|
||||
$("#id_domains")
|
||||
.autocompleter({
|
||||
choices: get_domains_list
|
||||
})
|
||||
.dynamic_input();
|
||||
|
||||
}
|
||||
|
||||
function accountform_init() {
|
||||
generalform_init();
|
||||
mailform_init();
|
||||
}
|
||||
|
||||
function mailform_prefill() {
|
||||
if ($("#id_role").attr("value") == "SimpleUsers") {
|
||||
$("#id_email").attr("value", $("#id_username").attr("value"));
|
||||
}
|
||||
}
|
||||
|
||||
function newaccount_cb() {
|
||||
$('input:text:visible:first').focus();
|
||||
accountform_init();
|
||||
$("#wizard").cwizard({formid: "newaccount_form"});
|
||||
$("#wizard").cwizard({
|
||||
formid: "newaccount_form",
|
||||
transition_callbacks: {
|
||||
1: mailform_prefill
|
||||
},
|
||||
error_callbacks: {
|
||||
1: generalform_init,
|
||||
2: mailform_init
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function editaccount_cb() {
|
||||
|
||||
+31
-19
@@ -1,29 +1,41 @@
|
||||
(function($) {
|
||||
var Autocompleter = function(element, options) {
|
||||
this.$element = $(element);
|
||||
this.options = $.extend({}, $.fn.autocompleter.defaults, options);
|
||||
this.choices = {
|
||||
value: null
|
||||
};
|
||||
if (typeof this.options.choices === "function") {
|
||||
this.options.choices(this.choices);
|
||||
} else {
|
||||
this.choices.value = this.options.choices();
|
||||
}
|
||||
this.$menu =
|
||||
$('<ul class="dropdown-menu autocompleter" data-toggle="dropdown" />');
|
||||
$("body").append(this.$menu);
|
||||
this.$menu.on("click", $.proxy(this.select_entry, this));
|
||||
|
||||
this.$element.attr("autocomplete", "off");
|
||||
this.$element.keydown($.proxy(this.keydown, this));
|
||||
this.$element.keyup($.proxy(this.keyup, this));
|
||||
this.$element.blur($.proxy(this.hide_menu, this));
|
||||
this.initialize(element, options);
|
||||
};
|
||||
|
||||
Autocompleter.prototype = {
|
||||
constructor: Autocompleter,
|
||||
|
||||
initialize: function(element, options) {
|
||||
this.$element = $(element);
|
||||
this.options = $.extend({}, $.fn.autocompleter.defaults, options);
|
||||
this.choices = {
|
||||
value: null
|
||||
};
|
||||
if (typeof this.options.choices === "function") {
|
||||
this.options.choices(this.choices);
|
||||
} else {
|
||||
this.choices.value = this.options.choices();
|
||||
}
|
||||
this.$menu =
|
||||
$('<ul class="dropdown-menu autocompleter" data-toggle="dropdown" />');
|
||||
$("body").append(this.$menu);
|
||||
this.$menu.on("click", $.proxy(this.select_entry, this));
|
||||
|
||||
this.$element.attr("autocomplete", "off");
|
||||
this.listen();
|
||||
},
|
||||
|
||||
listen: function() {
|
||||
this.$element.keydown($.proxy(this.keydown, this));
|
||||
this.$element.keyup($.proxy(this.keyup, this));
|
||||
this.$element.blur($.proxy(this.hide_menu, this));
|
||||
},
|
||||
|
||||
unbind: function() {
|
||||
this.$element.off("keydown keyup blur");
|
||||
},
|
||||
|
||||
check_user_input: function() {
|
||||
var value = this.$element.attr("value");
|
||||
var start = -1;
|
||||
|
||||
@@ -28,8 +28,12 @@
|
||||
$.post($form.attr("action"), data, $.proxy(function(resp) {
|
||||
if (resp.status == "ok") {
|
||||
if (!last) {
|
||||
var stepid = resp.stepid + 1;
|
||||
$('input:text:visible:first').focus();
|
||||
$(".modal-header").find("small").html(resp.title);
|
||||
if (this.options.transition_callbacks[stepid] != undefined) {
|
||||
this.options.transition_callbacks[stepid]();
|
||||
}
|
||||
this.$element.carousel('next');
|
||||
} else {
|
||||
$("#modalbox").modal('hide').remove();
|
||||
@@ -38,12 +42,17 @@
|
||||
return;
|
||||
}
|
||||
if (resp.stepid != undefined && resp.form != undefined) {
|
||||
$("#step" + (resp.stepid + 1)).html(resp.form);
|
||||
var stepid = resp.stepid + 1;
|
||||
$("#step" + stepid).html(resp.form);
|
||||
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));
|
||||
}
|
||||
this.listen();
|
||||
//this.listen();
|
||||
}, this));
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user