tripal_cv.js 10 KB

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