Browse Source

got delete row form

alexgl 13 years ago
parent
commit
916e76f1f0

+ 24 - 101
base/tripal_views_setup/includes/tripal_views_setup.admin.inc

@@ -1,57 +1,34 @@
 <?php 
 <?php 
 
 
-// function tripal_views_setup_admin(){
-	// $add_url = url('admin/tripal/tripal_views_setup/new');
-	// $output = "<div id='add-new-search'><a href=\"$add_url\">Add New Search</a><div>";
-	// $output .= drupal_get_form('tripal_views_setup_admin_form');
-// 
-	// return $rows;
-// }
-
-
 function tripal_views_setup_admin_form(){
 function tripal_views_setup_admin_form(){
 	
 	
-	// $query_results = db_query('SELECT * FROM public.tripal_views_setup;');
-	$result = db_query('SELECT * FROM public.tripal_views_setup;');
-	
 	$form = array();
 	$form = array();
-	$int_i = 0;
 	
 	
-		
-	//set limit for pager]
-	$limit = 20;
-  //define table header
-  $header = array(
-    '', //note empty value, will use this later
-    array('data' => t('Setup ID'), 'field' => 'setup_id', 'sort' => 'asc'),
-    array('data' => t('MView ID'), 'field' => 'mview_id'),
-    array('data' => t('Base Table Name'), 'field' => 'base_table_name'),
-  );
+	$form['#theme'] = 'tripal';
+	
+	$query_results = db_query('SELECT * FROM public.tripal_views_setup;');
 	
 	
-	//allows sorting
-	$tablesort = tablesort_sql($header);
-	//add pager to results
-	// $result = pager_query($query_results,$limit, $tablesort);
+	$header = array('Setup ID', 'Name', 'Materialized View ID', 'Base Table Name', 'Description');
+	$rows = array();
 	
 	
-	while ($item = db_fetch_object($result)){
-		//add row key
-		$checkboxes[$item->setup_id] = '';
-		$form['setup_id'][$item->setup_id] = array(
-			'#value' => $item->setup_id,
-		);
-		$form['mview_id'][$item->mview_id] = array(
-			'#value' => $item->mview_id,
-		);
-		
-		$form['base_table_name'][$item->setup_id] = array(
-			'#value' => $item->base_table_name,
-		);
-		
+	$results = array();
+	while($result = db_fetch_object($query_results)){
+		$rows[] = array($result->setup_id, $result->name, $result->mview_id, $result->base_table_name, $result->description,);
+		$results[] = $result; 
+	}
+	
+	$options = array();
+	foreach ($results as $key => $value) {
+		if(!empty($value))
+			$options[] = $value->setup_id;// . ' | ' . $value->name . ' | ' . $value->mview_id . ' | ' . $value->base_table_name;
 	}
 	}
-
-	$form['checkboxes'] = array('#type' => 'checkboxes', '#options' => $checkboxes);
-	$form['pager'] = array('#value' => theme('pager', NULL, $limit, 0));	
 	
 	
+	$form['existing_rows'] = array(
+		'#type' => 'select',
+		'#options' => $options,
+		'#description' => '<strong>Select a View Setup to delete from the database.</strong>',
+		'#prefix' => theme('table', $header, $rows),
+	);
 	
 	
 	$form['submit'] = array(
 	$form['submit'] = array(
 		'#type' => 'submit',
 		'#type' => 'submit',
@@ -68,70 +45,16 @@ function tripal_views_setup_admin_form(){
 		'#value' => l(t(' New'), 'admin/tripal/tripal_views_setup_new'),
 		'#value' => l(t(' New'), 'admin/tripal/tripal_views_setup_new'),
 	);
 	);
 	
 	
-	
-	dpm($form, 'admin_form');
 	return $form;
 	return $form;
-	//return system_settings_form($form);
 }
 }
 
 
 
 
-function tripal_views_setup_admin_form_submit($form_id, $form){
-	$form_values = $form['values'];
-	dpm($form, 'submitted form');
-	dpm($form_values, 'submitted form values');
-	$featured = $form_values['row_checkboxes'];
-	$selected_checkbox = array();
-	
-	foreach($featured as $key => $value){
-		if($value){
-			$selected_checkbox[] = "'$value'";
-		}
-	}
-	
-	dpm($selected_checkbox, 'selected');
-	
-	// foreach ($selected_checkbox as $key => $value) {
-// 		
-		// dpm((string)$value, 'delete value');
-		// dpm("DELETE FROM public.tripal_views_setup WHERE setup_id = $value;", 'delete stuff');
-		// db_query("DELETE FROM public.tripal_views_setup WHERE setup_id = $value;");
-// 		
-	// }
-	
+function tripal_views_setup_admin_form_submit($form, &$form_state){
+	$value = $form['existing_rows']['#options'][$form_state['values']['existing_rows']];
+	db_query("DELETE FROM public.tripal_views_setup WHERE setup_id = $value;");
 }
 }
 
 
 
 
 
 
 
 
 
 
-
-
-function tripal_views_setup_new_search_form(){
-	$form = array();
-	
-	$form['q1'] = array(
-		'#type' => 'select',
-		'#options' => tripal_views_setup_mview_list(),
-		
-	);
-	
-	return $form;
-}
-
-function tripal_views_setup_mview_list(){
-	//must return an array of strings ie:
-	$options = array(
-		'dummyoption' => t('dummyoptiontext'),
-	);
-
-	return $options;
-}
-
-function tripal_views_setup_btable_list(){
-	//must return an array of strings ie:
-	$options = array(
-		'dummyoption2' => t('dummyoptiontext2'),
-	);
-
-	return $options;
-}

+ 0 - 2
base/tripal_views_setup/tripal_views_setup.info

@@ -4,5 +4,3 @@ core = 6.x
 package = Tripal
 package = Tripal
 
 
 dependencies[] = schema
 dependencies[] = schema
-dependencies[] = tripal_helper_form
-

+ 1 - 34
base/tripal_views_setup/tripal_views_setup.module

@@ -11,6 +11,7 @@ function tripal_views_setup_menu(){
 	  'description' => t('Tripal Views Setups settings page, allows you to select and create materialized views and chado tables to use for searches.'),
 	  '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 callback' => 'drupal_get_form',
 	  'page arguments' => array('tripal_views_setup_admin_form'),
 	  'page arguments' => array('tripal_views_setup_admin_form'),
+	  // 'page callback' => 'tripal_views_setup_admin_form_page',
 	  'access arguments' => array('access administration pages'),
 	  'access arguments' => array('access administration pages'),
 	  'type' => MENU_NORMAL_ITEM,
 	  'type' => MENU_NORMAL_ITEM,
 	);
 	);
