Rename 'ajax' to 'json' because we don't use XML

We use json as response
This commit is contained in:
djmaze 2020-12-30 15:50:47 +01:00
parent 76cf24f426
commit 950579c7f5
18 changed files with 83 additions and 91 deletions

View file

@ -411,10 +411,10 @@ export const Notification = {
ClientViewError: 902,
InvalidInputArgument: 903,
AjaxFalse: 950,
AjaxAbort: 951,
AjaxParse: 952,
AjaxTimeout: 953,
JsonFalse: 950,
JsonAbort: 951,
JsonParse: 952,
// JsonTimeout: 953,
UnknownNotification: 999,
UnknownError: 999

View file

@ -87,7 +87,7 @@ export function settingsSaveHelperSimpleFunction(koTrigger, context) {
}
let __themeTimer = 0,
__themeAjax = null;
__themeJson = null;
/**
* @param {string} value
@ -98,7 +98,7 @@ export function changeTheme(value, themeTrigger = ()=>{}) {
const themeLink = doc.getElementById('app-theme-link'),
clearTimer = () => {
__themeTimer = setTimeout(() => themeTrigger(SaveSettingsStep.Idle), 1000);
__themeAjax = null;
__themeJson = null;
};
let themeStyle = doc.getElementById('app-theme-style'),
@ -118,13 +118,13 @@ export function changeTheme(value, themeTrigger = ()=>{}) {
themeTrigger(SaveSettingsStep.Animate);
if (__themeAjax) {
__themeAjax.abort();
if (__themeJson) {
__themeJson.abort();
}
let init = {};
if (window.AbortController) {
__themeAjax = new AbortController();
init.signal = __themeAjax.signal;
__themeJson = new AbortController();
init.signal = __themeJson.signal;
}
rl.fetchJSON(url, init)
.then(data => {

View file

@ -2,11 +2,11 @@ import { StorageResultType, Notification } from 'Common/Enums';
import { pInt, pString } from 'Common/Utils';
import { serverRequest } from 'Common/Links';
let iAjaxErrorCount = 0,
let iJsonErrorCount = 0,
iTokenErrorCount = 0,
bUnload = false;
const getURL = (add = '') => serverRequest('Ajax') + add,
const getURL = (add = '') => serverRequest('Json') + add,
updateToken = data => {
if (data.UpdateToken) {
@ -28,7 +28,7 @@ checkResponseError = data => {
Notification.UnknownError
].includes(err)
) {
++iAjaxErrorCount;
++iJsonErrorCount;
}
if (Notification.InvalidToken === err) {
@ -39,7 +39,7 @@ checkResponseError = data => {
rl.logoutReload();
}
if (window.rl && (data.ClearAuth || data.Logout || 7 < iAjaxErrorCount)) {
if (window.rl && (data.ClearAuth || data.Logout || 7 < iJsonErrorCount)) {
rl.hash.clear();
if (!data.ClearAuth) {
@ -118,7 +118,7 @@ class AbstractFetchRemote
if (StorageResultType.Success === sType && data && !data.Result) {
checkResponseError(data);
} else if (StorageResultType.Success === sType && data && data.Result) {
iAjaxErrorCount = iTokenErrorCount = 0;
iJsonErrorCount = iTokenErrorCount = 0;
}
if (fCallback) {
@ -152,7 +152,7 @@ class AbstractFetchRemote
}).catch(err => {
if (err.name == 'AbortError') { // handle abort()
err = Notification.AjaxAbort;
err = Notification.JsonAbort;
}
return Promise.reject(err);
});
@ -222,7 +222,7 @@ class AbstractFetchRemote
this.abort(action, true);
if (!data) {
return Promise.reject(Notification.AjaxParse);
return Promise.reject(Notification.JsonParse);
}
updateToken(data);
@ -249,13 +249,13 @@ class AbstractFetchRemote
if (!data.Result || action !== data.Action) {
checkResponseError(data);
const err = data ? data.ErrorCode : null;
return Promise.reject(err || Notification.AjaxFalse);
return Promise.reject(err || Notification.JsonFalse);
}
return data;
}).catch(err => {
if (err.name == 'AbortError') { // handle abort()
return Promise.reject(Notification.AjaxAbort);
return Promise.reject(Notification.JsonAbort);
}
return Promise.reject(err);
});

View file

@ -11,7 +11,7 @@ class CustomAdminSettingsTabPlugin extends \RainLoop\Plugins\AbstractPlugin
$this->addJs('js/CustomAdminSettings.js', true); // add js file
$this->addAjaxHook('AjaxAdminGetData', 'AjaxAdminGetData');
$this->addJsonHook('JsonAdminGetData', 'JsonAdminGetData');
$this->addTemplate('templates/PluginCustomAdminSettingsTab.html', true);
}
@ -19,9 +19,9 @@ class CustomAdminSettingsTabPlugin extends \RainLoop\Plugins\AbstractPlugin
/**
* @return array
*/
public function AjaxAdminGetData()
public function JsonAdminGetData()
{
return $this->ajaxResponse(__FUNCTION__, array(
return $this->jsonResponse(__FUNCTION__, array(
'PHP' => phpversion()
));
}

View file

@ -31,7 +31,7 @@
self.php(oData.Result.PHP || '');
}
}, 'AjaxAdminGetData');
}, 'JsonAdminGetData');
};

