You are here

function node_gallery_upload_js in Node Gallery 6

1 string reference to 'node_gallery_upload_js'
node_gallery_menu in ./node_gallery.module
Implementation of hook_menu()

File

./node_gallery.pages.inc, line 100
Node gallery pages.

Code

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('Validation error, please try again. If this error persists, please contact the site administrator.'));
    $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);

  //if upload failed.
  if (drupal_get_messages(NULL, 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['edit_images'] = $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;
}