diff --git a/backend/app/plugins/wiaas/assets/css/wiaas-admin-delivery-process.css b/backend/app/plugins/wiaas/assets/css/wiaas-admin-delivery-process.css new file mode 100644 index 0000000..430216a --- /dev/null +++ b/backend/app/plugins/wiaas/assets/css/wiaas-admin-delivery-process.css @@ -0,0 +1,10 @@ +.wiaas_delivery_step_nav { + + + +} + + +.gravityflow_workflow_detail #postbox-container-1 > div:nth-child(2) { + display: none; +} diff --git a/backend/app/plugins/wiaas/assets/js/wiaas-admin-delivery-process.js b/backend/app/plugins/wiaas/assets/js/wiaas-admin-delivery-process.js new file mode 100644 index 0000000..10341bb --- /dev/null +++ b/backend/app/plugins/wiaas/assets/js/wiaas-admin-delivery-process.js @@ -0,0 +1,8 @@ +jQuery(document).ready(function ($) { + $('.wiaas_delivery_step_nav').click(function (e) { + var action = $(this).data('step'); + + $('#wiaas_delivery_process_navigation_action').val(action); + + }); +}); diff --git a/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-delivery-process.php b/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-delivery-process.php index 512a03e..caf1120 100644 --- a/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-delivery-process.php +++ b/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-delivery-process.php @@ -8,14 +8,26 @@ class Wiaas_Admin_Delivery_Process { add_action( 'gravityflow_title_entry_detail', array( __CLASS__, 'process_title' ), 10, 3 ); - add_action('add_meta_boxes', array(__CLASS__, 'add_delivery_process_metabox'), 100); add_action( 'wp_ajax_wiaas_create_order_delivery_process', array(__CLASS__, 'wiaas_ajax_create_order_delivery_process') ); - add_filter('gravityflow_admin_actions_workflow_detail', array (__CLASS__, 'filter_process_send_to_step_options'), 10, 5); + add_action('gravityflow_entry_detail', array(__CLASS__, 'maybe_display_delivery_process_navigation'), 9, 3); + + add_filter('gravityflow_admin_action_feedback', array(__CLASS__, 'maybe_process_admin_step_change_action'), 10, 4); + + add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 ); } + public static function enqueue_scripts() { + + $plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) ); + + wp_enqueue_script( 'wiaas_admin_delivery_process', $plugin_url . '/assets/js/wiaas-admin-delivery-process.js' ); + wp_enqueue_style( 'wiaas_admin_delivery_process', $plugin_url . '/assets/css/wiaas-admin-delivery-process.css' ); + } + + public static function add_delivery_process_metabox() { add_meta_box( @@ -29,45 +41,84 @@ class Wiaas_Admin_Delivery_Process { } - public static function filter_process_send_to_step_options($admin_actions, $current_step, $steps, $form, $entry) { + public static function maybe_process_admin_step_change_action($feedback, $admin_action, $form, $entry) { - $delivery_process_actions = array(); + $admin_action = rgpost( 'wiaas_delivery_process_navigation_action' ); - if ( $current_step ) { + list( $base_admin_action, $action_id ) = rgexplode( '|', $admin_action, 2 ); - $previous_step_id = null; - // get previous step id for current step - foreach ($steps as $index => $step) { + if ( $base_admin_action == 'send_to_step' ) { + $step_id = $action_id; + $api = new Gravity_Flow_API( $form['id'] ); + $api->send_to_step( $entry, $step_id ); + $entry = GFAPI::get_entry( $entry['id'] ); + $new_step = $api->get_current_step( $entry ); + $feedback = $new_step ? + sprintf( esc_html__( 'Sent to step: %s', 'wiaas' ), $new_step->get_name() ) : + esc_html__( 'Workflow Complete', 'wiaas' ); + } - $next_step = gravity_flow()->get_next_step($step, $entry, $form); + return $feedback; + } - if ($next_step && $next_step->get_id() === $current_step->get_id()) { - $previous_step_id = $step->get_id(); - } - } + public static function maybe_display_delivery_process_navigation($form, $entry, $current_step) { - if (! empty($previous_step_id)) { + if(! GFAPI::current_user_can_any( 'gravityflow_workflow_detail_admin_actions' ) || empty( $current_step ) ) { + return; + } - $delivery_process_actions[] = array( - 'label' => esc_html__( 'Previous step', 'wiaas' ), - 'value' => 'send_to_step|' . $previous_step_id - ); - } + $steps = gravity_flow()->get_steps($form['id'], $entry); - // get next step id for current step - $next_step = gravity_flow()->get_next_step($current_step, $entry, $form); - if ($next_step) { + // get next step id + $next_step = gravity_flow()->get_next_step($current_step, $entry, $form); + $next_step_id = empty($next_step) ? null : $next_step->get_id(); - $delivery_process_actions[] = array( - 'label' => esc_html__( 'Next step', 'wiaas' ), - 'value' => 'send_to_step|' . $next_step->get_id() - ); - } - } + // get previous step id + foreach ($steps as $step) { - return $delivery_process_actions; - } + $next = gravity_flow()->get_next_step($step, $entry, $form); + if ($next && $next->get_id() === $current_step->get_id()) { + $previous_step = $step; + } + } + $previous_step_id = empty($previous_step) ? null : $previous_step->get_id(); + + // bail out if none exist + if ( empty($next_step_id) && empty($previous_step_id) ) { + + return; + } + + /** + * @reference Gravity_Flow::maybe_process_admin_action for used field names + * which are being checked there + * + */ + + ?> + +