tripal_analysis_blast.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // Copyright 2009 Clemson University
  3. //
  4. if (Drupal.jsEnabled) {
  5. $(document).ready(function(){
  6. // If Anlaysis admin page is shown, get the settings for selected database
  7. if ($("#edit-blastdb")[0]) {
  8. tripal_update_regex($("#edit-blastdb")[0]);
  9. tripal_set_genbank_style();
  10. }
  11. // Set blast hit alignment droppable box
  12. tripal_set_blast_subbox();
  13. });
  14. //------------------------------------------------------------
  15. // Update the blast results based on the user selection
  16. function tripal_update_blast(link,db_id){
  17. tripal_startAjax();
  18. $.ajax({
  19. url: link.href,
  20. dataType: 'json',
  21. type: 'POST',
  22. success: function(data){
  23. $("#blast_db_" + db_id).html(data.update);
  24. // make sure the newly added expandable boxes are closed
  25. tripal_set_blast_subbox(db_id);
  26. tripal_stopAjax();
  27. }
  28. });
  29. return false;
  30. }
  31. //------------------------------------------------------------
  32. // Update regular expression for selected database
  33. function tripal_update_regex(options){
  34. // Get the dbname from DOM
  35. var index = options.selectedIndex;
  36. var dbid = options[index].value;
  37. // Form the link for the following ajax call
  38. var baseurl = tripal_get_base_url();
  39. var link = baseurl + '/tripal_blast_regex/' + dbid;
  40. // Make ajax call to retrieve regular expressions
  41. $.ajax( {
  42. url : link,
  43. dataType : 'json',
  44. type : 'POST',
  45. success : tripal_set_parser,
  46. });
  47. }
  48. // Set parser for the admin page
  49. function tripal_set_parser(data) {
  50. // Set title if it exists
  51. if (data.name) {
  52. $("#edit-displayname").val(data.name);
  53. } else {
  54. $("#edit-displayname").val("");
  55. }
  56. // If genbank_style is TRUE, check the Genbank style box, clear all regular expressions, and disable
  57. // the text fields
  58. if (data.genbank_style == 1) {
  59. $("#edit-gb-style-parser").attr("checked", true);
  60. $("#edit-hit-id").val("");
  61. $("#edit-hit-def").val("");
  62. $("#edit-hit-accession").val("");
  63. // Otherwise, uncheck the Genbank style box and set the regular expressions
  64. } else {
  65. $("#edit-gb-style-parser").attr("checked", false);
  66. if (data.reg1) {
  67. $("#edit-hit-id").val(data.reg1);
  68. // Show default hit-id parser if it's not set
  69. } else {
  70. $("#edit-hit-id").val("^(.*?)\s.*$");
  71. }
  72. if (data.reg2) {
  73. $("#edit-hit-def").val(data.reg2);
  74. // Show default hit-def parser if it's not set
  75. } else {
  76. $("#edit-hit-def").val("^.*?\s(.*)$");
  77. }
  78. if (data.reg3) {
  79. $("#edit-hit-accession").val(data.reg3);
  80. // Show default hit-accession parser if it's not set
  81. } else {
  82. $("#edit-hit-accession").val("^(.*?)\s.*$");
  83. }
  84. }
  85. tripal_set_genbank_style();
  86. }
  87. // ------------------------------------------------------------
  88. // Use genbank style parser. Hid regular expression text feilds
  89. function tripal_set_genbank_style (){
  90. // Disable regular expressions if genbank style parser is used (checked)
  91. if ($("#edit-gb-style-parser").is(":checked")) {
  92. $("#edit-hit-id-wrapper > label").css("color", "grey");
  93. $("#edit-hit-def-wrapper > label").css("color", "grey");
  94. $("#edit-hit-accession-wrapper > label").css("color", "grey");
  95. $("#edit-hit-id").attr('disabled', 'disabled');
  96. $("#edit-hit-def").attr('disabled', 'disabled');
  97. $("#edit-hit-accession").attr('disabled', 'disabled');
  98. } else {
  99. $("#edit-hit-id-wrapper > label").css("color", "black");
  100. $("#edit-hit-def-wrapper > label").css("color", "black");
  101. $("#edit-hit-accession-wrapper > label").css("color", "black");
  102. $("#edit-hit-id").removeAttr('disabled');
  103. $("#edit-hit-def").removeAttr('disabled');
  104. $("#edit-hit-accession").removeAttr('disabled');
  105. }
  106. }
  107. // -------------------------------------------------------------
  108. // Function that toggles the blast droppable subbox content
  109. function tripal_set_blast_subbox(db_id){
  110. $('.blast-hit-arrow-icon').hover(
  111. function() {
  112. $(this).css("cursor", "pointer");
  113. },
  114. function() {
  115. $(this).css("cursor", "pointer");
  116. }
  117. );
  118. if (!db_id){
  119. $('.tripal_expandableSubBoxContent').hide();
  120. $('.blast-hit-arrow-icon').click(
  121. function() {
  122. // Find the width of the table column for the tripal_expandableSubBoxContent
  123. var width = $(this).parent().parent().width();
  124. width -= 40;
  125. // Traverse through html DOM objects to find tripal_expandableSubBoxContent and change its settings
  126. var subbox = $(this).parent().parent().next().children().children();
  127. subbox.css("width", width + 'px');
  128. subbox.slideToggle('fast', function () {
  129. var image = $(this).parent().parent().prev().children().children().children();
  130. var icon_url = image.attr("src");
  131. if (subbox.is(':visible')) {
  132. var changed_icon_url = icon_url.replace(/arrow_r.png/,"arrow_d.png");
  133. image.attr("src", changed_icon_url);
  134. } else {
  135. var icon_url = icon_url.replace(/arrow_d.png/,"arrow_r.png");
  136. image.attr("src", icon_url);
  137. }
  138. });
  139. }
  140. );
  141. // Update only the part of DOM objects that have been changed by ajax. This is a solution
  142. // to solve the problem that droppable subbox opened then closed immediately.
  143. } else {
  144. $("#blast_db_" + db_id + ' div.tripal_expandableSubBoxContent').hide();
  145. var changedObject = $("#blast_db_" + db_id + " img.blast-hit-arrow-icon");
  146. changedObject.click(
  147. function() {
  148. // Find the width of the table column for the tripal_expandableSubBoxContent
  149. var width = $(this).parent().parent().width();
  150. width -= 40;
  151. // Traverse through html DOM objects to find tripal_expandableSubBoxContent and change its settings
  152. var subbox = $(this).parent().parent().next().next().children().children();
  153. subbox.css("width", width + 'px');
  154. subbox.slideToggle('fast', function () {
  155. var image = $(this).parent().parent().prev().prev().children().children();
  156. var icon_url = image.attr("src");
  157. if (subbox.is(':visible')) {
  158. var changed_icon_url = icon_url.replace(/arrow_r.png/,"arrow_d.png");
  159. image.attr("src", changed_icon_url);
  160. } else {
  161. var icon_url = icon_url.replace(/arrow_d.png/,"arrow_r.png");
  162. image.attr("src", icon_url);
  163. }
  164. });
  165. }
  166. );
  167. }
  168. }
  169. }