forked from ovity/octotree
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.error.js
More file actions
49 lines (41 loc) · 1.21 KB
/
Copy pathview.error.js
File metadata and controls
49 lines (41 loc) · 1.21 KB
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
class ErrorView {
constructor($dom, store) {
this.store = store
this.$view = $dom
.find('.octotree_errorview')
.submit(this._saveToken.bind(this))
}
show(err) {
const $token = this.$view.find('input[name="token"]')
const $submit = this.$view.find('button[type="submit"]')
const $help = $submit.next()
const token = this.store.get(STORE.TOKEN)
this.$view.find('.octotree_view_header').html(err.error)
this.$view.find('.message').html(err.message)
if (err.needAuth) {
$submit.show()
$token.show()
$help.show()
if (token) $token.val(token)
}
else {
$submit.hide()
$token.hide()
$help.hide()
}
$(this).trigger(EVENT.VIEW_READY)
}
_saveToken(event) {
event.preventDefault()
const $error = this.$view.find('.error').text('')
const $token = this.$view.find('[name="token"]')
const oldToken = this.store.get(STORE.TOKEN)
const newToken = $token.val()
if (!newToken) return $error.text('Token is required')
this.store.set(STORE.TOKEN, newToken, () => {
const changes = {[STORE.TOKEN]: [oldToken, newToken]}
$(this).trigger(EVENT.OPTS_CHANGE, changes)
$token.val('')
})
}
}