This repository has been archived by the owner on Mar 25, 2019. It is now read-only.
/
classify.coffee
168 lines (138 loc) · 4.72 KB
/
classify.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
Spine = require 'spine'
Subject = require 'models/subject'
Classification = require 'models/classification'
Dialog = require 'lib/dialog'
Recent = require 'zooniverse/lib/models/recent'
Favorite = require 'zooniverse/lib/models/favorite'
User = require 'zooniverse/lib/models/user'
UserGroup = require 'models/user_group'
LoginForm = require 'zooniverse/lib/controllers/login_form'
class Classify extends Spine.Controller
elements:
'#classify .galaxy img': 'image'
'.tree .question': 'question'
'.top .buttons .invert': 'invertLink'
'.top .buttons .favorite': 'favoriteLink'
events:
'click #classify .galaxy img': 'toggleInverted'
'click .tree .answer': 'answer'
'click .tree .checkbox': 'checkBox'
'click .top .buttons .help': 'help'
'click .top .buttons .restart': 'restart'
'click .top .buttons .invert': 'toggleInverted'
'click .top .buttons .favorite': 'toggleFavorite'
constructor: ->
super
@classificationCount = 0
$('.example-thumbnail').die('click').live 'click', @showExample
Subject.bind 'fetched', @nextSubject
User.bind 'sign-in', @render
User.bind 'sign-in', @hideLoginPrompt
UserGroup.bind 'participate', @render
Classification.bind 'classified', @loginPrompt
Subject.next()
$('#zooniverse-top-bar-login .buttons button[name="signup"]').unbind('click').bind 'click', @signupPrompt
active: ->
super
@render()
render: =>
return unless @isActive()
if @subject
@html require('views/classify')(@)
else
@html '''
<div id="classify" class="down-for-maintenance hidden">
<p style="text-align: center;">Thanks to all your hard work we've finished classifying everything for now. Please check back soon!</p>
</div>
'''
setTimeout => @$('#classify').removeClass 'hidden'
loginPrompt: =>
unless User.current
@classificationCount += 1
if @classificationCount in [3, 9]
@loginPrompt = new Dialog
template: 'views/login_prompt'
callback: -> @el().remove()
@loginPrompt.show()
new LoginForm el: '.login-prompt .login'
signupPrompt: (ev) =>
@loginPrompt = new Dialog
template: 'views/signup_prompt'
callback: -> @el().remove()
@loginPrompt.show()
loginForm = new LoginForm el: '.login-prompt .login'
loginForm.signUp()
hideLoginPrompt: =>
if User.current and $('.login-prompt:visible')[0]
@loginPrompt.close()
@loginPrompt.el().remove()
nextSubject: =>
@subject = Subject.current
if @subject?
@classification = new Classification subject_id: @subject.id
@render()
setTimeout =>
if @subject?.showInverted() then @toggleInverted()
answer: (ev) =>
answer = $(ev.target).closest '.answer'
id = answer.data 'id'
talk = answer.data 'talk'
if talk
url = "https://talk.galaxyzoo.org/#/subjects/#{ @subject.zooniverse_id }"
window.open url, '_blank'
window.focus()
checks = _ $('.buttons .active.checkbox')
checkIds = checks.collect (check) -> $(check).data('id')
@classification.annotate id, checkIds
@updateQuestion()
ev.preventDefault()
checkBox: (ev) ->
item = $(ev.target).closest('.checkbox')
item.toggleClass 'active'
help: (ev) ->
@helpDialog = new Dialog
template: 'views/help'
quickHide: true
closeButton: true
callback: -> @el().remove()
@helpDialog.question = @classification.question
@helpDialog.show()
ev.preventDefault()
restart: (ev) ->
@classification = new Classification subject_id: @subject.id
@render()
ev.preventDefault()
toggleInverted: (ev) ->
if @image.hasClass 'inverted'
@image.attr 'src', Subject.current.location.standard
else
@image.attr 'src', Subject.current.location.inverted
@invertLink.toggleClass 'active'
@image.toggleClass 'inverted'
toggleFavorite: (ev) ->
@favoriteLink.toggleClass 'active'
@classification.isFavorited = @favoriteLink.hasClass 'active'
ev.preventDefault()
showExample: (ev) =>
dialog = new Dialog
template: 'views/example'
quickHide: true
closeButton: true
dialog.example = $(ev.target).closest('.example-thumbnail').data 'example'
dialog.show()
dialog.el().find('.dialog').css 'height', @helpDialog.el().find('.dialog').height()
ev.preventDefault()
updateQuestion: ->
if @atEnd() or @talkHidden()
@classification.send()
@finish()
else
@question.html require('views/question')(@classification.question)
talkHidden: ->
@classification.question.isTalk() and UserGroup.current?.metadata?.hide_talk
atEnd: ->
!@classification.question
finish: ->
Subject.next()
@nextSubject()
module.exports = Classify