/
todolist.coffee
60 lines (49 loc) · 1.41 KB
/
todolist.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
module.exports = ->
@Widgets = @Widgets || {}
World = this
@Widgets.TodoList = @Widget.List.extend
root: "#todo-list"
length: ->
@items().then (i) -> i.length
edit: (index) ->
@at(index).then (widget) ->
widget.doubleClick()
complete: (index) ->
@clickAt({
selector: "input",
index: index
})
checkEachClass: (className) ->
@map( (item) =>
item.isVisible().then (vis) ->
item.hasClass(className)
)
isEditing: (index) ->
@at(index).then (el) ->
el.hasClass("editing")
isCompleted: (index) ->
@at(index).then (el) ->
el.hasClass("completed")
isChecked: (index) ->
@at(index).then (el) ->
el.getAttribute({
selector: ".toggle",
attribute: "checked"
})
checkButtonVisibility: (index, button) ->
@at(index).then (widget) ->
widget.isVisible({
selector: button
})
clearAll: ->
toggle = new World.Widgets.ToggleAll()
@isVisible().then (visible) =>
if(visible)
toggle.isVisible().then (vis) =>
if(vis)
toggle.isChecked().then (atr) =>
if(!atr)
toggle.click().then =>
World.Widget.click({selector: "#clear-completed"})
else
World.Widget.click({selector: "#clear-completed"})