I have this jQuery click handler function that has three jobs:
- Set the time interval for the refresh rate
- Change the color on the clicked refresh rate selection
- Callback the tablesort functions to resort the newly loaded data
I'd like to pull out the separate functionality into named functions, but I'm unsure (being a somewhat JS newb) how to do that an achieve the same behavior.
Javascript Code:
$(document).ready(function() {
    $("#refresh-buttons").on("click", "button", function(event) {
        var interval = 0;
        switch(event.target.id)  {
          case "refresh-off" :
                interval = 50000000;
                $(this).parent().children().removeClass("pressed-button");
                $(this).addClass("pressed-button");
                break;
          case "refresh-5-sec" :
              interval = 5000;
              $(this).parent().children().removeClass("pressed-button");
              $(this).addClass("pressed-button");
              break;
          case "refresh-30-sec" :
              interval = 30000;
              $(this).parent().children().removeClass("pressed-button");
              $(this).addClass("pressed-button");
              break;
          case "refresh-60-sec" :
              interval = 60000;
              $(this).parent().children().removeClass("pressed-button");
              $(this).addClass("pressed-button");
              break;
        }
        if (interval != 0)
        {
            clearInterval(intervalId);
            intervalId = setInterval(function(){
                $('#status-tables').load('/dashboard/index #status-tables', function(){
                  $("#workstation-table").tablesorter();
                  $("#report-table1").tablesorter({sortList:[[1,0]]} );
                  $("#report-table2").tablesorter({sortList:[[1,0]]});
                });
            }, interval);
        }
    });
});