mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-09-04 12:14:11 +08:00
Add error message on adminpanel contacts configuration page.
This commit is contained in:
parent
a531846b8f
commit
869e0ed181
9 changed files with 120 additions and 60 deletions
|
@ -21,11 +21,13 @@ function AdminContacts()
|
|||
this.testing = ko.observable(false);
|
||||
this.testContactsSuccess = ko.observable(false);
|
||||
this.testContactsError = ko.observable(false);
|
||||
this.testContactsErrorMessage = ko.observable('');
|
||||
|
||||
this.testContactsCommand = Utils.createCommand(this, function () {
|
||||
|
||||
this.testContactsSuccess(false);
|
||||
this.testContactsError(false);
|
||||
this.testContactsErrorMessage('');
|
||||
this.testing(true);
|
||||
|
||||
RL.remote().testContacts(this.onTestContactsResponse, {
|
||||
|
@ -45,13 +47,18 @@ Utils.addSettingsViewModel(AdminContacts, 'AdminSettingsContacts', 'Contacts', '
|
|||
|
||||
AdminContacts.prototype.onTestContactsResponse = function (sResult, oData)
|
||||
{
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
this.testContactsSuccess(false);
|
||||
this.testContactsError(false);
|
||||
this.testContactsErrorMessage('');
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result && oData.Result.Result)
|
||||
{
|
||||
this.testContactsSuccess(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.testContactsError(true);
|
||||
this.testContactsErrorMessage(oData.Result.Message || '');
|
||||
}
|
||||
|
||||
this.testing(false);
|
||||
|
@ -61,6 +68,7 @@ AdminContacts.prototype.onShow = function ()
|
|||
{
|
||||
this.testContactsSuccess(false);
|
||||
this.testContactsError(false);
|
||||
this.testContactsErrorMessage('');
|
||||
};
|
||||
|
||||
AdminContacts.prototype.onBuild = function ()
|
||||
|
|
|
@ -228,6 +228,16 @@ class Utils
|
|||
return !\preg_match('/[^\x09\x10\x13\x0A\x0D\x20-\x7E]/', $sValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sValue
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function IsUtf8($sValue)
|
||||
{
|
||||
return (bool) \preg_match('//u', $sValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $iSize
|
||||
* @param int $iRound
|
||||
|
@ -831,55 +841,55 @@ class Utils
|
|||
{
|
||||
return \json_encode($mInput, defined('JSON_UNESCAPED_UNICODE') ? JSON_UNESCAPED_UNICODE : 0);
|
||||
|
||||
if (\is_null($mInput))
|
||||
{
|
||||
return 'null';
|
||||
}
|
||||
else if ($mInput === false)
|
||||
{
|
||||
return 'false';
|
||||
}
|
||||
else if ($mInput === true)
|
||||
{
|
||||
return 'true';
|
||||
}
|
||||
else if (\is_scalar($mInput))
|
||||
{
|
||||
if (\is_float($mInput))
|
||||
{
|
||||
$mInput = \str_replace(',', '.', \strval($mInput));
|
||||
}
|
||||
|
||||
return '"'.\MailSo\Base\Utils::InlineRebuildStringToJsString($mInput).'"';
|
||||
}
|
||||
|
||||
$bIsList = true;
|
||||
for ($iIndex = 0, \reset($mInput), $iLen = \count($mInput); $iIndex < $iLen; $iIndex++, \next($mInput))
|
||||
{
|
||||
if (\key($mInput) !== $iIndex)
|
||||
{
|
||||
$bIsList = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$aResult = array();
|
||||
if ($bIsList)
|
||||
{
|
||||
foreach ($mInput as $mValue)
|
||||
{
|
||||
$aResult[] = \MailSo\Base\Utils::Php2js($mValue);
|
||||
}
|
||||
return '['.\join(',', $aResult).']';
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($mInput as $sKey => $mValue)
|
||||
{
|
||||
$aResult[] = \MailSo\Base\Utils::Php2js($sKey).':'.\MailSo\Base\Utils::Php2js($mValue);
|
||||
}
|
||||
return '{'.\join(',', $aResult).'}';
|
||||
}
|
||||
// if (\is_null($mInput))
|
||||
// {
|
||||
// return 'null';
|
||||
// }
|
||||
// else if ($mInput === false)
|
||||
// {
|
||||
// return 'false';
|
||||
// }
|
||||
// else if ($mInput === true)
|
||||
// {
|
||||
// return 'true';
|
||||
// }
|
||||
// else if (\is_scalar($mInput))
|
||||
// {
|
||||
// if (\is_float($mInput))
|
||||
// {
|
||||
// $mInput = \str_replace(',', '.', \strval($mInput));
|
||||
// }
|
||||
//
|
||||
// return '"'.\MailSo\Base\Utils::InlineRebuildStringToJsString($mInput).'"';
|
||||
// }
|
||||
//
|
||||
// $bIsList = true;
|
||||
// for ($iIndex = 0, \reset($mInput), $iLen = \count($mInput); $iIndex < $iLen; $iIndex++, \next($mInput))
|
||||
// {
|
||||
// if (\key($mInput) !== $iIndex)
|
||||
// {
|
||||
// $bIsList = false;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// $aResult = array();
|
||||
// if ($bIsList)
|
||||
// {
|
||||
// foreach ($mInput as $mValue)
|
||||
// {
|
||||
// $aResult[] = \MailSo\Base\Utils::Php2js($mValue);
|
||||
// }
|
||||
// return '['.\join(',', $aResult).']';
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// foreach ($mInput as $sKey => $mValue)
|
||||
// {
|
||||
// $aResult[] = \MailSo\Base\Utils::Php2js($sKey).':'.\MailSo\Base\Utils::Php2js($mValue);
|
||||
// }
|
||||
// return '{'.\join(',', $aResult).'}';
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1942,7 +1942,11 @@ class Actions
|
|||
$this->setConfigFromParams($oConfig, 'ContactsPdoUser', 'contacts', 'pdo_user', 'string');
|
||||
$this->setConfigFromParams($oConfig, 'ContactsPdoPassword', 'contacts', 'pdo_password', 'dummy');
|
||||
|
||||
return $this->DefaultResponse(__FUNCTION__, $this->PersonalAddressBookProvider(null, true)->Test());
|
||||
$sTestMessage = $this->PersonalAddressBookProvider(null, true)->Test();
|
||||
return $this->DefaultResponse(__FUNCTION__, array(
|
||||
'Result' => '' === $sTestMessage,
|
||||
'Message' => \MailSo\Base\Utils::Utf8Clear($sTestMessage, '?')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -72,7 +72,7 @@ abstract class PdoAbstract
|
|||
$oPdo = false;
|
||||
try
|
||||
{
|
||||
$oPdo = new \PDO($sDsn, $sDbLogin, $sDbPassword);
|
||||
$oPdo = @new \PDO($sDsn, $sDbLogin, $sDbPassword);
|
||||
if ($oPdo)
|
||||
{
|
||||
$oPdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
|
|
|
@ -24,13 +24,13 @@ class PersonalAddressBook extends \RainLoop\Providers\AbstractProvider
|
|||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @return string
|
||||
*/
|
||||
public function Test()
|
||||
{
|
||||
\sleep(1);
|
||||
return $this->oDriver instanceof \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface ?
|
||||
$this->oDriver->Test() : false;
|
||||
$this->oDriver->Test() : 'Personal address book driver is not allowed';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -752,8 +752,31 @@ class PdoPersonalAddressBook
|
|||
*/
|
||||
public function Test()
|
||||
{
|
||||
$this->Sync();
|
||||
return 0 < $this->getVersion('mysql-pab-version');
|
||||
$sResult = '';
|
||||
try
|
||||
{
|
||||
$this->Sync();
|
||||
|
||||
if (0 >= $this->getVersion('mysql-pab-version'))
|
||||
{
|
||||
$sResult = 'Unknown database error';
|
||||
}
|
||||
}
|
||||
catch (\Exception $oException)
|
||||
{
|
||||
$sResult = $oException->getMessage();
|
||||
if (!empty($sResult) && !\MailSo\Base\Utils::IsAscii($sResult) && !\MailSo\Base\Utils::IsUtf8($sResult))
|
||||
{
|
||||
$sResult = @\utf8_encode($sResult);
|
||||
}
|
||||
|
||||
if (!\is_string($sResult) || empty($sResult))
|
||||
{
|
||||
$sResult = 'Unknown database error';
|
||||
}
|
||||
}
|
||||
|
||||
return $sResult;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -59,5 +59,12 @@
|
|||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group" data-bind="visible: '' !== testContactsErrorMessage()">
|
||||
<div class="controls">
|
||||
<div class="row">
|
||||
<div class="alert span8" data-bind="text: testContactsErrorMessage"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -5261,11 +5261,13 @@ function AdminContacts()
|
|||
this.testing = ko.observable(false);
|
||||
this.testContactsSuccess = ko.observable(false);
|
||||
this.testContactsError = ko.observable(false);
|
||||
this.testContactsErrorMessage = ko.observable('');
|
||||
|
||||
this.testContactsCommand = Utils.createCommand(this, function () {
|
||||
|
||||
this.testContactsSuccess(false);
|
||||
this.testContactsError(false);
|
||||
this.testContactsErrorMessage('');
|
||||
this.testing(true);
|
||||
|
||||
RL.remote().testContacts(this.onTestContactsResponse, {
|
||||
|
@ -5285,13 +5287,18 @@ Utils.addSettingsViewModel(AdminContacts, 'AdminSettingsContacts', 'Contacts', '
|
|||
|
||||
AdminContacts.prototype.onTestContactsResponse = function (sResult, oData)
|
||||
{
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
this.testContactsSuccess(false);
|
||||
this.testContactsError(false);
|
||||
this.testContactsErrorMessage('');
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result && oData.Result.Result)
|
||||
{
|
||||
this.testContactsSuccess(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.testContactsError(true);
|
||||
this.testContactsErrorMessage(oData.Result.Message || '');
|
||||
}
|
||||
|
||||
this.testing(false);
|
||||
|
@ -5301,6 +5308,7 @@ AdminContacts.prototype.onShow = function ()
|
|||
{
|
||||
this.testContactsSuccess(false);
|
||||
this.testContactsError(false);
|
||||
this.testContactsErrorMessage('');
|
||||
};
|
||||
|
||||
AdminContacts.prototype.onBuild = function ()
|
||||
|
|
6
rainloop/v/0.0.0/static/js/admin.min.js
vendored
6
rainloop/v/0.0.0/static/js/admin.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue