tripal_analysis_kegg.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. if (Drupal.jsEnabled) {
  2. $(document).ready(function() {
  3. $(".tripal_kegg_brite_tree").attr("id", function(){
  4. init_kegg_tree($(this).attr("id"));
  5. });
  6. // Select default KEGG analysis when available
  7. var selectbox = $('#edit-tripal-analysis-kegg-select');
  8. if(selectbox){
  9. selectbox[0].selectedIndex = 1;
  10. tripal_analysis_kegg_org_report(selectbox.val());
  11. }
  12. });
  13. //------------------------------------------------------------
  14. function tripal_analysis_kegg_org_report(item){
  15. if(!item){
  16. $("#tripal_analysis_kegg_org_report").html('');
  17. return false;
  18. }
  19. // Get the base url. Drupal can not pass it through the form so we need
  20. // to get it ourself. Use different patterns to match the url in case
  21. // the Clean URL function is turned on
  22. var baseurl = location.href.substring(0,location.href.lastIndexOf('/?q=/node'));
  23. if(!baseurl) {
  24. var baseurl = location.href.substring(0,location.href.lastIndexOf('/node'));
  25. }
  26. if (!baseurl) {
  27. // This base_url is obtained when Clean URL function is off
  28. var baseurl = location.href.substring(0,location.href.lastIndexOf('/?q=node'));
  29. }
  30. if (!baseurl) {
  31. // The last possibility is we've assigned an alias path, get base_url till the last /
  32. var baseurl = location.href.substring(0,location.href.indexOf('/',10));
  33. }
  34. // Form the link for the following ajax call
  35. var link = baseurl + '/tripal_analysis_kegg_org_report/' + item;
  36. tripal_startAjax();
  37. $.ajax({
  38. url: link,
  39. dataType: 'json',
  40. type: 'POST',
  41. success: function(data){
  42. $("#tripal_analysis_kegg_org_report").html(data[0]);
  43. $(".tripal_kegg_brite_tree").attr("id", function(){
  44. init_kegg_tree($(this).attr("id"));
  45. });
  46. tripal_stopAjax();
  47. }
  48. });
  49. return false;
  50. }
  51. //------------------------------------------------------------
  52. // Update the BRITE hierarchy based on the user selection
  53. function tripal_update_brite(link,type_id){
  54. tripal_startAjax();
  55. $.ajax({
  56. url: link.href,
  57. dataType: 'json',
  58. type: 'POST',
  59. success: function(data){
  60. $("#tripal_kegg_brite_hierarchy").html(data.update);
  61. $("#tripal_kegg_brite_header").html(data.brite_term);
  62. tripal_stopAjax();
  63. init_kegg_tree(data.id);
  64. }
  65. });
  66. return false;
  67. }
  68. //------------------------------------------------------------
  69. // This function initializes a KEGG term tree
  70. function init_kegg_tree(id){
  71. // Get the base url. Drupal can not pass it through the form so we need
  72. // to get it ourself. Use different patterns to match the url in case
  73. // the Clean URL function is turned on
  74. var baseurl = location.href.substring(0,location.href.lastIndexOf('/?q=/node'));
  75. if(!baseurl) {
  76. var baseurl = location.href.substring(0,location.href.lastIndexOf('/node'));
  77. }
  78. if (!baseurl) {
  79. // This base_url is obtained when Clena URL function is off
  80. var baseurl = location.href.substring(0,location.href.lastIndexOf('/?q=node'));
  81. }
  82. if (!baseurl) {
  83. // The last possibility is we've assigned an alias path, get base_url till the last /
  84. var baseurl = location.href.substring(0,location.href.lastIndexOf('/'));
  85. }
  86. // Form the link for the following ajax call
  87. var link = baseurl + "/sites/all/themes/theme_tripal/js/jsTree/source/themes/";
  88. $("#" + id).tree ({
  89. data : {
  90. type : "predefined", // ENUM [json, xml_flat, xml_nested, predefined]
  91. method : "GET", // HOW TO REQUEST FILES
  92. async : false, // BOOL - async loading onopen
  93. async_data : function (NODE) { return { id : $(NODE).attr("id") || 0 } }, // PARAMETERS PASSED TO SERVER
  94. url : false, // FALSE or STRING - url to document to be used (async or not)
  95. json : false, // FALSE or OBJECT if type is JSON and async is false - the tree dump as json
  96. xml : false // FALSE or STRING
  97. },
  98. ui : {
  99. dots : true, // BOOL - dots or no dots
  100. rtl : false, // BOOL - is the tree right-to-left
  101. animation : 0, // INT - duration of open/close animations in miliseconds
  102. hover_mode : true, // SHOULD get_* functions chage focus or change hovered item
  103. scroll_spd : 4,
  104. theme_path : link, // Path to themes
  105. theme_name : "classic",// Name of theme
  106. },
  107. rules : {
  108. multiple : false, // FALSE | CTRL | ON - multiple selection off/ with or without holding Ctrl
  109. metadata : false, // FALSE or STRING - attribute name (use metadata plugin)
  110. type_attr : "rel", // STRING attribute name (where is the type stored if no metadata)
  111. multitree : false, // BOOL - is drag n drop between trees allowed
  112. createat : "bottom", // STRING (top or bottom) new nodes get inserted at top or bottom
  113. use_inline : false, // CHECK FOR INLINE RULES - REQUIRES METADATA
  114. clickable : "all", // which node types can the user select | default - all
  115. renameable : false, // which node types can the user select | default - all
  116. deletable : false, // which node types can the user delete | default - all
  117. creatable : false, // which node types can the user create in | default - all
  118. draggable : "none", // which node types can the user move | default - none | "all"
  119. dragrules : "all", // what move operations between nodes are allowed | default - none | "all"
  120. drag_copy : false, // FALSE | CTRL | ON - drag to copy off/ with or without holding Ctrl
  121. droppable : [],
  122. drag_button : "left"
  123. },
  124. callback : { // various callbacks to attach custom logic to
  125. // before focus - should return true | false
  126. beforechange: function(NODE,TREE_OBJ) { return true },
  127. beforeopen : function(NODE,TREE_OBJ) { return true },
  128. beforeclose : function(NODE,TREE_OBJ) { return true },
  129. // before move - should return true | false
  130. beforemove : function(NODE,REF_NODE,TYPE,TREE_OBJ) { return true },
  131. // before create - should return true | false
  132. beforecreate: function(NODE,REF_NODE,TYPE,TREE_OBJ) { return true },
  133. // before rename - should return true | false
  134. beforerename: function(NODE,LANG,TREE_OBJ) { return true },
  135. // before delete - should return true | false
  136. beforedelete: function(NODE,TREE_OBJ) { return true },
  137. onJSONdata : function(DATA,TREE_OBJ) { return DATA; },
  138. onselect : function(NODE,TREE_OBJ) {
  139. window.onerror = function(){return true;};
  140. throw 'exit';
  141. }, // node selected
  142. ondeselect : function(NODE,TREE_OBJ) { }, // node deselected
  143. onchange : function(NODE,TREE_OBJ) { }, // focus changed
  144. onrename : function(NODE,LANG,TREE_OBJ,RB) { }, // node renamed ISNEW - TRUE|FALSE, current language
  145. onmove : function(NODE,REF_NODE,TYPE,TREE_OBJ,RB) { }, // move completed (TYPE is BELOW|ABOVE|INSIDE)
  146. oncopy : function(NODE,REF_NODE,TYPE,TREE_OBJ,RB) { }, // copy completed (TYPE is BELOW|ABOVE|INSIDE)
  147. oncreate : function(NODE,REF_NODE,TYPE,TREE_OBJ,RB) { }, // node created, parent node (TYPE is createat)
  148. ondelete : function(NODE, TREE_OBJ,RB) { }, // node deleted
  149. onopen : function(NODE, TREE_OBJ) { }, // node opened
  150. onopen_all : function(TREE_OBJ) { }, // all nodes opened
  151. onclose : function(NODE, TREE_OBJ) { }, // node closed
  152. error : function(TEXT, TREE_OBJ) { }, // error occured
  153. // double click on node - defaults to open/close & select
  154. ondblclk : function(NODE, TREE_OBJ) { TREE_OBJ.toggle_branch.call(TREE_OBJ, NODE); TREE_OBJ.select_branch.call(TREE_OBJ, NODE); },
  155. // right click - to prevent use: EV.preventDefault(); EV.stopPropagation(); return false
  156. onrgtclk : function(NODE, TREE_OBJ, EV) { },
  157. onload : function(TREE_OBJ) { },
  158. onfocus : function(TREE_OBJ) { },
  159. ondrop : function(NODE,REF_NODE,TYPE,TREE_OBJ) {}
  160. }
  161. });
  162. }
  163. }