tou_schedule_months.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. $(document).ready(function(){
  2. ///////////////////////////////////////////////
  3. // General Setup //////////////////////////////
  4. $('.summer-month-range-selection').show();
  5. $('.month-fields').hide();
  6. var first_month_of_summer = parseInt($('#date_first_month_of_summer').val(), 10);
  7. var last_month_of_summer = parseInt($('#date_last_month_of_summer').val(), 10);
  8. disable_inappropriate_select_options(first_month_of_summer, last_month_of_summer);
  9. ///////////////////////////////////////////////
  10. // When Summer Range Select Changes ///////////
  11. $('.summer-range-select').change(function(){
  12. var first_month_of_summer = parseInt($('#date_first_month_of_summer').val(), 10);
  13. var last_month_of_summer = parseInt($('#date_last_month_of_summer').val(), 10);
  14. set_months_season_values(first_month_of_summer, last_month_of_summer);
  15. disable_inappropriate_select_options(first_month_of_summer, last_month_of_summer);
  16. });
  17. ///////////////////////////////////////////////
  18. // Available Named Functions //////////////////
  19. function set_months_season_values(first_month, last_month){
  20. for (var i = 1; i <= 12; i++) {
  21. if (first_month <= i && i <= last_month) {
  22. season_value = 'summer'
  23. } else {
  24. season_value = 'winter'
  25. }
  26. i = (i < 10)?("0"+i):i; // Add leading zero to values under 10
  27. $("#tou_schedule_month_"+ i +"_season").val(season_value);
  28. }
  29. }
  30. // // // // // // // // // // // // // //
  31. function disable_inappropriate_select_options(first_month_number, last_month_number){
  32. //alert("Disable inappropriate select options.");
  33. $('#date_first_month_of_summer > option').each(function() {
  34. if ( this.value > last_month_number ) {
  35. $(this).attr('disabled','disabled')
  36. } else {
  37. $(this).removeAttr('disabled')
  38. }
  39. });
  40. $('#date_last_month_of_summer > option').each(function() {
  41. if ( this.value < first_month_number ) {
  42. $(this).attr('disabled','disabled')
  43. } else {
  44. $(this).removeAttr('disabled')
  45. }
  46. });
  47. }
  48. });