Guest User

Untitled

a guest
Jun 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. //collect all select form fields, set the iterator to 0, instantiate a placeholder for the current time type
  2. var allSelects = $$('div.type-select select');
  3. var iter = 0;
  4. var currentTimeType;
  5.  
  6. $$('a.vacation','a.sick','a.holiday','a.overhead').each(function(anchor,index){
  7.  
  8. if( ! $defined(currentTimeType)) { currentTimeType = anchor.getAttribute('class'); }
  9.  
  10. //while we're still on the current class of anchor, keep iterating
  11. if(currentTimeType == anchor.getAttribute('class'))
  12. {
  13. //add a 'rel' attribute to each of the anchors
  14. anchor.set('rel',iter);
  15.  
  16. iter += 3;
  17. } else {
  18.  
  19. //if we change anchor classes, reset the iterator, set the current time type, and set the 'rel' attribute
  20. //for the current anchor, then increment the iterator for the next pass
  21. iter = 0;
  22. currentTimeType = anchor.getAttribute('class');
  23. anchor.set('rel',iter);
  24. iter += 3;
  25. }
  26.  
  27. //console.log(anchor.getAttribute('class') + " with iterator of " + iter);
  28.  
  29. //add the 'click' event handler
  30. anchor.addEvent('click',function(event){
  31.  
  32. //prevent the browser from trying to load a page or doing something else
  33. event.stop();
  34.  
  35. //get the 'rel' value and convert it to a number for use as an index
  36. var relNumProject = Number(this.getAttribute('rel'));
  37. var relNumCategory = Number(relNumProject + 1);
  38.  
  39. //fill the appropriate form fields for a given anchor
  40. switch(this.getAttribute('class')) {
  41.  
  42. case 'vacation':
  43. //set the appropriate values for 'vacation' in the form fields
  44. allSelects[relNumProject].set('value','909c59fea1803eb7763757781c67e868').fireEvent('change');
  45. allSelects[relNumCategory].set('value','b251b10ca58d3b33a70b366961935c99').fireEvent('change');
  46. break;
  47.  
  48. case 'sick':
  49. //set the appropriate values for 'sick' in the form fields
  50. allSelects[relNumProject].set('value','909c59fea1803eb7763757781c67e868').fireEvent('change');
  51. allSelects[relNumCategory].set('value','b866d5a11b1ea2b5e68e6275d1c9119e').fireEvent('change');
  52. break;
  53.  
  54. case 'holiday':
  55. //set the appropriate values for 'holiday' in the form fields
  56. allSelects[relNumProject].set('value','909c59fea1803eb7763757781c67e868').fireEvent('change');
  57. allSelects[relNumCategory].set('value','039d8e8643935db2d758be8316f08729').fireEvent('change');
  58. break;
  59.  
  60. case 'overhead':
  61. //set the appropriate values for 'overhead' in the form fields
  62. allSelects[relNumProject].set('value','909c59fea1803eb7763757781c67e868').fireEvent('change');
  63. allSelects[relNumCategory].set('value','634b7e0a09f98fbaf36700f3e33c1801').fireEvent('change');
  64. break;
  65.  
  66. }
  67.  
  68. });
  69.  
  70.  
  71. });
Add Comment
Please, Sign In to add comment