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 * Handle clicks on the matrix 67 */ 68 var $formPluginMatrix = jQuery('#farmer__pluginmatrix').hide(); 69 $formPluginMatrix.on('click', 'td', function () { 70 var $td = jQuery(this); 71 $td.html('⌛').css('background-color','transparent'); 72 jQuery.post( 73 DOKU_BASE + 'lib/exe/ajax.php', 74 { 75 call: 'plugin_farmer_modPlugin', 76 plugin: $td.data('plugin'), 77 ani: $td.data('animal') 78 }, 79 function (data) { 80 $td.replaceWith(data); 81 }, 82 'html' 83 ); 84 }); 85 86 /** 87 * show the matrix interface 88 */ 89 function showMatrix() { 90 jQuery.post( 91 DOKU_BASE + 'lib/exe/ajax.php', 92 { 93 call: 'plugin_farmer_getPluginMatrix' 94 }, 95 function (data) { 96 $formPluginMatrix.html(data); 97 $formPluginMatrix.show(); 98 }, 99 'html' 100 ) 101 } 102 103 // make sure there's enough space for the dropdown 104 $animalSelect.on('chosen:showing_dropdown', function (evt, params) { 105 jQuery(evt.target).parent('fieldset').animate({ 106 "padding-bottom": '20em' 107 }, 400); 108 }).on('chosen:hiding_dropdown', function (evt, params) { 109 jQuery(evt.target).parent('fieldset').animate({ 110 "padding-bottom": '7px' 111 }, 400); 112 }); 113 114 var $aclPolicyFieldset = jQuery('#aclPolicyFieldset'); 115 if ($aclPolicyFieldset.length) { 116 $animalSelect.on('change', function (evt, params) { 117 var $this = jQuery(this); 118 if ($this.val() === '') { 119 $aclPolicyFieldset.slideDown(); 120 } else { 121 $aclPolicyFieldset.slideUp(); 122 } 123 }); 124 } 125 126 127 128 129 jQuery("input[name=bulkSingleSwitch]:radio").change(function () { 130 if (jQuery('#farmer__bulk').prop("checked")) { 131 $formAllAnimals.show(); 132 $formSingleAnimal.hide(); 133 $formPluginMatrix.hide(); 134 } else if (jQuery('#farmer__single').prop("checked")) { 135 $formAllAnimals.hide(); 136 $formSingleAnimal.show(); 137 $formPluginMatrix.hide(); 138 } else { 139 $formAllAnimals.hide(); 140 $formSingleAnimal.hide(); 141 showMatrix(); 142 } 143 }); 144 jQuery('#farmer__bulk').click(); 145 146 147 }); 148 149})(); 150