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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
<div xmlns:py="http://purl.org/kid/ns#"
class="simpleroster">
<form action="${action}" name="${name}" method="${method}" class="tableform"
onsubmit="preSubmit()" >
<?python searchurl = tg.url('/userlist_ajax') ?>
<script type="text/javascript">
// this is used for round-trip recontruction of the names.
// the hidden fields only contain uids.
var uid_to_cn_hash = new Hash();
// used to filter search results.
// records uids already in the group
var member_hash = new Hash();
// used to prevent double adding
// records uid to be added
var added_hash = new Hash();
function toggleProtectedFields(checkbox) {
var gidnumberField = $('form_gidnumber');
if (checkbox.checked) {
gidnumberField.disabled = false;
$('form_editprotected').value = 'true';
} else {
gidnumberField.disabled = true;
$('form_editprotected').value = '';
}
}
/*
* Callback used for afterFinish in scriptaculous effect
*/
function removeElement(effect) {
Element.remove(effect.element);
}
function adduser(uid, cn) {
uid_to_cn_hash[uid] = cn;
if ((added_hash[uid] == 1) || (member_hash[uid] == 1)) {
return null;
}
added_hash[uid] = 1;
var newdiv = document.createElement('div');
newdiv.appendChild(document.createTextNode(
cn.escapeHTML() + " (" + uid.escapeHTML() + ") "));
var undolink = document.createElement('a');
undolink.setAttribute('href', '');
undolink.setAttribute('onclick',
'new Effect.Fade(Element.up(this), {afterFinish: removeElement});' +
'added_hash.remove("' + uid + '");' +
'return false;');
undolink.appendChild(document.createTextNode("undo"));
newdiv.appendChild(undolink);
var uidInfo = document.createElement('input');
uidInfo.setAttribute('type', 'hidden');
uidInfo.setAttribute('name', 'uidadd');
uidInfo.setAttribute('value', uid);
newdiv.appendChild(uidInfo);
newdiv.style.display = 'none';
$('newmembers').appendChild(newdiv);
return newdiv
}
function adduserHandler(element, uid, cn) {
var newdiv = adduser(uid, cn)
if (newdiv != null) {
new Effect.Fade(Element.up(element));
new Effect.Appear(newdiv);
/* Element.up(element).remove(); */
}
}
function removeuser(uid, cn) {
uid_to_cn_hash[uid] = cn;
var newdiv = document.createElement('div');
newdiv.appendChild(document.createTextNode(
cn.escapeHTML() + " (" + uid.escapeHTML() + ") "));
var undolink = document.createElement('a');
undolink.setAttribute('href', '');
undolink.setAttribute('onclick',
'new Effect.Fade(Element.up(this), {afterFinish: removeElement});' +
"new Effect.Appear($('member-" + uid + "'));" +
'return false;');
undolink.appendChild(document.createTextNode("undo"));
newdiv.appendChild(undolink);
var uidInfo = document.createElement('input');
uidInfo.setAttribute('type', 'hidden');
uidInfo.setAttribute('name', 'uiddel');
uidInfo.setAttribute('value', uid);
newdiv.appendChild(uidInfo);
newdiv.style.display = 'none';
$('delmembers').appendChild(newdiv);
return newdiv
}
function removeuserHandler(element, uid, cn) {
var newdiv = removeuser(uid, cn);
new Effect.Fade(Element.up(element));
new Effect.Appear(newdiv);
/* Element.up(element).remove(); */
}
function enterDoSearch(e) {
var keyPressed;
if (window.event) {
keyPressed = window.event.keyCode;
} else {
keyPressed = e.which;
}
if (keyPressed == 13) {
return doSearch();
} else {
return true;
}
}
function doSearch() {
$('searchresults').update("Searching...");
new Ajax.Updater('searchresults',
'${searchurl}',
{ asynchronous:true,
parameters: { uid: $('uid').value },
evalScripts: true });
return false;
}
function preSubmit() {
var json = uid_to_cn_hash.toJSON();
$('form_uid_to_cn_json').value = json;
return true;
}
</script>
<div py:for="field in hidden_fields"
py:replace="field.display(value_for(field), **params_for(field))"
/>
<div class="formsection">Group Details</div>
<table class="formtable" cellpadding="2" cellspacing="0" border="0">
<tr>
<th>
<label class="fieldlabel" for="${group.cn.field_id}"
py:content="group.cn.label" />:
</th>
<td>
<!-- <span py:replace="group.cn.display(value_for(group.cn))" />
<span py:if="tg.errors.get('cn')" class="fielderror"
py:content="tg.errors.get('cn')" /> -->
${value_for(group.cn)}
</td>
</tr>
<tr>
<th>
<label class="fieldlabel" for="${group.description.field_id}"
py:content="group.description.label" />:
</th>
<td>
<span py:replace="group.description.display(value_for(group.description))" />
<span py:if="tg.errors.get('description')" class="fielderror"
py:content="tg.errors.get('description')" />
</td>
</tr>
<tr>
<th>
<label class="fieldlabel" for="${group.gidnumber.field_id}"
py:content="group.gidnumber.label" />:
</th>
<td>
<span py:replace="group.gidnumber.display(value_for(group.gidnumber))" />
<span py:if="tg.errors.get('gidnumber')" class="fielderror"
py:content="tg.errors.get('gidnumber')" />
<script type="text/javascript">
document.getElementById('form_gidnumber').disabled = true;
</script>
</td>
</tr>
</table>
<div>
<div class="formsection">Group Members</div>
<div class="floatlist">
<div class="floatheader">To Remove:</div>
<div id="delmembers">
</div>
</div>
<div>
<div py:for="member in members" id="member-${member.get('uid')}">
<?python
member_uid = member.get('uid')
member_name = "%s %s" % (member.get('givenname', ''),
member.get('sn', ''))
?>
${member_name} (${member_uid})
<a href="#"
onclick="removeuserHandler(this, '${member_uid}', '${member_name}');
return false;"
>remove</a>
<script type="text/javascript">
member_hash["${member_uid}"] = 1;
</script>
</div>
</div>
</div>
<div style="clear:both">
<div class="formsection">Add Persons</div>
<div class="floatlist">
<div class="floatheader">To Add:</div>
<div id="newmembers">
</div>
</div>
<div>
<div id="search">
<input id="uid" type="text" name="uid"
onkeypress="return enterDoSearch(event);" />
<input type="button" value="Find Users"
onclick="return doSearch();"
/>
</div>
<div id="searchresults">
</div>
</div>
</div>
<table class="formtable" cellpadding="2" cellspacing="0" border="0">
<tr>
<th>
<br />
<input type="submit" class="submitbutton" name="submit"
value="Update Group"/>
</th>
<td>
<br />
<input type="submit" class="submitbutton" name="submit"
value="Cancel Edit" />
</td>
</tr>
</table>
</form>
<script type="text/javascript">
/*
* This section restores the contents of the add and remove lists
* dynamically if we have to refresh the page
*/
if ($('form_uid_to_cn_json').value != "") {
uid_to_cn_hash = new Hash($('form_uid_to_cn_json').value.evalJSON());
}
if ($('form_editprotected').value != "") {
$('toggleprotected_checkbox').checked = true;
toggleProtectedFields($('toggleprotected_checkbox'));
}
</script>
<?python
uidadds = value.get('uidadd', [])
if not(isinstance(uidadds,list) or isinstance(uidadds,tuple)):
uidadds = [uidadds]
uiddels = value.get('uiddel', [])
if not(isinstance(uiddels,list) or isinstance(uiddels,tuple)):
uiddels = [uiddels]
?>
<script py:for="uidadd in uidadds">
var uid = "${uidadd}";
var cn = uid_to_cn_hash[uid];
var newdiv = adduser(uid, cn);
if (newdiv != null) {
newdiv.style.display = 'block';
}
</script>
<script py:for="uiddel in uiddels">
var uid = "${uiddel}";
var cn = uid_to_cn_hash[uid];
var newdiv = removeuser(uid, cn);
newdiv.style.display = 'block';
$('member-' + uid).style.display = 'none';
</script>
</div>
|