1/** 2 * ACL Manager AJAX enhancements 3 * 4 * @author Andreas Gohr <andi@splitbrain.org> 5 */ 6var dw_acl = { 7 /** 8 * Initialize the object and attach the event handlers 9 */ 10 init: function () { 11 var $tree; 12 13 //FIXME only one underscore!! 14 if (jQuery('#acl_manager').length === 0) { 15 return; 16 } 17 18 jQuery('#acl__user select').change(dw_acl.userselhandler); 19 jQuery('#acl__user input[type=submit]').click(dw_acl.loadinfo); 20 21 $tree = jQuery('#acl__tree'); 22 $tree.dw_tree({toggle_selector: 'img', 23 load_data: function (show_sublist, $clicky) { 24 // get the enclosed link and the edit form 25 var $frm = jQuery('#acl__detail form'); 26 27 jQuery.post( 28 DOKU_BASE + 'lib/plugins/acl/ajax.php', 29 jQuery.extend(dw_acl.parseatt($clicky.parent().find('a')[0].search), 30 {ajax: 'tree', 31 current_ns: $frm.find('input[name=ns]').val(), 32 current_id: $frm.find('input[name=id]').val()}), 33 show_sublist, 34 'html' 35 ); 36 }, 37 38 toggle_display: function ($clicky, opening) { 39 $clicky.attr('src', 40 DOKU_BASE + 'lib/images/' + 41 (opening ? 'minus' : 'plus') + '.gif'); 42 }}); 43 $tree.delegate('a', 'click', dw_acl.treehandler); 44 }, 45 46 /** 47 * Handle user dropdown 48 * 49 * Hides or shows the user/group entry box depending on what was selected in the 50 * dropdown element 51 */ 52 userselhandler: function () { 53 // make entry field visible/invisible 54 jQuery('#acl__user input').toggle(this.value === '__g__' || 55 this.value === '__u__'); 56 dw_acl.loadinfo(); 57 }, 58 59 /** 60 * Load the current permission info and edit form 61 */ 62 loadinfo: function () { 63 jQuery('#acl__info').load( 64 DOKU_BASE + 'lib/plugins/acl/ajax.php', 65 jQuery('#acl__detail form').serialize() + '&ajax=info' 66 ); 67 return false; 68 }, 69 70 /** 71 * parse URL attributes into a associative array 72 * 73 * @todo put into global script lib? 74 */ 75 parseatt: function (str) { 76 if (str[0] === '?') { 77 str = str.substr(1); 78 } 79 var attributes = {}; 80 var all = str.split('&'); 81 for (var i = 0; i < all.length; i++) { 82 var att = all[i].split('='); 83 attributes[att[0]] = decodeURIComponent(att[1]); 84 } 85 return attributes; 86 }, 87 88 /** 89 * Handles clicks to the tree nodes 90 */ 91 treehandler: function () { 92 var $link, $frm; 93 94 $link = jQuery(this); 95 96 // remove highlighting 97 jQuery('#acl__tree a.cur').removeClass('cur'); 98 99 // add new highlighting 100 $link.addClass('cur'); 101 102 // set new page to detail form 103 $frm = jQuery('#acl__detail form'); 104 if ($link.hasClass('wikilink1')) { 105 $frm.find('input[name=ns]').val(''); 106 $frm.find('input[name=id]').val(dw_acl.parseatt($link[0].search).id); 107 } else if ($link.hasClass('idx_dir')) { 108 $frm.find('input[name=ns]').val(dw_acl.parseatt($link[0].search).ns); 109 $frm.find('input[name=id]').val(''); 110 } 111 dw_acl.loadinfo(); 112 113 return false; 114 } 115}; 116 117jQuery(dw_acl.init); 118 119var acl = { 120 init: DEPRECATED_WRAP(dw_acl.init, dw_acl), 121 userselhandler: DEPRECATED_WRAP(dw_acl.userselhandler, dw_acl), 122 loadinfo: DEPRECATED_WRAP(dw_acl.loadinfo, dw_acl), 123 parseatt: DEPRECATED_WRAP(dw_acl.parseatt, dw_acl), 124 treehandler: DEPRECATED_WRAP(dw_acl.treehandler, dw_acl) 125}; 126