Skip to content

Commit

Permalink
Merge branch 'master' into issue-35
Browse files Browse the repository at this point in the history
Conflicts:
	stream-notifications.php
	views/rule-form.php
  • Loading branch information
shadyvb committed Feb 1, 2014
2 parents e74d313 + 0bcf28c commit 14adc75
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
31 changes: 27 additions & 4 deletions includes/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ 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 . '*' ) );
$data = $this->format_json_for_select2( $users, 'ID', 'display_name' );
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':
$actions = WP_Stream_Connectors::$term_labels['stream_action'];
Expand All @@ -125,7 +127,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();
Expand Down Expand Up @@ -157,6 +170,16 @@ public function format_json_for_select2( $data, $key = null, $val = null ) {
return $return;
}

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 ) . '%' );
}

/**
* Format JS options for the form, to be used with wp_localize_script
*
Expand Down Expand Up @@ -314,14 +337,14 @@ public function metabox_save( $rule ) {
);
?>
<a class="submitdelete deletion" href="<?php echo esc_url( $delete_link ) ?>">
<?php esc_html_e( 'Delete permanently', 'stream-notifications' ) ?>
<?php esc_html_e( 'Delete Permanently', 'stream-notifications' ) ?>
</a>
</div>
<?php endif; ?>

<div id="publishing-action">
<span class="spinner"></span>
<input type="submit" name="publish" id="publish" class="button button-primary button-large" value="<?php $rule->exists() ? esc_attr_e( 'Update', 'stream-notifications' ) : esc_attr_e( 'Save', 'stream-notifications' ) ?>" accesskey="p">
<input type="submit" name="publish" id="publish" class="button button-primary button-large" value="<?php $rule->exists() ? esc_attr_e( 'Update', 'stream-notifications' ) : esc_attr_e( 'Save', 'stream-notifications' ) ?>" accesskey="s">
</div>
<div class="clear"></div>
</div>
Expand Down
21 changes: 15 additions & 6 deletions ui/js/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -104,7 +114,6 @@ jQuery(function($){
},
dataType: "json",
success: function(j){
console.log(j.data)
$this.select2( 'data', j.data );
}
})
Expand Down Expand Up @@ -205,7 +214,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; }

Expand Down
5 changes: 5 additions & 0 deletions views/rule-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@
.select2-container.trigger-operator {
width: 140px !important;
}
.select2-choices img.avatar,
.select2-results img.avatar {
vertical-align: middle;
padding-right: 5px;
}
#alerts .add-alert {
margin: 0 0 12px 12px;
}
Expand Down

0 comments on commit 14adc75

Please sign in to comment.