View file

@ -11,8 +11,8 @@ class CustomSettingsTabPlugin extends \RainLoop\Plugins\AbstractPlugin
$this->addJs('js/CustomUserSettings.js'); // add js file
$this->addAjaxHook('AjaxGetCustomUserData', 'AjaxGetCustomUserData');
$this->addAjaxHook('AjaxSaveCustomUserData', 'AjaxSaveCustomUserData');
$this->addJsonHook('JsonGetCustomUserData', 'JsonGetCustomUserData');
$this->addJsonHook('JsonSaveCustomUserData', 'JsonSaveCustomUserData');
$this->addTemplate('templates/PluginCustomSettingsTab.html');
}
@ -20,7 +20,7 @@ class CustomSettingsTabPlugin extends \RainLoop\Plugins\AbstractPlugin
/**
* @return array
*/
public function AjaxGetCustomUserData()
public function JsonGetCustomUserData()
{
$aSettings = $this->getUserSettings();
@ -30,7 +30,7 @@ class CustomSettingsTabPlugin extends \RainLoop\Plugins\AbstractPlugin
// or get user's data from your custom storage ( DB / LDAP / ... ).
\sleep(1);
return $this->ajaxResponse(__FUNCTION__, array(
return $this->jsonResponse(__FUNCTION__, array(
'UserFacebook' => $sUserFacebook,
'UserSkype' => $sUserSkype
));
@ -39,15 +39,15 @@ class CustomSettingsTabPlugin extends \RainLoop\Plugins\AbstractPlugin
/**
* @return array
*/
public function AjaxSaveCustomUserData()
public function JsonSaveCustomUserData()
{
$sUserFacebook = $this->ajaxParam('UserFacebook');
$sUserSkype = $this->ajaxParam('UserSkype');
$sUserFacebook = $this->jsonParam('UserFacebook');
$sUserSkype = $this->jsonParam('UserSkype');
// or put user's data to your custom storage ( DB / LDAP / ... ).
\sleep(1);
return $this->ajaxResponse(__FUNCTION__, $this->saveUserSettings(array(
return $this->jsonResponse(__FUNCTION__, $this->saveUserSettings(array(
'UserFacebook' => $sUserFacebook,
'UserSkype' => $sUserSkype
)));

View file

@ -22,7 +22,7 @@
}, this);
}
CustomUserSettings.prototype.customAjaxSaveData = function ()
CustomUserSettings.prototype.customJsonSaveData = function ()
{
var self = this;
@ -46,7 +46,7 @@
// false
}
}, 'AjaxSaveCustomUserData', {
}, 'JsonSaveCustomUserData', {
'UserSkype': this.userSkype(),
'UserFacebook': this.userFacebook()
});
@ -68,11 +68,11 @@
self.userFacebook(oData.Result.UserFacebook || '');
}
}, 'AjaxGetCustomUserData');
}, 'JsonGetCustomUserData');
};
window.rl.addSettingsViewModel(CustomUserSettings, 'PluginCustomSettingsTab',
'SETTINGS_CUSTOM_PLUGIN/TAB_NAME', 'custom');
}());
}());

View file

@ -23,7 +23,7 @@
</div>
<div class="control-group">
<div class="controls">
<button class="btn" data-bind="click: customAjaxSaveData, enable: !savingOrLoading()">
<button class="btn" data-bind="click: customJsonSaveData, enable: !savingOrLoading()">
<i data-bind="css: {'icon-floppy': !saving(), 'icon-spinner animated': saving()}" class="icon-floppy"></i>
&nbsp;&nbsp;
<span class="i18n" data-i18n="SETTINGS_CUSTOM_PLUGIN/BUTTON_SAVE"></span>
@ -31,4 +31,4 @@
</div>
</div>
</div>
</div>
</div>

