From 4d0ad41242f3ecd121000b66120e742494954fa7 Mon Sep 17 00:00:00 2001 From: Shady Sharaf Date: Fri, 31 Jan 2014 01:24:13 +0200 Subject: [PATCH 1/4] Allow searching authors by display_name --- stream-notifications.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/stream-notifications.php b/stream-notifications.php index cf5e5a90f..37a6b5218 100644 --- a/stream-notifications.php +++ b/stream-notifications.php @@ -513,7 +513,9 @@ public function form_ajax_ep() { } else { switch ( $type ) { case 'author': + add_action( 'pre_user_query', array( $this, 'fix_user_query_display_name' ) ); $users = get_users( array( 'search' => '*' . $query . '*' ) ); + remove_action( 'pre_user_query', array( $this, 'fix_user_query_display_name' ) ); $data = $this->format_json_for_select2( $users, 'ID', 'display_name' ); break; case 'action': @@ -644,6 +646,16 @@ public function delete_record( $id ) { $this->matcher->refresh(); } + public function fix_user_query_display_name( $query ) { + global $wpdb; + $search = $query->query_vars['search']; + if ( empty( $search ) ) { + return; + } + $search = str_replace( '*', '', $search ); + $query->query_where .= $wpdb->prepare( " OR $wpdb->users.display_name LIKE %s", '%' . like_escape( $search ) . '%' ); + } + /** * Check if plugin dependencies are satisfied and add an admin notice if not * From 8892648ba25bc7e5aee027ffc913c8dcfbe517d0 Mon Sep 17 00:00:00 2001 From: Shady Sharaf Date: Fri, 31 Jan 2014 05:21:16 +0200 Subject: [PATCH 2/4] Show avatars for author fields in rule form Finishes #27 --- stream-notifications.php | 13 ++++++++++++- ui/js/main.js | 19 ++++++++++++++----- views/rule-form.php | 5 +++++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/stream-notifications.php b/stream-notifications.php index 37a6b5218..5314ff8f8 100644 --- a/stream-notifications.php +++ b/stream-notifications.php @@ -525,7 +525,18 @@ public function form_ajax_ep() { break; } } - if ( isset( $data ) ) { + + // Add gravatar for authors + if ( $type == 'author' && get_option( 'show_avatars' ) ) { + foreach ( $data as $i => $item ) { + if ( $avatar = get_avatar( $item['id'], 20 ) ) { + $item['avatar'] = $avatar; + } + $data[$i] = $item; + } + } + + if ( $data ) { wp_send_json_success( $data ); } else { wp_send_json_error(); diff --git a/ui/js/main.js b/ui/js/main.js index 921c58eb2..0ad759e86 100644 --- a/ui/js/main.js +++ b/ui/js/main.js @@ -23,10 +23,23 @@ jQuery(function($){ tmpl_alert = _.template( $('script#alert-template-row').html() ), tmpl_alert_options = _.template( $('script#alert-template-options').html() ), + select2_format = function( item ) { + var text = item.text; + if ( typeof item.avatar != 'undefined' ) { + text = item.avatar + item.text; + } else{ + console.log('no avatar', item) + } + return text; + }, + select2_args = { allowClear: true, minimumResultsForSearch: 8, - width: '160px' + width: '160px', + format: select2_format, + formatSelection: select2_format, + formatResult: select2_format }, selectify = function( elements, args ) { @@ -63,9 +76,6 @@ jQuery(function($){ results: function (data) { var r = data.data || []; return {results: r}; - }, - formatSelection: function(item) { - return item.title; } }; elementArgs.initSelection = function(element, callback) { @@ -104,7 +114,6 @@ jQuery(function($){ }, dataType: "json", success: function(j){ - console.log(j.data) $this.select2( 'data', j.data ); } }) diff --git a/views/rule-form.php b/views/rule-form.php index 853c5fa31..2896982f0 100644 --- a/views/rule-form.php +++ b/views/rule-form.php @@ -343,4 +343,9 @@ .select2-container.trigger-operator { width: 140px !important; } + .select2-choices img.avatar, + .select2-results img.avatar { + vertical-align: middle; + padding-right: 5px; + } From ea9c46d461d40a2e63a0e7869736b5924f20c555 Mon Sep 17 00:00:00 2001 From: Shady Sharaf Date: Fri, 31 Jan 2014 07:57:32 +0200 Subject: [PATCH 3/4] Fix removal of alert options after clearing/changing alert type Fixes #37 --- ui/js/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/js/main.js b/ui/js/main.js index 64d2d1223..5da186bd3 100644 --- a/ui/js/main.js +++ b/ui/js/main.js @@ -205,7 +205,7 @@ jQuery(function($){ var $this = $(this), options = stream_notifications.adapters[ $this.val() ], index = $this.parents('.alert').first().attr('rel'); - $this.next('.alert-options').remove(); + $this.parent().next('.alert-options').remove(); if ( ! options ) { return; } From bd52b78e5e06ec9d6f5c1984a72dc3b877d1a368 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Fri, 31 Jan 2014 15:06:50 -0600 Subject: [PATCH 4/4] Trivial caps fix --- views/rule-form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/rule-form.php b/views/rule-form.php index a6be906b9..700839730 100644 --- a/views/rule-form.php +++ b/views/rule-form.php @@ -64,7 +64,7 @@ ); ?> - +