tripal_analysis_blast.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. // Get the base url. Drupal can not pass it through the form so we need
  38. // to get it ourself. Use different patterns to match the url in case
  39. // the Clean URL function is turned on
  40. var baseurl = location.href.substring(0,location.href.lastIndexOf('/?q=/node'));
  41. if(!baseurl) {
  42. var baseurl = location.href.substring(0,location.href.lastIndexOf('/node'));
  43. }
  44. if (!baseurl) {
  45. // This base_url is obtained when Clena URL function is off
  46. var baseurl = location.href.substring(0,location.href.lastIndexOf('/?q=node'));
  47. }
  48. if (!baseurl) {
  49. // The last possibility is we've assigned an alias path, get base_url till the last /
  50. var baseurl = location.href.substring(0,location.href.lastIndexOf('/'));
  51. }
  52. // Form the link for the following ajax call
  53. var link = baseurl + '/tripal_blast_regex/' + dbid;
  54. // Make ajax call to retrieve regular expressions
  55. $.ajax( {
  56. url : link,
  57. dataType : 'json',
  58. type : 'POST',
  59. success : tripal_set_parser,
  60. });
  61. }
  62. // Set parser for the admin page
  63. function tripal_set_parser(data) {
  64. // Set title if it exists
  65. if (data.name) {
  66. $("#edit-displayname").val(data.name);
  67. } else {
  68. $("#edit-displayname").val("");
  69. }
  70. // If genbank_style is TRUE, check the Genbank style box, clear all regular expressions, and disable
  71. // the text fields
  72. if (data.genbank_style == 1) {
  73. $("#edit-gb-style-parser").attr("checked", true);
  74. $("#edit-hit-id").val("");
  75. $("#edit-hit-def").val("");
  76. $("#edit-hit-accession").val("");
  77. // Otherwise, uncheck the Genbank style box and set the regular expressions
  78. } else {
  79. $("#edit-gb-style-parser").attr("checked", false);
  80. if (data.reg1) {
  81. $("#edit-hit-id").val(data.reg1);
  82. // Show default hit-id parser if it's not set
  83. } else {
  84. $("#edit-hit-id").val("^(.*?)\s.*$");
  85. }
  86. if (data.reg2) {
  87. $("#edit-hit-def").val(data.reg2);
  88. // Show default hit-def parser if it's not set
  89. } else {
  90. $("#edit-hit-def").val("^.*?\s(.*)$");
  91. }
  92. if (data.reg3) {
  93. $("#edit-hit-accession").val(data.reg3);
  94. // Show default hit-accession parser if it's not set
  95. } else {
  96. $("#edit-hit-accession").val("^(.*?)\s.*$");
  97. }
  98. }
  99. tripal_set_genbank_style();
  100. }
  101. // ------------------------------------------------------------
  102. // Use genbank style parser. Hid regular expression text feilds
  103. function tripal_set_genbank_style (){
  104. // Disable regular expressions if genbank style parser is used (checked)
  105. if ($("#edit-gb-style-parser").is(":checked")) {
  106. $("#edit-hit-id-wrapper > label").css("color", "grey");
  107. $("#edit-hit-def-wrapper > label").css("color", "grey");
  108. $("#edit-hit-accession-wrapper > label").css("color", "grey");
  109. $("#edit-hit-id").attr('disabled', 'disabled');
  110. $("#edit-hit-def").attr('disabled', 'disabled');
  111. $("#edit-hit-accession").attr('disabled', 'disabled');
  112. } else {
  113. $("#edit-hit-id-wrapper > label").css("color", "black");
  114. $("#edit-hit-def-wrapper > label").css("color", "black");
  115. $("#edit-hit-accession-wrapper > label").css("color", "black");
  116. $("#edit-hit-id").removeAttr('disabled');
  117. $("#edit-hit-def").removeAttr('disabled');
  118. $("#edit-hit-accession").removeAttr('disabled');
  119. }
  120. }
  121. // -------------------------------------------------------------
  122. // Function that toggles the blast droppable subbox content
  123. function tripal_set_blast_subbox(db_id){
  124. $('.blast-hit-arrow-icon').hover(
  125. function() {
  126. $(this).css("cursor", "pointer");
  127. },
  128. function() {
  129. $(this).css("cursor", "pointer");
  130. }
  131. );
  132. if (!db_id){
  133. $('.tripal_expandableSubBoxContent').hide();
  134. $('.blast-hit-arrow-icon').click(
  135. function() {
  136. // Find the width of the table column for the tripal_expandableSubBoxContent
  137. var width = $(this).parent().parent().width();
  138. width -= 40;
  139. // Traverse through html DOM objects to find tripal_expandableSubBoxContent and change its settings
  140. var subbox = $(this).parent().parent().next().next().children().children();
  141. subbox.css("width", width + 'px');
  142. subbox.slideToggle('fast', function () {
  143. var image = $(this).parent().parent().prev().prev().children().children();
  144. var icon_url = image.attr("src");
  145. if (subbox.is(':visible')) {
  146. var changed_icon_url = icon_url.replace(/arrow_r.png/,"arrow_d.png");
  147. image.attr("src", changed_icon_url);
  148. } else {
  149. var icon_url = icon_url.replace(/arrow_d.png/,"arrow_r.png");
  150. image.attr("src", icon_url);
  151. }
  152. });
  153. }
  154. );
  155. // Update only the part of DOM objects that have been changed by ajax. This is a solution
  156. // to solve the problem that droppable subbox opened then closed immediately.
  157. } else {
  158. $("#blast_db_" + db_id + ' div.tripal_expandableSubBoxContent').hide();
  159. var changedObject = $("#blast_db_" + db_id + " img.blast-hit-arrow-icon");
  160. changedObject.click(
  161. function() {
  162. // Find the width of the table column for the tripal_expandableSubBoxContent
  163. var width = $(this).parent().parent().width();
  164. width -= 40;
  165. // Traverse through html DOM objects to find tripal_expandableSubBoxContent and change its settings
  166. var subbox = $(this).parent().parent().next().next().children().children();
  167. subbox.css("width", width + 'px');
  168. subbox.slideToggle('fast', function () {
  169. var image = $(this).parent().parent().prev().prev().children().children();
  170. var icon_url = image.attr("src");
  171. if (subbox.is(':visible')) {
  172. var changed_icon_url = icon_url.replace(/arrow_r.png/,"arrow_d.png");
  173. image.attr("src", changed_icon_url);
  174. } else {
  175. var icon_url = icon_url.replace(/arrow_d.png/,"arrow_r.png");
  176. image.attr("src", icon_url);
  177. }
  178. });
  179. }
  180. );
  181. }
  182. }
  183. }