xref: /plugin/farmer/script/plugins.js (revision af1c6dd8b9c1e35385ddfb7549af221f4070c191)
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        jQuery('select.farmer_choosen_animals').chosen({
14            width: '100%',
15            search_contains: true,
16            allow_single_deselect: true,
17            "placeholder_text_single": LANG.plugins.farmer.animalSelect
18        });
19
20
21        // Plugin Management for all Animals
22        var $formAllAnimals = jQuery('#farmer__pluginsforall');
23        $formAllAnimals.find('select')
24            .change(function () {
25                $formAllAnimals.find('button').prop('disabled', false);
26            })
27            .chosen({
28                width: '100%',
29                search_contains: true,
30                "placeholder_text_single": LANG.plugins.farmer.pluginSelect
31            })
32        ;
33
34        // Plugin Management for single Animals
35        var $formSingleAnimal = jQuery('#farmer__pluginsforone');
36        $formSingleAnimal.find('select')
37            .change(function () {
38                var animal = jQuery(this).val();
39                $formSingleAnimal.find('button').prop('disabled', true);
40                jQuery.post(
41                    DOKU_BASE + 'lib/exe/ajax.php',
42                    {
43                        call: 'plugin_farmer_getPlugins_' + animal
44                    },
45                    function (data) {
46                        $formSingleAnimal.find('div.output').html(data);
47                        $formSingleAnimal.find('button').prop('disabled', false);
48                    },
49                    'html'
50                )}
51            )
52            .chosen({
53                width: '100%',
54                search_contains: true,
55                "placeholder_text_single": LANG.plugins.farmer.animalSelect
56            })
57        ;
58
59
60
61        // make sure there's enough space for the dropdown
62        jQuery('select').on('chosen:showing_dropdown', function (evt, params) {
63            jQuery(evt.target).parent('fieldset').animate({
64                "padding-bottom": '20em'
65            }, 400);
66        }).on('chosen:hiding_dropdown', function (evt, params) {
67            jQuery(evt.target).parent('fieldset').animate({
68                "padding-bottom": '7px'
69            }, 400);
70        });
71
72
73        jQuery("input[name=bulkSingleSwitch]:radio").change(function () {
74            if (jQuery('#farmer__bulk').prop("checked")) {
75                $formAllAnimals.show();
76                $formSingleAnimal.hide();
77            } else {
78                $formAllAnimals.hide();
79                $formSingleAnimal.show();
80
81
82            }
83        });
84        jQuery('#farmer__bulk').click();
85
86
87    });
88
89})();
90