Index: relativity.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/relativity/relativity.module,v
retrieving revision 1.49
diff -r1.49 relativity.module
50c50
< function relativity_list_possible_children($type='', $parent_nid='') {
---
> function relativity_list_possible_children($type='', $parent_nid='', $is_autocomplete=false) {
54a55,57
> if($is_autocomplete == null){
> $is_autocomplete = false;
> }
110c113,117
< $links[$key][] = array('title' => $child_node->title, 'child_node' => $child_node->nid, 'parent_node' => $parent_nid);
---
> if ($is_autocomplete === false) {
> $links[$key][] = array('title' => $child_node->title, 'child_node' => $child_node->nid, 'parent_node' => $parent_nid);
> } else {
> $links[$child_node->title.' [nid:' . $child_node->nid . ']'] = check_plain($child_node->title);
> }
112c119,123
< $links[] = theme('relativity_link', $child_node->title, "addparent/$child_node->nid/parent/$parent_nid", $parent_nid);
---
> if ($is_autocomplete === false) {
> $links[] = theme('relativity_link', $child_node->title, "addparent/$child_node->nid/parent/$parent_nid", $parent_nid);
> } else {
> $links[$child_node->title.' [nid:' . $child_node->nid . ']'] = check_plain($child_node->title);
> }
116a128,132
> if($is_autocomplete !== false){
> print drupal_to_js($links);
> exit();
> }
>
301a318
> 'callback arguments' => array('','',arg(5)),
485,489d501
< // Node Sorting Options
< $group['sorting_options'] = array(
< '#type' => 'fieldset',
< '#title' => t('Node Sorting Options'),
< );
497a510,526
>
> $group['global_options']['relativity_select_method'] = array(
> '#type' => 'radios',
> '#title' => t('How should nodes be selected?'),
> '#return_value' => 1,
> '#default_value' => variable_get('relativity_select_method', t('Both')),
> '#options' => array(t('List') => t('List'), t('Autocomplete') => t('Autocomplete'), t('Both') => t('Both')),
> '#description' => '
- '. t('List') . t(' : A link to a paged list of nodes') .'
'
> .'- '. t('Autocomplete') . t(' : A autocomplete form') .'
'
> .'- '. t('Both') . t(' : The two options together') .'
',
> );
>
> // Node Sorting Options
> $group['sorting_options'] = array(
> '#type' => 'fieldset',
> '#title' => t('Node Sorting Options'),
> );
1572,1573c1601,1617
< if ($may_create) { // If 'create' link is present ...
< $output .= ' | '; // insert a pipe separator between links
---
> // If 'create' link is present ... insert a pipe separator between links
> $list = ($may_create?' | ':'').l(t('Attach existing !type (from a list)', array('!type'=>$type_name)), "relativity/listnodes/$type/parent/$parent_nid", array('class' => 'relativity_attach_' . $type));
>
> switch (variable_get('relativity_select_method', t('Both'))) {
> case t('List'):
> $output .= $list;
> break;
>
> case t('Autocomplete'):
> $output .= drupal_get_form('relativity_autocomplete_child', array('type_name'=>$type_name, 'type'=>$type, 'parent_nid'=>$parent_nid));
> break;
>
> default:
> $output .= $list;
> $output .= '
';
> $output .= drupal_get_form('relativity_autocomplete_child', array('type_name'=>$type_name, 'type'=>$type, 'parent_nid'=>$parent_nid));
> break;
1575,1576c1619,1620
< $output .= l(t('Attach existing !type', array('!type'=>$type_name)), "relativity/listnodes/$type/parent/$parent_nid", array('class' => 'relativity_attach_' . $type));
< $output .= "
\n";
---
>
> $output .= "
\n";
1617a1662,1730
> /**
> * Defines a form for autocomplete_child.
> *
> */
> function relativity_autocomplete_child($details) {
> $form['relativity_child_name'] = array(
> '#title' => t('Attach existing !type (auto-complete)', array('!type'=>$details['type_name'])),
> '#type' => 'textfield',
> '#autocomplete_path' => 'relativity/listnodes/'.$details['type'].'/parent/'.$details['parent_nid'].'/true',
> '#description' => t('Type the title of the !type', array('!type'=>$details['type_name']))
> );
> $form['relativity_child_type'] = array(
> '#type' => 'hidden',
> '#value'=> $details['child_type'],
> );
> $form['relativity_child_parent_nid'] = array(
> '#type' => 'hidden',
> '#value'=> $details['parent_nid'],
> );
> $form['relativity_submit'] = array(
> '#type' => 'submit',
> '#value' => t('Submit')
> );
>
> return $form;
> }
>
> /**
> * Handle autocomplete_child form submission.
> */
> function relativity_autocomplete_child_submit($form_id, $form_values) {
> //extract nid if it exsists
> preg_match('/\[nid:(\d*)]/', $form_values['relativity_child_name'], $matches);
> if ( count($matches) > 1 ) {
> $nid = $matches[1];
> }
> else { //no NID set, so try to grab it
> $node_title = $form_values['relativity_child_name'];
> $result = db_query("SELECT nid FROM {node} WHERE LOWER(title) LIKE LOWER('%s%%')", $node_title, 0, 10);
>
> if (db_num_rows($result) == 1) {
> $nid = db_result($result);
> }
> else if (db_num_rows($result) > 1) { //too many results
> $error = t('More than one %type has the title "%title", please select the required node from !link',
> array(
> '%type' => $form_values['relativity_child_type_name'],
> '%title' => $node_title,
> '!link' => l('this list','relativity/listnodes/'. $form_values['relativity_child_type'] .'/parent/'. $form_values['relativity_child_parent_nid']))
> );
> }
> }
>
> if (!$nid){
> $error = t('No %type found with the title "%title"',
> array(
> '%type' => $form_values['relativity_child_type_name'],
> '%title' => $node_title
> )
> );
> }
>
> if ($error){
> drupal_set_message($error, 'error');
> } else {
> drupal_goto('relativity/addparent/'.$nid.'/parent/'.$form_values['relativity_child_parent_nid']);
> }
> }
>