Ver Fonte

will use menu callbacks with wild cards

alexgl há 13 anos atrás
pai
commit
99621d1a2c

+ 236 - 236
base/tripal_views_setup/includes/tripal_views_setup.admin.inc

@@ -123,7 +123,7 @@ function tripal_views_setup_new_setup_form(&$form_state, $ahah_values = array())
          'effect' => 'fade',
          'event' => 'change',
          'method' => 'replace',
-	   ),
+	),
 	);
 
 	// ignore this for now... we'll come back to it later -- spf
@@ -173,16 +173,16 @@ function tripal_views_setup_new_setup_form(&$form_state, $ahah_values = array())
 		);
 		foreach ($columns as $column){
 			// each ahah element must have it's own matching menu item, maybe this is why our created ahahs don't work
-// 			for ($i = 0; $i < $howmany; $i++) {
-				$item = array(
+			// 			for ($i = 0; $i < $howmany; $i++) {
+			$item = array(
 					'link_path' => "admin/tripal/tripal_views_setup/ajax/field_col_join-$i",
 			     'title' => 'Get Join Columns',
 			     'page callback' => 'tripal_view_setup_ajax_field_col_join',
 			  	 'type' => MENU_CALLBACK,
 			     'access arguments' => array('access administration pages'),
-				);
-// 			}
-			
+			);
+			// 			}
+				
 			menu_link_save($item);// saves the menu item
 
 			$column = trim($column);  // trim trailing and leading spaces
@@ -218,14 +218,14 @@ function tripal_views_setup_new_setup_form(&$form_state, $ahah_values = array())
               'effect' => 'fade',
               'event' => 'change',
               'method' => 'replace',
-			   ),
+			),
 			);
-         if($table){
-            $table_desc = module_invoke_all('chado_'.$table.'_schema');
-            $columns = array_keys($table_desc['fields']);
-         } else {
-            $columns = array();
-         }
+			if($table){
+				$table_desc = module_invoke_all('chado_'.$table.'_schema');
+				$columns = array_keys($table_desc['fields']);
+			} else {
+				$columns = array();
+			}
 			$form['view_setup_table']["fields_column_join_column_$mview_id-$i"] = array(
             '#type' => 'select',
 		      '#prefix' => "<div id=\"fields-column-join-column-$mview_id-$i\" class=\"fields-column-join-column\">",
@@ -245,237 +245,237 @@ function tripal_views_setup_new_setup_form(&$form_state, $ahah_values = array())
             '#value' => "</div>",
 			);
 			$i++;
-		}
+			}
 
-	   $form['view_setup_table']['submit'] = array(
+			$form['view_setup_table']['submit'] = array(
 	      '#type' => 'submit',
 	      '#value' => 'Create',
-	   );
+			);
 
