Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //collect all select form fields, set the iterator to 0, instantiate a placeholder for the current time type
- var allSelects = $$('div.type-select select');
- var iter = 0;
- var currentTimeType;
- $$('a.vacation','a.sick','a.holiday','a.overhead').each(function(anchor,index){
- if( ! $defined(currentTimeType)) { currentTimeType = anchor.getAttribute('class'); }
- //while we're still on the current class of anchor, keep iterating
- if(currentTimeType == anchor.getAttribute('class'))
- {
- //add a 'rel' attribute to each of the anchors
- anchor.set('rel',iter);
- iter += 3;
- } else {
- //if we change anchor classes, reset the iterator, set the current time type, and set the 'rel' attribute
- //for the current anchor, then increment the iterator for the next pass
- iter = 0;
- currentTimeType = anchor.getAttribute('class');
- anchor.set('rel',iter);
- iter += 3;
- }
- //console.log(anchor.getAttribute('class') + " with iterator of " + iter);
- //add the 'click' event handler
- anchor.addEvent('click',function(event){
- //prevent the browser from trying to load a page or doing something else
- event.stop();
- //get the 'rel' value and convert it to a number for use as an index
- var relNumProject = Number(this.getAttribute('rel'));
- var relNumCategory = Number(relNumProject + 1);
- //fill the appropriate form fields for a given anchor
- switch(this.getAttribute('class')) {
- case 'vacation':
- //set the appropriate values for 'vacation' in the form fields
- allSelects[relNumProject].set('value','909c59fea1803eb7763757781c67e868').fireEvent('change');
- allSelects[relNumCategory].set('value','b251b10ca58d3b33a70b366961935c99').fireEvent('change');
- break;
- case 'sick':
- //set the appropriate values for 'sick' in the form fields
- allSelects[relNumProject].set('value','909c59fea1803eb7763757781c67e868').fireEvent('change');
- allSelects[relNumCategory].set('value','b866d5a11b1ea2b5e68e6275d1c9119e').fireEvent('change');
- break;
- case 'holiday':
- //set the appropriate values for 'holiday' in the form fields
- allSelects[relNumProject].set('value','909c59fea1803eb7763757781c67e868').fireEvent('change');
- allSelects[relNumCategory].set('value','039d8e8643935db2d758be8316f08729').fireEvent('change');
- break;
- case 'overhead':
- //set the appropriate values for 'overhead' in the form fields
- allSelects[relNumProject].set('value','909c59fea1803eb7763757781c67e868').fireEvent('change');
- allSelects[relNumCategory].set('value','634b7e0a09f98fbaf36700f3e33c1801').fireEvent('change');
- break;
- }
- });
- });
Add Comment
Please, Sign In to add comment