const m = require('mithril') const videos = require('./videos') const Authentication = require('./authentication') const lang = require('./lang') const Menu = { oninit: function(vnode) { this.currentActive = 'home' this.loading = false this.browsing = true if (!videos.Tree.length) { videos.refreshTree() } this.onbeforeupdate() }, onbeforeupdate: function() { videos.calculateActiveBranches() let currentPath = m.route.get() this.browsing = currentPath === '/' || currentPath === '/browse' || videos.year }, logOut: function() { Authentication.clearToken() m.route.set('/') }, view: function() { let tree = videos.Tree let last = videos.Tree[videos.Tree.length - 1] let hasId = m.route.param('id') return Authentication.currentUser ? [ m('nav', [ m('h4', m(m.route.Link, { href: '/browse' }, lang.header_title /* Filadelfia archival center */)), m('a.change', { onclick: lang.langtoggle }, lang.lang_current), Authentication.currentUser.rank > 10 ? m(m.route.Link, { class: 'upload', href: '/upload' }, lang.upload_goto) // Upload : null, // 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, ] : null }, } module.exports = Menu