@@ -34,40 +35,6 @@ function tripal_views_setup_theme(){
 		'arguments' => array('form' => NULL,),
 		'arguments' => array('form' => NULL,),
 	);
 	);
 	
 	
-	$theme['tripal_views_setup_admin_form'] = array(
-		'arguments' => array(),
-	);
-	
 	return $theme;
 	return $theme;
 }
 }
 
 
-
-function theme_tripal_views_setup_admin_form($form){
-	$header = array(
-		theme('table_select_header_cell'),//using previously empty field
-		array('data' => t('Setup ID'), 'field' => 'setup_id', 'sort' => 'asc'),
-    array('data' => t('MView ID'), 'field' => 'mview_id'),
-    array('data' => t('Base Table Name'), 'field' => 'base_table_name'),
-  );
-	
-	if(!empty($form['checkboses']['#options'])) {
-		foreach (element_children($form['uid']) as $key) {
-			$rows[] = array(
-				drupal_render($form['checkboxes'][$key]),
-				drupal_render($form['setup_id'][$key]),
-				drupal_render($form['mview_id'][$key]),
-				drupal_render($form['base_table_name'][$key]),
-			);
-		}
-	}
-	else {
-		$row[] = array(array('data' => '<div class="error">click link above to add entries</div>', 'colspan' => 4));
-	}
-	
-	$output .= theme('table', $header, $rows);
-	
-	$output .= drupal_render($form);
-	return $output;
-	
-}
-

+ 0 - 5
tripal_helpers/tripal_helper_form/tripal_helper_form.info

@@ -1,5 +0,0 @@
-name = Tripal Helper Form
-description = Useful functions for dealing with forms for tripal 
-core = 6.x
-package = Tripal Helpers
-

+ 0 - 87
tripal_helpers/tripal_helper_form/tripal_helper_form.module

@@ -1,87 +0,0 @@
-<?php
-
-
-/**
- * taken from http://www.akchauhan.com/create-drupal-form-using-theme_table-like-module-list-form/
- * following as function theme_featured_product_form($form)
- * 
- * to be run as a regular function, within a module's theme function implementation
- */
-
-function tripal_helper_form_themeform($form, $field_keys){
-	$rows = array();
-	foreach (element_children($form) as $key) {
-		$row = array();
-		if (isset($form[$key]['name'])) {
- 
-			$status = drupal_render($form['row_checkboxes'][$key]);
-			$row[] = array(’data’ => $status, ‘class’ => ‘checkbox’);
- 
- 			$bool_first = TRUE;
- 			foreach ($field_keys as $field_key => $value) {
-				if($bool_first){
-					$row[] = ‘‘. drupal_render($form[$key][$value]) .’‘;//for "bold style"
-					$bool_first = FALSE;
-				}
-				else{
-					$row[] = array(’data’ => drupal_render($form[$key][$value]),);
-				}
-			}
- 
-			$rows[] = $row;
-		}
-	}
-
-	// Individual table headers.
-	$header = array();
-	$header[] = array(’data’ => t(’Select’), ‘class’ => ‘checkbox’);
-	
-	foreach ($field_keys as $key => $value) {
-		$header[] = t("'$value'");
-	}
- 
-	$output = theme(’table’, $header, $rows);
-	$output .= drupal_render($form);
-	dpm($output, 'formoutput');
-	return $output;
-}
-
-function tripal_helper_form_createformdata($form, $query_results, $data_array){
-	dpm($form, 'createform');
-	dpm($query_results, 'createqeuryresults');
-	dpm($data_array, 'createarray');
-	
-	// $status = array();
-	$options = array();
-	
-	foreach ($query_results as $qr_key => $qr_value) {
-		$options[$qr_key] = '';
-		
-		foreach ($data_array as $da_key => $da_value) {
-			dpm($qr_value->$da_value, '$da_value');
-			$form[$qr_key][$da_value] = array('#value' => $qr_value->$da_value);
-			
-		}
-		// $status[] = '-1';
-	}
-	
-	$form['row_checkboxes'] = array(
-		'#type' => 'checkboxes',
-		'#options' => $options,
-		// '#default_value' => $status,
-	);
-	
-	// $form['submit'] = array(
-		// '#type' => 'submit',
-		// '#value' => t('Remove'),
-	// );
-// 	
-	// $form['cancel'] = array(
-		// '#type' => 'markup',
-		// '#value' => l(t('Cancel'), 'dashboard'),
-	// );
-	
-	
-	
-	return $form;
-}