Files
piratepoet/assets/js/src/settings/reinstall_from_scratch.js
Amine Ben hammou 3dd8a973fd ES5 vars-on-top
2017-10-09 11:15:58 +00:00

44 lines
1.1 KiB
JavaScript

define(
[
'mailpoet'
],
function (
MailPoet
) {
var element;
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;
}
element = document.getElementById('mailpoet_reinstall');
if (element) {
element.addEventListener('click', eventHandler, false);
}
});