nfp_sites/filadelfia_web/app/header.js

74 lines
2.6 KiB
JavaScript
Raw Normal View History

2023-11-09 09:44:04 +00:00
const m = require('mithril')
const videos = require('./videos')
const Authentication = require('./authentication')
2023-11-15 04:43:05 +00:00
const lang = require('./lang')
2023-11-09 09:44:04 +00:00
const Menu = {
oninit: function(vnode) {
this.currentActive = 'home'
this.loading = false
2023-11-20 07:12:08 +00:00
this.browsing = true
if (!videos.Tree.length) {
videos.refreshTree()
}
2023-11-09 09:44:04 +00:00
this.onbeforeupdate()
},
onbeforeupdate: function() {
2023-11-20 07:12:08 +00:00
videos.calculateActiveBranches()
2023-11-09 09:44:04 +00:00
let currentPath = m.route.get()
2023-11-20 07:12:08 +00:00
this.browsing = currentPath === '/' || currentPath === '/browse' || videos.year
2023-11-09 09:44:04 +00:00
},
logOut: function() {
Authentication.clearToken()
m.route.set('/')
},
view: function() {
2023-11-20 07:12:08 +00:00
let tree = videos.Tree
let last = videos.Tree[videos.Tree.length - 1]
let hasId = m.route.param('id')
2023-11-09 09:44:04 +00:00
return Authentication.currentUser
? [
m('nav', [
2023-11-15 04:43:05 +00:00
m('h4', m(m.route.Link, { href: '/browse' }, lang.header_title /* Filadelfia archival center */)),
m('a.change', { onclick: lang.langtoggle }, lang.lang_current),
2023-11-09 09:44:04 +00:00
Authentication.currentUser.rank > 10
2023-11-15 04:43:05 +00:00
? m(m.route.Link, { class: 'upload', href: '/upload' }, lang.upload_goto) // Upload
2023-11-09 09:44:04 +00:00
: null,
2023-11-20 07:12:08 +00:00
// m('button.logout', { onclick: this.logOut }, lang.header_logout), // Log out
]),
!this.browsing && videos.error
? m('div.error', { onclick: videos.refreshTree }, [
videos.error, m('br'), 'Click here to try again'
])
: null,
this.browsing && !videos.error
? [
m('.nav', m('.inner', tree.map(year => {
return m(m.route.Link, {
class: [videos.year === year ? 'active' : '',
!year.videos.length ? 'empty' : ''].join(' '),
href: ['', (videos.year !== year && year !== last) || hasId ? year.title : 'browse' ].filter(x => x).join('/'),
}, year.title)
}))),
videos.year
? m('.nav', m('.inner', videos.year.branches.map(month => {
return m(m.route.Link, {
class: [videos.month === month ? 'active' : '',
!month.videos.length ? 'empty' : ''].join(' '),
href: ['', videos.year.title, videos.month !== month || hasId ? month.title : null ].filter(x => x).join('/'),
}, lang.months[month.title])
})))
: null,
]
: null,
2023-11-09 09:44:04 +00:00
]
: null
},
}
module.exports = Menu