1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
|
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
var contactSelectorAction = 'acls-contacts';
var defaultUserID = '';
var AclEditor = {
userRightsHeight: null,
userRightsWidth: null
};
var usersToSubscribe = [];
function addUser(userName, userID, type) {
var result = false;
if (!$(userID)) {
var ul = $("userList");
var lis = ul.childNodesWithTag("li");
var newNode = nodeForUser(userName, userID, canSubscribeUsers);
newNode.addClassName("normal-" + type);
var count = lis.length - 1;
var inserted = false;
while (count > -1 && !inserted) {
if ($(lis[count]).hasClassName("normal-user")) {
if ((count+1) < lis.length)
ul.insertBefore(newNode, lis[count+1]);
else
ul.appendChild(newNode);
inserted = true;
}
else {
count--;
}
}
if (!inserted) {
if (lis.length > 0)
ul.insertBefore(newNode, lis[0]);
else
ul.appendChild(newNode);
}
var url = window.location.href;
var elements = url.split("/");
elements[elements.length-1] = ("addUserInAcls?uid="
+ encodeURIComponent(userID.unescapeHTML()));
triggerAjaxRequest(elements.join("/"), addUserCallback, newNode);
result = true;
}
return result;
}
function addUserCallback(http) {
if (http.readyState == 4) {
if (!isHttpStatus204(http.status)) {
var node = http.callbackData;
node.parentNode.removeChild(node);
}
}
}
function setEventsOnUserNode(node) {
var n = $(node);
n.observe("mousedown", listRowMouseDownHandler);
n.observe("selectstart", listRowMouseDownHandler);
n.observe("dblclick", onOpenUserRights);
n.observe("click", onRowClick);
var cbParents = n.childNodesWithTag("label");
if (cbParents && cbParents.length) {
var cbParent = $(cbParents[0]);
var checkbox = cbParent.childNodesWithTag("input")[0];
$(checkbox).observe("change", onSubscriptionChange);
}
}
function onSubscriptionChange(event) {
var li = this.parentNode.parentNode;
var username = li.getAttribute("id");
var idx = usersToSubscribe.indexOf(username);
if (this.checked) {
if (idx < 0)
usersToSubscribe.push(username);
} else {
if (idx > -1)
usersToSubscribe.splice(idx, 1);
}
}
function nodeForUser(userName, userId, canSubscribe) {
var node = createElement("li");
node.id = userId;
var span = createElement("span");
span.addClassName("userFullName");
span.appendChild(document.createTextNode(" " + userName.unescapeHTML()));
node.appendChild(span);
if (canSubscribe) {
var label = createElement("label");
label.addClassName("subscriptionArea");
var cb = createElement("input");
cb.type = "checkbox";
label.appendChild(cb);
label.appendChild(document.createTextNode(_("Subscribe User")));
node.appendChild(label);
}
setEventsOnUserNode(node);
return node;
}
function onUserAdd(event) {
openUserFolderSelector(null, "user");
preventDefault(event);
}
function removeUserCallback(http) {
var node = http.callbackData;
if (http.readyState == 4
&& isHttpStatus204(http.status))
node.parentNode.removeChild(node);
else
log("error deleting user: " + node.getAttribute("id"));
}
function onUserRemove(event) {
var userList = $("userList");
var nodes = userList.getSelectedRows();
var url = window.location.href;
var elements = url.split("/");
elements[elements.length-1] = "removeUserFromAcls?uid=";
var baseURL = elements.join("/");
for (var i = 0; i < nodes.length; i++) {
var userId = nodes[i].id.unescapeHTML();
if (userId != defaultUserID && userId != "anonymous") {
triggerAjaxRequest(baseURL + encodeURIComponent(userId), removeUserCallback,
nodes[i]);
}
}
preventDefault(event);
}
function subscribeToFolder(refreshCallback, refreshCallbackData) {
var result = true;
if (UserLogin != refreshCallbackData["folder"]) {
result = addUser(refreshCallbackData["folderName"],
refreshCallbackData["folder"],
refreshCallbackData["type"]);
}
else
refreshCallbackData["window"].alert(_("You cannot subscribe to a folder that you own!"));
return result;
}
function openRightsForUserID(userID) {
var url = window.location.href;
var elements = url.split("/");
elements[elements.length-1] = "userRights?uid=" + encodeURIComponent(userID);
var height = AclEditor.userRightsHeight;
if (userID == "anonymous") {
height -= 42;
if (CurrentModule() == "Contacts") {
height -= 21;
}
}
window.open(elements.join("/"), "",
"width=" + AclEditor.userRightsWidth
+ ",height=" + height
+ ",resizable=0,scrollbars=0,toolbar=0,"
+ "location=0,directories=0,status=0,menubar=0,copyhistory=0");
}
function openRightsForUser(button) {
var nodes = $("userList").getSelectedRows();
if (nodes.length > 0)
openRightsForUserID(nodes[0].id.unescapeHTML());
return false;
}
function onOpenUserRights(event) {
openRightsForUser();
preventDefault(event);
}
function onAclLoadHandler() {
var ul = $("userList");
var lis = ul.childNodesWithTag("li");
for (var i = 0; i < lis.length; i++)
setEventsOnUserNode(lis[i]);
var input = $("defaultUserID");
if (input) {
defaultUserID = $("defaultUserID").value;
var userNode = nodeForUser(_("Any Authenticated User"),
defaultUserID.escapeHTML());
userNode.addClassName("any-user");
userNode.setAttribute("title",
_("Any user not listed above"));
ul.appendChild(userNode);
}
if (isPublicAccessEnabled && CurrentModule() != "Mail") {
userNode = nodeForUser(_("Public Access"), "anonymous");
userNode.addClassName("anonymous-user");
userNode.setAttribute("title",
_("Anybody accessing this resource from the public area"));
ul.appendChild(userNode);
}
var buttonArea = $("userSelectorButtons");
if (buttonArea) {
var buttons = buttonArea.childNodesWithTag("a");
$("aclAddUser").stopObserving ("click");
$("aclDeleteUser").stopObserving ("click");
$("aclAddUser").observe("mousedown", onUserAdd);
$("aclDeleteUser").observe("mousedown", onUserRemove);
}
AclEditor['userRightsHeight'] = window.opener.getUsersRightsWindowHeight();
AclEditor['userRightsWidth'] = window.opener.getUsersRightsWindowWidth();
Event.observe(window, "unload", onAclCloseHandler);
}
function onAclCloseHandler(event) {
if (usersToSubscribe.length) {
var url = (URLForFolderID($("folderID").value)
+ "/subscribeUsers?uids=" + usersToSubscribe.join(","));
new Ajax.Request(url, {
asynchronous: false,
method: 'get',
onFailure: function(transport) {
log("Can't subscribe users: " + transport.status);
}
});
}
return true;
}
document.observe("dom:loaded", onAclLoadHandler);
|