tripal_cv.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. if (Drupal.jsEnabled) {
  2. var baseurl;
  3. var isClean;
  4. $(document).ready(function() {
  5. // Get the base url. Drupal can not pass it through the form so we need
  6. // to get it ourself. Use different patterns to match the url in case
  7. // the Clean URL function is turned on
  8. baseurl = location.href.substring(0,location.href.lastIndexOf('/?q=/node'));
  9. isClean = 1;
  10. if(!baseurl) {
  11. baseurl = location.href.substring(0,location.href.lastIndexOf('/node'));
  12. isClean = 0;
  13. }
  14. if (!baseurl) {
  15. // This base_url is obtained when Clean URL function is off
  16. baseurl = location.href.substring(0,location.href.lastIndexOf('/?q=node'));
  17. isClean = 1;
  18. }
  19. if (!baseurl) {
  20. // The last possibility is we've assigned an alias path, get base_url till the last /
  21. baseurl = location.href.substring(0,location.href.indexOf('/',10));
  22. isClean = 0;
  23. }
  24. // any img object of class .tripal_cv_chart will have it's src attribute
  25. // populated when the document is ready by the following code. The id
  26. // for the object must have a unique identifier that the calling tripal
  27. // module recognizes
  28. tripal_cv_init_chart();
  29. // any div object of class .tripal_cv_tree will be populated with a
  30. // CV brower tree when the document is ready. The id for the object
  31. // must have a unique identifier that the calling tripal module
  32. // recognizes.
  33. tripal_cv_init_tree();
  34. $(window).scroll(function(){
  35. $('#tripal_cv_cvterm_info_box').animate(
  36. {top:$(window).scrollTop()+"px" },
  37. {queue: false, duration: 350}
  38. );
  39. });
  40. $("#tripal_cv_cvterm_info_box").hide();
  41. });
  42. //------------------------------------------------------------
  43. // FUNCTIONS
  44. //------------------------------------------------------------
  45. function tripal_cv_init_tree(){
  46. $(".tripal_cv_tree").attr("id", function(){
  47. var api = new jGCharts.Api();
  48. var tree_id = $(this).attr("id");
  49. var link = baseurl + "/";
  50. if(isClean){
  51. link += "?q=";
  52. }
  53. link += 'tripal_cv_tree/' + tree_id;
  54. tripal_startAjax();
  55. $.ajax({
  56. url: link,
  57. dataType: 'json',
  58. type: 'POST',
  59. success: function(data){
  60. vars = {
  61. cv : data[0],
  62. tree_id : data[1],
  63. }
  64. init_tree(tree_id,vars);
  65. tripal_stopAjax();
  66. }
  67. });
  68. });
  69. }
  70. function tripal_cv_init_chart(){
  71. $(".tripal_cv_chart").attr("src", function(){
  72. var api = new jGCharts.Api();
  73. var chart_id = $(this).attr("id");
  74. var link = baseurl + "/";
  75. if(isClean){
  76. link += "?q=";
  77. }
  78. link += '/tripal_cv_chart/' + chart_id;
  79. tripal_startAjax();
  80. $.ajax({
  81. url: link,
  82. dataType: 'json',
  83. type: 'POST',
  84. success: function(data){
  85. src = api.make(data[0]);
  86. chart_id = data[1];
  87. $('#' + chart_id).attr('src',src);
  88. tripal_stopAjax();
  89. }
  90. });
  91. });
  92. }
  93. // The Tripal CV module provides a CV term browser. This function
  94. // initializes that browser.
  95. function tripal_cv_init_browser(options){
  96. // Get the cv_id from DOM
  97. var index = options.selectedIndex;
  98. var cv_id = options[index].value;
  99. var link = baseurl + '/tripal_cv_init_browser/' + cv_id;
  100. $.ajax({
  101. url: link,
  102. dataType: 'json',
  103. type: 'POST',
  104. success: function(data){
  105. $("#cv_browser").html(data.update);
  106. vars = {
  107. cv : cv_id,
  108. }
  109. init_tree('browser',vars);
  110. }
  111. });
  112. return false;
  113. }
  114. //------------------------------------------------------------
  115. // When a term in CV term tree browser is clicked this
  116. // function loads the term info into a box on the page.
  117. function tripal_cv_cvterm_info(cvterm_id,vars){
  118. var link = baseurl + '/tripal_cv_cvterm_info/' + cvterm_id + '?cv=' + vars.cv + '&tree_id=' + vars.tree_id;
  119. // Get the cv_id from DOM
  120. $.ajax({
  121. url: link,
  122. dataType: 'json',
  123. type: 'POST',
  124. success: function(data){
  125. $("#tripal_cv_cvterm_info").html(data.update);
  126. $('#tripal_cv_cvterm_info_box').animate(
  127. {top:$(window).scrollTop()+"px" },
  128. {queue: false, duration: 350}
  129. );
  130. $("#tripal_cv_cvterm_info_box").show();
  131. }
  132. });
  133. return false;
  134. }
  135. //------------------------------------------------------------
  136. // This function initializes a CV term tree
  137. function init_tree(id,vars){
  138. var link = baseurl + '/tripal_cv_update_tree';
  139. var theme_link = baseurl + "/sites/all/themes/theme_tripal/js/jsTree/source/themes/";
  140. $("#" + id).tree ({
  141. data : {
  142. type : "json", // ENUM [json, xml_flat, xml_nested, predefined]
  143. method : "GET", // HOW TO REQUEST FILES
  144. async : true, // BOOL - async loading onopen
  145. async_data : function (NODE) {
  146. vars.term = $(NODE).attr("id") || "root";
  147. return vars
  148. }, // PARAMETERS PASSED TO SERVER
  149. url : link, // FALSE or STRING - url to document to be used (async or not)
  150. json : false, // FALSE or OBJECT if type is JSON and async is false - the tree dump as json
  151. xml : false // FALSE or STRING
  152. },
  153. ui : {
  154. dots : true, // BOOL - dots or no dots
  155. rtl : false, // BOOL - is the tree right-to-left
  156. animation : 30, // INT - duration of open/close animations in miliseconds
  157. hover_mode : true, // SHOULD get_* functions chage focus or change hovered item
  158. scroll_spd : 4,
  159. theme_path : theme_link, // Path to themes
  160. theme_name : "classic",// Name of theme
  161. },
  162. rules : {
  163. multiple : false, // FALSE | CTRL | ON - multiple selection off/ with or without holding Ctrl
  164. metadata : false, // FALSE or STRING - attribute name (use metadata plugin)
  165. type_attr : "rel", // STRING attribute name (where is the type stored if no metadata)
  166. multitree : false, // BOOL - is drag n drop between trees allowed
  167. createat : "bottom", // STRING (top or bottom) new nodes get inserted at top or bottom
  168. use_inline : false, // CHECK FOR INLINE RULES - REQUIRES METADATA
  169. clickable : "all", // which node types can the user select | default - all
  170. renameable : false, // which node types can the user select | default - all
  171. deletable : false, // which node types can the user delete | default - all
  172. creatable : false, // which node types can the user create in | default - all
  173. draggable : "none", // which node types can the user move | default - none | "all"
  174. dragrules : "all", // what move operations between nodes are allowed | default - none | "all"
  175. drag_copy : false, // FALSE | CTRL | ON - drag to copy off/ with or without holding Ctrl
  176. droppable : [],
  177. drag_button : "left"
  178. },
  179. callback : { // various callbacks to attach custom logic to
  180. // before focus - should return true | false
  181. beforechange: function(NODE,TREE_OBJ) { return true },
  182. beforeopen : function(NODE,TREE_OBJ) { return true },
  183. beforeclose : function(NODE,TREE_OBJ) { return true },
  184. // before move - should return true | false
  185. beforemove : function(NODE,REF_NODE,TYPE,TREE_OBJ) { return true },
  186. // before create - should return true | false
  187. beforecreate: function(NODE,REF_NODE,TYPE,TREE_OBJ) { return true },
  188. // before rename - should return true | false
  189. beforerename: function(NODE,LANG,TREE_OBJ) { return true },
  190. // before delete - should return true | false
  191. beforedelete: function(NODE,TREE_OBJ) { return true },
  192. onJSONdata : function(DATA,TREE_OBJ) { return DATA; },
  193. onselect : function(NODE,TREE_OBJ) { tripal_cv_cvterm_info( $(NODE).attr("id"),vars )}, // node selected
  194. ondeselect : function(NODE,TREE_OBJ) { }, // node deselected
  195. onchange : function(NODE,TREE_OBJ) { }, // focus changed
  196. onrename : function(NODE,LANG,TREE_OBJ,RB) { }, // node renamed ISNEW - TRUE|FALSE, current language
  197. onmove : function(NODE,REF_NODE,TYPE,TREE_OBJ,RB) { }, // move completed (TYPE is BELOW|ABOVE|INSIDE)
  198. oncopy : function(NODE,REF_NODE,TYPE,TREE_OBJ,RB) { }, // copy completed (TYPE is BELOW|ABOVE|INSIDE)
  199. oncreate : function(NODE,REF_NODE,TYPE,TREE_OBJ,RB) { }, // node created, parent node (TYPE is createat)
  200. ondelete : function(NODE, TREE_OBJ,RB) { }, // node deleted
  201. onopen : function(NODE, TREE_OBJ) { }, // node opened
  202. onopen_all : function(TREE_OBJ) { }, // all nodes opened
  203. onclose : function(NODE, TREE_OBJ) { }, // node closed
  204. error : function(TEXT, TREE_OBJ) { }, // error occured
  205. // double click on node - defaults to open/close & select
  206. ondblclk : function(NODE, TREE_OBJ) { TREE_OBJ.toggle_branch.call(TREE_OBJ, NODE); TREE_OBJ.select_branch.call(TREE_OBJ, NODE); },
  207. // right click - to prevent use: EV.preventDefault(); EV.stopPropagation(); return false
  208. onrgtclk : function(NODE, TREE_OBJ, EV) { },
  209. onload : function(TREE_OBJ) { },
  210. onfocus : function(TREE_OBJ) { },
  211. ondrop : function(NODE,REF_NODE,TYPE,TREE_OBJ) {}
  212. }
  213. });
  214. }
  215. }