-		$form['row_counter'] = array(
+			$form['row_counter'] = array(
 		   '#type' => 'hidden',
 		   '#value' => $i,
-		);
-	} // end if($form_state['values']['mview_id']) 
-	return $form;
-}
-/**
- *
- * @ingroup tripal_view_setup
- */
-function tripal_view_setup_ajax_mview_cols(){
-
-   // regenerate the form
-// 	$form = tripal_views_setup_ajax_rebuild_form($form_state, $args, $_POST);
-	$form = tripal_views_setup_ajax_rebuild_form();
-	
-   // because the AJAX sent a post of the mview_id, the form now has in it
-   // form components for the rows for the materialized view.  We want to add
-   // these components to the page, but we don't need to add the existing form 
-   // elements because they are already there.
-  $view_setup_table_form = $form['view_setup_table'];
-	unset($view_setup_table_form['#prefix'], $view_setup_table_form['#suffix']);
-	$output = theme('status_message') . drupal_render($view_setup_table_form);
-
-	// Final rendering callback.
-// 	$javascript = drupal_add_js(NULL, NULL, 'header');
-	drupal_json(array('status' => TRUE, 'data' => $output,));// 'settings' => call_user_func('array_merge_recursive', $javascript['setting'])));
-}
-/**
- *
- * @ingroup tripal_view_setup
- */
-function tripal_view_setup_ajax_field_col_join(){
-
-   // regenerate the form
-	$form = tripal_views_setup_ajax_rebuild_form();
-
-//    // get the information we need to pull out table select box that was changed
-//    $mview_id = $form_state['values']['mview_id'];
-// //   $row = $form_state['values']['mview_id'];
-
-// //   $row_select_box = $form['view_setup_table']["fields-column-join-column-$mview_id-1"];
-// //	unset($row_select_box['#prefix'], $row_select_box['#suffix']);
-// // 	$output = theme('status_message') . drupal_render($row_select_box);
-
-// 	// Final rendering callback.
-// // 	$javascript = $javascript = drupal_add_js(NULL);
-// // 	drupal_json(array('status' => TRUE, 'data' => $output, 'settings' => call_user_func('array_merge_recursive', $javascript['setting'])));
-//   $javascript = drupal_add_js(NULL, NULL, 'header');
-// 	drupal_json(array('status' => TRUE, 'data' => 'helloworld', 'settings' => call_user_func('array_merge_recursive', $javascript['setting'])));
-
-	$changed_elements = $form['fields-column-join-column-$mview_1-1'];
-	unset($changed_elements['#prefix'], $changed_elements['#suffix']);
-	$output = theme('status_messages') . drupal_render($changed_elements);
-	drupal_json(array(
+			);
+		} // end if($form_state['values']['mview_id'])
+		return $form;
+	}
+	/**
+	 *
+	 * @ingroup tripal_view_setup
+	 */
+	function tripal_view_setup_ajax_mview_cols(){
+
+		// regenerate the form
+		// 	$form = tripal_views_setup_ajax_rebuild_form($form_state, $args, $_POST);
+		$form = tripal_views_setup_ajax_rebuild_form();
+
+		// because the AJAX sent a post of the mview_id, the form now has in it
+		// form components for the rows for the materialized view.  We want to add
+		// these components to the page, but we don't need to add the existing form
+		// elements because they are already there.
+		$view_setup_table_form = $form['view_setup_table'];
+		unset($view_setup_table_form['#prefix'], $view_setup_table_form['#suffix']);
+		$output = theme('status_message') . drupal_render($view_setup_table_form);
+
+		// Final rendering callback.
+		// 	$javascript = drupal_add_js(NULL, NULL, 'header');
+		drupal_json(array('status' => TRUE, 'data' => $output,));// 'settings' => call_user_func('array_merge_recursive', $javascript['setting'])));
+	}
+	/**
+	 *
+	 * @ingroup tripal_view_setup
+	 */
+	function tripal_view_setup_ajax_field_col_join(){
+
+		// regenerate the form
+		$form = tripal_views_setup_ajax_rebuild_form();
+
+		//    // get the information we need to pull out table select box that was changed
+		//    $mview_id = $form_state['values']['mview_id'];
+		// //   $row = $form_state['values']['mview_id'];
+
+		// //   $row_select_box = $form['view_setup_table']["fields-column-join-column-$mview_id-1"];
+		// //	unset($row_select_box['#prefix'], $row_select_box['#suffix']);
+		// // 	$output = theme('status_message') . drupal_render($row_select_box);
+
+		// 	// Final rendering callback.
+		// // 	$javascript = $javascript = drupal_add_js(NULL);
+		// // 	drupal_json(array('status' => TRUE, 'data' => $output, 'settings' => call_user_func('array_merge_recursive', $javascript['setting'])));
+		//   $javascript = drupal_add_js(NULL, NULL, 'header');
+		// 	drupal_json(array('status' => TRUE, 'data' => 'helloworld', 'settings' => call_user_func('array_merge_recursive', $javascript['setting'])));
+
+		$changed_elements = $form['fields-column-join-column-$mview_1-1'];
+		unset($changed_elements['#prefix'], $changed_elements['#suffix']);
+		$output = theme('status_messages') . drupal_render($changed_elements);
+		drupal_json(array(
 		    'status'   => TRUE,
 		    'data'     => $output,
-	));
-}
-
-function tripal_views_setup_ajax_rebuild_form(){
-$form_state = array('storage' => NULL, 'submitted' => FALSE);
-$form_build_id = $_POST['form_build_id'];
-$form = form_get_cache($form_build_id, $form_state);
-$args = $form['#parameters'];
-$form_id = array_shift($args);
-$form_state['post'] = $form['#post'] = $_POST;
-// Enable the submit/validate handlers to determine whether AHAH-submittted.
-$form_state['ahah_submission'] = TRUE;
-$form['#programmed'] = $form['#redirect'] = FALSE;
-drupal_process_form($form_id, $form, $form_state);
-$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
-return $form;
-}
-/**
- *
- * @ingroup tripal_view_setup
- */
-function tripal_views_setup_ajax_rebuild_formz(&$form_state, &$args, &$_POST){
-
-	// Retrieve the form from the cache
-	$form_state = array('storage' => NULL, 'submitted' => FALSE,);
-	$form_build_id = $_POST['form_build_id'];
-	$form = form_get_cache($form_build_id, $form_state);
-
-	// Preparing to process the form
-	$args = $form['#parameters'];
-	$form_id = array_shift($args);
-	$form_state['post'] = $form['#post'] = $_POST;
-	$form['#programmed'] = $form['#redirect'] = FALSE;
-
-	// Sets the form_state so that the validate and submit handlers can tell
-	// when the form is submitted via AHAH
-	$form_state['ahah_submission'] = TRUE;
-
-	// Process the form with drupal_process_form. This function calls the submit
-	// handlers, which put whatever was worthy of keeping into $form_state.
-	drupal_process_form($form_id, $form, $form_state);
-
-	// You call drupal_rebuild_form which destroys $_POST.
-	// The form generator function is called and creates the form again but since
-	// it knows to use $form_state, the form will be different.
-	// The new form gets cached and processed again, but because $_POST is
-	// destroyed, the submit handlers will not be called again.
-	$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
-
-	dpm($form,'form at rebuild');
-	dpm($form_state['post'], 'post at rebuild');
-	
-	return $form;
-}
-
-
-/**
- *
- * @ingroup tripal_view_setup
- */
-// function tripal_views_setup_fields(&$form_state=NULL, $mview_id = NULL){
-
-// 	if(!$mview_id){
-// 		return;
-// 	}
-
-// 	// get the columns in this materialized view.  They are separated by commas
-// 	// where the first word is the column name and the rest is the type
-// 	$sql = "SELECT mv_specs FROM {tripal_mviews} WHERE mview_id = $mview_id";
-// 	$mview = db_fetch_object(db_query($sql));
-// 	$columns = explode(",",$mview->mv_specs);
-
-// 	$i=1;
-// 	$chado_tables = tripal_core_get_chado_tables();
-// 	$handlers = array();
-// 	$form["fields_headers"] = array(
-//        '#type' => 'markup',
-//        '#value' => "<div class=\"field-headers\">".
-//             "<div class=\"column-id\">Field Name and Type</div>".
-//             "<div class=\"fields-column-join\">Join Table</div>".
-//             "<div class=\"fields-column-join-column\">Join Column</div>".
-//             "<div class=\"fields-column-handler\">Handler</div></div>",
-// 	);
-// 	foreach ($columns as $column){
-
-// 		$column = trim($column);  // trim trailing and leading spaces
-// 		preg_match("/^(.*?)\ (.*?)$/",$column,$matches);
-// 		$column_name = $matches[1];
-// 		$column_type = $matches[2];
-
-// 		// first print the field name
-// 		$form["fields_start_$i"] = array(
-//        '#type' => 'markup',
-//        '#value' => "<div class=\"fields-new-row\">",
-// 		);
-
-// 		$form["fields_column_name_$i"] = array(
-//        '#type' => 'markup',
-//          '#attributes' => array('class' => 'fields-column-name'),
-//        '#value' => "<div class=\"column-id\"><span class=\"column-name\">$column_name</span>".
-//                      "<br><span class=\"column-type\">$column_type</span></div>",
-// 		);
-
-// 		// second print the table join drop down
-// 		$chado_tables = array_merge(array(NULL,), $chado_tables);
-// 		$form["fields_column_join_$i"] = array(
-//        '#type' => 'select',
-//        '#prefix' => "<div class=\"fields-column-join\">",
-//        '#suffix' => "</div>",
-//        '#options' => $chado_tables,
-//        '#required' => FALSE,
-//        '#ahah' => array(
-//          'path' => 'admin/tripal/tripal_views_setup/ajax/field_col_join',
-//          'wrapper' => "fields-column-join-column-$i",
-//          'effect' => 'fade',
-//          'event' => 'change',
-//          'method' => 'replace',
-// 		),
-// 		);
-// 		$form["fields_column_join_column_$i"] = array(
-//        '#type' => 'select',
-//        '#prefix' => "<div id=\"fields-column-join-column-$i\" class=\"fields-column-join-column\">",
-//        '#suffix' => "</div>",
-//        '#options' => array(),
-//        '#required' => FALSE,
-// 		);
-// 		$form["fields_column_handler_$i"] = array(
-//        '#type' => 'select',
-//          '#prefix' => "<div class=\"fields-column-handler\">",
-//          '#suffix' => "</div>",
-//        '#options' => $handlers,
-//        '#required' => FALSE,
-// 		);
-// 		$form["fields_end_$i"] = array(
-//        '#type' => 'markup',
-//        '#value' => "</div>",
-// 		);
-// 		$i++;
-// 	}
-
-// 	$form['row_counter'] = array(
-//     '#type' => 'hidden',
-//     '#value' => $i,
-// 	);
-
-// 	$form['submit'] = array(
-//     '#type' => 'submit',
-//     '#value' => 'Create',
-// 	);
-
-// 	return $form;
-// }
-
-// function tripal_views_setup_fields_form_submit($form, &$form_state){
-// 	----($form,'formfield');
-// 	----($form_state, 'formstatefield');
-
-// }
+		));
+	}
 
