pub_form.inc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. <?php
  2. /**
  3. * This is the chado_pub node form callback. The arguments
  4. * are out of order from a typical form because it's a defined callback
  5. */
  6. function chado_pub_form($node, $form_state) {
  7. tripal_core_ahah_init_form();
  8. $form = array();
  9. $pub = $node->pub;
  10. $pub_id = $pub->pub_id;
  11. $d_title = $form_state['values']['title'] ? $form_state['values']['title'] : $node->title;
  12. $d_uniquename = $form_state['values']['uniquename'] ? $form_state['values']['uniquename'] : $pub->uniquename;
  13. $d_type_id = $form_state['values']['type_id'] ? $form_state['values']['type_id'] : $pub->type_id->cvterm_id;
  14. $d_volume = $form_state['values']['volume'] ? $form_state['values']['volume'] : $pub->volume;
  15. $d_volumetitle = $form_state['values']['volumetitle'] ? $form_state['values']['volumetitle'] : $pub->volumetitle;
  16. $d_series_name = $form_state['values']['series_name'] ? $form_state['values']['series_name'] : $pub->series_name;
  17. $d_issue = $form_state['values']['issue'] ? $form_state['values']['issue'] : $pub->issue;
  18. $d_pyear = $form_state['values']['pyear'] ? $form_state['values']['pyear'] : $pub->pyear;
  19. $d_pages = $form_state['values']['pages'] ? $form_state['values']['pages'] : $pub->pages;
  20. $d_miniref = $form_state['values']['miniref'] ? $form_state['values']['miniref'] : $pub->miniref;
  21. $d_publisher = $form_state['values']['publisher'] ? $form_state['values']['publisher'] : $pub->publisher;
  22. $d_pubplace = $form_state['values']['pubplace'] ? $form_state['values']['pubplace'] : $pub->pubplace;
  23. $d_is_obsolete = $form_state['values']['is_obsolete'] ? $form_state['values']['is_obsolete'] : $pub->is_obsolete;
  24. // if the obsolete value is set by the database then it is in the form of
  25. // 't' or 'f', we need to convert to 1 or 0
  26. $d_is_obsolete = $d_is_obsolete == 't' ? 1 : $d_is_obsolete;
  27. $d_is_obsolete = $d_is_obsolete == 'f' ? 0 : $d_is_obsolete;
  28. // on AHAH callbacks we want to keep a list of all the properties that have been removed
  29. // we'll store this info in a hidden field and retrieve it here
  30. $d_removed = $form_state['values']['removed'];
  31. // get the defaults first from the database and then from the form_state
  32. $default_type = $pub->type_id->cvterm_id;
  33. // get the number of new fields that have been aded via AHAH callbacks
  34. $num_new = $form_state['values']['num_new'] ? $form_state['values']['num_new'] : 0;
  35. // initialze default properties array. This is where we store the property defaults
  36. $d_properties = array();
  37. // get the list of publication types. In the Tripal publication
  38. // ontologies these are all grouped under the term 'Publication Type'
  39. // we want the default to be 'Journal Article'
  40. $sql = "
  41. SELECT CVTS.cvterm_id, CVTS.name
  42. FROM {cvtermpath} CVTP
  43. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  44. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  45. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  46. WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Type' and
  47. NOT CVTS.is_obsolete = 1
  48. ORDER BY CVTS.name ASC
  49. ";
  50. $results = chado_query($sql);
  51. $pub_types = array();
  52. while ($pub_type = db_fetch_object($results)) {
  53. $pub_types[$pub_type->cvterm_id] = $pub_type->name;
  54. // if we don't have a default type then set the default to be 'Journal Article'
  55. if (strcmp($pub_type->name,"Journal Article") == 0 and !$d_type_id) {
  56. $d_type_id = $pub_type->cvterm_id;
  57. }
  58. }
  59. // get publication properties list
  60. $properties_select = array();
  61. $properties_select[] = 'Select a Property';
  62. $properties_list = array();
  63. $sql = "
  64. SELECT CVTS.cvterm_id, CVTS.name, CVTS.definition
  65. FROM {cvtermpath} CVTP
  66. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  67. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  68. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  69. WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Details' and
  70. NOT CVTS.is_obsolete = 1
  71. ORDER BY CVTS.name ASC
  72. ";
  73. $prop_types = chado_query($sql);
  74. while ($prop = db_fetch_object($prop_types)) {
  75. // the 'Citation' term is special because it serves
  76. // both as a property and as the uniquename for the publiation table
  77. if ($prop->name != "Citation") {
  78. $properties_select[$prop->cvterm_id] = $prop->name;
  79. }
  80. $properties_list[$prop->cvterm_id] = $prop;
  81. }
  82. $form['pub_id'] = array(
  83. '#type' => 'hidden',
  84. '#value' => $pub_id,
  85. );
  86. $form['title'] = array(
  87. '#type' => 'textarea',
  88. '#title' => t('Publication Title'),
  89. '#default_value' => $d_title,
  90. '#required' => TRUE,
  91. );
  92. $form['type_id'] = array(
  93. '#type' => 'select',
  94. '#title' => t('Publication Type'),
  95. '#options' => $pub_types,
  96. '#required' => TRUE,
  97. '#default_value' => $d_type_id,
  98. );
  99. $form['series_name'] = array(
  100. '#type' => 'textfield',
  101. '#title' => t('Series Name (e.g. Journal Name)'),
  102. '#description' => t('Full name of (journal) series.'),
  103. '#default_value' => $d_series_name,
  104. '#required' => TRUE,
  105. );
  106. $form['pyear'] = array(
  107. '#type' => 'textfield',
  108. '#title' => t('Publication Year'),
  109. '#default_value' => $d_pyear,
  110. '#required' => TRUE,
  111. '#size' => 5,
  112. );
  113. $form['uniquename'] = array(
  114. '#type' => 'textarea',
  115. '#title' => t('Citation'),
  116. '#default_value' => $d_uniquename,
  117. '#description' => t('All publications must have a unique citation. Please enter the full citation for this publication.
  118. For PubMed style citations list
  119. the last name of the author followed by initials. Each author should be separated by a comma. Next comes
  120. the title, followed by the series title (e.g. journal name), publication date (4 digit year, 3 character Month, day), volume, issue and page numbers. You may also use HTML to provide a link in the citation.
  121. Below is an example: <pre>Medeiros PM, Ladio AH, Santos AM, Albuquerque UP. <a href="http://www.ncbi.nlm.nih.gov/pubmed/23462414" target="_blank">Does the selection of medicinal plants by Brazilian local populations
  122. suffer taxonomic influence?</a> J Ethnopharmacol. 2013 Apr 19; 146(3):842-52.</pre>'),
  123. '#required' => TRUE,
  124. );
  125. // add in the properties that are actually stored in the pub table fields.
  126. $num_properties = chado_pub_node_form_add_pub_table_props($form, $form_state, $properties_list,
  127. $d_properties, $d_removed, $d_volume, $d_volumetitle, $d_issue, $d_pages);
  128. // add in the properties from the pubprop table
  129. $num_properties += chado_pub_node_form_add_pubprop_table_props($form, $form_state, $pub_id, $d_properties, $d_removed);
  130. // add in any new properties that have been added by the user through an AHAH callback
  131. $num_properties += chado_pub_node_form_add_new_props($form, $form_state, $num_new, $d_properties, $d_removed);
  132. // add an empty row of field to allow for addition of a new property
  133. chado_pub_node_form_add_new_empty_props($form, $properties_select);
  134. $form['removed'] = array(
  135. '#type' => 'hidden',
  136. '#value' => $d_removed,
  137. );
  138. $form['num_new'] = array(
  139. '#type' => 'hidden',
  140. '#value' => $num_new,
  141. );
  142. $form['is_obsolete'] = array(
  143. '#type' => 'checkbox',
  144. '#title' => t('Is Obsolete? (Check for Yes)'),
  145. '#required' => TRUE,
  146. '#default_value' => $d_is_obsolete,
  147. );
  148. return $form;
  149. }
  150. /*
  151. *
  152. */
  153. function chado_pub_node_form_add_new_empty_props(&$form, $properties_select) {
  154. // add one more blank set of property fields
  155. $form['properties']['new']["new_id"] = array(
  156. '#type' => 'select',
  157. '#options' => $properties_select,
  158. '#ahah' => array(
  159. 'path' => "tripal_pub/properties/description",
  160. 'wrapper' => 'tripal-pub-new_value-desc',
  161. 'event' => 'change',
  162. 'method' => 'replace',
  163. ),
  164. );
  165. $form['properties']['new']["new_value"] = array(
  166. '#type' => 'textarea',
  167. '#default_value' => '',
  168. '#cols' => 5,
  169. '#rows' => $rows,
  170. '#description' => '<div id="tripal-pub-new_value-desc"></div>'
  171. );
  172. $form['properties']['new']["add"] = array(
  173. '#type' => 'image_button',
  174. '#value' => t('Add'),
  175. '#src' => drupal_get_path('theme', 'tripal') . '/images/add.png',
  176. '#ahah' => array(
  177. 'path' => "tripal_pub/properties/add",
  178. 'wrapper' => 'tripal-pub-edit-properties-table',
  179. 'event' => 'click',
  180. 'method' => 'replace',
  181. ),
  182. '#attributes' => array('onClick' => 'return false;'),
  183. );
  184. }
  185. /*
  186. *
  187. */
  188. function chado_pub_node_form_add_new_props(&$form, $form_state, $num_new, &$d_properties, &$d_removed) {
  189. // first, add in all of the new properties that were added through a previous AHAH callback
  190. $j = 0;
  191. $num_properties++;
  192. // we need to find the
  193. if ($form_state['values']) {
  194. foreach ($form_state['values'] as $element_name => $value) {
  195. if (preg_match('/new_value-(\d+)-(\d+)/', $element_name, $matches)) {
  196. $new_id = $matches[1];
  197. $rank = $matches[2];
  198. // skip any properties that the user requested to delete through a previous
  199. // AHAH callback or through the current AHAH callback
  200. if($d_removed["$new_id-$rank"]) {
  201. continue;
  202. }
  203. if($form_state['post']['remove-' . $new_id . '-' . $rank]) {
  204. $d_removed["$new_id-$rank"] = 1;
  205. continue;
  206. }
  207. // get this new_id information
  208. $cvterm = tripal_core_chado_select('cvterm', array('name', 'definition'), array('cvterm_id' => $new_id));
  209. // add it to the $d_properties array
  210. $d_properties[$new_id][$rank]['name'] = $cvterm->name;
  211. $d_properties[$new_id][$rank]['id'] = $new_id;
  212. $d_properties[$new_id][$rank]['value'] = $value;
  213. $d_properties[$new_id][$rank]['definition'] = $cvterm->definition;
  214. $num_properties++;
  215. // determine how many rows we need in the textarea
  216. $rows = 1;
  217. if (preg_match('/Abstract/', $cvterm[0]->name)) {
  218. $rows = 10;
  219. }
  220. if ($cvterm[0]->name == 'Authors') {
  221. $rows = 2;
  222. }
  223. // add the new fields
  224. $form['properties']['new'][$new_id][$rank]["new_id-$new_id-$rank"] = array(
  225. '#type' => 'item',
  226. '#value' => $cvterm[0]->name
  227. );
  228. $form['properties']['new'][$new_id][$rank]["new_value-$new_id-$rank"] = array(
  229. '#type' => 'textarea',
  230. '#default_value' => $value,
  231. '#cols' => 50,
  232. '#rows' => $rows,
  233. '#description' => $cvterm->definition,
  234. );
  235. $form['properties']['new'][$new_id][$rank]["remove-$new_id-$rank"] = array(
  236. '#type' => 'image_button',
  237. '#value' => t('Remove'),
  238. '#src' => drupal_get_path('theme', 'tripal') . '/images/minus.png',
  239. '#ahah' => array(
  240. 'path' => "tripal_pub/properties/minus/$new_id/$rank",
  241. 'wrapper' => 'tripal-pub-edit-properties-table',
  242. 'event' => 'click',
  243. 'method' => 'replace',
  244. ),
  245. '#attributes' => array('onClick' => 'return false;'),
  246. );
  247. }
  248. }
  249. }
  250. // second add in any new properties added during this callback
  251. if($form_state['post']['add']) {
  252. $new_id = $form_state['values']['new_id'];
  253. $new_value = $form_state['values']['new_value'];
  254. // get the rank by counting the number of entries
  255. $rank = count($d_properties[$new_id]);
  256. // get this new_id information
  257. $cvterm = tripal_core_chado_select('cvterm', array('name', 'definition'), array('cvterm_id' => $new_id));
  258. // add it to the $d_properties array
  259. $d_properties[$new_id][$rank]['name'] = $cvterm->name;
  260. $d_properties[$new_id][$rank]['id'] = $new_id;
  261. $d_properties[$new_id][$rank]['value'] = $value;
  262. $d_properties[$new_id][$rank]['definition'] = $cvterm->definition;
  263. $num_properties++;
  264. // determine how many rows we need in the textarea
  265. $rows = 1;
  266. if (preg_match('/Abstract/', $cvterm[0]->name)) {
  267. $rows = 10;
  268. }
  269. if ($cvterm[0]->name == 'Authors') {
  270. $rows = 2;
  271. }
  272. // add the new fields
  273. $form['properties']['new'][$new_id][$rank]["new_id-$new_id-$rank"] = array(
  274. '#type' => 'item',
  275. '#value' => $cvterm[0]->name
  276. );
  277. $form['properties']['new'][$new_id][$rank]["new_value-$new_id-$rank"] = array(
  278. '#type' => 'textarea',
  279. '#default_value' => $new_value,
  280. '#cols' => 50,
  281. '#rows' => $rows,
  282. '#description' => $cvterm->definition,
  283. );
  284. $form['properties']['new'][$new_id][$rank]["remove-$new_id-$rank"] = array(
  285. '#type' => 'image_button',
  286. '#value' => t('Remove'),
  287. '#src' => drupal_get_path('theme', 'tripal') . '/images/minus.png',
  288. '#ahah' => array(
  289. 'path' => "tripal_pub/properties/minus/$new_id/$rank",
  290. 'wrapper' => 'tripal-pub-edit-properties-table',
  291. 'event' => 'click',
  292. 'method' => 'replace',
  293. ),
  294. '#attributes' => array('onClick' => 'return false;'),
  295. );
  296. }
  297. return $num_properties;
  298. }
  299. /*
  300. *
  301. */
  302. function chado_pub_node_form_add_pubprop_table_props(&$form, $form_state, $pub_id, &$d_properties, &$d_removed) {
  303. // get the properties for this publication
  304. $num_properties = 0;
  305. if(!$pub_id) {
  306. return $num_properties;
  307. }
  308. $sql = "
  309. SELECT CVT.cvterm_id, CVT.name, CVT.definition, PP.value, PP.rank
  310. FROM {pubprop} PP
  311. INNER JOIN {cvterm} CVT on CVT.cvterm_id = PP.type_id
  312. WHERE PP.pub_id = %d
  313. ORDER BY CVT.name, PP.rank
  314. ";
  315. $pub_props = chado_query($sql, $pub_id);
  316. while ($prop = db_fetch_object($pub_props)) {
  317. $type_id = $prop->cvterm_id;
  318. $rank = count($d_properties[$type_id]);
  319. // skip properties that are found in the pub table
  320. if($prop->name == "Volume" or $prop->name == "Volume Title" or
  321. $prop->name == "Issue" or $prop->name == "Pages" or
  322. $prop->name == "Citation") {
  323. continue;
  324. }
  325. // skip any properties that the user requested to delete through a previous
  326. // AHAH callback or through the current AHAH callback
  327. if($d_removed["$type_id-$rank"]) {
  328. continue;
  329. }
  330. if($form_state['post']['remove-' . $type_id . '-' . $rank]) {
  331. $d_removed["$type_id-$rank"] = 1;
  332. continue;
  333. }
  334. $d_properties[$type_id][$rank]['name'] = $prop->name;
  335. $d_properties[$type_id][$rank]['id'] = $type_id;
  336. $d_properties[$type_id][$rank]['value'] = $prop->value;
  337. $d_properties[$type_id][$rank]['definition'] = $prop->definition;
  338. $num_properties++;
  339. // determine how many rows we need in the textarea
  340. $rows = 1;
  341. if (preg_match('/Abstract/', $prop->name)) {
  342. $rows = 10;
  343. }
  344. if ($prop->name == 'Authors') {
  345. $rows = 2;
  346. }
  347. $form['properties'][$type_id][$rank]["prop_id-$type_id-$rank"] = array(
  348. '#type' => 'item',
  349. '#value' => $prop->name,
  350. );
  351. $form['properties'][$type_id][$rank]["prop_value-$type_id-$rank"] = array(
  352. '#type' => 'textarea',
  353. '#default_value' => $prop->value,
  354. '#cols' => 50,
  355. '#rows' => $rows,
  356. '#description' => $prop->definition,
  357. );
  358. $form['properties'][$type_id][$rank]["remove-$type_id-$rank"] = array(
  359. '#type' => 'image_button',
  360. '#value' => t('Remove'),
  361. '#src' => drupal_get_path('theme', 'tripal') . '/images/minus.png',
  362. '#ahah' => array(
  363. 'path' => "tripal_pub/properties/minus/$type_id/$rank",
  364. 'wrapper' => 'tripal-pub-edit-properties-table',
  365. 'event' => 'click',
  366. 'method' => 'replace',
  367. ),
  368. '#attributes' => array('onClick' => 'return false;'),
  369. );
  370. }
  371. return $num_properties;
  372. }
  373. /*
  374. *
  375. */
  376. function chado_pub_node_form_add_pub_table_props(&$form, $form_state, $properties_list,
  377. &$d_properties, &$d_removed, $d_volume, $d_volumetitle, $d_issue, $d_pages) {
  378. $num_properties = 0;
  379. $rank = 0;
  380. // add properties that are actually part of the pub table
  381. foreach($properties_list as $type_id => $prop) {
  382. // skip any properties that the user requested to delete through a previous
  383. // AHAH callback or through the current AHAH callback
  384. if($d_removed["$type_id-$rank"]) {
  385. continue;
  386. }
  387. if($form_state['post']["remove-$type_id-$rank"]) {
  388. $d_removed["$type_id-$rank"] = 1;
  389. continue;
  390. }
  391. // if any of the properties match the fields in the pub table then we want to include those
  392. // automatically
  393. if (($prop->name == 'Volume' and $d_volume) or
  394. ($prop->name == 'Issue' and $d_issue) or
  395. ($prop->name == 'Pages' and $d_pages) or
  396. ($prop->name == 'Volume Title' and $d_volumetitle)) {
  397. $d_properties[$type_id][$rank]['name'] = $prop->name;
  398. $d_properties[$type_id][$rank]['id'] = $type_id;
  399. $d_properties[$type_id][$rank]['definition'] = $prop->definition;
  400. $num_properties++;
  401. if ($prop->name == 'Volume') {
  402. $d_properties[$type_id][$rank]['value'] = $d_volume;
  403. }
  404. if ($prop->name == 'Issue') {
  405. $d_properties[$type_id][$rank]['value'] = $d_issue;
  406. }
  407. if ($prop->name == 'Pages') {
  408. $d_properties[$type_id][$rank]['value'] = $d_pages;
  409. }
  410. if ($prop->name == 'Volume Title') {
  411. $d_properties[$type_id][$rank]['value'] = $d_volumetitle;
  412. }
  413. // determine how many rows we need in the textarea
  414. $rows = 1;
  415. if (preg_match('/Abstract/', $prop->name)) {
  416. $rows = 10;
  417. }
  418. if ($prop->name == 'Authors') {
  419. $rows = 2;
  420. }
  421. // add in the fields
  422. $form['properties'][$type_id][$rank]["prop_id-$type_id-$rank"] = array(
  423. '#type' => 'item',
  424. '#value' => $prop->name
  425. );
  426. $form['properties'][$type_id][$rank]["prop_value-$type_id-$rank"] = array(
  427. '#type' => 'textarea',
  428. '#default_value' => $d_properties[$type_id][$rank]['value'],
  429. '#cols' => 50,
  430. '#rows' => $rows,
  431. '#description' => $description,
  432. );
  433. $form['properties'][$type_id][$rank]["remove-$type_id-$rank"] = array(
  434. '#type' => 'image_button',
  435. '#value' => t('Remove'),
  436. '#src' => drupal_get_path('theme', 'tripal') . '/images/minus.png',
  437. '#ahah' => array(
  438. 'path' => "tripal_pub/properties/minus/$type_id/$rank",
  439. 'wrapper' => 'tripal-pub-edit-properties-table',
  440. 'event' => 'click',
  441. 'method' => 'replace',
  442. ),
  443. '#attributes' => array('onClick' => 'return false;'),
  444. );
  445. }
  446. }
  447. return $num_properties;
  448. }
  449. /*
  450. *
  451. */
  452. function theme_chado_pub_node_form($form) {
  453. $properties_table = tripal_pub_theme_node_form_properties($form);
  454. $markup = drupal_render($form['pub_id']);
  455. $markup .= drupal_render($form['title']);
  456. $markup .= drupal_render($form['type_id']);
  457. $markup .= drupal_render($form['series_name']);
  458. $markup .= drupal_render($form['pyear']);
  459. $markup .= drupal_render($form['uniquename']);
  460. $markup .= "<b>Include Additional Details</b><br>You may add additional properties to this publication by scrolling to the bottom of this table, selecting a property type from the dropdown and adding text. You may add as many properties as desired by clicking the plus button on the right. To remove a property, click the minus button";
  461. $markup .= $properties_table;
  462. $markup .= drupal_render($form['is_obsolete']);
  463. $form['properties'] = array(
  464. '#type' => 'markup',
  465. '#value' => $markup,
  466. );
  467. return drupal_render($form);
  468. }
  469. /*
  470. *
  471. */
  472. function tripal_pub_theme_node_form_properties($form) {
  473. $rows = array();
  474. if ($form['properties']) {
  475. // first add in the properties derived from the pub and pubprop tables
  476. // the array tree for these properties looks like this:
  477. // $form['properties'][$type_id][$rank]["prop_id-$type_id-$rank"]
  478. foreach ($form['properties'] as $type_id => $elements) {
  479. // there are other fields in the properties array so we only
  480. // want the numeric ones those are our type_id
  481. if (is_numeric($type_id)) {
  482. foreach ($elements as $rank => $element) {
  483. if (is_numeric($rank)) {
  484. $rows[] = array(
  485. drupal_render($element["prop_id-$type_id-$rank"]),
  486. drupal_render($element["prop_value-$type_id-$rank"]),
  487. drupal_render($element["remove-$type_id-$rank"]),
  488. );
  489. }
  490. }
  491. }
  492. }
  493. // second, add in any new properties added by the user through AHAH callbacks
  494. // the array tree for these properties looks like this:
  495. // $form['properties']['new'][$type_id][$rank]["new_id-$new_id-$rank"]
  496. foreach ($form['properties']['new'] as $type_id => $elements) {
  497. if (is_numeric($type_id)) {
  498. foreach ($elements as $rank => $element) {
  499. if (is_numeric($rank)) {
  500. $rows[] = array(
  501. drupal_render($element["new_id-$type_id-$rank"]),
  502. drupal_render($element["new_value-$type_id-$rank"]),
  503. drupal_render($element["remove-$type_id-$rank"]),
  504. );
  505. }
  506. }
  507. }
  508. }
  509. // finally add in a set of blank field for adding a new property
  510. $rows[] = array(
  511. drupal_render($form['properties']['new']['new_id']),
  512. drupal_render($form['properties']['new']['new_value']),
  513. drupal_render($form['properties']['new']['add']),
  514. );
  515. }
  516. $headers = array('Property Type','Value', '');
  517. return theme('table', $headers, $rows, array('id'=> "tripal-pub-edit-properties-table"));
  518. }
  519. /*
  520. *
  521. */
  522. function tripal_pub_property_add() {
  523. $status = TRUE;
  524. // prepare and render the form
  525. $form = tripal_core_ahah_prepare_form();
  526. // we only want to return the properties as that's all we'll replace with this AHAh callback
  527. $data = tripal_pub_theme_node_form_properties($form);
  528. // bind javascript events to the new objects that will be returned
  529. // so that AHAH enabled elements will work.
  530. $settings = tripal_core_ahah_bind_events();
  531. // return the updated JSON
  532. drupal_json(
  533. array(
  534. 'status' => $status,
  535. 'data' => $data,
  536. 'settings' => $settings,
  537. )
  538. );
  539. }
  540. /*
  541. *
  542. */
  543. function tripal_pub_property_delete() {
  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_pub_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_pub_property_get_description() {
  565. $new_id = $_POST['new_id'];
  566. $values = array('cvterm_id' => $new_id);
  567. $cvterm = tripal_core_chado_select('cvterm', array('definition'), $values);
  568. $description = '&nbsp;';
  569. if ($cvterm[0]->definition) {
  570. $description = $cvterm[0]->definition;
  571. }
  572. drupal_json(
  573. array(
  574. 'status' => TRUE,
  575. 'data' => '<div id="tripal-pub-new_value-desc">' . $description . '</div>',
  576. )
  577. );
  578. }