houdini/client/js/campaigns/show/gift-option-list.js
Bradley M. Kuhn fc77ee76d6 Relicense Javascript code in accordance with project's new license
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.
2018-03-25 15:10:40 -04:00

82 lines
2.5 KiB
JavaScript

// License: LGPL-3.0-or-later
const h = require('snabbdom/h')
const flyd = require('flyd')
const R = require('ramda')
const request = require('../../common/request')
const format = require('../../common/format')
const branding = require('../../components/nonprofit-branding')
flyd.mergeAll = require('flyd/module/mergeall')
const quantityLeft = require('./gift-option-quantity-left')
const giftButton = require('./gift-option-button')
// Pass in a stream that has a value when the gift options need to be refreshed, so we know when to refresh em!
function init(giftsNeedRefresh$, parentState) {
var state = {
timeRemaining$: parentState.timeRemaining$
, clickOption$: flyd.stream()
, openEditGiftModal$: flyd.stream()
}
// XXX some legacy viewscript mixed in here
flyd.map(gift => {
appl.open_modal('giftOptionFormModal')
appl.def('gift_options', {current: gift, is_updating: true})
appl.def('gift_option_action', 'Edit')
}, state.openEditGiftModal$)
const pageloadGifts$ = index()
const refreshedGifts$ = flyd.flatMap(index, giftsNeedRefresh$)
state.giftOptions$ = flyd.mergeAll([
pageloadGifts$
, refreshedGifts$
, flyd.stream([]) // default before ajax loads
])
return state
}
function index() {
const path = `/nonprofits/${app.nonprofit_id}/campaigns/${app.campaign_id}/campaign_gift_options`
return flyd.map(
req => req.body.data
, request({path, method: 'get'}).load
)
}
function view(state) {
return h('aside.sideGifts.u-marginBottom--15', {
class: {'u-hide': !state.giftOptions$().length}
}, R.map(giftBox(state), state.giftOptions$())
)
}
const giftBox = state => gift => {
return h('section.u-relative', [
h('div.sideGift.pastelBox--grey--dark', [
h('h5.u-marginTop--0', gift.name)
, totalContributions(gift)
, quantityLeft(gift)
, h('p.u-marginBottom--15', gift.description)
, h('div', [ giftButton(state, gift) ])
])
, app.current_campaign_editor // Show edit button only if the current user is a campaign editor
? h('button.button--tiny.absolute.edit.hasShadow', {
on: {click: ev => state.openEditGiftModal$(gift)}
}, [
h('i.fa.fa-pencil')
, ' Edit Gift'
])
: '' // do not show gift edit button
])
}
const totalContributions = gift => {
if(gift.hide_contributions) return ''
return h('p', [
h('i.fa.fa-star', { style: { color: branding.base} })
, ` ${format.numberWithCommas(gift.total_gifts)} Contribution${gift.total_gifts === 1 ? '' : 's'}`
])
}
module.exports = {view, init}