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 (exports) { 9 'use strict'; 10 11 jQuery(document).ready(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 // Plugin Management for all Animals 21 var bulkPluginSelector = jQuery('#farmer__bulkPluginSelect'); 22 bulkPluginSelector.chosen({ 23 width: '100%', 24 search_contains: true, 25 "placeholder_text_single": LANG.plugins.farmer.pluginSelect 26 }); 27 bulkPluginSelector.change(function () { 28 jQuery('button').prop('disabled', false); 29 }); 30 31 // Plugin Management of a single Animal 32 var animalSelector = jQuery('#farmer__animalSelect'); 33 animalSelector.chosen({ 34 width: '100%', 35 search_contains: true, 36 "placeholder_text_single": LANG.plugins.farmer.animalSelect 37 }); 38 animalSelector.change(function () { 39 var animal = animalSelector.val(); 40 jQuery.post( 41 DOKU_BASE + 'lib/exe/ajax.php', 42 { 43 call: 'plugin_farmer_getPlugins_' + animal 44 }, 45 function (data) { 46 var submitButton = jQuery('<button type="submit" value="updateSingleAnimal" name="plugin_farmer[submit_type]">' + LANG.plugins.farmer.submit + '</button>'); 47 var resetButton = jQuery('<button type="reset">' + LANG.plugins.farmer.reset + '</button>'); 48 var pluginContainer = jQuery('#farmer__animalPlugins'); 49 pluginContainer.html(''); 50 pluginContainer.append(submitButton, resetButton); 51 jQuery.each(data[0], function (index, value) { 52 var checked = 'checked'; 53 if (typeof data[1][value] !== 'undefined' && data[1][value] === 0) { 54 checked = ''; 55 } 56 var pluginLabel = jQuery('<label></label>') 57 .append(jQuery('<span></span>').text(value)) 58 .append(jQuery('<input class="edit" type="checkbox" name="plugin_farmer_plugins[' + value + ']" ' + checked + '>')) 59 ; 60 pluginContainer.append(pluginLabel); 61 }); 62 pluginContainer.append(submitButton.clone(), resetButton.clone()); 63 64 // data is array you returned with action.php 65 }, 66 'json' 67 ); 68 }); 69 70 // make sure there's enough space for the dropdown 71 jQuery('select').on('chosen:showing_dropdown', function (evt, params) { 72 jQuery(evt.target).parent('fieldset').animate({ 73 "padding-bottom": '20em' 74 }, 400); 75 }).on('chosen:hiding_dropdown', function (evt, params) { 76 jQuery(evt.target).parent('fieldset').animate({ 77 "padding-bottom": '7px' 78 }, 400); 79 }); 80 81 82 jQuery("input[name=bulkSingleSwitch]:radio").change(function () { 83 if (jQuery('#farmer__bulk').prop("checked")) { 84 jQuery('#farmer__bulkForm').css('display', 'initial'); 85 } else { 86 jQuery('#farmer__bulkForm').css('display', 'none'); 87 } 88 if (jQuery('#farmer__single').prop("checked")) { 89 jQuery('#farmer__singlePluginForm').css('display', 'initial'); 90 } else { 91 jQuery('#farmer__singlePluginForm').css('display', 'none'); 92 } 93 }); 94 jQuery('#farmer__bulk').click(); 95 96 97 }); 98 99})(this.farmer__plugin = {}); 100