I am trying to create a Modal Window for the Node Delete page. The link is as follows within a view Block:

<a class="ctools-use-modal" href="modal_forms/nojs/node/[nid]/delete">Delete</a>

I am getting the following error:

An AJAX HTTP error occurred.
HTTP Result Code: 404
Debugging information follows.
Path: modal_forms/ajax/node/61/delete
StatusText: Not Found
ResponseText: 

Can anyone help me out with this please.

Comments

doors’s picture

Version: 7.x-1.2 » 7.x-1.x-dev
doors’s picture

Issue summary: View changes
Ruslan Piskarov’s picture

Hi @doors,
you can use the code like this:

function YOUMODULE_menu()
{
  $items['modal_forms/%ctools_js/node/%node/delete'] = array(
      'title' => 'Delete',
      'page callback' => 'YOUMODULE_ajax_node_delete_confirm',
      'page arguments' => array(1, 3),
      'access callback' => 'node_access',
      'access arguments' => array('delete', 3),
      'type' => MENU_CALLBACK,
      'file' => 'pse_modal_forms.pages.inc',
  );

  return $items;
}
function YOUMODULE_ajax_node_delete_confirm($js, $node) {
  if (!$js) {
    // We don't support degrading this from js because we're not
    // using the server to remember the state of the table.
    return MENU_ACCESS_DENIED;
  }

  module_load_include('inc', 'node', 'node.pages');
  ctools_include('modal');
  ctools_include('ajax');

  if ($node->title == 'Gallery Item') {
    $node->title = t('this photo');
  }
  $form_state = array(
      'build_info' => array(
          'args' => array(
              0 => $node,
          ),
      ),
      'ajax' => TRUE,
  );

  $output = ctools_modal_form_wrapper('node_delete_confirm', $form_state, $node);
  if (!empty($form_state['executed'])) {
    // We'll just overwrite the form output if it was successful.
    $output = array();
    ctools_add_js('ajax-responder');
    unset($_SESSION['messages']);
    if ($node->type == 'node_gallery_item') {
        $output[] = ajax_command_invoke(null, 'throwAwayThePicture', array('li.node-' . $node->nid));
    } else {
        $output[] = ajax_command_remove('li.node-' . $node->nid);
    }
    $output[] = ajax_command_remove('.messages.status');
    $output[] = ajax_command_before('.view-user-albums, .view-user-album-edit-page', '<div class="messages status"></div>');
    $output[] = ajax_command_append('.messages.status',
        t('@type %title has been deleted.', array('@type' => node_type_get_name($node), '%title' => $node->title)));
    $output[] = ctools_modal_command_dismiss();
    if (isset($_GET['destination'])) {
      $output[] = ctools_ajax_command_redirect($_GET['destination']);
    }
  }
  print ajax_render($output);
}

This code can not be copied and used. Just the idea of ​​how it can be implemented.

Thanks.

ishwar’s picture

Thanks #3 is working for me ...Great