in source/static-assets/js/main.js [242:342]
function readFormData () {
// Endpoint Addresses
$('.user-endpoint-input').each(function (address, index) {
var endpointID = ''
if ($(this).data('endpointid')) {
// Existing Endpoint, so update
endpointID = $(this).data('endpointid')
var endpointInput = this
endpoints.forEach(function (endpoint, index) {
if (endpointID === endpoint.Id) {
endpoint.Address = $(endpointInput).val()
}
})
} else if ($(this).val()) {
// New Endpoint, so create new endpoint
var tmpAddress = ''
tmpAddress = $(this).val()
endpoints.push({
Address: tmpAddress,
ChannelType: $(this).data('attribute'),
User: {
UserAttributes: {}
}
})
}
})
// Build temporary attributes object
var tmpAttributes = {}
metadata.attributes.forEach(function (attribute, index) {
tmpAttributes[attribute.id] = []
})
metadata.categories.forEach(function (category, index) {
category.publications.forEach(function (publication, index) {
tmpAttributes[publication.id] = []
})
})
// Textboxes and Dropdowns
$('.user-attribute-input').each(function (attribute, index) {
for (const property in tmpAttributes) {
if ($(this).data('attribute') === property) {
if ($(this).data('inputmask')) {
// We have an input mask so grab unmasked value
tmpAttributes[property].push($(this).inputmask('unmaskedvalue'))
} else {
tmpAttributes[property].push($(this).val())
}
}
}
})
// Radio Buttons
$('.user-attribute-radio').each(function (attribute, index) {
for (const property in tmpAttributes) {
if ($(this).attr('name') === property) {
if ($(this).prop('checked') && tmpAttributes[property].indexOf($(this).val()) < 0) {
tmpAttributes[property].push($(this).val())
}
}
}
})
// Checkboxes
$('.user-attribute-checkbox').each(function (attribute, index) {
for (const property in tmpAttributes) {
if ($(this).attr('name') === property) {
if ($(this).prop('checked')) {
tmpAttributes[property].push($(this).val())
}
}
}
})
// Publications
metadata.categories.forEach(function (category, index) {
category.publications.forEach(function (publication, index) {
$('.publication_' + publication.id).each(function (attribute, index) {
for (const property in tmpAttributes) {
if ($(this).attr('name') === property) {
if ($(this).prop('checked')) {
tmpAttributes[property].push($(this).val())
// If the user opted in to a publication and they were unsubscribed, then set their OptOut flag back to All
var selectedChannel = $(this).val()
endpoints.forEach(function (endpoint, index) {
if(endpoint.ChannelType === selectedChannel) endpoint.OptOut = 'NONE'
})
}
}
}
})
})
})
// Update endpoint Users Attributes
endpoints.forEach(function (endpoint, index) {
endpoint.User.UserAttributes = tmpAttributes
})
}