1/**
2 * Dokutranslate Moderator Group Manager AJAX enhancements
3 * Based on built-in ACL plugin
4 *
5 * @author Martin Doucha <next_ghost@quick.cz>
6 * @author Andreas Gohr <andi@splitbrain.org>
7 */
8var dw_dokutranslate = {
9    /**
10     * Initialize the object and attach the event handlers
11     */
12    init: function () {
13        var $tree;
14
15        //FIXME only one underscore!!
16        if (jQuery('#dokutranslate_manager').length === 0) {
17            return;
18        }
19
20        $tree = jQuery('#dokutranslate__tree');
21        $tree.dw_tree({toggle_selector: 'img',
22                       load_data: function (show_sublist, $clicky) {
23                           // get the enclosed link and the edit form
24                           var $frm = jQuery('#dokutranslate__detail form');
25
26                           jQuery.post(
27                               DOKU_BASE + 'lib/plugins/dokutranslate/ajax.php',
28                               jQuery.extend(dw_dokutranslate.parseatt($clicky.parent().find('a')[0].search),
29                                             {ajax: 'tree'
30                                              }),
31                               show_sublist,
32                               'html'
33                           );
34                       },
35
36                       toggle_display: function ($clicky, opening) {
37                           $clicky.attr('src',
38                                        DOKU_BASE + 'lib/images/' +
39                                        (opening ? 'minus' : 'plus') + '.gif');
40                       }});
41        $tree.delegate('a', 'click', dw_dokutranslate.treehandler);
42    },
43
44    /**
45     * Load the current permission info and edit form
46     */
47    modform: function () {
48        var $frm = jQuery('#dokutranslate__detail form');
49        jQuery('#dokutranslate__user')
50            .html('<img src="'+DOKU_BASE+'lib/images/throbber.gif" alt="..." />')
51            .load(
52                DOKU_BASE + 'lib/plugins/dokutranslate/ajax.php',
53//                jQuery('#dokutranslate__detail form').serialize() + '&ajax=info'
54                {ajax: 'modform',
55                 ns: $frm.find('input[name=ns]').val(),
56                 sectok: $frm.find('input[name=sectok]').val()
57                 }
58            );
59        return false;
60    },
61
62    /**
63     * parse URL attributes into a associative array
64     *
65     * @todo put into global script lib?
66     */
67    parseatt: function (str) {
68        if (str[0] === '?') {
69            str = str.substr(1);
70        }
71        var attributes = {};
72        var all = str.split('&');
73        for (var i = 0; i < all.length; i++) {
74            var att = all[i].split('=');
75            attributes[att[0]] = decodeURIComponent(att[1]);
76        }
77        return attributes;
78    },
79
80    /**
81     * Handles clicks to the tree nodes
82     */
83    treehandler: function () {
84        var $link, $frm;
85
86        $link = jQuery(this);
87
88            // remove highlighting
89            jQuery('#dokutranslate__tree a.cur').removeClass('cur');
90
91            // add new highlighting
92        $link.addClass('cur');
93
94            // set new page to detail form
95        $frm = jQuery('#dokutranslate__detail form');
96        $frm.find('input[name=ns]').val(dw_dokutranslate.parseatt($link[0].search).ns);
97        dw_dokutranslate.modform();
98
99        return false;
100    }
101};
102
103jQuery(dw_dokutranslate.init);
104
105var dokutranslate = {
106    init: DEPRECATED_WRAP(dw_dokutranslate.init, dw_dokutranslate),
107//    userselhandler: DEPRECATED_WRAP(dw_dokutranslate.userselhandler, dw_dokutranslate),
108    modform: DEPRECATED_WRAP(dw_dokutranslate.modform, dw_dokutranslate),
109    parseatt: DEPRECATED_WRAP(dw_dokutranslate.parseatt, dw_dokutranslate),
110    treehandler: DEPRECATED_WRAP(dw_dokutranslate.treehandler, dw_dokutranslate)
111};
112