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