xref: /plugin/farmer/script/plugins.js (revision 1413d607f0785a125b817eff45e6f87e939fb0bb)
1/**
2 * DokuWiki Plugin farmer (JS for plugin management)
3 *
4 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
5 * @author  Michael Große <grosse@cosmocode.de>
6 * @author  Andreas Gohr <gohr@cosmocode.de>
7 */
8(function () {
9    'use strict';
10
11    jQuery(function () {
12        // general animal select
13        var $animalSelect = jQuery('select.farmer_chosen_animals');
14        $animalSelect.chosen({
15            width: '100%',
16            search_contains: true,
17            allow_single_deselect: true,
18            "placeholder_text_single": LANG.plugins.farmer.animalSelect
19        });
20
21        jQuery('select.acl_chosen').chosen({
22            disable_search: true,
23            width: '100%'
24        });
25
26
27        // Plugin Management for all Animals
28        var $formAllAnimals = jQuery('#farmer__pluginsforall');
29        $formAllAnimals.find('select')
30            .change(function () {
31                $formAllAnimals.find('button').prop('disabled', false);
32            })
33            .chosen({
34                width: '100%',
35                search_contains: true,
36                "placeholder_text_single": LANG.plugins.farmer.pluginSelect
37            })
38        ;
39
40        // Plugin Management for single Animals
41        var $formSingleAnimal = jQuery('#farmer__pluginsforone');
42        $formSingleAnimal.find('select')
43            .change(function () {
44                var animal = jQuery(this).val();
45                $formSingleAnimal.find('button').prop('disabled', true);
46                jQuery.post(
47                    DOKU_BASE + 'lib/exe/ajax.php',
48                    {
49                        call: 'plugin_farmer_getPlugins_' + animal
50                    },
51                    function (data) {
52                        $formSingleAnimal.find('div.output').html(data);
53                        $formSingleAnimal.find('button').prop('disabled', false);
54                    },
55                    'html'
56                )}
57            )
58            .chosen({
59                width: '100%',
60                search_contains: true,
61                "placeholder_text_single": LANG.plugins.farmer.animalSelect
62            })
63        ;
64
65
66
67        // make sure there's enough space for the dropdown
68        $animalSelect.on('chosen:showing_dropdown', function (evt, params) {
69            jQuery(evt.target).parent('fieldset').animate({
70                "padding-bottom": '20em'
71            }, 400);
72        }).on('chosen:hiding_dropdown', function (evt, params) {
73            jQuery(evt.target).parent('fieldset').animate({
74                "padding-bottom": '7px'
75            }, 400);
76        });
77
78        var $aclPolicyFieldset = jQuery('#aclPolicyFieldset');
79        if ($aclPolicyFieldset.length) {
80            $animalSelect.on('change', function (evt, params) {
81                var $this = jQuery(this);
82                if ($this.val() == '') {
83                    $aclPolicyFieldset.slideDown();
84                } else {
85                    $aclPolicyFieldset.slideUp();
86                }
87            });
88        }
89
90
91        jQuery("input[name=bulkSingleSwitch]:radio").change(function () {
92            if (jQuery('#farmer__bulk').prop("checked")) {
93                $formAllAnimals.show();
94                $formSingleAnimal.hide();
95            } else {
96                $formAllAnimals.hide();
97                $formSingleAnimal.show();
98
99
100            }
101        });
102        jQuery('#farmer__bulk').click();
103
104
105    });
106
107})();
108