Files
piratepoet/assets/js/src/settings/reinstall_from_scratch.js
pavel-mailpoet 812c6634ba Mixpanel analytics [MAILPOET-686] (#940)
* Send analytics data to mixpanel

[MAILPOET-686]
2017-06-20 12:20:50 +03:00

43 lines
1.1 KiB
JavaScript

define(
[
'mailpoet'
],
function(
MailPoet
) {
function eventHandler() {
if (confirm(MailPoet.I18n.t('reinstallConfirmation'))) {
MailPoet.trackEvent(
'User has reinstalled MailPoet via Settings',
{'MailPoet Free version': window.mailpoet_version}
);
MailPoet.Modal.loading(true);
MailPoet.Ajax.post({
'api_version': window.mailpoet_api_version,
'endpoint': 'setup',
'action': 'reset'
}).always(function () {
MailPoet.Modal.loading(false);
}).done(function () {
window.location = 'admin.php?page=mailpoet-newsletters';
}).fail(function (response) {
if (response.errors.length > 0) {
MailPoet.Notice.error(
response.errors.map(function (error) {
return error.message;
}),
{scroll: true}
);
}
});
}
return false;
}
var element = document.getElementById('mailpoet_reinstall');
if (element) {
element.addEventListener('click', eventHandler, false);
}
});