admin.js
99 lines
| 1 | (function ($) { |
| 2 | |
| 3 | $(document).ready(function () { |
| 4 | |
| 5 | // default chosen |
| 6 | $('.pvc-chosen').chosen({ |
| 7 | disable_search_threshold: 8, |
| 8 | display_selected_options: false, |
| 9 | search_contains: true, |
| 10 | width: '300px' |
| 11 | }); |
| 12 | |
| 13 | |
| 14 | // time types and position |
| 15 | $('.pvc-chosen-short').chosen({ |
| 16 | disable_search_threshold: 8, |
| 17 | width: '200px' |
| 18 | }); |
| 19 | |
| 20 | |
| 21 | // ask whether to reset options to defaults |
| 22 | $(document).on('click', '.reset_pvc_settings', function () { |
| 23 | return confirm(pvcArgsSettings.resetToDefaults); |
| 24 | }); |
| 25 | |
| 26 | |
| 27 | // remove ip box |
| 28 | $(document).on('click', '.remove-exclude-ip', function () { |
| 29 | var parent = $(this).parent(), |
| 30 | nextParent = parent.parent(), |
| 31 | addButton = parent.find('.add-exclude-ip').hide(), |
| 32 | addCurrentIPButton = parent.find('.add-current-ip').hide(); |
| 33 | |
| 34 | // remove ip box |
| 35 | parent.remove(); |
| 36 | |
| 37 | var children = nextParent.find('div'); |
| 38 | |
| 39 | // was there add button? |
| 40 | if (addButton.length === 1) { |
| 41 | children.last().append(addButton.show(), ' ', addCurrentIPButton.show()); |
| 42 | // children.last().append(); |
| 43 | } |
| 44 | |
| 45 | // only one ip box left? |
| 46 | if (children.length === 1) { |
| 47 | children.find('.remove-exclude-ip').hide(); |
| 48 | } |
| 49 | }); |
| 50 | |
| 51 | |
| 52 | // add ip box |
| 53 | $(document).on('click', '.add-exclude-ip', function () { |
| 54 | var parent = $(this).parent(), |
| 55 | newBox = parent.clone().hide(); |
| 56 | |
| 57 | // clear value |
| 58 | newBox.find('input').first().val(''); |
| 59 | |
| 60 | // remove add buttons |
| 61 | $(this).remove(); |
| 62 | parent.find('.add-current-ip').remove(); |
| 63 | |
| 64 | // add and display new ip box |
| 65 | parent.after(newBox.show()); |
| 66 | |
| 67 | parent.parent().find('.remove-exclude-ip').show(); |
| 68 | }); |
| 69 | |
| 70 | |
| 71 | // add current ip |
| 72 | $(document).on('click', '.add-current-ip', function () { |
| 73 | // fills input with user's current ip |
| 74 | $(this).parent().find('input').first().val($(this).attr('data-rel')); |
| 75 | }); |
| 76 | |
| 77 | |
| 78 | // display user roles if needed |
| 79 | $(document).on('change', '.pvc-chosen-groups', function () { |
| 80 | var foundRoles = false; |
| 81 | |
| 82 | // check whether roles are selected |
| 83 | $(this).find(':selected').each(function (i, item) { |
| 84 | if (item.value === 'roles') { |
| 85 | foundRoles = true; |
| 86 | } |
| 87 | }); |
| 88 | |
| 89 | // are roles selected? |
| 90 | if (foundRoles) { |
| 91 | $(this).parent().find('.pvc_user_roles').fadeIn(300); |
| 92 | } else { |
| 93 | $(this).parent().find('.pvc_user_roles').fadeOut(300); |
| 94 | } |
| 95 | }); |
| 96 | |
| 97 | }); |
| 98 | |
| 99 | })(jQuery); |