dashboard.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. $(document).ready(
  2. function(){
  3. $('.dragbox')
  4. .each(function(){
  5. $(this).hover(function(){
  6. $(this).find('h4').addClass('collapse');
  7. }, function(){
  8. $(this).find('h4').removeClass('collapse');
  9. })
  10. .find('h4').hover(function(){
  11. $(this).find('.configure').css('visibility', 'visible');
  12. }, function(){
  13. $(this).find('.configure').css('visibility', 'hidden');
  14. })
  15. .click(function(){
  16. $(this).siblings('.dragbox-content').toggle();
  17. //Save state on change of collapse state of panel
  18. updateWidgetData();
  19. })
  20. .end()
  21. .find('.configure').css('visibility', 'hidden');
  22. });
  23. $('.column').sortable({
  24. connectWith: '.column',
  25. handle: 'h4',
  26. cursor: 'move',
  27. placeholder: 'placeholder',
  28. forcePlaceholderSize: true,
  29. opacity: 0.4,
  30. start: function(event, ui){
  31. $(ui.item).find('.dragbox-content').toggle();
  32. },
  33. stop: function(){
  34. updateWidgetData();
  35. }
  36. })
  37. .disableSelection();
  38. }
  39. );
  40. function updateWidgetData(){
  41. var items=[];
  42. $('.column').each(function(){
  43. var columnId=$(this).attr('id');
  44. $('.dragbox', this).each(function(i){
  45. var collapsed=0;
  46. if($(this).find('.dragbox-content').css('display')=="none")
  47. collapsed=1;
  48. //Create Item object for current panel
  49. var item={
  50. id: $(this).attr('id'),
  51. collapsed: collapsed,
  52. order : i,
  53. column: columnId
  54. };
  55. //Push item object into items array
  56. items.push(item);
  57. });
  58. });
  59. //Assign items array to sortorder JSON variable
  60. var sortorder={ items: items };
  61. //Pass sortorder variable to server using ajax to save state
  62. $.post('home.php?m=dashboard&p=updateWidgets', 'data='+$.toJSON(sortorder), function(response){
  63. if(response.indexOf("success") < 0){
  64. $("#console").html('<h0><div class="Failed">Failed to update widget order.</div></h0>').hide().fadeIn(1000);
  65. }
  66. });
  67. }