3 var contactSelectorAction = 'acls-contacts';
5 function addContact(tag, fullContactName, contactId, contactName,
7 if (tag == "assistant")
8 addUser(contactName, contactId, false);
9 else if (tag == "delegate")
10 addUser(contactName, contactId, true);
13 function addUser(userName, userId, delegate) {
14 var uidList = $("uixselector-userRoles-uidList");
17 if (uidList.value.length > 0) {
18 uids = uidList.value.split(",");
23 if (uids.indexOf(userId) < 0) {
25 var ul = $("uixselector-userRoles-display");
26 ul.appendChild(nodeForUser(userName, userId));
27 uidList.value = uids.join(",");
30 roleList = $("delegates");
32 roleList = $("assistants");
33 if (roleList.value.length > 0) {
34 uids = roleList.value.split(",");
36 roleList.value = uids.join(",");
39 roleList.value = userId;
43 function nodeForUser(userName, userId) {
44 var node = document.createElement("li");
45 node.setAttribute("uid", userId);
46 node.setAttribute("class", "");
47 node.addEventListener("mousedown", listRowMouseDownHandler, true);
48 node.addEventListener("click", onRowClick, true);
50 var image = document.createElement("img");
51 image.setAttribute("src", ResourcesURL + "/abcard.gif");
53 node.appendChild(image);
54 node.appendChild(document.createTextNode(" " + userName));
60 $("aclForm").submit();
65 function updateSelectedRole(list) {
66 var select = $("userRoleDropDown");
67 var selection = list.getSelectedRows();
68 if (selection.length > 0) {
69 select.style.visibility = "visible;";
70 var selected = selection[0];
71 var assistantsValue = $("assistants");
72 var uid = selected.getAttribute("uid");
73 var regexp = new RegExp("(^|,)" + uid + "(,|$)","i");
74 if (regexp.test(assistantsValue.value))
75 select.selectedIndex = 0;
77 select.selectedIndex = 1;
80 select.style.visibility = "hidden;";
83 function onAclSelectionChange() {
84 log("selectionchange");
85 updateSelectedRole(this);
88 function onUsersChange(type) {
89 var select = $("userRoleDropDown");
90 if (type == "removal") {
92 if (select.selectedIndex == 0)
93 list = $("assistants");
95 list = $("delegates");
97 var uids = $("uixselector-userRoles-uidList");
98 var listArray = list.value.split(",");
99 var newListArray = new Array();
100 for (var i = 0; i < listArray.length; i++) {
101 var regexp = new RegExp("(^|,)" + listArray[i] + "($|,)");
102 if (regexp.test(uids.value))
103 newListArray.push(listArray[i]);
105 if (newListArray.length > 0)
106 list.value = newListArray.join(",");
111 updateSelectedRole($("uixselector-userRoles-display"));
114 function onUserRoleDropDownChange() {
118 if (this.selectedIndex == 0) {
119 oldList = $("delegates");
120 newList = $("assistants");
122 oldList = $("assistants");
123 newList = $("delegates");
126 var uid = $("uixselector-userRoles-display").getSelectedRows()[0].getAttribute("uid");
128 if (newList.value.length > 0) {
129 newListArray = newList.value.split(",");
130 newListArray.push(uid);
133 newListArray = new Array(uid);
134 newList.value = newListArray.join(",");
136 var oldListArray = oldList.value.split(",").without(uid);
137 if (oldListArray.length > 0)
138 oldList.value = oldListArray.join(",");
142 log("assistants: " + $("assistants").value);
143 log("delegates: " + $("delegates").value);
146 function onAclLoadHandler() {
147 $("userRoles").changeNotification = onUsersChange;
149 var ul = $("uixselector-userRoles-display");
150 ul.addEventListener("selectionchange",
151 onAclSelectionChange, false);
152 var select = $("userRoleDropDown");
153 select.addEventListener("change", onUserRoleDropDownChange, false);
156 window.addEventListener("load", onAclLoadHandler, false);