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') 64 .html('<img src="'+DOKU_BASE+'lib/images/throbber.gif" alt="..." />') 65 .load( 66 DOKU_BASE + 'lib/plugins/acl/ajax.php', 67 jQuery('#acl__detail form').serialize() + '&ajax=info' 68 ); 69 return false; 70 }, 71 72 /** 73 * parse URL attributes into a associative array 74 * 75 * @todo put into global script lib? 76 */ 77 parseatt: function (str) { 78 if (str[0] === '?') { 79 str = str.substr(1); 80 } 81 var attributes = {}; 82 var all = str.split('&'); 83 for (var i = 0; i < all.length; i++) { 84 var att = all[i].split('='); 85 attributes[att[0]] = decodeURIComponent(att[1]); 86 } 87 return attributes; 88 }, 89 90 /** 91 * Handles clicks to the tree nodes 92 */ 93 treehandler: function () { 94 var $link, $frm; 95 96 $link = jQuery(this); 97 98 // remove highlighting 99 jQuery('#acl__tree a.cur').removeClass('cur'); 100 101 // add new highlighting 102 $link.addClass('cur'); 103 104 // set new page to detail form 105 $frm = jQuery('#acl__detail form'); 106 if ($link.hasClass('wikilink1')) { 107 $frm.find('input[name=ns]').val(''); 108 $frm.find('input[name=id]').val(dw_acl.parseatt($link[0].search).id); 109 } else if ($link.hasClass('idx_dir')) { 110 $frm.find('input[name=ns]').val(dw_acl.parseatt($link[0].search).ns); 111 $frm.find('input[name=id]').val(''); 112 } 113 dw_acl.loadinfo(); 114 115 return false; 116 } 117}; 118 119jQuery(dw_acl.init); 120 121var acl = { 122 init: DEPRECATED_WRAP(dw_acl.init, dw_acl), 123 userselhandler: DEPRECATED_WRAP(dw_acl.userselhandler, dw_acl), 124 loadinfo: DEPRECATED_WRAP(dw_acl.loadinfo, dw_acl), 125 parseatt: DEPRECATED_WRAP(dw_acl.parseatt, dw_acl), 126 treehandler: DEPRECATED_WRAP(dw_acl.treehandler, dw_acl) 127}; 128