summaryrefslogtreecommitdiff
path: root/platform/www/lib/plugins/farmer/script/plugins.js
blob: f092b39f83c4c794121435b12fbe0168a1a22b2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
 * DokuWiki Plugin farmer (JS for plugin management)
 *
 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
 * @author  Michael Große <grosse@cosmocode.de>
 * @author  Andreas Gohr <gohr@cosmocode.de>
 */
(function () {
    'use strict';

    jQuery(function () {
        // general animal select
        var $animalSelect = jQuery('select.farmer_chosen_animals');
        $animalSelect.chosen({
            width: '100%',
            search_contains: true,
            allow_single_deselect: true,
            "placeholder_text_single": LANG.plugins.farmer.animalSelect
        });

        jQuery('select.acl_chosen').chosen({
            disable_search: true,
            width: '100%'
        });


        // Plugin Management for all Animals
        var $formAllAnimals = jQuery('#farmer__pluginsforall');
        $formAllAnimals.find('select')
            .change(function () {
                $formAllAnimals.find('button').prop('disabled', false);
            })
            .chosen({
                width: '100%',
                search_contains: true,
                "placeholder_text_single": LANG.plugins.farmer.pluginSelect
            })
        ;

        // Plugin Management for single Animals
        var $formSingleAnimal = jQuery('#farmer__pluginsforone');
        $formSingleAnimal.find('select')
            .change(function () {
                var animal = jQuery(this).val();
                $formSingleAnimal.find('button').prop('disabled', true);
                jQuery.post(
                    DOKU_BASE + 'lib/exe/ajax.php',
                    {
                        call: 'plugin_farmer_getPlugins_' + animal
                    },
                    function (data) {
                        $formSingleAnimal.find('div.output').html(data);
                        $formSingleAnimal.find('button').prop('disabled', false);
                    },
                    'html'
                )}
            )
            .chosen({
                width: '100%',
                search_contains: true,
                "placeholder_text_single": LANG.plugins.farmer.animalSelect
            })
        ;

        /**
         * Handle clicks on the matrix
         */
        var $formPluginMatrix = jQuery('#farmer__pluginmatrix').hide();
        $formPluginMatrix.on('click', 'td', function () {
            var $td = jQuery(this);
            $td.html('⌛').css('background-color','transparent');
            jQuery.post(
                DOKU_BASE + 'lib/exe/ajax.php',
                {
                    call: 'plugin_farmer_modPlugin',
                    plugin: $td.data('plugin'),
                    ani: $td.data('animal')
                },
                function (data) {
                    $td.replaceWith(data);
                },
                'html'
            );
        });

        /**
         * show the matrix interface
         */
        function showMatrix() {
            jQuery.post(
                DOKU_BASE + 'lib/exe/ajax.php',
                {
                    call: 'plugin_farmer_getPluginMatrix'
                },
                function (data) {
                    $formPluginMatrix.html(data);
                    $formPluginMatrix.show();
                },
                'html'
            )
        }

        // make sure there's enough space for the dropdown
        $animalSelect.on('chosen:showing_dropdown', function (evt, params) {
            jQuery(evt.target).parent('fieldset').animate({
                "padding-bottom": '20em'
            }, 400);
        }).on('chosen:hiding_dropdown', function (evt, params) {
            jQuery(evt.target).parent('fieldset').animate({
                "padding-bottom": '7px'
            }, 400);
        });

        var $aclPolicyFieldset = jQuery('#aclPolicyFieldset');
        if ($aclPolicyFieldset.length) {
            $animalSelect.on('change', function (evt, params) {
                var $this = jQuery(this);
                if ($this.val() === '') {
                    $aclPolicyFieldset.slideDown();
                } else {
                    $aclPolicyFieldset.slideUp();
                }
            });
        }




        jQuery("input[name=bulkSingleSwitch]:radio").change(function () {
            if (jQuery('#farmer__bulk').prop("checked")) {
                $formAllAnimals.show();
                $formSingleAnimal.hide();
                $formPluginMatrix.hide();
            } else if (jQuery('#farmer__single').prop("checked")) {
                $formAllAnimals.hide();
                $formSingleAnimal.show();
                $formPluginMatrix.hide();
            } else {
                $formAllAnimals.hide();
                $formSingleAnimal.hide();
                showMatrix();
            }
        });
        jQuery('#farmer__bulk').click();


    });

})();