Created
April 4, 2011 23:22
-
-
Save stevecastaneda/902691 to your computer and use it in GitHub Desktop.
Before the refactor...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Detach the task from it's current location and save to var task | |
var task = null; | |
task = $("#task_<%= @task.id %>").detach(); | |
// Was this the last task for one of the sections? | |
// If so, remove the header and spacer (remove), add no-tasks span if today | |
if($("#tasks_today > div.task").length == 0) { | |
if($("#tasks_today").children("div").children("span").length == 0) { | |
$("#tasks_today > hr").before('<div class="span-7 last"><span>Nothing to do. <%= link_to "Bored?", "#", :id => "bored_link" %></span></div>'); | |
} | |
} | |
if($("#tasks_tomorrow > div.task").length == 0) { | |
$("#tasks_tomorrow h6").remove(); | |
$("#tasks_tomorrow > hr").remove(); | |
} | |
if($("#tasks_this_week > div.task").length == 0) { | |
$("#tasks_this_week h6").remove(); | |
$("#tasks_this_week > hr").remove(); | |
} | |
if($("#tasks_next_week > div.task").length == 0) { | |
$("#tasks_next_week h6").remove(); | |
$("#tasks_next_week > hr").remove(); | |
} | |
if($("#tasks_later > div.task").length == 0) { | |
$("#tasks_later h6").remove(); | |
$("#tasks_later > hr").remove(); | |
} | |
// In what section does the task need to be added back into? (id of parent div) | |
<% if @task.due_date <= Date.today %> | |
var id = "#tasks_today"; | |
var desc = null; | |
<% elsif @task.due_date == Date.tomorrow %> | |
var id = "#tasks_tomorrow"; | |
var desc = "Tomorrow"; | |
<% elsif @task.due_date > Date.tomorrow && @task.due_date <= Date.today.end_of_week %> | |
var id = "#tasks_this_week"; | |
var desc = "This Week"; | |
<% elsif @task.due_date > Date.today.end_of_week && @task.due_date <= Date.today.end_of_week.advance(:days => 7) %> | |
var id = "#tasks_next_week"; | |
var desc = "Next Week"; | |
<% else %> | |
var id = "#tasks_later"; | |
var desc = "Beyond a Week"; | |
<% end %> | |
// Is this the first task for this new section? | |
<% if @task.due_date <= Date.today %> | |
// Remove the no-task span if it's for today | |
$("#tasks_today").children("div").children("span").parent().remove(); | |
<% else %> | |
// Else just add the h6 and hr spacer to prep for the new task | |
if($(id).children("div.task").length == 0) { | |
$(id).append("<h6>" + desc + "</h6>"); | |
$(id).append('<hr class="space" />'); | |
} | |
<% end %> | |
// Add the task saved in var task back into the right section | |
$(id).children("hr").before(task); | |
// Reload the task partial to show updated days until or overdue description | |
$("#task_<%= @task.id %>").html("<%= escape_javascript(render(:partial => 'tasks/task', :locals => {:task => @task }))%>") | |
// Add or remove the overdue class as needed | |
<% if @task.due_date < Date.today %> | |
$("#task_<%= @task.id %>").addClass("overdue"); | |
<% else %> | |
$("#task_<%= @task.id %>").removeClass("overdue"); | |
<% end %> | |
// Highlight the task that was just moved | |
$("#task_<%= @task.id %>").effect("highlight", {}, 1250); | |
// Delete task just in case | |
task = null; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment