+var userMgr = {
+ _adduserDisplayed: false,
+ _deluserDisplayed: false,
+
+ init: function() {
+ if (sypSettings.loggedUser != "admin") {
+ return;
+ }
+
+ $("#add_user").show();
+
+ $("#add_user").click(function () {
+ userMgr.toggleAddUser();
+ return false;
+ });
+ $("#newuser_close").click(function () {
+ userMgr.closeAddUser()
+ });
+ $("#newuser").submit(function() {
+ try {
+ userMgr.add();
+ } catch(e) {}
+ return false;
+ });
+ },
+
+ uninit: function() {
+ if (this._adduserDisplayed) {
+ this.closeAddUser();
+ }
+ $("#add_user").unbind("click");
+ $("#add_user").hide();
+ $("#newuser_close").unbind("click");
+ $("#newuser").unbind("submit");
+ },
+
+ toggleAddUser: function() {
+ if (this._adduserDisplayed) {
+ this.closeAddUser();
+ } else {
+ this.showAddUser();
+ }
+ },
+
+ showAddUser: function() {
+ if (!Admin.cancelCurrentFeature()) {
+ return;
+ }
+
+ $(document).unbind("keydown").keydown(function(e) {
+ if (e.keyCode == 27) {
+ userMgr.closeAddUser()
+ e.preventDefault();
+ }
+ });
+
+ Admin.reset();
+ $("#newuser_area").show();
+ $("#newuser_name, #newuser_password, #newuser_password_confirm").val("");
+ $("#newuser_name, #newuser_password, #newuser_password_confirm, #newuser_submit").removeAttr('disabled');
+ $("#newuser_name").focus();;
+ this.commError("");
+
+ this._adduserDisplayed = true;
+ },
+
+ closeAddUser: function() {
+ $("#newuser_area").hide();
+ $(document).unbind("keydown");
+ this._adduserDisplayed = false;
+ },
+
+ add: function() {
+ var newuser_name = $("#newuser_name").val();
+ if (!newuser_name) {
+ this.commError(SypStrings.newUserNonameError);
+ $("#newuser_name").focus();
+ return;
+ }
+
+ var newuser_pass = $("#newuser_password").val();
+ var newuser_pass_confirm = $("#newuser_password_confirm").val();
+ if (newuser_pass != newuser_pass_confirm) {
+ this.commError(SypStrings.newUserPasswordmatchError);
+ $("#newuser_password").focus().select();
+ return;
+ }
+
+ this.commError("");
+
+ AjaxMgr.add({
+ form: $("#newuser"),
+ oncomplete: OpenLayers.Function.bind(this.ajaxReply, this),
+ onsend: function() { $("#newuser_throbber").css("visibility", "visible"); }
+ });
+ },
+
+ ajaxReply: function (data) {
+ $("#newuser_throbber").css("visibility", "hidden");
+ if (!data) {
+ this.commError(SypStrings.ServerError);
+ return;
+ }
+
+ var xml = new OpenLayers.Format.XML().read(data);
+ switch (xml.documentElement.nodeName.toLowerCase()) {
+ case "error":
+ switch (xml.documentElement.getAttribute("reason")) {
+ case "unauthorized":
+ pwdMgr.reset();
+ $("#cookie_warning").show();
+ Admin.reset();
+ this.uninit();
+ break;
+ case "server":
+ this.commError(SypStrings.ServerError);
+ $("#newuser_name").focus().select();
+ break;
+ case "request":
+ this.commError(SypStrings.RequestError);
+ $("#newuser_name").focus().select();
+ break;
+ case "newuser_exists":
+ this.commError(SypStrings.newUserExistsError);
+ $("#newuser_name").focus().select();
+ break;
+ default:
+ this.commError(SypStrings.UnconsistentError);
+ $("#newuser_name").focus().select();
+ break;
+ }
+ break;
+ case "success":
+ switch (xml.documentElement.getAttribute("request")) {
+ case "newuser":
+ this.commSuccess(SypStrings.newUserSuccess);
+ $("#newuser_name, #newuser_password, #newuser_password_confirm, #newuser_submit").attr('disabled', 'disabled');
+ break;
+ default:
+ this.commError(SypStrings.UnconsistentError);
+ $("newuser_name").focus().select();
+ break;
+ }
+ break;
+ default:
+ this.commError(SypStrings.UnconsistentError);
+ $("newuser_name").focus().select();
+ break;
+ }
+ },
+
+ commSuccess: function (message) {
+ $("#newuser_comm").text(message);
+ $("#newuser_comm").removeClass("error success").addClass("success");
+ },
+
+ commError: function (message) {
+ $("#newuser_comm").text(message);
+ $("#newuser_comm").removeClass("error success").addClass("error");
+ }
+}
+