View file

@ -9,7 +9,7 @@ class DemoAccountPlugin extends \RainLoop\Plugins\AbstractPlugin
{
$this->addHook('filter.app-data', 'FilterAppData');
$this->addHook('filter.action-params', 'FilterActionParams');
$this->addHook('ajax.action-pre-call', 'AjaxActionPreCall');
$this->addHook('json.action-pre-call', 'JsonActionPreCall');
$this->addHook('filter.send-message', 'FilterSendMessage');
$this->addHook('main.fabrica', 'MainFabrica');
}
@ -63,7 +63,7 @@ class DemoAccountPlugin extends \RainLoop\Plugins\AbstractPlugin
return ($oAccount && $oAccount->Email() === $this->Config()->Get('plugin', 'email'));
}
public function AjaxActionPreCall($sAction)
public function JsonActionPreCall($sAction)
{
if ('AccountSetup' === $sAction &&
$this->isDemoAccount($this->Manager()->Actions()->GetAccount()))

View file

@ -141,7 +141,7 @@ class Actions
$this->sSpecAuthToken = '';
$this->sUpdateAuthToken = '';
$this->bIsAjax = false;
$this->bIsJson = false;
$oConfig = $this->Config();
$this->Plugins()->RunHook('filter.application-config', array($oConfig));
@ -163,9 +163,9 @@ class Actions
return $this;
}
public function SetIsAjax(bool $bIsAjax): self
public function SetIsJson(bool $bIsJson): self
{
$this->bIsAjax = $bIsAjax;
$this->bIsJson = $bIsJson;
return $this;
}
@ -180,9 +180,9 @@ class Actions
return $this->sUpdateAuthToken;
}
public function GetIsAjax(): bool
public function GetIsJson(): bool
{
return $this->bIsAjax;
return $this->bIsJson;
}
public function GetShortLifeSpecAuthToken(int $iLife = 60): string

View file

@ -387,7 +387,7 @@ trait User
$aResult = array();
$this->Plugins()->RunHook('ajax.suggestions-input-parameters', array(&$sQuery, &$iLimit, $oAccount));
$this->Plugins()->RunHook('json.suggestions-input-parameters', array(&$sQuery, &$iLimit, $oAccount));
$iLimit = (int) $iLimit;
if (5 > $iLimit)
@ -395,7 +395,7 @@ trait User
$iLimit = 5;
}
$this->Plugins()->RunHook('ajax.suggestions-pre', array(&$aResult, $sQuery, $oAccount, $iLimit));
$this->Plugins()->RunHook('json.suggestions-pre', array(&$aResult, $sQuery, $oAccount, $iLimit));
if ($iLimit > \count($aResult) && 0 < \strlen($sQuery))
{
@ -442,7 +442,7 @@ trait User
$aResult = \array_slice($aResult, 0, $iLimit);
}
$this->Plugins()->RunHook('ajax.suggestions-post', array(&$aResult, $sQuery, $oAccount, $iLimit));
$this->Plugins()->RunHook('json.suggestions-post', array(&$aResult, $sQuery, $oAccount, $iLimit));
$aResult = Utils::RemoveSuggestionDuplicates($aResult);
if ($iLimit < \count($aResult))

View file

