Permalink
Browse files

When a pomodoro is running, add the ability to reset the timer. This …

…marks the current pomodoro as a reset pomodoro (failed).
  • Loading branch information...
Marc Jeanson
Marc Jeanson committed Jan 25, 2012
1 parent 628fa63 commit 33cee7367dc4720764c6b3c6208260ec81668f17
@@ -27,3 +27,9 @@ window.pomodoro_timer = (activity_id, pomodoro_id, time_in_seconds) ->
$.ajax
url: '/activities/' + activity_id + '/pomodoros/' + pomodoro_id + '/complete.js'
type: 'PUT'
+
+window.reset_pomodoro_timer = (time_in_seconds) ->
+ $("#reset_timer").html ""
+ $("#timer").resetTimer
+ time_in_seconds: time_in_seconds
+ autostart: false
@@ -11,6 +11,11 @@ def complete
@pomodoro.complete!
end
+ def reset
+ @pomodoro = @activity.pomodoros.find(params[:id])
+ @pomodoro.reset!
+ end
+
private
def find_activity
@activity = Activity.find params[:activity_id]
View
@@ -6,4 +6,8 @@ class Pomodoro < ActiveRecord::Base
def complete!
self.update_attribute :completed_at, Time.now
end
+
+ def reset!
+ self.update_attribute :reset_at, Time.now
+ end
end
@@ -0,0 +1 @@
+= link_to t('navigation.reset_pomodoro'), reset_activity_pomodoro_path(activity_id: activity_id, id: pomodoro_id), remote: true, method: :put
@@ -1 +1,4 @@
div id="timer"
+div id="reset_timer"
+ - if @pomodoro
+ == render 'activities/reset_link', locals: { activity_id: @pomodoro.activity.id, pomodoro_id: @pomodoro.id }
@@ -0,0 +1 @@
+$("#reset_timer").html ""
@@ -1 +1,2 @@
pomodoro_timer(<%= @activity.id %>, <%= @pomodoro.id %>, 1500)
+$("#reset_timer").html "<%= escape_javascript(render partial: 'activities/reset_link', locals: { activity_id: @pomodoro.activity.id, pomodoro_id: @pomodoro.id }) %>"
@@ -0,0 +1 @@
+reset_pomodoro_timer(1500)
View
@@ -7,6 +7,7 @@ en:
edit_activity: "Edit"
delete_activity: "Delete"
start_pomodoro: "Start"
+ reset_pomodoro: "Reset"
flash:
notices:
activity_created: "The Activity was created"
View
@@ -4,6 +4,7 @@
resources :pomodoros do
member do
put 'complete'
+ put 'reset'
end
end
end

0 comments on commit 33cee73

Please sign in to comment.