13d12
< define('VIEWS_BULK_OPS_STEP_ALL', 5);
79a79
>   $form['#multistep'] = TRUE;
90,105d89
<   if (count($all_operations) > 1) {
<     $form['#multistep'] = TRUE;
<     // Calculate next step. Take into consideration whether the action is configurable or not.
<     $step = isset($form_values) ? (int) $form_values['step'] + 1: VIEWS_BULK_OPS_STEP_VIEW;
<     if ($step == VIEWS_BULK_OPS_STEP_CONFIG) {
<       $action = $form_values['action'];
<       if (!isset($all_operations[$action]) || !$all_operations[$action]['configurable']) {
<         $step = VIEWS_BULK_OPS_STEP_CONFIRM;
<       }
<     }
<   } else {
<     $form['#multistep'] = FALSE; 
<     $form['#redirect'] = FALSE;	
<     $form['#after_build'] = array('views_bulk_operations_form_preview');
<     $step = VIEWS_BULK_OPS_STEP_ALL;
<   }  
106a91,98
>   // Calculate next step. Take into consideration whether the action is configurable or not.
>   $step = isset($form_values) ? (int) $form_values['step'] + 1: VIEWS_BULK_OPS_STEP_VIEW;
>   if ($step == VIEWS_BULK_OPS_STEP_CONFIG) {
>     $action = $form_values['action'];
>     if (!isset($all_operations[$action]) || !$all_operations[$action]['configurable']) {
>       $step = VIEWS_BULK_OPS_STEP_CONFIRM;
>     }
>   }
112,158c104,129
<   case VIEWS_BULK_OPS_STEP_ALL: // All in one  
< 	  if ($step == VIEWS_BULK_OPS_STEP_VIEW) {  
<       $options[0] = t('- Choose an operation -');
<       foreach ($all_operations as $operation => $values) {
<         $options[$operation] = $values['label'];
<       }
<       $form['select'] = array(
<         '#type' => 'fieldset',
<         '#title' => t('Bulk operations'),
<         //'#description' => t('Please select the operation to perform on the selected nodes.'),
<         '#options' => $options,
<         '#prefix' => '<div id="views-bulk-operations-select">',
<         '#suffix' => '</div>',
<       );
<       $form['select']['action'] = array(
<         '#type' => 'select',
<         '#title' => '',
<         //'#description' => t('Please select the operation to perform on the selected nodes.'),
<         '#options' => $options,
<         '#prefix' => '<div id="views-bulk-operations-dropdown">',
<         '#suffix' => '</div>',
<       );
<       $form['select']['submit'] = array(
<         '#type' => 'submit',
<         '#value' => t('Execute'),
<         '#prefix' => '<div id="views-bulk-operations-submit">',
<         '#suffix' => '</div>',
<       );
<  	} else if ($step == VIEWS_BULK_OPS_STEP_ALL) {
<  	  $keys   = array_keys($all_operations);
<        $action = $keys[0];
<        $form['action'] = array(
<          '#type' => 'hidden',
<          '#value' => $action,
<        );	  
<        $form_action = call_user_func($action, 'form', array(), array());
<        $form = array_merge($form, $form_action);
<        $form['preview'] = array(
<          '#prefix' => '<br />',
<          '#type' => 'submit',
<          '#value' => t('Preview'),
<        );
<        $form['submit'] = array(
<          '#type' => 'submit',
<          '#value' => $all_operations[$action]['label'],
<        );	  
<  	}
---
>     $options[0] = t('- Choose an operation -');
>     foreach ($all_operations as $operation => $values) {
>       $options[$operation] = $values['label'];
>     }
>     $form['select'] = array(
>       '#type' => 'fieldset',
>       '#title' => t('Bulk operations'),
>       //'#description' => t('Please select the operation to perform on the selected nodes.'),
>       '#options' => $options,
>       '#prefix' => '<div id="views-bulk-operations-select">',
>       '#suffix' => '</div>',
>     );
>     $form['select']['action'] = array(
>       '#type' => 'select',
>       '#title' => '',
>       //'#description' => t('Please select the operation to perform on the selected nodes.'),
>       '#options' => $options,
>       '#prefix' => '<div id="views-bulk-operations-dropdown">',
>       '#suffix' => '</div>',
>     );
>     $form['select']['submit'] = array(
>       '#type' => 'submit',
>       '#value' => t('Execute'),
>       '#prefix' => '<div id="views-bulk-operations-submit">',
>       '#suffix' => '</div>',
>     );
173d143
< 	  '#weight'   => 10,	  
248,276d217
< function views_bulk_operations_form_preview($form) {
<   global $form_values;
< 
<   $op = isset($form_values['op']) ? $form_values['op'] : '';
<   if ($op == t('Preview')) {
<     // Invoke full validation for the form, to protect against cross site
<     // request forgeries (CSRF) and setting arbitrary values for fields such as
<     // the input format. Preview the node only when form validation does not
<     // set any errors.
<     drupal_validate_form($form['form_id']['#value'], $form);
<     if (!form_get_errors()) {
<       // Preview the values here
< 	    $form['fs_preview'] = array(
<         '#type'   => 'fieldset',
< 		    '#attributes' => array('class' => 'preview'),
<         '#tree'   => true,
< 	      '#weight' => -5,
< 	      '#collapsible' => false,
< 	    );
<       $elements = module_invoke_all('views_bulk_operations_preview', $form_values['nodes']['selected']);
< 	    $form['fs_preview'] = array_merge($form['fs_preview'], $elements);	  
< 	  }
<   }
<   if (form_get_errors() || $op != t('Preview')) {
<     unset($form['submit']);
<   }	  
<   return $form;
< }
< 
290,303c231,237
<   switch ($form_values['step']) {
<     case VIEWS_BULK_OPS_STEP_VIEW:
<       if (!array_sum($form_values['nodes'])) { // If all 0, no node selected
<         form_set_error('nodes', t('No nodes selected. Please select one or more nodes.'));
<       }
<       if (!$form_values['action']) { // No action selected
<         form_set_error('action', t('No action selected. Please select an action to perform.'));
<       }	  
< 	  break;
< 	case VIEWS_BULK_OPS_STEP_ALL:
<       if (!array_sum($form_values['nodes']['selected'])) { // If all 0, no node selected
<         form_set_error('nodes', t('No nodes selected. Please select one or more nodes.'));
<       }	
< 	  break;
---
>   if ($form_values['step'] == VIEWS_BULK_OPS_STEP_VIEW) {
>     if (!array_sum($form_values['nodes'])) { // If all 0, no node selected
>       form_set_error('nodes', t('No nodes selected. Please select one or more nodes.'));
>     }
>     if (!$form_values['action']) { // No action selected
>       form_set_error('action', t('No action selected. Please select an action to perform.'));
>     }
308,322c242,245
<   switch ($form_values['step']) {
<     case VIEWS_BULK_OPS_STEP_CONFIRM:
<       $nodes = unserialize($form_values['nodes']);
<   	  break;
<     case VIEWS_BULK_OPS_STEP_ALL:  
<       $op = isset($form_values['op']) ? $form_values['op'] : '';
<       if ($op == t('Preview')) {
< 	    return;
< 	  }
< 	  $nodes = $form_values['nodes'];
<       break;	
< 	default:
< 	  return;
<   }
<   
---
> 
>   if ($form_values['step'] < VIEWS_BULK_OPS_STEP_CONFIRM) return;
> 
>   $nodes = unserialize($form_values['nodes']);
348c271
<           //drupal_set_message(t('Performed %action on node %nid.', array('%action' => $operations[$action]['label'], '%nid' => $node->title)));
---
>           drupal_set_message(t('Performed %action on node %nid.', array('%action' => $operations[$action]['label'], '%nid' => $node->title)));
351d273
< 	    call_user_func($action, 'done', $form_values, NULL);
765,768d686
< 	    if (arg(0) != 'admin') {
< 		    $return_operations = $stored_operations;
< 	      break;
< 	    }	
