houdini/client/js/nonprofits/donate/page.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

85 lines
2.8 KiB
JavaScript

// License: LGPL-3.0-or-later
require('parsleyjs')
const render = require('ff-core/render')
const donate = require('./wizard')
const snabbdom = require('snabbdom')
const flyd = require('flyd')
const R = require('ramda')
const url = require('url')
const request = require('../../common/request')
const patch = snabbdom.init([
require('snabbdom/modules/eventlisteners')
, require('snabbdom/modules/class')
, require('snabbdom/modules/props')
, require('snabbdom/modules/style')
])
const params = url.parse(location.href, true).query
const params$ = flyd.stream(params)
app.params$ = params$
if(params.campaign_id && params.gift_option_id) {
setGiftOptionParams(params.campaign_id, params.gift_option_id)
}
// Listen to postMessages to change params
window.addEventListener('message', receiveMessage, false)
function receiveMessage(event) {
var ps
try { ps = JSON.parse(event.data) }
catch(e) {}
if(ps && ps.sender === 'commitchange') {
if (ps.command) {
var event = new CustomEvent('message:'+ps.command,{data:ps});
container.dispatchEvent(event);
}
if(ps.command === 'setDonationParams') {
params$(ps)
// Fetch the gift option data if they passed a gift option id
if(ps.campaign_id && ps.gift_option_id) {
setGiftOptionParams(ps.campaign_id, ps.gift_option_id)
}
}
}
}
// Given a gift option id, make a request to get its full data and set the other params accordingly
function setGiftOptionParams(campaign_id, gift_id) {
flyd.map(
resp => {
if(resp.status !== 200) return
var gift_option = resp.body.data
var params = params$()
params.gift_option = gift_option
params.single_amount = (gift_option.amount_one_time || gift_option.amount_recurring) / 100
if(params.type === 'recurring' && gift_option.amount_recurring) {
params.single_amount = gift_option.amount_recurring / 100
} else if(!gift_option.amount_one_time && gift_option.amount_recurring) {
params.type = 'recurring'
} else if(params.type === 'recurring' && !gift_option.amount_recurring) {
params.type = undefined
}
params$(params)
}
, request({
method: 'get'
, path: `/nonprofits/${ENV.nonprofitID}/campaigns/${campaign_id}/campaign_gift_options/${gift_id}`
}).load
)
}
var state = donate.init(params$)
var container = document.querySelector('.js-donateForm')
if(app.nonprofit.plan_tier > 0) {
$(".donationWizard").trigger("render:pre");
var event = new CustomEvent('render:pre');
container.parentNode.dispatchEvent(event);
render({patch, view: donate.view, state, container})
jQuery(function($){
$(".donationWizard").trigger("render:post").addClass("displayed-updated");
});
// event = new CustomEvent('render:post');
// container.parentNode.dispatchEvent(event);
}