Skip to content

Commit

Permalink
Merge dc24420 into 701bd8f
Browse files Browse the repository at this point in the history
  • Loading branch information
carakas committed May 20, 2019
2 parents 701bd8f + dc24420 commit dffe6d5
Show file tree
Hide file tree
Showing 9 changed files with 359 additions and 24 deletions.
20 changes: 18 additions & 2 deletions src/Backend/Modules/FormBuilder/Actions/Edit.php
Expand Up @@ -83,6 +83,7 @@ private function loadForm(): void
$this->form->addText('textbox_classname');
$this->form->addCheckbox('textbox_required');
$this->form->addCheckbox('textbox_reply_to');
$this->form->addCheckbox('textbox_mailmotor');
$this->form->addText('textbox_required_error_message');
$this->form->addDropdown(
'textbox_validation',
Expand Down Expand Up @@ -190,6 +191,14 @@ private function loadForm(): void
// heading dialog
$this->form->addText('heading');

// mailmotor dialog
$settings = BackendModel::get('fork.settings');
$this->form->addText(
'mailmotor_list_id',
$settings->get('Mailmotor', 'list_id_' . BL::getWorkingLanguage()) ?? $settings->get('Mailmotor', 'list_id')
);
$this->form->addText('mailmotor_label', BL::lbl('MailmotorSubscribeToNewsletter'));

// paragraph dialog
$this->form->addEditor('paragraph');
$this->form->getField('paragraph')->setAttribute('cols', 30);
Expand All @@ -206,13 +215,20 @@ protected function parse(): void

$this->template->assign('id', $this->record['id']);
$this->template->assign('name', $this->record['name']);
$recaptchaSiteKey = BackendModel::get('fork.settings')->get('Core', 'google_recaptcha_site_key');
$recaptchaSecretKey = BackendModel::get('fork.settings')->get('Core', 'google_recaptcha_secret_key');
$settings = BackendModel::get('fork.settings');
$recaptchaSiteKey = $settings->get('Core', 'google_recaptcha_site_key');
$recaptchaSecretKey = $settings->get('Core', 'google_recaptcha_secret_key');
$mailmotorListId = $settings->get('Mailmotor', 'list_id');

if (!($recaptchaSiteKey || $recaptchaSecretKey)) {
$this->template->assign('recaptchaMissing', true);
}

if (BackendModel::isModuleInstalled('Mailmotor')) {
$this->template->assign('showMailmotorOption', !empty($mailmotorListId));
$this->template->assign('mailmotorMailEngine', $settings->get('Mailmotor', 'mail_engine'));
}

// parse error messages
$this->parseErrorMessages();

Expand Down
26 changes: 26 additions & 0 deletions src/Backend/Modules/FormBuilder/Ajax/SaveField.php
Expand Up @@ -36,6 +36,7 @@ public function execute(): void
'textarea',
'textbox',
'recaptcha',
'mailmotor',
]
)) {
$type = '';
Expand All @@ -49,6 +50,7 @@ public function execute(): void
$defaultValues = trim($this->getRequest()->request->get('default_values', ''));
$placeholder = trim($this->getRequest()->request->get('placeholder', ''));
$classname = trim($this->getRequest()->request->get('classname', ''));
$listId = trim($this->getRequest()->request->get('list_id', ''));
$required = $this->getRequest()->request->getBoolean('required');
$requiredErrorMessage = trim($this->getRequest()->request->get('required_error_message', ''));
$validation = $this->getRequest()->request->get('validation');
Expand All @@ -61,6 +63,7 @@ public function execute(): void

// special field for textbox
$replyTo = $this->getRequest()->request->getBoolean('reply_to');
$useToSubscribeWithMailmotor = $this->getRequest()->request->getBoolean('use_to_subscribe_with_mailmotor');
$sendConfirmationMailTo = $this->getRequest()->request->getBoolean('send_confirmation_mail_to');
$confirmationMailSubject = trim($this->getRequest()->request->get('confirmation_mail_subject'));

Expand Down Expand Up @@ -114,6 +117,9 @@ public function execute(): void
if ($replyTo && $validation !== 'email') {
$errors['reply_to_error_message'] = BL::getError('EmailValidationIsRequired');
}
if ($useToSubscribeWithMailmotor && $validation !== 'email') {
$errors['use_to_subscribe_with_mailmotor_error_message'] = BL::getError('ActivateEmailValidationToUseThisOption');
}
if ($sendConfirmationMailTo && $validation !== 'email') {
$errors['send_confirmation_mail_to_error_message'] = BL::getError(
'ActivateEmailValidationToUseThisOption'
Expand Down Expand Up @@ -191,6 +197,20 @@ public function execute(): void
if ($required && $requiredErrorMessage === '') {
$errors['required_error_message'] = BL::getError('ErrorMessageIsRequired');
}
} elseif ($type === 'mailmotor') {
// validate checkbox
if ($label === '') {
$errors['label'] = BL::getError('LabelIsRequired');
}

try {
$mailmotorGateway = $this->getContainer()->get('mailmotor.factory.public')->getSubscriberGateway();
if ($listId === '' || !$mailmotorGateway->ping($listId)) {
$errors['list_id'] = BL::getError('WrongMailEngineCredentials', 'Mailmotor');
}
} catch (\Exception $mailMotorException) {
$errors['list_id'] = BL::getError('WrongMailEngineCredentials', 'Mailmotor');
}
}

// got errors
Expand Down Expand Up @@ -256,6 +276,12 @@ public function execute(): void
$settings['reply_to'] = $replyTo;
$settings['send_confirmation_mail_to'] = $sendConfirmationMailTo;
$settings['confirmation_mail_subject'] = $confirmationMailSubject;
$settings['use_to_subscribe_with_mailmotor'] = $useToSubscribeWithMailmotor;
}

if ($type === 'mailmotor') {
unset($settings['values']);
$settings['list_id'] = $listId;
}

// only for datetime input
Expand Down
42 changes: 42 additions & 0 deletions src/Backend/Modules/FormBuilder/Installer/Data/locale.xml
Expand Up @@ -315,6 +315,48 @@
<translation language="el"><![CDATA[Αποθήκευση στη Βάση δεδομένων και αποστολή email]]></translation>
<translation language="pl"><![CDATA[zapisz w bazie danych i wyślij email]]></translation>
</item>
<item type="label" name="MailmotorListId">
<translation language="de"><![CDATA[list id]]></translation>
<translation language="el"><![CDATA[κατάλογος id]]></translation>
<translation language="en"><![CDATA[list id]]></translation>
<translation language="es"><![CDATA[ID de la lista]]></translation>
<translation language="fr"><![CDATA[list id]]></translation>
<translation language="hu"><![CDATA[lista id]]></translation>
<translation language="it"><![CDATA[lista id]]></translation>
<translation language="lt"><![CDATA[sąrašas ID]]></translation>
<translation language="nl"><![CDATA[list id]]></translation>
<translation language="ru"><![CDATA[список идентификаторов]]></translation>
<translation language="sv"><![CDATA[lista id]]></translation>
<translation language="uk"><![CDATA[список ідентифікаторів]]></translation>
<translation language="zh"><![CDATA[列表ID]]></translation>
<translation language="pl"><![CDATA[ID listy]]></translation>
</item>
<item type="label" name="MailmotorSubscribeToNewsletter">
<translation language="de"><![CDATA[Newsletter abonnieren]]></translation>
<translation language="el"><![CDATA[Εγγραφή στο Newsletter]]></translation>
<translation language="en"><![CDATA[subscribe to newsletter]]></translation>
<translation language="es"><![CDATA[Suscríbete al boletín]]></translation>
<translation language="fr"><![CDATA[s'inscrire à la Newsletter]]></translation>
<translation language="hu"><![CDATA[Feliratkozás a hírlevélre]]></translation>
<translation language="it"><![CDATA[Iscriviti alla Newsletter]]></translation>
<translation language="lt"><![CDATA[Prenumeruoti naujienas]]></translation>
<translation language="nl"><![CDATA[inschrijven op nieuwsbrief]]></translation>
<translation language="ru"><![CDATA[Подписаться на новостную рассылку]]></translation>
<translation language="sv"><![CDATA[Prenumerera på nyhetsbrev]]></translation>
<translation language="uk"><![CDATA[Підписатися на Розсилку]]></translation>
<translation language="zh"><![CDATA[订阅通讯]]></translation>
<translation language="pl"><![CDATA[Zapisz się do newslettera]]></translation>
</item>
<item type="message" name="HelpMailmotor">
<translation language="de"><![CDATA[Verwenden Sie diese E-Mail-Adresse, um sich bei mailmotor anzumelden.]]></translation>
<translation language="en"><![CDATA[Use this email address to subscribe with mailmotor.]]></translation>
<translation language="es"><![CDATA[Utilice esta dirección de correo electrónico para suscribirse con mailmotor.]]></translation>
<translation language="fr"><![CDATA[Utilisez cette adresse email pour vous abonner à mailmotor.]]></translation>
<translation language="it"><![CDATA[Usa questo indirizzo e-mail per iscriverti con Mailmotor.]]></translation>
<translation language="nl"><![CDATA[Gebruik dit e-mailadres om u in te schrijven bij mailmotor.]]></translation>
<translation language="ru"><![CDATA[Используйте этот адрес электронной почты для подписки на рассылку с помощью mailmotor.]]></translation>
<translation language="pl"><![CDATA[Użyj tego adresu e-mail, aby zapisać się do programu Mailmotor.]]></translation>
</item>
<item type="label" name="MethodEmail">
<translation language="nl"><![CDATA[email verzenden]]></translation>
<translation language="en"><![CDATA[send email]]></translation>
Expand Down
86 changes: 85 additions & 1 deletion src/Backend/Modules/FormBuilder/Js/FormBuilder.js
Expand Up @@ -206,7 +206,10 @@ jsBackend.FormBuilder.Fields = {
case 'radiobuttonDialog':
jsBackend.FormBuilder.Fields.saveRadiobutton()
break
case 'checkboxDialog':
case 'mailmotorDialog':
jsBackend.FormBuilder.Fields.saveMailmotorbutton()
break
case 'checkboxDialogcheckboxDialog':
jsBackend.FormBuilder.Fields.saveCheckbox()
break
}
Expand Down Expand Up @@ -419,6 +422,11 @@ jsBackend.FormBuilder.Fields = {
) {
$('#textboxReplyTo').prop('checked', true)
}
if (data.data.field.settings.use_to_subscribe_with_mailmotor &&
data.data.field.settings.use_to_subscribe_with_mailmotor === true
) {
$('#textboxMailmotor').prop('checked', true)
}
if (data.data.field.settings.send_confirmation_mail_to &&
data.data.field.settings.send_confirmation_mail_to === true
) {
Expand Down Expand Up @@ -605,6 +613,15 @@ jsBackend.FormBuilder.Fields = {

// show dialog
$('#checkboxDialog').modal('show')
} else if (data.data.field.type === 'mailmotor') {
// mailmotor edit
// fill in form
$('#mailmotorId').val(data.data.field.id)
$('#mailmotorLabel').val(utils.string.htmlDecode(data.data.field.settings.label))
$('#mailmotorListId').val(utils.string.htmlDecode(data.data.field.settings.list_id))

// show dialog
$('#mailmotorDialog').modal('show')
} else if (data.data.field.type === 'heading') {
// heading edit
// fill in form
Expand Down Expand Up @@ -1159,6 +1176,65 @@ jsBackend.FormBuilder.Fields = {
})
},

/**
* Handle mailmotorButton save
*/
saveMailmotorbutton: function () {
// init vars
var fieldId = $('#mailmotorId').val()
var type = 'mailmotor'
var label = $('#mailmotorLabel').val()
var listId = $('#mailmotorListId').val()

// make the call
$.ajax({
data: $.extend({}, jsBackend.FormBuilder.Fields.paramsSave, {
form_id: jsBackend.FormBuilder.formId,
field_id: fieldId,
type: type,
label: label,
list_id: listId
}),
success: function (data, textStatus) {
// success
if (data.code === 200) {
// clear errors
$('.jsFieldError').html('')

// form contains errors
if (typeof data.data.errors !== 'undefined') {
// assign errors
if (typeof data.data.errors.label !== 'undefined') {
$('#mailmotorLabelError').html(data.data.errors.label)
}

if (typeof data.data.errors.list_id !== 'undefined') {
$('#mailmotorListIdError').html(data.data.errors.list_id)
}

// toggle error messages
jsBackend.FormBuilder.Fields.toggleValidationErrors('mailmotorDialog')
} else {
// saved!
// append field html
jsBackend.FormBuilder.Fields.setField(data.data.field_id, data.data.field_html)

// close console box
$('#mailmotorDialog').modal('hide')
}
} else {
// show error message
jsBackend.messages.add('danger', textStatus)
}

// alert the user
if (data.code !== 200 && jsBackend.debug) {
window.alert(data.message)
}
}
})
},

/**
* Handle submit save
*/
Expand Down Expand Up @@ -1297,6 +1373,9 @@ jsBackend.FormBuilder.Fields = {
if (typeof data.data.errors.reply_to_error_message !== 'undefined') {
$('#textboxReplyToErrorMessageError').html(data.data.errors.reply_to_error_message)
}
if (typeof data.data.errors.use_to_subscribe_with_mailmotor_error_message !== 'undefined') {
$('#textboxMailmotorErrorMessageError').html(data.data.errors.use_to_subscribe_with_mailmotor_error_message)
}

// toggle error messages
jsBackend.FormBuilder.Fields.toggleValidationErrors('textareaDialog')
Expand Down Expand Up @@ -1340,6 +1419,7 @@ jsBackend.FormBuilder.Fields = {
var validationParameter = $('#textboxValidationParameter').val()
var errorMessage = $('#textboxErrorMessage').val()
var classname = $('#textboxClassname').val()
var mailmotor = $('#textboxMailmotor').is(':checked')
var autocomplete = $('#textboxAutocomplete').val()

// make the call
Expand All @@ -1351,6 +1431,7 @@ jsBackend.FormBuilder.Fields = {
label: label,
default_values: value,
reply_to: replyTo,
use_to_subscribe_with_mailmotor: mailmotor,
send_confirmation_mail_to: sendConfirmationMailTo,
confirmation_mail_subject: confirmationMailSubject,
required: required,
Expand Down Expand Up @@ -1386,6 +1467,9 @@ jsBackend.FormBuilder.Fields = {
if (typeof data.data.errors.reply_to_error_message !== 'undefined') {
$('#textboxReplyToErrorMessageError').html(data.data.errors.reply_to_error_message)
}
if (typeof data.data.errors.use_to_subscribe_with_mailmotor_error_message !== 'undefined') {
$('#textboxMailmotorErrorMessageError').html(data.data.errors.use_to_subscribe_with_mailmotor_error_message)
}
if (typeof data.data.errors.send_confirmation_mail_to_error_message !== 'undefined') {
$('#textboxSendConfirmationMailToErrorMessageError').html(data.data.errors.send_confirmation_mail_to_error_message)
}
Expand Down

0 comments on commit dffe6d5

Please sign in to comment.