+	function tripal_views_setup_ajax_rebuild_form(){
+		$form_state = array('storage' => NULL, 'submitted' => FALSE);
+		$form_build_id = $_POST['form_build_id'];
+		$form = form_get_cache($form_build_id, $form_state);
+		$args = $form['#parameters'];
+		$form_id = array_shift($args);
+		$form_state['post'] = $form['#post'] = $_POST;
+		// Enable the submit/validate handlers to determine whether AHAH-submittted.
+		$form_state['ahah_submission'] = TRUE;
+		$form['#programmed'] = $form['#redirect'] = FALSE;
+		drupal_process_form($form_id, $form, $form_state);
+		$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
+		return $form;
+	}
+	/**
+	 *
+	 * @ingroup tripal_view_setup
+	 */
+	function tripal_views_setup_ajax_rebuild_formz(&$form_state, &$args, &$_POST){
+
+		// Retrieve the form from the cache
+		$form_state = array('storage' => NULL, 'submitted' => FALSE,);
+		$form_build_id = $_POST['form_build_id'];
+		$form = form_get_cache($form_build_id, $form_state);
+
+		// Preparing to process the form
+		$args = $form['#parameters'];
+		$form_id = array_shift($args);
+		$form_state['post'] = $form['#post'] = $_POST;
+		$form['#programmed'] = $form['#redirect'] = FALSE;
+
+		// Sets the form_state so that the validate and submit handlers can tell
+		// when the form is submitted via AHAH
+		$form_state['ahah_submission'] = TRUE;
+
+		// Process the form with drupal_process_form. This function calls the submit
+		// handlers, which put whatever was worthy of keeping into $form_state.
+		drupal_process_form($form_id, $form, $form_state);
+
+		// You call drupal_rebuild_form which destroys $_POST.
+		// The form generator function is called and creates the form again but since
+		// it knows to use $form_state, the form will be different.
+		// The new form gets cached and processed again, but because $_POST is
+		// destroyed, the submit handlers will not be called again.
+		$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
+
+		dpm($form,'form at rebuild');
+		dpm($form_state['post'], 'post at rebuild');
+
+		return $form;
+	}
 
 
-/**
- *
- * @ingroup tripal_view_setup
- */
-function tripal_views_setup_new_setup_form_submit($form, &$form_state){
-	dpm($form, 'form on submit');
-	dpm($form_state, 'forms_state on submit');
-}
+	/**
+	 *
+	 * @ingroup tripal_view_setup
+	 */
+	// function tripal_views_setup_fields(&$form_state=NULL, $mview_id = NULL){
+
+	// 	if(!$mview_id){
+	// 		return;
+	// 	}
+
+	// 	// get the columns in this materialized view.  They are separated by commas
+	// 	// where the first word is the column name and the rest is the type
+	// 	$sql = "SELECT mv_specs FROM {tripal_mviews} WHERE mview_id = $mview_id";
+	// 	$mview = db_fetch_object(db_query($sql));
+	// 	$columns = explode(",",$mview->mv_specs);
+
+	// 	$i=1;
+	// 	$chado_tables = tripal_core_get_chado_tables();
+	// 	$handlers = array();
+	// 	$form["fields_headers"] = array(
+	//        '#type' => 'markup',
+	//        '#value' => "<div class=\"field-headers\">".
+	//             "<div class=\"column-id\">Field Name and Type</div>".
+	//             "<div class=\"fields-column-join\">Join Table</div>".
+	//             "<div class=\"fields-column-join-column\">Join Column</div>".
+	//             "<div class=\"fields-column-handler\">Handler</div></div>",
+	// 	);
+	// 	foreach ($columns as $column){
+
+	// 		$column = trim($column);  // trim trailing and leading spaces
+	// 		preg_match("/^(.*?)\ (.*?)$/",$column,$matches);
+	// 		$column_name = $matches[1];
+	// 		$column_type = $matches[2];
+
+	// 		// first print the field name
+	// 		$form["fields_start_$i"] = array(
+	//        '#type' => 'markup',
+	//        '#value' => "<div class=\"fields-new-row\">",
+	// 		);
+
+	// 		$form["fields_column_name_$i"] = array(
+	//        '#type' => 'markup',
+	//          '#attributes' => array('class' => 'fields-column-name'),
+	//        '#value' => "<div class=\"column-id\"><span class=\"column-name\">$column_name</span>".
+	//                      "<br><span class=\"column-type\">$column_type</span></div>",
+	// 		);
+
+	// 		// second print the table join drop down
+	// 		$chado_tables = array_merge(array(NULL,), $chado_tables);
+	// 		$form["fields_column_join_$i"] = array(
+	//        '#type' => 'select',
+	//        '#prefix' => "<div class=\"fields-column-join\">",
+	//        '#suffix' => "</div>",
+	//        '#options' => $chado_tables,
+	//        '#required' => FALSE,
+	//        '#ahah' => array(
+	//          'path' => 'admin/tripal/tripal_views_setup/ajax/field_col_join',
+	//          'wrapper' => "fields-column-join-column-$i",
+	//          'effect' => 'fade',
+	//          'event' => 'change',
+	//          'method' => 'replace',
+	// 		),
+	// 		);
+	// 		$form["fields_column_join_column_$i"] = array(
+	//        '#type' => 'select',
+	//        '#prefix' => "<div id=\"fields-column-join-column-$i\" class=\"fields-column-join-column\">",
+	//        '#suffix' => "</div>",
+	//        '#options' => array(),
+	//        '#required' => FALSE,
+	// 		);
+	// 		$form["fields_column_handler_$i"] = array(
+	//        '#type' => 'select',
+	//          '#prefix' => "<div class=\"fields-column-handler\">",
+	//          '#suffix' => "</div>",
+	//        '#options' => $handlers,
+	//        '#required' => FALSE,
+	// 		);
+	// 		$form["fields_end_$i"] = array(
+	//        '#type' => 'markup',
+	//        '#value' => "</div>",
+	// 		);
+	// 		$i++;
+	// 	}
+
+	// 	$form['row_counter'] = array(
+	//     '#type' => 'hidden',
+	//     '#value' => $i,
+	// 	);
+
+	// 	$form['submit'] = array(
+	//     '#type' => 'submit',
+	//     '#value' => 'Create',
+	// 	);
+
+	// 	return $form;
+	// }
+
+	// function tripal_views_setup_fields_form_submit($form, &$form_state){
+	// 	----($form,'formfield');
+	// 	----($form_state, 'formstatefield');
+
+	// }
+
+
+
+	/**
+	 *
+	 * @ingroup tripal_view_setup
+	 */
+	function tripal_views_setup_new_setup_form_submit($form, &$form_state){
+		dpm($form, 'form on submit');
+		dpm($form_state, 'forms_state on submit');
+	}

