diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/book/book.css | 2 | ||||
-rw-r--r-- | modules/book/book.module | 5 | ||||
-rw-r--r-- | modules/book/book.pages.inc | 42 | ||||
-rw-r--r-- | modules/field/field.form.inc | 26 | ||||
-rw-r--r-- | modules/field/field.test | 15 | ||||
-rw-r--r-- | modules/poll/poll.module | 10 | ||||
-rw-r--r-- | modules/poll/poll.test | 19 | ||||
-rw-r--r-- | modules/simpletest/tests/form_test.module | 2 | ||||
-rw-r--r-- | modules/system/system-rtl.css | 4 | ||||
-rw-r--r-- | modules/system/system.css | 8 | ||||
-rw-r--r-- | modules/system/system.module | 28 | ||||
-rw-r--r-- | modules/upload/upload.module | 18 |
12 files changed, 93 insertions, 86 deletions
diff --git a/modules/book/book.css b/modules/book/book.css index 8c62e4ae9..757b4bdd2 100644 --- a/modules/book/book.css +++ b/modules/book/book.css @@ -47,7 +47,7 @@ html.js #edit-book-pick-book { #book-admin-edit select.progress-disabled { margin-right: 0; } -#book-admin-edit tr.ahah-new-content { +#book-admin-edit tr.ajax-new-content { background-color: #ffd; } #book-admin-edit .form-item { diff --git a/modules/book/book.module b/modules/book/book.module index 9f2e6f241..3b5e88868 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -490,10 +490,11 @@ function _book_add_form_elements(&$form, $node) { '#description' => t('Your page will be a part of the selected book.'), '#weight' => -5, '#attributes' => array('class' => 'book-title-select'), - '#ahah' => array( + '#ajax' => array( 'path' => 'book/js/form', 'wrapper' => 'edit-book-plid-wrapper', - 'effect' => 'slide', + 'effect' => 'fade', + 'speed' => 'fast', ), ); } diff --git a/modules/book/book.pages.inc b/modules/book/book.pages.inc index cc61821ad..3e139cd81 100644 --- a/modules/book/book.pages.inc +++ b/modules/book/book.pages.inc @@ -234,28 +234,26 @@ function book_remove_form_submit($form, &$form_state) { * Prints the replacement HTML in JSON format. */ function book_form_update() { - $cached_form_state = array(); + // Load the form based upon the $_POST data sent via the ajax call. + list($form, $form_state) = ajax_get_form(); + + $commands = array(); $bid = $_POST['book']['bid']; - if ($form = form_get_cache($_POST['form_build_id'], $cached_form_state)) { - // Validate the bid. - if (isset($form['book']['bid']['#options'][$bid])) { - $book_link = $form['#node']->book; - $book_link['bid'] = $bid; - // Get the new options and update the cache. - $form['book']['plid'] = _book_parent_select($book_link); - form_set_cache($_POST['form_build_id'], $form, $cached_form_state); - // Build and render the new select element, then return it in JSON format. - $form_state = array(); - $form = form_builder($form['form_id']['#value'] , $form, $form_state); - $output = drupal_render($form['book']['plid']); - drupal_json(array('status' => TRUE, 'data' => $output)); - } - else { - drupal_json(array('status' => FALSE, 'data' => '')); - } - } - else { - drupal_json(array('status' => FALSE, 'data' => '')); + + // Validate the bid. + if (isset($form['book']['bid']['#options'][$bid])) { + $book_link = $form['#node']->book; + $book_link['bid'] = $bid; + // Get the new options and update the cache. + $form['book']['plid'] = _book_parent_select($book_link); + form_set_cache($form['values']['form_build_id'], $form, $form_state); + + // Build and render the new select element, then return it in JSON format. + $form_state = array(); + $form = form_builder($form['form_id']['#value'], $form, $form_state); + + $commands[] = ajax_command_replace(NULL, drupal_render($form['book']['plid'])); } - exit(); + + ajax_render($commands); } diff --git a/modules/field/field.form.inc b/modules/field/field.form.inc index 20998c349..10f687a56 100644 --- a/modules/field/field.form.inc +++ b/modules/field/field.form.inc @@ -190,7 +190,7 @@ function field_multiple_value_form($field, $instance, $items, &$form, &$form_sta '#value' => t('Add another item'), // Submit callback for disabled JavaScript. '#submit' => array('field_add_more_submit'), - '#ahah' => array( + '#ajax' => array( 'path' => 'field/js_add_more/' . $bundle_name_url_css . '/' . $field_name_url_css, 'wrapper' => $field_name_url_css . '-wrapper', 'method' => 'replace', @@ -362,13 +362,13 @@ function field_add_more_js($bundle_name, $field_name) { } if ($invalid) { - drupal_json(array('data' => '')); - exit; + ajax_render(array()); } // We don't simply return a new empty widget row to append to existing ones, // because: // - ahah.js won't simply let us add a new row to a table + // @todo ajax.js lets you. :) // - attaching the 'draggable' behavior won't be easy // So we resort to rebuilding the whole table of widgets including the // existing ones, which makes us jump through a few hoops. @@ -428,21 +428,15 @@ function field_add_more_js($bundle_name, $field_name) { foreach ($form_path as $key) { $field_form = $field_form[$key]; } - // Add a div around the new field to receive the ahah effect. - $field_form[$delta]['#prefix'] = '<div class="ahah-new-content">' . (isset($field_form[$delta]['#prefix']) ? $field_form[$delta]['#prefix'] : ''); + // Add a DIV around the new field to receive the AJAX effect. + $field_form[$delta]['#prefix'] = '<div class="ajax-new-content">' . (isset($field_form[$delta]['#prefix']) ? $field_form[$delta]['#prefix'] : ''); $field_form[$delta]['#suffix'] = (isset($field_form[$delta]['#suffix']) ? $field_form[$delta]['#suffix'] : '') . '</div>'; // Prevent duplicate wrapper. unset($field_form['#prefix'], $field_form['#suffix']); - // If a newly inserted widget contains AHAH behaviors, they normally won't - // work because AHAH doesn't know about those - it just attaches to the exact - // form elements that were initially specified in the Drupal.settings object. - // The new ones didn't exist then, so we need to update Drupal.settings - // by ourselves in order to let AHAH know about those new form elements. - $javascript = drupal_add_js(NULL, NULL); - $output_js = isset($javascript['setting']) ? '<script type="text/javascript">jQuery.extend(Drupal.settings, ' . drupal_to_js(call_user_func_array('array_merge_recursive', $javascript['setting'])) . ');</script>' : ''; - - $output = theme('status_messages') . drupal_render($field_form) . $output_js; - drupal_json(array('status' => TRUE, 'data' => $output)); - exit; + $output = theme('status_messages') . drupal_render($field_form); + + $commands = array(); + $commands[] = ajax_command_replace(NULL, $output); + ajax_render($commands); } diff --git a/modules/field/field.test b/modules/field/field.test index fce0fd8c2..49a1694bf 100644 --- a/modules/field/field.test +++ b/modules/field/field.test @@ -1336,12 +1336,19 @@ class FieldFormTestCase extends DrupalWebTestCase { unset($this->additionalCurlOptions[CURLOPT_URL]); // The response is drupal_json, so we need to undo some escaping. - $response = json_decode(str_replace(array('\x3c', '\x3e', '\x26'), array("<", ">", "&"), $this->drupalGetContent())); - $this->assertTrue(is_object($response), t('The response is an object')); - $this->assertIdentical($response->status, TRUE, t('Response status is true')); + $commands = json_decode(str_replace(array('\x3c', '\x3e', '\x26'), array("<", ">", "&"), $this->drupalGetContent())); + + // The JSON response will be two AJAX commands. The first is a settings + // command and the second is the replace command. + $settings = reset($commands); + $replace = next($commands); + + $this->assertTrue(is_object($settings), t('The response settings command is an object')); + $this->assertTrue(is_object($replace), t('The response replace command is an object')); + // This response data is valid HTML so we will can reuse everything we have // for HTML pages. - $this->content = $response->data; + $this->content = $replace->data; // Needs to be emptied out so the new content will be parsed. $this->elements = ''; diff --git a/modules/poll/poll.module b/modules/poll/poll.module index 26236fd7d..b8493a397 100644 --- a/modules/poll/poll.module +++ b/modules/poll/poll.module @@ -263,14 +263,14 @@ function poll_form($node, $form_state) { } // We name our button 'poll_more' to avoid conflicts with other modules using - // AHAH-enabled buttons with the id 'more'. + // AJAX-enabled buttons with the id 'more'. $form['choice_wrapper']['poll_more'] = array( '#type' => 'submit', '#value' => t('More choices'), '#description' => t("If the amount of boxes above isn't enough, click here to add more choices."), '#weight' => 1, '#submit' => array('poll_more_choices_submit'), // If no javascript action. - '#ahah' => array( + '#ajax' => array( 'callback' => 'poll_choice_js', 'wrapper' => 'poll-choices', 'method' => 'replace', @@ -320,7 +320,7 @@ function poll_more_choices_submit($form, &$form_state) { // Make the changes we want to the form state. if ($form_state['values']['poll_more']) { - $n = $_GET['q'] == 'system/ahah' ? 1 : 5; + $n = $_GET['q'] == 'system/ajax' ? 1 : 5; $form_state['choice_count'] = count($form_state['values']['choice']) + $n; } } @@ -373,9 +373,7 @@ function poll_choice_js($form, $form_state) { // Prevent duplicate wrappers. unset($choice_form['#prefix'], $choice_form['#suffix']); - $output = theme('status_messages') . drupal_render($choice_form); - - drupal_json(array('status' => TRUE, 'data' => $output)); + return theme('status_messages') . drupal_render($choice_form); } /** diff --git a/modules/poll/poll.test b/modules/poll/poll.test index f5b018095..a5f668efa 100644 --- a/modules/poll/poll.test +++ b/modules/poll/poll.test @@ -340,17 +340,24 @@ class PollJSAddChoice extends DrupalWebTestCase { // @TODO: the framework should make it possible to submit a form to a // different URL than its action or the current. For now, we can just force // it. - $this->additionalCurlOptions[CURLOPT_URL] = url('system/ahah', array('absolute' => TRUE)); + $this->additionalCurlOptions[CURLOPT_URL] = url('system/ajax', array('absolute' => TRUE)); $this->drupalPost(NULL, $edit, t('More choices')); unset($this->additionalCurlOptions[CURLOPT_URL]); // The response is drupal_json, so we need to undo some escaping. - $response = json_decode(str_replace(array('\x3c', '\x3e', '\x26'), array("<", ">", "&"), $this->drupalGetContent())); - $this->assertTrue(is_object($response), t('The response is an object')); - $this->assertIdentical($response->status, TRUE, t('Response status is true')); - // This response data is valid HTML so we will can reuse everything we have + $commands = json_decode(str_replace(array('\x3c', '\x3e', '\x26'), array("<", ">", "&"), $this->drupalGetContent())); + + // The JSON response will be two AJAX commands. The first is a settings + // command and the second is the replace command. + $settings = reset($commands); + $replace = next($commands); + + $this->assertTrue(is_object($settings), t('The response settings command is an object')); + $this->assertTrue(is_object($replace), t('The response replace command is an object')); + + // This replace data is valid HTML so we will can reuse everything we have // for HTML pages. - $this->content = $response->data; + $this->content = $replace->data; // Needs to be emptied out so the new content will be parsed. $this->elements = ''; diff --git a/modules/simpletest/tests/form_test.module b/modules/simpletest/tests/form_test.module index 34b495f5d..6646e85a8 100644 --- a/modules/simpletest/tests/form_test.module +++ b/modules/simpletest/tests/form_test.module @@ -294,7 +294,7 @@ function form_test_mock_form_submit($form, &$form_state) { * It uses two steps for editing a virtual "thing". Any changes to it are saved * in the form storage and have to be present during any step. By setting the * request parameter "cache" the form can be tested with caching enabled, as - * it would be the case, if the form would contain some #ahah callbacks. + * it would be the case, if the form would contain some #ajax callbacks. * * @see form_storage_test_form_submit(). */ diff --git a/modules/system/system-rtl.css b/modules/system/system-rtl.css index 0983da8dc..511143a04 100644 --- a/modules/system/system-rtl.css +++ b/modules/system/system-rtl.css @@ -81,10 +81,10 @@ div.teaser-button-wrapper { .progress-disabled { float: right; } -.ahah-progress { +.ajax-progress { float: right; } -.ahah-progress .throbber { +.ajax-progress .throbber { float: right; } input.password-field { diff --git a/modules/system/system.css b/modules/system/system.css index 8e020a33e..531ae65ed 100644 --- a/modules/system/system.css +++ b/modules/system/system.css @@ -450,20 +450,20 @@ html.js .no-js { .progress-disabled { float: left; /* LTR */ } -.ahah-progress { +.ajax-progress { float: left; /* LTR */ } -.ahah-progress .throbber { +.ajax-progress .throbber { width: 15px; height: 15px; margin: 2px; background: transparent url(../../misc/throbber.gif) no-repeat 0px -18px; float: left; /* LTR */ } -tr .ahah-progress .throbber { +tr .ajax-progress .throbber { margin: 0 2px; } -.ahah-progress-bar { +.ajax-progress-bar { width: 16em; } diff --git a/modules/system/system.module b/modules/system/system.module index d6a4ab3ee..001949c04 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -286,7 +286,7 @@ function system_elements() { '#name' => 'op', '#button_type' => 'submit', '#executes_submit_callback' => TRUE, - '#process' => array('form_process_ahah'), + '#process' => array('ajax_process_form'), '#theme_wrappers' => array('button'), ); @@ -295,7 +295,7 @@ function system_elements() { '#name' => 'op', '#button_type' => 'submit', '#executes_submit_callback' => FALSE, - '#process' => array('form_process_ahah'), + '#process' => array('ajax_process_form'), '#theme_wrappers' => array('button'), ); @@ -303,7 +303,7 @@ function system_elements() { '#input' => TRUE, '#button_type' => 'submit', '#executes_submit_callback' => TRUE, - '#process' => array('form_process_ahah'), + '#process' => array('ajax_process_form'), '#return_value' => TRUE, '#has_garbage_value' => TRUE, '#src' => NULL, @@ -315,7 +315,7 @@ function system_elements() { '#size' => 60, '#maxlength' => 128, '#autocomplete_path' => FALSE, - '#process' => array('form_process_text_format', 'form_process_ahah'), + '#process' => array('form_process_text_format', 'ajax_process_form'), '#theme' => 'textfield', '#theme_wrappers' => array('form_element'), ); @@ -324,7 +324,7 @@ function system_elements() { '#input' => TRUE, '#size' => 60, '#maxlength' => 128, - '#process' => array('form_process_ahah'), + '#process' => array('ajax_process_form'), '#theme' => 'password', '#theme_wrappers' => array('form_element'), ); @@ -340,7 +340,7 @@ function system_elements() { '#cols' => 60, '#rows' => 5, '#resizable' => TRUE, - '#process' => array('form_process_text_format', 'form_process_ahah'), + '#process' => array('form_process_text_format', 'ajax_process_form'), '#theme' => 'textarea', '#theme_wrappers' => array('form_element'), ); @@ -355,7 +355,7 @@ function system_elements() { $type['radio'] = array( '#input' => TRUE, '#default_value' => NULL, - '#process' => array('form_process_ahah'), + '#process' => array('ajax_process_form'), '#theme' => 'radio', '#theme_wrappers' => array('form_element'), '#form_element_skip_title' => TRUE, @@ -372,7 +372,7 @@ function system_elements() { $type['checkbox'] = array( '#input' => TRUE, '#return_value' => 1, - '#process' => array('form_process_ahah'), + '#process' => array('ajax_process_form'), '#theme' => 'checkbox', '#theme_wrappers' => array('form_element'), '#form_element_skip_title' => TRUE, @@ -382,7 +382,7 @@ function system_elements() { '#input' => TRUE, '#size' => 0, '#multiple' => FALSE, - '#process' => array('form_process_ahah'), + '#process' => array('ajax_process_form'), '#theme' => 'select', '#theme_wrappers' => array('form_element'), ); @@ -391,7 +391,7 @@ function system_elements() { '#input' => TRUE, '#delta' => 10, '#default_value' => 0, - '#process' => array('form_process_weight', 'form_process_ahah'), + '#process' => array('form_process_weight', 'ajax_process_form'), ); $type['date'] = array( @@ -430,7 +430,7 @@ function system_elements() { $type['hidden'] = array( '#input' => TRUE, - '#process' => array('form_process_ahah'), + '#process' => array('ajax_process_form'), '#theme' => 'hidden', ); @@ -447,7 +447,7 @@ function system_elements() { '#collapsible' => FALSE, '#collapsed' => FALSE, '#value' => NULL, - '#process' => array('form_process_fieldset', 'form_process_ahah'), + '#process' => array('form_process_fieldset', 'ajax_process_form'), '#pre_render' => array('form_pre_render_fieldset'), '#theme_wrappers' => array('fieldset'), ); @@ -476,9 +476,9 @@ function system_menu() { 'access callback' => TRUE, 'type' => MENU_CALLBACK, ); - $items['system/ahah'] = array( + $items['system/ajax'] = array( 'title' => 'AHAH callback', - 'page callback' => 'form_ahah_callback', + 'page callback' => 'ajax_form_callback', 'access callback' => TRUE, 'type' => MENU_CALLBACK, ); diff --git a/modules/upload/upload.module b/modules/upload/upload.module index b04b92894..772e329ed 100644 --- a/modules/upload/upload.module +++ b/modules/upload/upload.module @@ -60,7 +60,7 @@ function upload_permission() { */ function upload_node_links($node, $build_mode) { $links = array(); - + // Display a link with the number of attachments $num_files = 0; foreach ($node->files as $file) { @@ -236,7 +236,7 @@ function upload_form_alter(&$form, $form_state, $form_id) { '#weight' => 30, ); - // Wrapper for fieldset contents (used by ahah.js). + // Wrapper for fieldset contents (used by ajax.js). $form['attachments']['wrapper'] = array( '#prefix' => '<div id="attach-wrapper">', '#suffix' => '</div>', @@ -582,7 +582,7 @@ function _upload_form($node) { '#type' => 'submit', '#value' => t('Attach'), '#name' => 'attach', - '#ahah' => array( + '#ajax' => array( 'path' => 'upload/js', 'wrapper' => 'attach-wrapper', 'progress' => array('type' => 'bar', 'message' => t('Please wait...')), @@ -692,9 +692,11 @@ function upload_js() { $form = form_builder('upload_js', $form, $form_state); $output = theme('status_messages') . drupal_render($form); - // We send the updated file attachments form. - // Don't call drupal_json(). ahah.js uses an iframe and - // the header output by drupal_json() causes problems in some browsers. - print drupal_to_js(array('status' => TRUE, 'data' => $output)); - exit; + $commands = array(); + $commands[] = ajax_command_replace(NULL, $output); + + // AJAX uploads use an <iframe> and some browsers have problems with the + // 'text/javascript' Content-Type header with iframes. Passing FALSE to + // ajax_render() prevents the header from being sent. + ajax_render($commands, FALSE); } |