Phase 6 part 5, step 1: a shared site theme
internal/theme embeds a Hugo theme from federated-website's look and the 13 section types both sites share, with the header, footer, colors, font and logo set per site in hugo.toml, and a README of each type's fields. The catalogue reader reads themes' sections and READMEs after the site's own; lead forms know a theme site needs only the Lead Capture address. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/* Sends the site's lead forms to EspoCRM's Lead Capture. Written by
|
||||
Supermarket: the form posts here instead of to [params.leads] action
|
||||
directly, so its fields can be mapped onto a Lead's. */
|
||||
(function () {
|
||||
var mapped = { email: 'emailAddress', 'e-mail': 'emailAddress', phone: 'phoneNumber', tel: 'phoneNumber',
|
||||
company: 'accountName', organization: 'accountName', organisation: 'accountName', church: 'accountName' };
|
||||
function label(form, name) {
|
||||
var el = form.querySelector('[name="' + name + '"]');
|
||||
var l = el && el.id && form.querySelector('label[for="' + el.id + '"]');
|
||||
return l ? l.childNodes[0].textContent.trim() : name;
|
||||
}
|
||||
window.leadPost = function (form, data) {
|
||||
var lead = { firstName: null, lastName: null, emailAddress: null, accountName: null, phoneNumber: null };
|
||||
var notes = [];
|
||||
data.forEach(function (value, name) {
|
||||
value = String(value).trim();
|
||||
if (!value) return;
|
||||
var key = name.toLowerCase();
|
||||
if (key === 'name' || key === 'full_name' || key === 'fullname') {
|
||||
var parts = value.split(/\s+/);
|
||||
lead.lastName = parts.pop();
|
||||
lead.firstName = parts.length ? parts.join(' ') : null;
|
||||
} else if (key === 'first_name' || key === 'firstname') {
|
||||
lead.firstName = value;
|
||||
} else if (key === 'last_name' || key === 'lastname') {
|
||||
lead.lastName = value;
|
||||
} else if (mapped[key]) {
|
||||
lead[mapped[key]] = value;
|
||||
} else if (key === 'source') {
|
||||
notes.unshift('Form: ' + value);
|
||||
} else if (key === 'page') {
|
||||
notes.push('Page: ' + location.origin + value);
|
||||
} else {
|
||||
notes.push(label(form, name) + ': ' + value);
|
||||
}
|
||||
});
|
||||
if (!lead.lastName) lead.lastName = lead.emailAddress || 'Website visitor';
|
||||
var q = new URLSearchParams(location.search);
|
||||
['utm_campaign', 'utm_source', 'utm_medium', 'utm_content'].forEach(function (k) {
|
||||
if (q.get(k)) notes.push(k + ': ' + q.get(k));
|
||||
});
|
||||
if (document.referrer) notes.push('Came from: ' + document.referrer);
|
||||
lead.description = notes.join('\n') || null;
|
||||
return fetch(form.action, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
||||
body: JSON.stringify(lead)
|
||||
});
|
||||
};
|
||||
})();
|
||||
Reference in New Issue
Block a user