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