Controllers.prototype.manageIFASegment = (function() { const template = `

Segment name:


Segments list (.csv only):


`; return newSegment; function newSegment(core, e, data, returnCB, segID) { return new Segment(core, e, data, returnCB, segID); } function Segment(core, e, data, returnCB, segID) { let em = new EventManager(), container = null, form = null, fe = null; // yes it's a hack. init({name: window['__ifa_seg_name'] || ''}); delete window['__ifa_seg_name']; this.exit = exit; function init(inbound) { container = document.createElement('div'); container.classList.add('manageProximity'); form = getElementFromString(render(template, inbound)); fe = form.querySelector('form'); fe.onsubmit = saveAction; container.appendChild(form); e.appendChild(container); returnCB(); } function saveAction(e) { preventDefault(e); const xhr = new XMLHttpRequest(), method = !!segID ? 'PUT' : 'POST', ep = '/api/v1/segments/ifa/' + (!!segID ? segID : core.userID); // Add any event handlers here... xhr.onload = () => responseAction(JSON.parse(xhr.response), xhr.status); xhr.open(method, ep, true); xhr.send(new FormData(fe)); } function responseAction(e, s) { console.log(e, s); if (s === 200) { core.notifications.setSuccess('Successfully Saved IFA Segment (ID: ' + e.data + ')'); } else { core.notifications.setErrors(e.errors); return; } pop('Pop!', 'Dashboard - Segments', '/dashboard/segments'); } function exit() { removeChild(e, container); em.reset(); } } function newSaveButton() { var btn = document.createElement('a'); btn.setAttribute('class', 'button mint'); btn.textContent = 'Save'; return btn; } })();