tripal_analysis.form.inc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. <?php
  2. /**
  3. * When editing or creating a new node of type 'chado_analysis' we need
  4. * a form. This function creates the form that will be used for this.
  5. *
  6. * @ingroup tripal_analysis
  7. */
  8. function chado_analysis_form(&$node, $form_state = NULL) {
  9. tripal_core_ahah_init_form();
  10. $form = array();
  11. $analysis = $node->analysis;
  12. // add in the description column. It is a text field and may not be included
  13. // if the text is too big.
  14. $analysis = tripal_core_expand_chado_vars($analysis, 'field', 'analysis.description');
  15. // get form defaults
  16. $analysis_id = $node->analysis_id;
  17. if (!$analysis_id) {
  18. $analysis_id = $analysis->analysis_id;
  19. }
  20. $analysisname = $node->analysisname;
  21. if (!$analysisname) {
  22. $analysisname = $analysis->name;
  23. }
  24. $program = $node->program;
  25. if (!$program) {
  26. $program = $analysis->program;
  27. }
  28. $programversion = $node->programversion;
  29. if (!$programversion) {
  30. $programversion = $analysis->programversion;
  31. }
  32. $algorithm = $node->algorithm;
  33. if (!$algorithm) {
  34. $algorithm = $analysis->algorithm;
  35. }
  36. $sourcename = $node->sourcename;
  37. if (!$sourcename) {
  38. $sourcename = $analysis->sourcename;
  39. }
  40. $sourceversion = $node->sourceversion;
  41. if (!$sourceversion) {
  42. $sourceversion = $analysis->sourceversion;
  43. }
  44. $sourceuri = $node->sourceuri;
  45. if (!$sourceuri) {
  46. $sourceuri = $analysis->sourceuri;
  47. }
  48. $timeexecuted = $node->timeexecuted;
  49. if (!$timeexecuted) {
  50. $timeexecuted = $analysis->timeexecuted;
  51. }
  52. $description = $node->description;
  53. if (!$description) {
  54. $description = $analysis->description;
  55. }
  56. // on AHAH callbacks we want to keep a list of all the properties that have been removed
  57. // we'll store this info in a hidden field and retrieve it here
  58. $d_removed = $form_state['values']['removed'];
  59. // get the number of new fields that have been aded via AHAH callbacks
  60. $num_new = $form_state['values']['num_new'] ? $form_state['values']['num_new'] : 0;
  61. // initialze default properties array. This is where we store the property defaults
  62. $d_properties = array();
  63. $form['title']= array(
  64. '#type' => 'hidden',
  65. '#default_value' => $node->title,
  66. );
  67. $form['analysis_id']= array(
  68. '#type' => 'hidden',
  69. '#default_value' => $analysis_id,
  70. );
  71. $form['analysisname']= array(
  72. '#type' => 'textfield',
  73. '#title' => t('Analysis Name'),
  74. '#required' => TRUE,
  75. '#default_value' => $analysisname,
  76. '#description' => t("This should be a brief name that
  77. describes the analysis succintly. This name will helps the user find analyses."),
  78. );
  79. $form['program']= array(
  80. '#type' => 'textfield',
  81. '#title' => t('Program'),
  82. '#required' => TRUE,
  83. '#default_value' => $program,
  84. '#description' => t("Program name, e.g. blastx, blastp, sim4, genscan."),
  85. );
  86. $form['programversion']= array(
  87. '#type' => 'textfield',
  88. '#title' => t('Program Version'),
  89. '#required' => TRUE,
  90. '#default_value' => $programversion,
  91. '#description' => t("Version description, e.g. TBLASTX 2.0MP-WashU [09-Nov-2000]. Enter 'n/a' if no version is available."),
  92. );
  93. $form['algorithm']= array(
  94. '#type' => 'textfield',
  95. '#title' => t('Algorithm'),
  96. '#required' => FALSE,
  97. '#default_value' => $algorithm,
  98. '#description' => t("Algorithm name, e.g. blast."),
  99. );
  100. $form['sourcename']= array(
  101. '#type' => 'textfield',
  102. '#title' => t('Source Name'),
  103. '#required' => TRUE,
  104. '#default_value' => $sourcename,
  105. '#description' => t('The name of the source data. This could be a file name, data set name or a
  106. small description for how the data was collected. For long descriptions use the description field below'),
  107. );
  108. $form['sourceversion']= array(
  109. '#type' => 'textfield',
  110. '#title' => t('Source Version'),
  111. '#required' => FALSE,
  112. '#default_value' => $sourceversion,
  113. '#description' => t('If the source dataset has a version, include it here'),
  114. );
  115. $form['sourceuri']= array(
  116. '#type' => 'textfield',
  117. '#title' => t('Source URI'),
  118. '#required' => FALSE,
  119. '#default_value' => $sourceuri,
  120. '#description' => t("This is a permanent URL or URI for the source of the analysis.
  121. Someone could recreate the analysis directly by going to this URI and
  122. fetching the source data (e.g. the blast database, or the training model)."),
  123. );
  124. // Get time saved in chado
  125. $default_time = $timeexecuted;
  126. $year = preg_replace("/^(\d+)-\d+-\d+ .*/", "$1", $default_time);
  127. $month = preg_replace("/^\d+-0?(\d+)-\d+ .*/", "$1", $default_time);
  128. $day = preg_replace("/^\d+-\d+-0?(\d+) .*/", "$1", $default_time);
  129. // If the time is not set, use current time
  130. if (!$default_time) {
  131. $default_time = time();
  132. $year = format_date($default_time, 'custom', 'Y');
  133. $month = format_date($default_time, 'custom', 'n');
  134. $day = format_date($default_time, 'custom', 'j');
  135. }
  136. $form['timeexecuted']= array(
  137. '#type' => 'date',
  138. '#title' => t('Time Executed'),
  139. '#required' => TRUE,
  140. '#default_value' => array(
  141. 'year' => $year,
  142. 'month' => $month,
  143. 'day' => $day,
  144. ),
  145. );
  146. $form['description']= array(
  147. '#type' => 'textarea',
  148. '#rows' => 15,
  149. '#title' => t('Materials & Methods (Description and/or Program Settings)'),
  150. '#required' => FALSE,
  151. '#default_value' => $description,
  152. '#description' => t('Please provide all necessary information to allow
  153. someone to recreate the analysis, including materials and methods
  154. for collection of the source data and performing the analysis'),
  155. );
  156. // get the analysis properties
  157. $properties_select = array();
  158. $properties_select[] = 'Select a Property';
  159. $properties_list = array();
  160. $sql = "
  161. SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
  162. FROM {cvterm} CVT
  163. INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
  164. WHERE
  165. CV.name = 'analysis_property' AND
  166. NOT CVT.is_obsolete = 1
  167. ORDER BY CVT.name ASC
  168. ";
  169. $prop_types = chado_query($sql);
  170. while ($prop = db_fetch_object($prop_types)) {
  171. $properties_select[$prop->cvterm_id] = $prop->name;
  172. $properties_list[$prop->cvterm_id] = $prop;
  173. }
  174. $form['properties'] = array(
  175. '#type' => 'fieldset',
  176. '#title' => t('Analysis Details'),
  177. '#description' => t('You may add additional
  178. properties by
  179. selecting a property type from the dropdown and adding text. You may add
  180. as many properties as desired by clicking the plus button on the right. To
  181. remove a property, click the minus button. If a property is not available
  182. you may add it by ' . l('adding the term', 'admin/tripal/tripal_cv/cvterm/add') . '
  183. to the <b>analysis_property</b> vocabulary within the <b>tripal</b> database'),
  184. );
  185. $form['properties']['table'] = array(
  186. '#type' => 'markup',
  187. '#value' => '',
  188. '#prefix' => '<div id="tripal-analysis-edit-properties-table">',
  189. '#suffix' => '</div>',
  190. );
  191. // add in the properties from the analysisprop table
  192. $num_properties += chado_analysis_node_form_add_analysisprop_table_props($form, $form_state, $analysis_id, $d_properties, $d_removed);
  193. // add in any new properties that have been added by the user through an AHAH callback
  194. $num_new = chado_analysis_node_form_add_new_props($form, $form_state, $d_properties, $d_removed);
  195. // add an empty row of field to allow for addition of a new property
  196. chado_analysis_node_form_add_new_empty_props($form, $properties_select);
  197. return $form;
  198. }
  199. /**
  200. * Validates the user input before creating an analysis node
  201. *
  202. * @ingroup tripal_analysis
  203. */
  204. function chado_analysis_validate($node, &$form) {
  205. // use the analysis parent to validate the node
  206. tripal_analysis_validate($node, $form);
  207. }
  208. /**
  209. * This validation is being used for three activities:
  210. * CASE A: Update a node that exists in both drupal and chado
  211. * CASE B: Synchronizing a node from chado to drupal
  212. * CASE C: Inserting a new node that exists in niether drupal nor chado
  213. *
  214. * @ingroup tripal_analysis
  215. */
  216. function tripal_analysis_validate($node, &$form) {
  217. // Only nodes being updated will have an nid already
  218. if (!is_null($node->nid)) {
  219. // CASE A: We are validating a form for updating an existing node
  220. // get the existing node
  221. $values = array('analysis_id' => $node->analysis_id);
  222. $result = tripal_core_chado_select('analysis', array('*'), $values);
  223. $analysis = $result[0];
  224. // if the name has changed make sure it doesn't conflict with an existing name
  225. if($analysis->name != $node->analysisname) {
  226. $values = array('name' => $node->analysisname);
  227. $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
  228. if($result and count($result) > 0) {
  229. form_set_error('analysisname', 'Cannot update the analysis with this analysis name. An analysis with this name already exists.');
  230. return;
  231. }
  232. }
  233. // if the unique constraint has changed check to make sure it doesn't conflict with an
  234. // existing record
  235. if($analysis->program != $node->program or $analysis->programversion != $node->programversion or
  236. $analysis->sourcename != $node->sourcename) {
  237. $values = array(
  238. 'program' => $node->program,
  239. 'programversion' => $node->programversion,
  240. 'sourcename' => $node->sourcename,
  241. );
  242. $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
  243. if ($result and count($result) > 0) {
  244. if ($analysis->program != $node->program) {
  245. $field = 'program';
  246. }
  247. if ($analysis->programversion != $node->programversion) {
  248. $field = 'programversion';
  249. }
  250. if ($analysis->sourcename != $node->sourcename) {
  251. $field = 'sourcename';
  252. }
  253. form_set_error($field, 'Cannot update the analysis with this program,
  254. program version and source name. An analysis with these values already exists.');
  255. return;
  256. }
  257. }
  258. }
  259. else{
  260. // To differentiate if we are syncing or creating a new analysis altogther, see if an
  261. // analysis_id already exists
  262. if ($node->analysis_id and $node->analysis_id != 0) {
  263. // CASE B: Synchronizing a node from chado to drupal
  264. // we don't need to do anything.
  265. }
  266. else {
  267. // CASE C: We are validating a form for inserting a new node
  268. // The unique constraint for the chado analysis table is: program, programversion, sourcename
  269. $values = array(
  270. 'program' => $node->program,
  271. 'programversion' => $node->programversion,
  272. 'sourcename' => $node->sourcename,
  273. );
  274. $analysis = tripal_core_chado_select('analysis', array('analysis_id'), $values);
  275. if ($analysis and count($analysis) > 0) {
  276. form_set_error('program', 'Cannot add the analysis with this program,
  277. program version and source name. An analysis with these values already exists.');
  278. return;
  279. }
  280. // make sure we have a unique analysis name. This is not a requirement
  281. // for the analysis table but we use the analysis name for the Drupal node
  282. // title, so it should be unique
  283. $values = array('name' => $node->analysisname);
  284. $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
  285. if($result and count($result) > 0) {
  286. form_set_error('analysisname', 'Cannot add the analysis with this analysis name. An analysis with this name already exists.');
  287. return;
  288. }
  289. }
  290. }
  291. }
  292. /*
  293. *
  294. */
  295. function chado_analysis_node_form_add_new_empty_props(&$form, $properties_select) {
  296. // add one more blank set of property fields
  297. $form['properties']['table']['new']["new_id"] = array(
  298. '#type' => 'select',
  299. '#options' => $properties_select,
  300. '#ahah' => array(
  301. 'path' => "tripal_analysis/properties/description",
  302. 'wrapper' => 'tripal-analysis-new_value-desc',
  303. 'event' => 'change',
  304. 'method' => 'replace',
  305. ),
  306. );
  307. $form['properties']['table']['new']["new_value"] = array(
  308. '#type' => 'textarea',
  309. '#default_value' => '',
  310. '#cols' => 5,
  311. '#rows' => $rows,
  312. '#description' => '<div id="tripal-analysis-new_value-desc"></div>'
  313. );
  314. $form['properties']['table']['new']["add"] = array(
  315. '#type' => 'image_button',
  316. '#value' => t('Add'),
  317. '#src' => drupal_get_path('theme', 'tripal') . '/images/add.png',
  318. '#ahah' => array(
  319. 'path' => "tripal_analysis/properties/add",
  320. 'wrapper' => 'tripal-analysis-edit-properties-table',
  321. 'event' => 'click',
  322. 'method' => 'replace',
  323. ),
  324. '#attributes' => array('onClick' => 'return false;'),
  325. );
  326. }
  327. /*
  328. *
  329. */
  330. function chado_analysis_node_form_add_new_props(&$form, $form_state, &$d_properties, &$d_removed) {
  331. // first, add in all of the new properties that were added through a previous AHAH callback
  332. $j = 0;
  333. $num_properties++;
  334. // we need to find the
  335. if ($form_state['values']) {
  336. foreach ($form_state['values'] as $element_name => $value) {
  337. if (preg_match('/new_value-(\d+)-(\d+)/', $element_name, $matches)) {
  338. $new_id = $matches[1];
  339. $rank = $matches[2];
  340. // skip any properties that the user requested to delete through a previous
  341. // AHAH callback or through the current AHAH callback
  342. if($d_removed["$new_id-$rank"]) {
  343. continue;
  344. }
  345. if($form_state['post']['remove-' . $new_id . '-' . $rank]) {
  346. $d_removed["$new_id-$rank"] = 1;
  347. continue;
  348. }
  349. // get this new_id information
  350. $cvterm = tripal_core_chado_select('cvterm', array('name', 'definition'), array('cvterm_id' => $new_id));
  351. // add it to the $d_properties array
  352. $d_properties[$new_id][$rank]['name'] = $cvterm->name;
  353. $d_properties[$new_id][$rank]['id'] = $new_id;
  354. $d_properties[$new_id][$rank]['value'] = $value;
  355. $d_properties[$new_id][$rank]['definition'] = $cvterm->definition;
  356. $num_properties++;
  357. // determine how many rows we need in the textarea
  358. $rows = 1;
  359. // add the new fields
  360. $form['properties']['table']['new'][$new_id][$rank]["new_id-$new_id-$rank"] = array(
  361. '#type' => 'item',
  362. '#value' => $cvterm[0]->name
  363. );
  364. $form['properties']['table']['new'][$new_id][$rank]["new_value-$new_id-$rank"] = array(
  365. '#type' => 'textarea',
  366. '#default_value' => $value,
  367. '#cols' => 50,
  368. '#rows' => $rows,
  369. '#description' => $cvterm->definition,
  370. );
  371. $form['properties']['table']['new'][$new_id][$rank]["remove-$new_id-$rank"] = array(
  372. '#type' => 'image_button',
  373. '#value' => t('Remove'),
  374. '#src' => drupal_get_path('theme', 'tripal') . '/images/minus.png',
  375. '#ahah' => array(
  376. 'path' => "tripal_analysis/properties/minus/$new_id/$rank",
  377. 'wrapper' => 'tripal-analysis-edit-properties-table',
  378. 'event' => 'click',
  379. 'method' => 'replace',
  380. ),
  381. '#attributes' => array('onClick' => 'return false;'),
  382. );
  383. }
  384. }
  385. }
  386. // second add in any new properties added during this callback
  387. if($form_state['post']['add']) {
  388. $new_id = $form_state['values']['new_id'];
  389. $new_value = $form_state['values']['new_value'];
  390. // get the rank by counting the number of entries
  391. $rank = count($d_properties[$new_id]);
  392. // get this new_id information
  393. $cvterm = tripal_core_chado_select('cvterm', array('name', 'definition'), array('cvterm_id' => $new_id));
  394. // add it to the $d_properties array
  395. $d_properties[$new_id][$rank]['name'] = $cvterm->name;
  396. $d_properties[$new_id][$rank]['id'] = $new_id;
  397. $d_properties[$new_id][$rank]['value'] = $value;
  398. $d_properties[$new_id][$rank]['definition'] = $cvterm->definition;
  399. $num_properties++;
  400. // determine how many rows we need in the textarea
  401. $rows = 1;
  402. // add the new fields
  403. $form['properties']['table']['new'][$new_id][$rank]["new_id-$new_id-$rank"] = array(
  404. '#type' => 'item',
  405. '#value' => $cvterm[0]->name
  406. );
  407. $form['properties']['table']['new'][$new_id][$rank]["new_value-$new_id-$rank"] = array(
  408. '#type' => 'textarea',
  409. '#default_value' => $new_value,
  410. '#cols' => 50,
  411. '#rows' => $rows,
  412. '#description' => $cvterm->definition,
  413. );
  414. $form['properties']['table']['new'][$new_id][$rank]["remove-$new_id-$rank"] = array(
  415. '#type' => 'image_button',
  416. '#value' => t('Remove'),
  417. '#src' => drupal_get_path('theme', 'tripal') . '/images/minus.png',
  418. '#ahah' => array(
  419. 'path' => "tripal_analysis/properties/minus/$new_id/$rank",
  420. 'wrapper' => 'tripal-analysis-edit-properties-table',
  421. 'event' => 'click',
  422. 'method' => 'replace',
  423. ),
  424. '#attributes' => array('onClick' => 'return false;'),
  425. );
  426. }
  427. return $num_properties;
  428. }
  429. /*
  430. *
  431. */
  432. function chado_analysis_node_form_add_analysisprop_table_props(&$form, $form_state, $analysis_id, &$d_properties, &$d_removed) {
  433. // get the properties for this analysis
  434. $num_properties = 0;
  435. if(!$analysis_id) {
  436. return $num_properties;
  437. }
  438. $sql = "
  439. SELECT CVT.cvterm_id, CVT.name, CVT.definition, PP.value, PP.rank
  440. FROM {analysisprop} PP
  441. INNER JOIN {cvterm} CVT on CVT.cvterm_id = PP.type_id
  442. INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
  443. WHERE PP.analysis_id = %d and CV.name = 'analysis_property'
  444. ORDER BY CVT.name, PP.rank
  445. ";
  446. $analysis_props = chado_query($sql, $analysis_id);
  447. while ($prop = db_fetch_object($analysis_props)) {
  448. $type_id = $prop->cvterm_id;
  449. $rank = count($d_properties[$type_id]);
  450. // skip any properties that the user requested to delete through a previous
  451. // AHAH callback or through the current AHAH callback
  452. if($d_removed["$type_id-$rank"]) {
  453. continue;
  454. }
  455. if($form_state['post']['remove-' . $type_id . '-' . $rank]) {
  456. $d_removed["$type_id-$rank"] = 1;
  457. continue;
  458. }
  459. $d_properties[$type_id][$rank]['name'] = $prop->name;
  460. $d_properties[$type_id][$rank]['id'] = $type_id;
  461. $d_properties[$type_id][$rank]['value'] = $prop->value;
  462. $d_properties[$type_id][$rank]['definition'] = $prop->definition;
  463. $num_properties++;
  464. $form['properties']['table'][$type_id][$rank]["prop_id-$type_id-$rank"] = array(
  465. '#type' => 'item',
  466. '#value' => $prop->name,
  467. );
  468. $form['properties']['table'][$type_id][$rank]["prop_value-$type_id-$rank"] = array(
  469. '#type' => 'textarea',
  470. '#default_value' => $prop->value,
  471. '#cols' => 50,
  472. '#rows' => $rows,
  473. '#description' => $prop->definition,
  474. );
  475. $form['properties']['table'][$type_id][$rank]["remove-$type_id-$rank"] = array(
  476. '#type' => 'image_button',
  477. '#value' => t('Remove'),
  478. '#src' => drupal_get_path('theme', 'tripal') . '/images/minus.png',
  479. '#ahah' => array(
  480. 'path' => "tripal_analysis/properties/minus/$type_id/$rank",
  481. 'wrapper' => 'tripal-analysis-edit-properties-table',
  482. 'event' => 'click',
  483. 'method' => 'replace',
  484. ),
  485. '#attributes' => array('onClick' => 'return false;'),
  486. );
  487. }
  488. return $num_properties;
  489. }
  490. /*
  491. *
  492. */
  493. function tripal_analysis_theme_node_form_properties($form) {
  494. $rows = array();
  495. if ($form['properties']) {
  496. // first add in the properties derived from the analysisprop table
  497. // the array tree for these properties looks like this:
  498. // $form['properties']['table'][$type_id][$rank]["prop_id-$type_id-$rank"]
  499. foreach ($form['properties']['table'] as $type_id => $elements) {
  500. // there are other fields in the properties array so we only
  501. // want the numeric ones those are our type_id
  502. if (is_numeric($type_id)) {
  503. foreach ($elements as $rank => $element) {
  504. if (is_numeric($rank)) {
  505. $rows[] = array(
  506. drupal_render($element["prop_id-$type_id-$rank"]),
  507. drupal_render($element["prop_value-$type_id-$rank"]),
  508. drupal_render($element["remove-$type_id-$rank"]),
  509. );
  510. }
  511. }
  512. }
  513. }
  514. // second, add in any new properties added by the user through AHAH callbacks
  515. // the array tree for these properties looks like this:
  516. // $form['properties']['table']['new'][$type_id][$rank]["new_id-$new_id-$rank"]
  517. foreach ($form['properties']['table']['new'] as $type_id => $elements) {
  518. if (is_numeric($type_id)) {
  519. foreach ($elements as $rank => $element) {
  520. if (is_numeric($rank)) {
  521. $rows[] = array(
  522. drupal_render($element["new_id-$type_id-$rank"]),
  523. drupal_render($element["new_value-$type_id-$rank"]),
  524. drupal_render($element["remove-$type_id-$rank"]),
  525. );
  526. }
  527. }
  528. }
  529. }
  530. // finally add in a set of blank field for adding a new property
  531. $rows[] = array(
  532. drupal_render($form['properties']['table']['new']['new_id']),
  533. drupal_render($form['properties']['table']['new']['new_value']),
  534. drupal_render($form['properties']['table']['new']['add']),
  535. );
  536. }
  537. $headers = array('Property Type','Value', '');
  538. return theme('table', $headers, $rows);
  539. }
  540. /*
  541. *
  542. */
  543. function tripal_analysis_property_add() {
  544. $status = TRUE;
  545. // prepare and render the form
  546. $form = tripal_core_ahah_prepare_form();
  547. // we only want to return the properties as that's all we'll replace with this AHAh callback
  548. $data = tripal_analysis_theme_node_form_properties($form);
  549. // bind javascript events to the new objects that will be returned
  550. // so that AHAH enabled elements will work.
  551. $settings = tripal_core_ahah_bind_events();
  552. // return the updated JSON
  553. drupal_json(
  554. array(
  555. 'status' => $status,
  556. 'data' => $data,
  557. 'settings' => $settings,
  558. )
  559. );
  560. }
  561. /*
  562. *
  563. */
  564. function tripal_analysis_property_delete() {
  565. $status = TRUE;
  566. // prepare and render the form
  567. $form = tripal_core_ahah_prepare_form();
  568. // we only want to return the properties as that's all we'll replace with this AHAh callback
  569. $data = tripal_analysis_theme_node_form_properties($form);
  570. // bind javascript events to the new objects that will be returned
  571. // so that AHAH enabled elements will work.
  572. $settings = tripal_core_ahah_bind_events();
  573. // return the updated JSON
  574. drupal_json(
  575. array(
  576. 'status' => $status,
  577. 'data' => $data,
  578. 'settings' => $settings,
  579. )
  580. );
  581. }
  582. /*
  583. *
  584. */
  585. function tripal_analysis_property_get_description() {
  586. $new_id = $_POST['new_id'];
  587. $values = array('cvterm_id' => $new_id);
  588. $cvterm = tripal_core_chado_select('cvterm', array('definition'), $values);
  589. $description = '&nbsp;';
  590. if ($cvterm[0]->definition) {
  591. $description = $cvterm[0]->definition;
  592. }
  593. drupal_json(
  594. array(
  595. 'status' => TRUE,
  596. 'data' => '<div id="tripal-analysis-new_value-desc">' . $description . '</div>',
  597. )
  598. );
  599. }
  600. /*
  601. *
  602. */
  603. function theme_chado_analysis_node_form($form) {
  604. $properties_table = tripal_analysis_theme_node_form_properties($form);
  605. $markup .= $properties_table;
  606. $form['properties']['table'] = array(
  607. '#type' => 'markup',
  608. '#value' => $markup,
  609. '#prefix' => '<div id="tripal-analysis-edit-properties-table">',
  610. '#suffix' => '</div>',
  611. );
  612. $form['buttons']['#weight'] = 50;
  613. return drupal_render($form);
  614. }