]> err.no Git - scalable-opengroupware.org/blob - UI/WebServerResources/UIxAclEditor.js
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1009 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / WebServerResources / UIxAclEditor.js
1 /* test */
2
3 var contactSelectorAction = 'acls-contacts';
4
5 function addContact(tag, fullContactName, contactId, contactName,
6                     contactEmail) {
7    if (tag == "assistant")
8       addUser(contactName, contactId, false);
9    else if (tag == "delegate")
10       addUser(contactName, contactId, true);
11 }
12
13 function addUser(userName, userId, delegate) {
14    var uidList = $("uixselector-userRoles-uidList");
15    var uids;
16
17    if (uidList.value.length > 0) {
18       uids = uidList.value.split(",");
19    } else {
20       uids = new Array();
21    }
22
23    if (uids.indexOf(userId) < 0) {
24       uids.push(userId);
25       var ul = $("uixselector-userRoles-display");
26       ul.appendChild(nodeForUser(userName, userId));
27       uidList.value = uids.join(",");
28       var roleList;
29       if (delegate)
30         roleList = $("delegates");
31       else
32         roleList = $("assistants");
33       if (roleList.value.length > 0) {
34         uids = roleList.value.split(",");
35         uids.push(userId);
36         roleList.value = uids.join(",");
37       }
38       else
39         roleList.value = userId;
40    }
41 }
42
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);
49
50    var image = document.createElement("img");
51    image.setAttribute("src", ResourcesURL + "/abcard.gif");
52
53    node.appendChild(image);
54    node.appendChild(document.createTextNode(" " + userName));
55
56    return node;
57 }
58
59 function saveAcls() {
60   $("aclForm").submit();
61
62   return false;
63 }
64
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;
76     else
77       select.selectedIndex = 1;
78   }
79   else
80     select.style.visibility = "hidden;";
81 }
82
83 function onAclSelectionChange() {
84   log("selectionchange");
85   updateSelectedRole(this);
86 }
87
88 function onUsersChange(type) {
89   var select = $("userRoleDropDown");
90   if (type == "removal") {
91     var list;
92     if (select.selectedIndex == 0)
93       list = $("assistants");
94     else
95       list = $("delegates");
96
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]);
104     }
105     if (newListArray.length > 0)
106       list.value = newListArray.join(",");
107     else
108       list.value = "";
109   }
110
111   updateSelectedRole($("uixselector-userRoles-display"));
112 }
113
114 function onUserRoleDropDownChange() {
115   var oldList;
116   var newList;
117
118   if (this.selectedIndex == 0) {
119     oldList = $("delegates");
120     newList = $("assistants");
121   } else {
122     oldList = $("assistants");
123     newList = $("delegates");
124   }
125
126   var uid = $("uixselector-userRoles-display").getSelectedRows()[0].getAttribute("uid");
127   var newListArray;
128   if (newList.value.length > 0) {
129     newListArray = newList.value.split(",");
130     newListArray.push(uid);
131   }
132   else
133     newListArray = new Array(uid);
134   newList.value = newListArray.join(",");
135
136   var oldListArray = oldList.value.split(",").without(uid);
137   if (oldListArray.length > 0)
138     oldList.value = oldListArray.join(",");
139   else
140     oldList.value = "";
141
142   log("assistants: " + $("assistants").value);
143   log("delegates: " + $("delegates").value);
144 }
145
146 function onAclLoadHandler() {
147   $("userRoles").changeNotification = onUsersChange;
148
149   var ul = $("uixselector-userRoles-display");
150   ul.addEventListener("selectionchange",
151                       onAclSelectionChange, false);
152   var select = $("userRoleDropDown");
153   select.addEventListener("change", onUserRoleDropDownChange, false);
154 }
155
156 window.addEventListener("load", onAclLoadHandler, false);