tripal_cv.js 9.8 KB

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