fc77ee76d6
The primary license of the project is changing to: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later The Additional Permission is designed to permit publicly distributed Javascript code to be relicensed under LGPL-3.0-or-later, but not server-side Javascript code. As such, we've relicensed here static Javscript files under LGPL-3.0-or-later, and those that run as part of build and/or server side under AGPL-3.0-or-later. Note that in future, Javascript files may be updated to be stronger copyleft license with the Additional Permission, particularly if they adapted to run on server side and/or turned into templates. Of course, we'd seek public discussion with the contributor community about such changes. This commit is one of the many steps to relicense the entire codebase. Documentation granting permission for this relicensing (from all past contributors who hold copyrights) is on file with Software Freedom Conservancy, Inc.
105 lines
2.7 KiB
JavaScript
105 lines
2.7 KiB
JavaScript
// License: LGPL-3.0-or-later
|
|
const R = require('ramda')
|
|
const flyd = require('flyd')
|
|
const h = require('snabbdom/h')
|
|
const format = require('../../common/format')
|
|
const branding = require('../../components/nonprofit-branding')
|
|
|
|
// This is the box currently at the top right that shows some big metrics for
|
|
// the campaign, a big Contribute button (if enabled to show), days remaining
|
|
// (and a "campaign is done" message if no days remaining)
|
|
|
|
function init(parentState) {
|
|
var state = {
|
|
clickContribute$: flyd.stream()
|
|
, timeRemaining$: parentState.timeRemaining$
|
|
, metrics$: parentState.metrics$
|
|
, loading$: parentState.loadingMetrics$
|
|
}
|
|
|
|
return state
|
|
}
|
|
|
|
|
|
function view(state) {
|
|
return h('div.pastelBox--grey--dark.u-relative.u-marginBottom--15.u-padding--15', [
|
|
metrics(state)
|
|
, endedMessage(state)
|
|
, progressBar(state)
|
|
, contributeButton(state)
|
|
])
|
|
}
|
|
|
|
const metrics = state => {
|
|
return h('div.campaignMetrics', [
|
|
totalSupporters(state)
|
|
, totalRaised(state)
|
|
, daysLeft(state)
|
|
])
|
|
}
|
|
|
|
const totalSupporters = state => {
|
|
if(!app.campaign.show_total_count) return ''
|
|
return h('div', [
|
|
h('h4', [
|
|
state.loading$() ? h('i.fa.fa-spin.fa-spinner') : format.numberWithCommas(state.metrics$().supporters_count)
|
|
])
|
|
, h('p', 'supporters')
|
|
])
|
|
}
|
|
|
|
const totalRaised = state => {
|
|
if(!app.campaign.show_total_raised) return ''
|
|
return h('div', [
|
|
h('h4', [
|
|
state.loading$() ? h('i.fa.fa-spin.fa-spinner') : '$' + format.centsToDollars(state.metrics$().total_raised, {noCents: true})
|
|
])
|
|
, h('p', [
|
|
'raised'
|
|
, app.campaign.hide_goal
|
|
? ''
|
|
: ' of $' + format.centsToDollars(app.campaign.goal_amount) + ' goal'
|
|
])
|
|
])
|
|
}
|
|
|
|
const daysLeft = state => {
|
|
if(!state.timeRemaining$()) return ''
|
|
return h('div', [
|
|
h('h4', state.timeRemaining$())
|
|
, h('p', 'remaining')
|
|
])
|
|
}
|
|
|
|
const endedMessage = state => {
|
|
if(state.timeRemaining$()) return ''
|
|
return h('p', [
|
|
`This campaign has ended, but you can still contribute by clicking the button below.`
|
|
])
|
|
}
|
|
|
|
const progressBar = state => {
|
|
if(app.campaign.hide_thermometer) return ''
|
|
return h('div.progressBar--medium.u-marginBottom--15', [
|
|
h('div.progressBar--medium-fill', {
|
|
style: {
|
|
width: R.clamp(1,100, format.percent(
|
|
state.metrics$().goal_amount
|
|
, state.metrics$().total_raised
|
|
) + '%')
|
|
, 'background-color': branding.light
|
|
, transition: 'width 1s'
|
|
}
|
|
})
|
|
])
|
|
}
|
|
|
|
const contributeButton = state => {
|
|
return h('a.js-contributeButton.button--jumbo.u-width--full', {
|
|
style: {'background-color': branding.base}
|
|
, on: {click: state.clickContribute$}
|
|
}, [ 'Contribute' ])
|
|
}
|
|
|
|
module.exports = { init, view }
|
|
|