Index: node_gallery.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/node_gallery/node_gallery.pages.inc,v
retrieving revision 1.11.4.34
diff -u -r1.11.4.34 node_gallery.pages.inc
--- node_gallery.pages.inc	30 Sep 2010 02:18:37 -0000	1.11.4.34
+++ node_gallery.pages.inc	5 Oct 2010 19:26:59 -0000
@@ -57,6 +57,23 @@
   return theme('gallery_list', $items, $account) . theme('pager', NULL, variable_get('node_gallery_page_number', 20), 0);
 }
 
+function node_gallery_upload_form_submit($form, &$form_state) {
+  //save the values for the current step into the storage array
+  $form_state['storage']['steps'][$form_state['storage']['step']] = $form_state['values'];
+  
+  if ($form_state['storage']['step'] == 1) {
+  }
+    
+  // check the button that was clicked and action the step change
+  if ($form_state['clicked_button']['#id']=='edit-next') {
+      $form_state['storage']['step']++;
+  }
+    
+  //tell Drupal we are redrawing the same form
+  $form_state['rebuild'] = TRUE;
+    
+}
+
 function node_gallery_upload_form($form_state, $gallery) {
   drupal_set_breadcrumb(array(
     l(t('Home'), NULL),
@@ -65,46 +82,54 @@
     l($gallery->title, 'node/'. $gallery->nid)
     ));
   
-  $config = node_gallery_get_config($gallery->type);
-  //bad hack, this is for node_gallery_image item_form, since we use ahah in here;
-  drupal_add_tabledrag('upload-attachments', 'order', 'sibling', 'upload-weight');
-  drupal_add_js('misc/autocomplete.js');
+  if (empty($form_state['storage']['step'])) {
+      $form_state['storage']['step'] = 1;
+  }
   
-  $form['#attributes']['enctype'] = 'multipart/form-data';
-  $form['#node'] = $gallery;
   //just a mark for submit handler.
   $form['is_upload'] = array(
     '#type' => 'value',
     '#value' => TRUE,
   );
-  
-  $form['upload_wrapper'] = array(
-    '#prefix' => '<div id="gallery-upload-wrapper">',
-    '#suffix' => '</div>',
-  );
-  
-  $upload_number = is_numeric($config['number_uploads']) ? $config['number_uploads'] : 5;
-  for ($i = 1; $i <= $upload_number; $i++) {
-    $form['upload_wrapper']['uploads-'. $i] = array(
-      '#type' => 'file',
-      '#title' => t('Please select an image'),
-    );
+   
+  switch ($form_state['storage']['step']) {
+    case 1:
+      $form_state['storage']['gallery'] = $gallery;
+      $config = node_gallery_get_config($gallery->type);
+      
+      $form['#attributes']['enctype'] = 'multipart/form-data';
+     
+      $upload_number = is_numeric($config['number_uploads']) ? $config['number_uploads'] : 5;
+      for ($i = 1; $i <= $upload_number; $i++) {
+        $form['uploads-'. $i] = array(
+          '#type' => 'file',
+          '#title' => t('Please select an image'),
+        );
+      }
+        
+      $form['description'] = array(
+        '#value' => node_gallery_upload_limits($config),
+      );
+      $form['next'] = array(
+        '#type' => 'submit',
+        '#value' => t('Submit Images'),
+        '#weight' => 20,
+      );
+      break;
+    case 2:
+      drupal_add_tabledrag('upload-attachments', 'order', 'sibling', 'upload-weight');
+      drupal_add_js('misc/autocomplete.js');
+      
+      //this is upload form, we don't want to show the node's existing images;
+      unset($form_state['storage']['gallery']->images);
+      $form['#node'] =  $form_state['storage']['gallery'];
+      
+      // Handle new uploads, and merge tmp files into node-files.
+      node_gallery_upload_images($form, $form_state);
+      
+      $form = node_gallery_edit_images_form($form_state, $form_state['storage']['gallery']);
+      break;
   }
-  
-  $form['upload_wrapper']['description'] = array(
-    '#value' => node_gallery_upload_limits($config),
-  );
-  $form['upload_wrapper']['next'] = array(
-    '#type' => 'submit',
-    '#value' => t('Submit Images'),
-    '#weight' => 20,
-    '#ahah' => array(
-      'path' => 'node_gallery/upload/js',
-      'wrapper' => 'gallery-upload-wrapper',
-      'progress' => array('type' => 'bar', 'message' => t('Please wait...')),
-    ),
-  );
-  
   return $form;
 }
 
@@ -112,7 +137,7 @@
   //bad hacks, since we use ahah, we have to validate the upload image nodes here.
   if (!empty($form_state['values']['files'])) {
     foreach ($form_state['values']['files'] as $key => $image_form_state) {
-      node_validate($image_form_state['edit_form'], $form['files'][$key]['edit_form']);
+        node_validate($image_form_state['edit_form'], $form['files'][$key]['edit_form']);
     }    
   }
 }*/
@@ -135,52 +160,6 @@
   return theme('item_list', $items, t('notes'), 'ul', array('class' => 'upload-notes'));
 }
 
-function node_gallery_upload_js() {
-  $cached_form_state = array();
-  $files = array();
-  
-  // Load the form from the Form API cache.
-  if (!($cached_form = form_get_cache($_POST['form_build_id'], $cached_form_state)) || !isset($cached_form['#node']) || !isset($cached_form['upload_wrapper'])) {
-    form_set_error('form_token', t('The upload failed, please try again.'));
-    $output = theme('status_messages');
-    print drupal_to_js(array('status' => TRUE, 'data' => $output));
-    exit();
-  }
-  
-  $form_state = array('values' => $_POST);
-  
-  //this is upload form, we don't want to show the node's existing images;
-  unset($cached_form['#node']->images);
-  // Handle new uploads, and merge tmp files into node-files.
-  node_gallery_upload_images($cached_form, $form_state);
-  
-  // Exit if no images were successfully uploaded
-  if (empty($form_state['values']['files'])) {
-    if (drupal_get_messages('error', FALSE)) {
-      print drupal_to_js(array('status' => TRUE, 'data' => theme('status_messages') . drupal_get_form('node_gallery_upload_form')));
-    }
-    exit;
-  }
-  
-  $form = node_gallery_edit_images_form($form_state, $cached_form['#node']);
-  $cached_form = array_merge($cached_form, $form);
-  
-  form_set_cache($_POST['form_build_id'], $cached_form, $cached_form_state);
-  // Render the form for output.
-  $form += array(
-    '#post' => $_POST,
-    '#programmed' => FALSE,
-    '#tree' => FALSE,
-    '#parents' => array(),
-  );
-  //drupal_alter('form', $form, array(), 'upload_js');
-  $form_state = array('submitted' => FALSE);
-  $form = form_builder('node_gallery_upload_js', $form, $form_state);
-  
-  print drupal_to_js(array('status' => TRUE, 'data' => theme('status_messages') . drupal_render($form)));
-  exit;
-}
-
 function node_gallery_upload_file_limits($user, $config) {
   $file_limit = $config['upload_limits']['general']['file_max_size'];
   $user_limit = $config['upload_limits']['general']['user_max_size'];
@@ -702,4 +681,5 @@
     }
   }
   return $errors;
-}
\ No newline at end of file
+}
+