+ 22 - 22
base/tripal_views_setup/tripal_views_setup.module

@@ -3,54 +3,54 @@
 require_once 'includes/tripal_views_setup.admin.inc';
 
 function tripal_views_setup_menu(){
-  $items = array();
+	$items = array();
 
-  $items['admin/tripal/tripal_views_setup'] = array(
+	$items['admin/tripal/tripal_views_setup'] = array(
     'title' => t('Tripal Views Setups'),
     'description' => t('Tripal Views Setups settings page, allows you to select and create materialized views and chado tables to use for searches.'),
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tripal_views_setup_admin_form'),
-    // 'page callback' => 'tripal_views_setup_admin_form_page',
+	// 'page callback' => 'tripal_views_setup_admin_form_page',
     'access arguments' => array('access administration pages'),
     'type' => MENU_NORMAL_ITEM,
-  );
+	);
 
-  //page to actually create setup->mview->chado table relationships
-   $items['admin/tripal/tripal_views_setup_new'] = array(
+	//page to actually create setup->mview->chado table relationships
+	$items['admin/tripal/tripal_views_setup_new'] = array(
      'title' => 'Create New Views Setup',
      'page callback' => 'drupal_get_form',
      'page arguments' => array('tripal_views_setup_new_setup_form'),
      'access arguments' => array('access administration pages'), //TODO: figure out the proper permissions arguments
      'type' => MENU_NORMAL_ITEM,
-   );
+	);
 
-   $items['admin/tripal/tripal_views_setup/ajax/mview_cols'] = array(
+	$items['admin/tripal/tripal_views_setup/ajax/mview_cols'] = array(
      'title' => 'Get MView Columns',
      'page callback' => 'tripal_view_setup_ajax_mview_cols',
      'access arguments' => array('access administration pages'),
      'type' => MENU_CALLBACK,
-   );
+	);
 
-  $items['admin/tripal/tripal_views_setup/ajax/field_col_join'] = array(
-     'title' => 'Get Join Columns',
-     'page callback' => 'tripal_view_setup_ajax_field_col_join',
-  	 'type' => MENU_CALLBACK,
-     'access arguments' => array('access administration pages'),
-     
-   );
+	$items['admin/tripal/tripal_views_setup/ajax/field_col_join/%/%'] = array(
+    'title' => 'Get Join Columns',
+    'page callback' => 'tripal_view_setup_ajax_field_col_join',
+		'page arguments' => array(5,6),
+    'access arguments' => array('access administration pages'),
+  	'type' => MENU_CALLBACK,
+	);
 
-  return $items;
+	return $items;
 }
 
 function tripal_views_setup_theme(){
-  $theme = array();
+	$theme = array();
 
-//   $theme['tripal_views_setup_fields_form'] = array(
-  $theme['tripal_views_setup_new_setup_form'] = array(
+	//   $theme['tripal_views_setup_fields_form'] = array(
+	$theme['tripal_views_setup_new_setup_form'] = array(
     'arguments' => array('form' => NULL),
       'template'  => 'tripal_views_setup_fields_form',
-   );
+	);
 
-  return $theme;
+	return $theme;
 }