Skip to content

Commit e5c8677

Browse files
author
Luke Carbis
committed
Fix author and role exclude dropdown
1 parent c6ed40c commit e5c8677

File tree

3 files changed

+38
-41
lines changed

3 files changed

+38
-41
lines changed

classes/class-settings.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ public function get_users() {
8484
'message' => esc_html__( 'There was an error in the request', 'stream' ),
8585
);
8686

87-
$search = wp_unslash( trim( wp_stream_filter_input( INPUT_POST, 'find' ) ) );
87+
$search = '';
88+
$input = wp_stream_filter_input( INPUT_POST, 'find' );
89+
90+
if ( ! isset( $input['term'] ) ) {
91+
$search = wp_unslash( trim( $input['term'] ) );
92+
}
8893

8994
$request = (object) array(
9095
'find' => $search,
@@ -123,6 +128,7 @@ public function get_users() {
123128

124129
$response->status = true;
125130
$response->message = '';
131+
$response->roles = $this->get_roles();
126132
$response->users = array();
127133
$users_added_to_response = array();
128134

ui/css/admin.css

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,33 @@
1818
overflow: visible;
1919
}
2020

21-
.post-type-wp_stream_alerts .select2 .select2-selection {
21+
.post-type-wp_stream_alerts .select2 .select2-selection,
22+
.stream-exclude-list .select2 .select2-selection{
2223
border-color: #ccc;
2324
background: #f7f7f7;
2425
-webkit-box-shadow: 0 1px 0 #ccc;
2526
box-shadow: 0 1px 0 #ccc;
2627
}
2728

28-
.post-type-wp_stream_alerts .select2 .select2-selection--multiple {
29+
.post-type-wp_stream_alerts .select2 .select2-selection--multiple,
30+
.stream-exclude-list .select2 .select2-selection--multiple{
2931
font-size: 0;
3032
min-height: 28px;
3133
}
3234

33-
.post-type-wp_stream_alerts .select2-container.select2-container--focus .select2-selection--multiple {
35+
.post-type-wp_stream_alerts .select2-container.select2-container--focus .select2-selection--multiple,
36+
.stream-exclude-list .select2-container.select2-container--focus .select2-selection--multiple{
3437
border: solid #ccc 1px;
3538
}
3639

37-
.post-type-wp_stream_alerts .select2-container .select2-selection--multiple .select2-selection__choice {
40+
.post-type-wp_stream_alerts .select2-container .select2-selection--multiple .select2-selection__choice,
41+
.stream-exclude-list .select2-container .select2-selection--multiple .select2-selection__choice{
3842
margin-top: 4px;
3943
margin-bottom: 3px;
4044
}
4145

42-
.post-type-wp_stream_alerts .select2 .select2-selection .select2-selection__rendered {
46+
.post-type-wp_stream_alerts .select2 .select2-selection .select2-selection__rendered,
47+
.stream-exclude-list .select2 .select2-selection .select2-selection__rendered{
4348
color: #555;
4449
}
4550

@@ -470,6 +475,11 @@
470475
border: 1px solid rgba(160,0,0,0.75);
471476
}
472477

478+
.stream-exclude-list .icon-users {
479+
top: -3px !important;
480+
position: relative !important;
481+
}
482+
473483
.post-type-wp_stream_alerts .select2-results__option .parent {
474484
font-weight: bold;
475485
}

ui/js/exclude.js

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -76,38 +76,10 @@ jQuery( function( $ ) {
7676
};
7777
},
7878
processResults: function( response ) {
79-
var roles = [];
80-
81-
$( 'option', $input_user ).each( function() {
82-
if ( $( this ).val() === '' ) {
83-
return;
84-
}
85-
if ( ! $.isNumeric( $( this ).val() ) ) {
86-
roles.push({
87-
'id' : $( this ).val(),
88-
'text' : $( this ).text()
89-
});
90-
}
91-
});
92-
93-
roles = $.grep(
94-
roles,
95-
function( role ) {
96-
var roleVal = $input_user.data( 'select2' ).dropdown.$search
97-
.val()
98-
.toLowerCase();
99-
var rolePos = role
100-
.text
101-
.toLowerCase()
102-
.indexOf( roleVal );
103-
return rolePos >= 0;
104-
}
105-
);
106-
10779
var answer = {
10880
results: [
10981
{ text: '', id: '' },
110-
{ text: 'Roles', children: roles },
82+
{ text: 'Roles', children: [] },
11183
{ text: 'Users', children: [] }
11284
]
11385
};
@@ -116,15 +88,23 @@ jQuery( function( $ ) {
11688
return answer;
11789
}
11890

119-
$.each( response.data.users, function( k, user ) {
120-
if ( $.contains( roles, user.id ) ) {
121-
user.disabled = true;
122-
}
91+
if ( undefined === response.data.users || undefined === response.data.roles ) {
92+
return answer;
93+
}
94+
95+
var roles = [];
96+
97+
$.each( response.data.roles, function( id, text ) {
98+
roles.push({
99+
'id' : id,
100+
'text' : text
101+
});
123102
});
124103

104+
answer.results[ 1 ].children = roles;
125105
answer.results[ 2 ].children = response.data.users;
126106

127-
// Notice we return the value of more so Select2 knows if more results can be loaded
107+
// Return the value of more so Select2 knows if more results can be loaded
128108
return answer;
129109
}
130110
},
@@ -263,7 +243,8 @@ jQuery( function( $ ) {
263243
initSettingsSelect2();
264244

265245
$( '.stream-exclude-list tr:not(.hidden) select.select2-select.author_or_role' ).each( function() {
266-
$( this ).val( $( this ).data( 'selected-id' ) ).trigger( 'change' );
246+
var $option = $('<option selected>' + $( this ).data( 'selected-text' ) + '</option>').val( $( this ).data( 'selected-id' ) );
247+
$( this ).append( $option ).trigger( 'change' );
267248
});
268249

269250
$( '.stream-exclude-list tr:not(.hidden) select.select2-select.connector_or_context' ).each( function() {

0 commit comments

Comments
 (0)