@ -131,17 +131,17 @@ class Identity implements JsonSerializable
return $this;
}
public function FromJSON(array $aData, bool $bAjax = false): bool
public function FromJSON(array $aData, bool $bJson = false): bool
{
if (!empty($aData['Email'])) {
$this->sId = !empty($aData['Id']) ? $aData['Id'] : '';
$this->sEmail = $bAjax ? Utils::IdnToAscii($aData['Email'], true) : $aData['Email'];
$this->sEmail = $bJson ? Utils::IdnToAscii($aData['Email'], true) : $aData['Email'];
$this->sName = isset($aData['Name']) ? $aData['Name'] : '';
$this->sReplyTo = !empty($aData['ReplyTo']) ? $aData['ReplyTo'] : '';
$this->sBcc = !empty($aData['Bcc']) ? $aData['Bcc'] : '';
$this->sSignature = !empty($aData['Signature']) ? $aData['Signature'] : '';
$this->bSignatureInsertBefore = isset($aData['SignatureInsertBefore']) ?
($bAjax ? '1' === $aData['SignatureInsertBefore'] : !!$aData['SignatureInsertBefore']) : true;
($bJson ? '1' === $aData['SignatureInsertBefore'] : !!$aData['SignatureInsertBefore']) : true;
return true;
}

View file

@ -52,7 +52,7 @@ class Template implements \JsonSerializable
$this->bPopulateAlways = $bPopulateAlways;
}
public function FromJSON(array $aData, bool $bAjax = false) : bool
public function FromJSON(array $aData, bool $bJson = false) : bool
{
if (isset($aData['ID'], $aData['Name'], $aData['Body']))
{

View file

@ -232,11 +232,11 @@ abstract class AbstractPlugin
return $this;
}
protected function addAjaxHook(string $sActionName, string $sFunctionName) : self
protected function addJsonHook(string $sActionName, string $sFunctionName) : self
{
if ($this->oPluginManager)
{
$this->oPluginManager->AddAdditionalAjaxAction($sActionName, array(&$this, $sFunctionName));
$this->oPluginManager->AddAdditionalJsonAction($sActionName, array(&$this, $sFunctionName));
}
return $this;
@ -253,11 +253,11 @@ abstract class AbstractPlugin
return $this;
}
protected function ajaxResponse(string $sFunctionName, array $aData) : self
protected function jsonResponse(string $sFunctionName, array $aData) : self
{
if ($this->oPluginManager)
{
return $this->oPluginManager->AjaxResponseHelper(
return $this->oPluginManager->JsonResponseHelper(
$this->oPluginManager->convertPluginFolderNameToClassName($this->Name()).'::'.$sFunctionName, $aData);
}
@ -269,7 +269,7 @@ abstract class AbstractPlugin
*
* @return mixed
*/
public function ajaxParam(string $sKey, $mDefault = null)
public function jsonParam(string $sKey, $mDefault = null)
{
if ($this->oPluginManager)
{

View file

@ -47,7 +47,7 @@ class Manager
/**
* @var array
*/
private $aAdditionalAjax;
private $aAdditionalJson;
/**
* @var array
@ -76,8 +76,8 @@ class Manager
$this->aTemplates = array();
$this->aAdminTemplates = array();
$this->aAjaxFilters = array();
$this->aAdditionalAjax = array();
$this->aJsonFilters = array();
$this->aAdditionalJson = array();
$this->aProcessTemplate = array();
$this->bIsEnabled = (bool) $this->oActions->Config()->Get('plugins', 'enable', false);
@ -438,36 +438,36 @@ class Manager
/**
* @param mixed $mCallback
*/
public function AddAdditionalAjaxAction(string $sActionName, $mCallback) : self
public function AddAdditionalJsonAction(string $sActionName, $mCallback) : self
{
if ($this->bIsEnabled && \is_callable($mCallback) && 0 < \strlen($sActionName))
{
$sActionName = 'DoPlugin'.$sActionName;
if (!isset($this->aAdditionalAjax[$sActionName]))
if (!isset($this->aAdditionalJson[$sActionName]))
{
$this->aAdditionalAjax[$sActionName] = $mCallback;
$this->aAdditionalJson[$sActionName] = $mCallback;
}
}
return $this;
}
public function HasAdditionalAjax(string $sActionName) : bool
public function HasAdditionalJson(string $sActionName) : bool
{
return $this->bIsEnabled && isset($this->aAdditionalAjax[$sActionName]);
return $this->bIsEnabled && isset($this->aAdditionalJson[$sActionName]);
}
/**
* @return mixed
*/
public function RunAdditionalAjax(string $sActionName)
public function RunAdditionalJson(string $sActionName)
{
if ($this->bIsEnabled)
{
if (isset($this->aAdditionalAjax[$sActionName]))
if (isset($this->aAdditionalJson[$sActionName]))
{
return \call_user_func($this->aAdditionalAjax[$sActionName]);
return \call_user_func($this->aAdditionalJson[$sActionName]);
}
}
@ -479,7 +479,7 @@ class Manager
*
* @return mixed
*/
public function AjaxResponseHelper(string $sFunctionName, $mData)
public function JsonResponseHelper(string $sFunctionName, $mData)
{
return $this->oActions->DefaultResponse($sFunctionName, $mData);
}

View file

@ -74,7 +74,7 @@ class ServiceActions
return $this;
}
public function ServiceAjax() : string
public function ServiceJson() : string
{
\ob_start();
@ -87,7 +87,7 @@ class ServiceActions
$sAction = $this->aPaths[2];
}
$this->oActions->SetIsAjax(true);
$this->oActions->SetIsJson(true);
try
{
@ -105,7 +105,7 @@ class ServiceActions
$sMethodName = 'Do'.$sAction;
$this->Logger()->Write('Action: '.$sMethodName, \MailSo\Log\Enumerations\Type::NOTE, 'AJAX');
$this->Logger()->Write('Action: '.$sMethodName, \MailSo\Log\Enumerations\Type::NOTE, 'JSON');
$aPost = $this->oHttp->GetPostAsArray();
if ($aPost)
@ -133,15 +133,15 @@ class ServiceActions
if (\method_exists($this->oActions, $sMethodName) &&
\is_callable(array($this->oActions, $sMethodName)))
{
$this->Plugins()->RunHook('ajax.action-pre-call', array($sAction));
$this->Plugins()->RunHook('json.action-pre-call', array($sAction));
$aResponseItem = \call_user_func(array($this->oActions, $sMethodName));
$this->Plugins()->RunHook('ajax.action-post-call', array($sAction, &$aResponseItem));
$this->Plugins()->RunHook('json.action-post-call', array($sAction, &$aResponseItem));
}
else if ($this->Plugins()->HasAdditionalAjax($sMethodName))
else if ($this->Plugins()->HasAdditionalJson($sMethodName))
{
$this->Plugins()->RunHook('ajax.action-pre-call', array($sAction));
$aResponseItem = $this->Plugins()->RunAdditionalAjax($sMethodName);
$this->Plugins()->RunHook('ajax.action-post-call', array($sAction, &$aResponseItem));
$this->Plugins()->RunHook('json.action-pre-call', array($sAction));
$aResponseItem = $this->Plugins()->RunAdditionalJson($sMethodName);
$this->Plugins()->RunHook('json.action-post-call', array($sAction, &$aResponseItem));
}
}
@ -189,7 +189,7 @@ class ServiceActions
}
}
$this->Plugins()->RunHook('filter.ajax-response', array($sAction, &$aResponseItem));
$this->Plugins()->RunHook('filter.json-response', array($sAction, &$aResponseItem));
\header('Content-Type: application/json; charset=utf-8');
@ -211,7 +211,7 @@ class ServiceActions
$iLimit = (int) $this->Config()->Get('labs', 'log_ajax_response_write_limit', 0);
$this->Logger()->Write(0 < $iLimit && $iLimit < \strlen($sResult)
? \substr($sResult, 0, $iLimit).'...' : $sResult, \MailSo\Log\Enumerations\Type::INFO, 'AJAX');
? \substr($sResult, 0, $iLimit).'...' : $sResult, \MailSo\Log\Enumerations\Type::INFO, 'JSON');
}
return $sResult;
@ -316,14 +316,7 @@ class ServiceActions
$aResponseItem = $this->oActions->ExceptionResponse($sAction, $oException);
}
if ('iframe' === $this->oHttp->GetPost('jua-post-type', ''))
{
\header('Content-Type: text/html; charset=utf-8');
}
else
{
\header('Content-Type: application/json; charset=utf-8');
}
\header('Content-Type: application/json; charset=utf-8');
$this->Plugins()->RunHook('filter.upload-response', array(&$aResponseItem));
$sResult = \MailSo\Base\Utils::Php2js($aResponseItem, $this->Logger());

5
vendors/jua/jua.js vendored
View file

@ -88,7 +88,7 @@
* @param {Jua} oJua
* @param {Object} oOptions
*/
class AjaxDriver
class XHRDriver
{
constructor(oJua, oOptions)
{
@ -170,7 +170,6 @@
fStartFunction && fStartFunction(sUid);
oFormData.append('jua-post-type', 'ajax');
oFormData.append(this.oOptions.name, oFileInfo['File']);
Object.entries(aHidden).forEach(([key, value]) =>
oFormData.append(key, (typeof value === "function" ? value(oFileInfo) : value).toString())
@ -305,7 +304,7 @@
self.oQueue = new Queue(oOptions.queueSize);
self.oDriver = new AjaxDriver(self, oOptions);
self.oDriver = new XHRDriver(self, oOptions);
let el = oOptions.clickElement;
if (el) {

File diff suppressed because one or more lines are too long