Guest User

Untitled

a guest
May 20th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. var Sorter = Class.create({
  2. initialize: function(element,columns){
  3. this.table=element;
  4. this.des=new SortableTable(element,columns);
  5. this.asc= new SortableTableOne(element,columns);
  6. this.initDOMReferences();
  7. this.lastColumnOrder=null;
  8. },
  9. initDOMReferences: function(){
  10. this.handler = this.order.bind(this);
  11. var headerColumns = this.table.down('thead').childElements()[1].childElements();
  12.  
  13. headerColumns.each(function(column,i){
  14. column._id = i+1;
  15. column._orderId = parseInt(((i+1)/2).toFixed(0))-1;
  16. });
  17. this.table.observe('click',this.handler);
  18. },
  19. order: function(e){
  20. var element = e.element();
  21. if('_id' in element){
  22. if (element.className.endsWith('up')){
  23. this.up(element);
  24. }else{
  25. this.down(element);
  26. }
  27. }
  28. },
  29. sortByIndex:function(index){
  30. var i = parseInt(((index)/2).toFixed(0))-1;
  31. if ((index%2) > 0){
  32. this.up(i);
  33. }else{
  34. this.down(i);
  35. }
  36. },
  37. up: function(column){
  38. if (this.shouldSort(column)){
  39. this.des.sort(column._orderId);
  40. this.toggle(this.lastColumnOrder);
  41. this.toggle(column);
  42. this.lastColumnOrder = column;
  43. }
  44. },
  45. down: function(column){
  46. downEvent++;
  47. if (this.shouldSort(column)){
  48. this.asc.sort(column._orderId);
  49. this.toggle(this.lastColumnOrder);
  50. this.toggle(column);
  51. this.lastColumnOrder = column;
  52. }
  53. },
  54. toggle: function(column){
  55. if(column != null){
  56. if (column.className.endsWith('up')){
  57. column.className = (column.className == "selectedup"?"up":"selectedup");
  58. }else{
  59. column.className = (column.className == "selecteddown"?"down":"selecteddown");
  60. }
  61. }
  62. },
  63. shouldSort: function(column){
  64. var value = false;
  65. if (this.lastColumnOrder == null){
  66. value=true;
  67. }else if ((this.lastColumnOrder._id != column._id)){
  68. value=true;
  69. }
  70. return value;
  71. }
  72. }); //Sorter Class
Add Comment
Please, Sign In to add comment