3 this.ctl = $('acl_manager');
6 var sel = $('acl__user').getElementsByTagName('select')[0];
8 addEvent(sel,'change',acl.userselhandler);
9 addEvent($('acl__tree'),'click',acl.treehandler);
10 addEvent($('acl__user').getElementsByTagName('input')[1],'click',acl.loadinfo);
15 * Handle user dropdown
17 userselhandler: function(e){
18 // make entry field visible/invisible
19 if(this.value == '__g__' || this.value == '__u__'){
20 $('acl__user').getElementsByTagName('input')[0].style.display = ''; //acl_w
21 $('acl__user').getElementsByTagName('input')[1].style.display = ''; //submit
23 $('acl__user').getElementsByTagName('input')[0].style.display = 'none';
24 $('acl__user').getElementsByTagName('input')[1].style.display = 'none';
31 * Load the current permission info and edit form
33 * @param frm - Form element with needed data
37 var frm = $('acl__detail').getElementsByTagName('form')[0];
39 // prepare an AJAX call
40 var ajax = new sack(DOKU_BASE + 'lib/plugins/acl/ajax.php');
41 ajax.AjaxFailedAlert = '';
42 ajax.encodeURIString = false;
43 if(ajax.failed) return true;
47 data[0] = ajax.encVar('ns',frm.elements['ns'].value);
48 data[1] = ajax.encVar('id',frm.elements['id'].value);
49 data[2] = ajax.encVar('acl_t',frm.elements['acl_t'].value);
50 data[3] = ajax.encVar('acl_w',frm.elements['acl_w'].value);
51 data[4] = ajax.encVar('sectok',frm.elements['sectok'].value);
52 data[5] = ajax.encVar('ajax','info');
54 ajax.elementObj = $('acl__info');
56 ajax.runAJAX(data.join('&'));
61 * parse URL attributes into a associative array
63 * @todo put into global script lib?
65 parseatt: function(str){
66 if(str[0] == '?') str = str.substr(1);
68 var all = str.split('&');
69 for(var i=0; i<all.length; i++){
70 var att = all[i].split('=');
71 attributes[att[0]] = decodeURIComponent(att[1]);
77 * htmlspecialchars equivalent
79 * @todo put in gloabl scripts lib?
82 str = str.replace(/&/g,"&");
83 str = str.replace(/\"/g,""");
84 str = str.replace(/\'/g,"'");
85 str = str.replace(/</g,"<");
86 str = str.replace(/>/g,">");
92 * Open or close a subtree using AJAX
94 * @author Andreas Gohr <andi@splitbrain.org>
96 treetoggle: function(clicky){
97 var listitem = clicky.parentNode.parentNode;
99 // if already open, close by removing the sublist
100 var sublists = listitem.getElementsByTagName('ul');
102 listitem.removeChild(sublists[0]);
103 clicky.src = DOKU_BASE+'lib/images/plus.gif';
108 // get the enclosed link (is always the first one)
109 var link = listitem.getElementsByTagName('a')[0];
111 // prepare an AJAX call to fetch the subtree
112 var ajax = new sack(DOKU_BASE + 'lib/plugins/acl/ajax.php');
113 ajax.AjaxFailedAlert = '';
114 ajax.encodeURIString = false;
115 if(ajax.failed) return true;
118 var ul = document.createElement('ul');
119 listitem.appendChild(ul);
120 ajax.elementObj = ul;
121 ajax.runAJAX(link.search.substr(1)+'&ajax=tree');
122 clicky.src = DOKU_BASE+'lib/images/minus.gif';
127 * Handles all clicks in the tree, dispatching the right action based on the
130 treehandler: function(e){
131 if(e.target.src){ // is it an image?
132 acl.treetoggle(e.target);
133 } else if(e.target.href){ // is it a link?
134 // remove highlighting
135 var obj = getElementsByClass('cur',$('acl__tree'),'a');
136 for(var i=0; i<obj.length; i++){
137 obj[i].className = obj[i].className.replace(/ cur/,'');
140 // add new highlighting
141 e.target.className += ' cur';
143 // set new page to detail form
144 var frm = $('acl__detail').getElementsByTagName('form')[0];
145 if(e.target.className.search(/wikilink1/) > -1){
146 frm.elements['ns'].value = '';
147 frm.elements['id'].value = acl.hsc(acl.parseatt(e.target.search)['id']);
148 }else if(e.target.className.search(/idx_dir/) > -1){
149 frm.elements['ns'].value = acl.hsc(acl.parseatt(e.target.search)['ns']);
150 frm.elements['id'].value = '';
163 addInitEvent(acl.init);