Skip to content

Commit

Permalink
Ahora el botón de test de la configuración de email solamente aparece…
Browse files Browse the repository at this point in the history
… cuando se selecciona smtp, ya que para el resto no hay implementada opción de test.
  • Loading branch information
NeoRazorX committed May 20, 2022
1 parent dcb8026 commit 1d97042
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 35 deletions.
46 changes: 29 additions & 17 deletions Core/Controller/ConfigEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@
* Controller to edit main settings
*
* @author Daniel Fernández Giménez <hola@danielfg.es>
* @author Carlos Garcia Gomez <carlos@facturascripts.com>
* @author Carlos Garcia Gomez <carlos@facturascripts.com>
*/
class ConfigEmail extends PanelController
{

/**
* @return array
*/
public function getPageData()
public function getPageData(): array
{
$pageData = parent::getPageData();
$pageData['menu'] = 'admin';
Expand Down Expand Up @@ -98,18 +95,8 @@ protected function createViewsEmailSent(string $viewName = 'ListEmailSent')
*/
protected function execAfterAction($action)
{
switch ($action) {
case 'testmail':
if (false === $this->editAction()) {
break;
}
$email = new NewMail();
if ($email->test()) {
$this->toolBox()->i18nLog()->notice('mail-test-ok');
break;
}
$this->toolBox()->i18nLog()->warning('mail-test-error');
break;
if ($action === 'testmail') {
$this->testMailAction();
}
}

Expand All @@ -121,6 +108,15 @@ protected function loadData($viewName, $view)
case 'ConfigEmail':
$view->loadData('email');
$view->model->name = 'email';
if ($view->model->mailer === 'smtp') {
// añadimos el botón test
$this->addButton($viewName, [
'action' => 'testmail',
'color' => 'info',
'icon' => 'fas fa-envelope',
'label' => 'test'
]);
}
break;

case 'ListEmailNotification':
Expand All @@ -129,4 +125,20 @@ protected function loadData($viewName, $view)
break;
}
}

protected function testMailAction()
{
// guardamos los datos del formulario primero
if (false === $this->editAction()) {
return;
}

$email = new NewMail();
if ($email->test()) {
$this->toolBox()->i18nLog()->notice('mail-test-ok');
return;
}

$this->toolBox()->i18nLog()->warning('mail-test-error');
}
}
4 changes: 2 additions & 2 deletions Core/Lib/Email/NewMail.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* This file is part of FacturaScripts
* Copyright (C) 2019-2021 Carlos Garcia Gomez <carlos@facturascripts.com>
* Copyright (C) 2019-2022 Carlos Garcia Gomez <carlos@facturascripts.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
Expand Down Expand Up @@ -362,7 +362,7 @@ public function test(): bool
return $this->mail->smtpConnect($this->smtpOptions());

default:
$this->toolBox()->i18nLog()->warning('not-implemented');
$this->toolBox()->i18nLog()->warning('test-' . $this->mail->Mailer . '-not-implemented');
return false;
}
}
Expand Down
27 changes: 11 additions & 16 deletions Core/XMLView/ConfigEmail.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
* This file is part of FacturaScripts
* Copyright (C) 2017-2021 Carlos Garcia Gomez <carlos@facturascripts.com>
* Copyright (C) 2017-2022 Carlos Garcia Gomez <carlos@facturascripts.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
Expand All @@ -23,27 +23,27 @@
<columns>
<group name="email" icon="fas fa-envelope" numcolumns="12">
<column name="name" display="none" order="0">
<widget type="text" fieldname="name" readonly="true" required="true" />
<widget type="text" fieldname="name" readonly="true" required="true"/>
</column>
<column name="email" order="100">
<widget type="text" fieldname="email" icon="fas fa-envelope" />
<widget type="text" fieldname="email" icon="fas fa-envelope"/>
</column>
<column name="password" order="110">
<widget type="password" fieldname="password" icon="fas fa-key" />
<widget type="password" fieldname="password" icon="fas fa-key"/>
</column>
<column name="email-signature" numcolumns="12" order="130">
<widget type="textarea" fieldname="signature" />
<widget type="textarea" fieldname="signature"/>
</column>
</group>
<group name="advanced" title="advanced" icon="fas fa-server" numcolumns="12" valign="bottom">
<column name="user" numcolumns="3" order="100">
<widget type="text" fieldname="user" />
<widget type="text" fieldname="user"/>
</column>
<column name="host" numcolumns="4" order="110">
<widget type="text" fieldname="host" icon="fas fa-server" />
<widget type="text" fieldname="host" icon="fas fa-server"/>
</column>
<column name="port" numcolumns="2" order="120">
<widget type="number" fieldname="port" min="0" />
<widget type="number" fieldname="port" min="0"/>
</column>
<column name="enc" title="encrypt" numcolumns="3" order="130">
<widget type="select" fieldname="enc" icon="fas fa-shield-alt">
Expand All @@ -67,21 +67,16 @@
</widget>
</column>
<column name="lowsecure" title="low-security" order="160">
<widget type="checkbox" fieldname="lowsecure" />
<widget type="checkbox" fieldname="lowsecure"/>
</column>
</group>
<group name="copy" title="email-cc" icon="fas fa-mail-bulk" numcolumns="12">
<column name="email-cc" description="accepts-emails-commas" order="100">
<widget type="text" fieldname="emailcc" icon="fas fa-envelope" />
<widget type="text" fieldname="emailcc" icon="fas fa-envelope"/>
</column>
<column name="email-bcc" description="accepts-emails-commas" order="110">
<widget type="text" fieldname="emailbcc" icon="fas fa-envelope" />
<widget type="text" fieldname="emailbcc" icon="fas fa-envelope"/>
</column>
</group>
</columns>
<rows>
<row type="actions">
<button type="action" label="test" color="info" action="testmail" icon="fas fa-envelope" />
</row>
</rows>
</view>

0 comments on commit 1d97042

Please sign in to comment.