Skip to content

Commit

Permalink
Fix action dropdown, update values based on context
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Carbis committed Nov 2, 2016
1 parent 3626ba8 commit e923a92
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
1 change: 0 additions & 1 deletion ui/js/alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ jQuery( function( $ ) {
var parts = value.split( '-' );
$( this ).siblings( '.connector' ).val( parts[0] );
$( this ).siblings( '.context' ).val( parts[1] );
// $(this).removeAttr('name');
}
});

Expand Down
42 changes: 42 additions & 0 deletions ui/js/exclude.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ jQuery( function( $ ) {

return null;
}
}).on( 'change', function() {
var row = $( this ).closest( 'tr' ),
connector = $( this ).val();
if ( connector && 0 < connector.indexOf( '-' ) ) {
var connector_split = connector.split( '-' );
connector = connector_split[0];
}
getActions( row, connector );
});
});

Expand Down Expand Up @@ -323,6 +331,40 @@ jQuery( function( $ ) {
recalculate_rules_selected();
});

function getActions( row, connector ) {
var trigger_action = $( '.select2-select.action', row ),
action_value = trigger_action.val();

trigger_action.empty();
trigger_action.prop( 'disabled', true );

var placeholder = $( '<option/>', {value: '', text: ''} );
trigger_action.append( placeholder );

var data = {
'action' : 'get_actions',
'connector' : connector
};

$.post( window.ajaxurl, data, function( response ) {
var success = response.success,
actions = response.data;
if ( ! success ) {
return;
}
for ( var key in actions ) {
if ( actions.hasOwnProperty( key ) ) {
var value = actions[key];
var option = $( '<option/>', {value: key, text: value} );
trigger_action.append( option );
}
}
trigger_action.val( action_value );
trigger_action.prop( 'disabled', false );
$( document ).trigger( 'alert-actions-updated' );
});
};

function recalculate_rules_selected() {
var $selectedRows = $( 'table.stream-exclude-list tbody tr:not( .hidden ) input.cb-select:checked' ),
$deleteButton = $( '#exclude_rules_remove_rules' );
Expand Down

0 comments on commit e923a92

Please sign in to comment.