diff --git a/CHANGELOG.txt b/CHANGELOG.txt new file mode 100644 index 0000000000000000000000000000000000000000..14663cb7668435d67ddbffa121ab5650fcfe6b3d --- /dev/null +++ b/CHANGELOG.txt @@ -0,0 +1,6 @@ +5.x-1.0-beta2 +Bug Fixes + * Getting collapsable fieldsets working for in autofill popups. + * http://drupal.org/node/345353: Getting autofill working w/out page refresh. +Notes + * Needs Popups API 1.0-beta2 or better. \ No newline at end of file diff --git a/popups_reference.module b/popups_reference.module index c6cf7deed2c0bd0e237ab571a96f43b32ea59164..6df01eb9f42f204036a30a5e16683246b0120fc5 100644 --- a/popups_reference.module +++ b/popups_reference.module @@ -6,39 +6,6 @@ * Modify the Node Reference widget to use a popup to add a new node. */ -function _popups_reference_counter() { - static $count = 0; - return $count++; -} - -/** - * Generates 'Add new...' link - * for each allowed content type - */ -function _popups_reference_links($field, $src_type, $id=null) { - if ($id) { // Creating link to select box. - $pclass = $id; - // Target just the select box for replacing. - popups_add_popups(array('.'.$pclass=>array( - 'targetSelectors'=>array('#'.$id), - 'behaviors' => array("Drupal.popups.collapsibleBehavior"), - ))); - } - else { // Creating link to autofill box. - $pclass = 'popups'; - popups_add_popups(); - } - $links = array(); - $all_types = node_get_types(); - foreach ($field['referenceable_types'] as $type => $value) { - if (!empty($value) && user_access("create $type content")) { - $path = "node/add/$type"; - $links[] = l("Add $type", $path, array('class' => $pclass), "destination=node/add/$src_type"); - } - } - return $links; -} - /** * Implementation of hook_form_alter(). */ @@ -46,13 +13,14 @@ function popups_reference_form_alter($form_id, &$form) { if (isset($form['type'])) { $node = $form['#node']; if ($form['type']['#value'] .'_node_form' == $form_id) { -//firep($form_id, 'form_id'); +//dsm($form_id, 'form_id'); $fields = content_fields(); +// dsm($form); foreach ($form as $key => $item) { //firep($key); if (is_array($item)) { - // firep($item['#type'], $key); $type = $item['#type']; +// dsm("$key, $type"); if ($type == 'fieldset') { // loop through all the subitems. // firep($item, $key); foreach ($form[$key] as $subkey => $subitem) { @@ -71,12 +39,13 @@ function popups_reference_form_alter($form_id, &$form) { function popups_reference_alter_item(&$form, $key, $item, $fields) { -//firep($key .', '. $field_name .', '. $fields[$field_name] .', '. $fields[$field_name]['type']); $field_name = strstr($key, 'field_'); +//dsm($key .', '. $field_name .', '. $fields[$field_name] .', '. $fields[$$field_name]['type']); +//dsm($key .', '. $field_name .', '. $fields[$field_name] .', '. $fields[$field_name]['type']); if (isset($fields[$field_name]) && $fields[$field_name]['type'] == 'nodereference') { $type = $form['type']['#value']; $field = content_fields($field_name, $form['type']['#value']); -//firep($field['widget']['type']); +//dsm($key .', '. $field['widget']['type']); if ($field['widget']['type'] == 'nodereference_select') { $id = 'popups-reference-' . _popups_reference_counter(); @@ -87,11 +56,51 @@ function popups_reference_alter_item(&$form, $key, $item, $fields) { } else if ($field['widget']['type'] == 'nodereference_autocomplete') { - $links = _popups_reference_links($field, $type, $id); + $links = _popups_reference_links($field, $type); $form[$key]['#suffix'] = '
Add New: ' . implode(', ', $links) .'
'; } } } - +/** + * Generates 'Add new...' link + * for each allowed content type + */ +function _popups_reference_links($field, $src_type, $id=null) { + if ($id) { // Creating link to select box. + $pclass = $id; + // Target just the select box for replacing. + popups_add_popups( + array('.'.$pclass=>array( + 'targetSelectors' => array('#'.$id), // Only reload the select box element. + 'behaviors' => array("Drupal.popups.collapsibleBehavior"), + )) + ); + } + else { // Creating link to autofill box. +// $pclass = 'popups'; +// popups_add_popups(); + $pclass = 'popups-reference-autofill'; + popups_add_popups( + array('.'.$pclass=>array( + 'noReload' => TRUE, // Don't refresh the original page. + 'behaviors' => array("Drupal.popups.collapsibleBehavior"), + )) + ); + } + $links = array(); + $all_types = node_get_types(); + foreach ($field['referenceable_types'] as $type => $value) { + if (!empty($value) && user_access("create $type content")) { + $path = "node/add/$type"; + $links[] = l("Add $type", $path, array('class' => $pclass), "destination=node/add/$src_type"); + } + } + return $links; +} + +function _popups_reference_counter() { + static $count = 0; + return $count++; +}