tripal_cv.js 9.3 KB

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