tripal.user_files.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. (function ($) {
  2. Drupal.behaviors.TripalUserFiles = {
  3. attach: function (context, settings) {
  4. // The Drupal theme_items_list duplicates the classes of the li on
  5. // the ul of nexted children. This screws up our collapse/open so
  6. // we'll remove it.
  7. $('#tripal-user-file-tree ul').removeAttr('class');
  8. // Set default actions for closed and open folders.
  9. $('.tripal-user-tree-node-closed').children().hide();
  10. $('.tripal-user-tree-node-closed').click(function(event) {
  11. expandNode($(this));
  12. });
  13. $('.tripal-user-tree-node-open').click(function(event) {
  14. collapseNode($(this));
  15. });
  16. // Keep clicks on the files from propagating up to folders and
  17. // causing collapse.
  18. $('.tripal-user-tree-node-file').click(function(event) {
  19. event.stopPropagation();
  20. // Reset the colors for all of the elements.
  21. $('li.even').css("background-color", "#EEEEEE");
  22. $('li.odd').css("background-color", "#FFFFFF");
  23. // Get the file details.
  24. showFileDetails($(this));
  25. // Higlight the selected file.
  26. $(this).css("background-color", "#CCCCCC");
  27. });
  28. }
  29. }
  30. /**
  31. * Prints the details of the selected file from the tree.
  32. */
  33. function showFileDetails(item) {
  34. var fid = item.attr('fid');
  35. var uid = item.attr('uid');
  36. $.ajax({
  37. url : baseurl + '/user/' + uid + '/files/' + fid,
  38. success: function(data) {
  39. $('#tripal-user-file-details').html(data);
  40. }
  41. });
  42. }
  43. /**
  44. * Collapses a node in the CV tree browser and removes its children.
  45. */
  46. function collapseNode(item) {
  47. item.removeClass('tripal-user-tree-node-open');
  48. item.addClass('tripal-user-tree-node-closed');
  49. item.children().hide()
  50. item.unbind('click');
  51. item.click(function(event){
  52. expandNode($(this));
  53. })
  54. }
  55. /**
  56. * Expands a node in the CV tree browser and loads it's children via AJAX.
  57. */
  58. function expandNode(item){
  59. item.removeClass('tripal-user-tree-node-closed');
  60. item.addClass('tripal-user-tree-node-open');
  61. item.children().show()
  62. item.unbind('click');
  63. item.click(function(event){
  64. collapseNode($(this));
  65. })
  66. }
  67. })(jQuery);