-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix IP exclude rules settings #1036
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
07eb979
Bump select2 to 4.0.10
kasparsd 9761670
Bump the version strings too
kasparsd 99b219d
Skip header and footer rows which don’t have select enabled
kasparsd ef2862d
Pass the targets for re-usability instead
kasparsd 3c112cb
Revert "Bump the version strings too"
kasparsd 0497e96
Simplify the overrides
kasparsd 2607a05
Revert "Bump select2 to 4.0.10"
kasparsd 6431dde
Sanitize as strings by default
kasparsd 20fd91e
Ugly hack to ensure we always pass an empty value or the order of row…
kasparsd 5a0f238
Add the placeholder row at the bottom since we want new rows there
kasparsd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
/* globals jQuery, ajaxurl, wp_stream_regenerate_alt_rows */ | ||
jQuery( | ||
function( $ ) { | ||
var initSettingsSelect2 = function() { | ||
var $excludeRows = $( '.stream-exclude-list tbody tr:not(.hidden)' ); | ||
var $placeholderRow = $( '.stream-exclude-list tr.helper' ); | ||
|
||
var initSettingsSelect2 = function( $rowsWithSelect2 ) { | ||
var $input_user; | ||
|
||
$( '.stream-exclude-list tr:not(.hidden) select.select2-select.connector_or_context' ).each( | ||
$( 'select.select2-select.connector_or_context', $rowsWithSelect2 ).each( | ||
function( k, el ) { | ||
$( el ).select2( | ||
{ | ||
|
@@ -64,7 +67,7 @@ jQuery( | |
} | ||
); | ||
|
||
$( '.stream-exclude-list tr:not(.hidden) select.select2-select.action' ).each( | ||
$( 'select.select2-select.action', $rowsWithSelect2 ).each( | ||
function( k, el ) { | ||
$( el ).select2( | ||
{ | ||
|
@@ -74,7 +77,7 @@ jQuery( | |
} | ||
); | ||
|
||
$( '.stream-exclude-list tr:not(.hidden) select.select2-select.author_or_role' ).each( | ||
$( 'select.select2-select.author_or_role', $rowsWithSelect2 ).each( | ||
function( k, el ) { | ||
$input_user = $( el ); | ||
|
||
|
@@ -173,7 +176,7 @@ jQuery( | |
} | ||
); | ||
|
||
$( '.stream-exclude-list tr:not(.hidden) select.select2-select.ip_address' ).each( | ||
$( 'select.select2-select.ip_address', $rowsWithSelect2 ).each( | ||
function( k, el ) { | ||
var $input_ip = $( el ), | ||
searchTerm = ''; | ||
|
@@ -271,7 +274,7 @@ jQuery( | |
} | ||
); | ||
|
||
$( '.stream-exclude-list tr:not(.hidden) .exclude_rules_remove_rule_row' ).on( | ||
$( '.exclude_rules_remove_rule_row', $rowsWithSelect2 ).on( | ||
'click', function() { | ||
var $thisRow = $( this ).closest( 'tr' ); | ||
|
||
|
@@ -283,16 +286,16 @@ jQuery( | |
); | ||
}; | ||
|
||
initSettingsSelect2(); | ||
initSettingsSelect2( $excludeRows ); | ||
|
||
$( '.stream-exclude-list tr:not(.hidden) select.select2-select.author_or_role' ).each( | ||
$( 'select.select2-select.author_or_role', $excludeRows ).each( | ||
function() { | ||
var $option = $( '<option selected>' + $( this ).data( 'selected-text' ) + '</option>' ).val( $( this ).data( 'selected-id' ) ); | ||
$( this ).append( $option ).trigger( 'change' ); | ||
} | ||
); | ||
|
||
$( '.stream-exclude-list tr:not(.hidden) select.select2-select.connector_or_context' ).each( | ||
$( 'select.select2-select.connector_or_context', $excludeRows ).each( | ||
function() { | ||
var parts = [ | ||
$( this ).siblings( '.connector' ).val(), | ||
|
@@ -307,25 +310,12 @@ jQuery( | |
|
||
$( '#exclude_rules_new_rule' ).on( | ||
'click', function() { | ||
var $excludeList = $( 'table.stream-exclude-list' ); | ||
|
||
$( 'tr:not(.hidden) select.select2-select', $excludeList ).each( | ||
function() { | ||
$( this ).select2( 'destroy' ); | ||
} | ||
); | ||
|
||
var $lastRow = $( 'tr', $excludeList ).last(), | ||
$newRow = $lastRow.clone(); | ||
var $newRow = $placeholderRow.clone(); | ||
|
||
$newRow.removeAttr( 'class' ); | ||
$( '.stream-exclude-list tbody :input' ).off(); | ||
$( ':input', $newRow ).off().val( '' ); | ||
|
||
$lastRow.after( $newRow ); | ||
|
||
initSettingsSelect2(); | ||
$newRow.insertBefore( $placeholderRow ); | ||
|
||
initSettingsSelect2( $newRow ); | ||
recalculate_rules_found(); | ||
recalculate_rules_selected(); | ||
} | ||
|
@@ -369,6 +359,12 @@ jQuery( | |
$( '.stream-exclude-list tbody tr:not(.hidden) select.select2-select.ip_address', this ).each( | ||
function() { | ||
var firstSelected = $( 'option:selected', this ).first(); | ||
|
||
// Ugly hack to ensure we always pass an empty value or the order of rows gets messed up. | ||
if ( ! firstSelected.length ) { | ||
$( this ).append( '<option selected="selected"></option>' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the core fix -- we add a dummy option and mark it selected to ensure it gets delivered to the backend. |
||
} | ||
|
||
$( 'option:selected:not(:first)', this ).each( | ||
function() { | ||
firstSelected.attr( 'value', firstSelected.attr( 'value' ) + ',' + $( this ).attr( 'value' ) ); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't recreate the select2 fields for rows with them already present.