-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset-pomodoro.coffee
45 lines (36 loc) · 1.07 KB
/
set-pomodoro.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
define [
'cs!modules/core'
'rdust!templates/set-pomodoro'
], (Core) ->
SetPomodoroView = Core.Layout.extend
template: 'rdust!templates/set-pomodoro'
id: 'modal'
events:
'click .save': 'save'
'click .cancel': 'cancel'
'click .rate-item': 'setPomo'
initialize: () ->
@model.on 'change', @render, @
return
serialize: () ->
data = @model.toJSON()
data.total_minutes = data.total * 25
data
save: () ->
@model.set({ total: parseInt(@$('.set-pomo').data('value')) }, { validate: true })
if @model.validationError?
@$('#error').html(@model.validationError).show()
else
@remove()
return
cancel: () ->
@remove()
return
setPomo: (e) ->
$el = $(e.target)
$el.siblings().removeClass('set-pomo')
$el.addClass('set-pomo')
@$('.pomo-count').text("#{$el.data('value')} pomidoro")
@$('.pomo-mins').text("#{$el.data('value')*25} minutes")
afterRender: () ->
@$("[data-value='#{@model.get('total')}']").addClass('set-pomo')