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.
67 lines
2.1 KiB
JavaScript
67 lines
2.1 KiB
JavaScript
// License: LGPL-3.0-or-later
|
|
const R = require('ramda')
|
|
const h = require('snabbdom/h')
|
|
const flyd = require('flyd')
|
|
const render = require('ff-core/render')
|
|
const request = require('../common/request')
|
|
const snabbdom = require('snabbdom')
|
|
const flyd_lift = require('flyd/module/lift')
|
|
const flyd_mergeAll = require('flyd/module/mergeall')
|
|
const url = require('url')
|
|
|
|
// TODO move this into sub-component in the future
|
|
const mailchimpModal = require('./settings/mailchimp-integration-settings')
|
|
|
|
// This is the root component for the supporters dashboard/CRM, found on /nonprofits/:nonprofit_id/supporters
|
|
|
|
function init() {
|
|
var state = { }
|
|
var thisUrl = url.parse(location.href, true)
|
|
const mailchimpSyncClick$ = getMailchimpClickSync()
|
|
const mailchimpKeyResp$ = request({method: 'get', path: `/nonprofits/${app.nonprofit_id}/nonprofit_keys`, query: {select: 'mailchimp_token'}}).load
|
|
const hasKey$ = flyd.filter(resp => resp.status === 200, mailchimpKeyResp$)
|
|
const modalID$ = flyd_mergeAll([
|
|
flyd_lift(openModalOrAuth, mailchimpSyncClick$, mailchimpKeyResp$)
|
|
, flyd.map(()=> thisUrl.query['show-modal'], hasKey$)
|
|
])
|
|
state.mailchimpModal = mailchimpModal.init(modalID$)
|
|
return state
|
|
}
|
|
|
|
// Either return the modal ID to open, or redirect the page to the mailchimp oauth screen
|
|
const openModalOrAuth = (ev, resp) => {
|
|
if(resp.status === 200) {
|
|
return 'mailchimpSettingsModal'
|
|
} else {
|
|
window.location.href = `/nonprofits/${app.nonprofit_id}/nonprofit_keys/mailchimp_login`
|
|
return null
|
|
}
|
|
}
|
|
|
|
const getMailchimpClickSync = () => {
|
|
const s = flyd.stream()
|
|
document.querySelector('.js-openMailchimpModal')
|
|
.addEventListener('click', ev => {appl.close_modal(); s(ev)})
|
|
return s
|
|
}
|
|
|
|
|
|
function view(state) {
|
|
return h('div', [
|
|
mailchimpModal.view(state.mailchimpModal)
|
|
])
|
|
}
|
|
|
|
|
|
// -- Render to the page
|
|
|
|
var container = document.querySelector('#js-main')
|
|
const patch = snabbdom.init([
|
|
require('snabbdom/modules/eventlisteners')
|
|
, require('snabbdom/modules/class')
|
|
, require('snabbdom/modules/props')
|
|
, require('snabbdom/modules/style')
|
|
])
|
|
var state = init()
|
|
render({patch, view, state, container})
|
|
|