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.
86 lines
2.6 KiB
JavaScript
86 lines
2.6 KiB
JavaScript
// License: LGPL-3.0-or-later
|
|
const R = require('ramda')
|
|
const h = require('snabbdom/h')
|
|
const flyd = require('flyd')
|
|
const modal = require('ff-core/modal')
|
|
const button = require('ff-core/button')
|
|
const request = require('../../common/request')
|
|
const serialize = require('form-serialize')
|
|
const notification = require('ff-core/notification')
|
|
const flyd_flatMap = require('flyd/module/flatmap')
|
|
const flyd_mergeAll = require('flyd/module/mergeall')
|
|
|
|
function init(modalID$) {
|
|
const pathPrefix = `/nonprofits/${app.nonprofit_id}`
|
|
var state = {
|
|
submitForm$: flyd.stream()
|
|
, tagMasters$: flyd.map(R.prop('body'), request({method: 'get', path: pathPrefix + '/tag_masters'}).load)
|
|
}
|
|
|
|
const emailLists$ = flyd.map(R.prop('body'), request({method: 'get', path: pathPrefix + '/email_lists'}).load)
|
|
state.selectedTagMasterIds$ = flyd.map(R.map(ls => ls.tag_master_id), emailLists$)
|
|
|
|
const response$ = flyd_flatMap(
|
|
form => request({
|
|
method: 'post'
|
|
, path: `/nonprofits/${app.nonprofit_id}/email_lists`
|
|
, send: {tag_masters: serialize(form, {hash: true})}
|
|
}).load
|
|
, state.submitForm$ )
|
|
|
|
state.loading$ = flyd_mergeAll([
|
|
flyd.map(()=> false, response$)
|
|
, flyd.map(()=> true, state.submitForm$)
|
|
])
|
|
|
|
state.modalID$ = flyd_mergeAll([
|
|
modalID$
|
|
, flyd.map(()=> null, response$)
|
|
])
|
|
|
|
const message$ = flyd_mergeAll([
|
|
flyd.map(()=> 'Tags successfully synced! Your email lists should show on MailChimp within 5-10 minutes', response$)
|
|
])
|
|
state.notification = notification.init({message$})
|
|
|
|
return state
|
|
}
|
|
|
|
|
|
function view(state) {
|
|
var body = h('form', {on: {submit: ev => {ev.preventDefault(); state.submitForm$(ev.currentTarget)}}}, [
|
|
h('p', "You're connected on Mailchimp. Choose the tags that you want to keep in sync with your Mailchimp Email Lists.")
|
|
, h('hr')
|
|
, h('div.fields',
|
|
R.map(
|
|
tm => h('fieldset', [
|
|
h('input', {
|
|
props: {
|
|
type: 'checkbox'
|
|
, name: tm.name
|
|
, value: tm.id
|
|
, id: `mailchimpCheckbox--${tm.id}`
|
|
, checked: (state.selectedTagMasterIds$()||[]).indexOf(tm.id) !== -1
|
|
}
|
|
})
|
|
, h('label', {props: {htmlFor: `mailchimpCheckbox--${tm.id}`}}, tm.name)
|
|
])
|
|
, (state.tagMasters$() || {data: []}).data )
|
|
)
|
|
, h('hr')
|
|
, h('div.u-centered', [
|
|
button({loading$: state.loading$})
|
|
])
|
|
])
|
|
return h('div', [
|
|
modal({
|
|
thisID: 'mailchimpSettingsModal'
|
|
, id$: state.modalID$
|
|
, title: 'MailChimp Sync'
|
|
, body
|
|
})
|
|
, notification.view(state.notification)
|
|
])
|
|
}
|
|
|
|
module.exports = {view, init}
|