script.js 3.9 KB

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