Skip to content

Commit

Permalink
[BUGFIX] Expose interfaces of AjaxDataHandler
Browse files Browse the repository at this point in the history
Since the AjaxDataHandler is meant to be used in other modules as well,
the interfaces responsible for the response and the messages need to be
public to be able to write type-safe callbacks.

Resolves: #84172
Releases: master
Change-Id: Ib49f25181bc8c83a0cdc89da3a9b466b6bd25d59
Reviewed-on: https://review.typo3.org/56041
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
andreaskienast authored and lolli42 committed Mar 16, 2018
1 parent 417d2b5 commit ecce565
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 17 deletions.
Expand Up @@ -12,6 +12,8 @@
*/

import {SeverityEnum} from './Enum/Severity';
import MessageInterface from './AjaxDataHandler/MessageInterface';
import ResponseInterface from './AjaxDataHandler/ResponseInterface';
import * as $ from 'jquery';
import Icons = require('./Icons');
import Modal = require('./Modal');
Expand All @@ -24,18 +26,6 @@ enum Identifiers {
icon = '.t3js-icon'
}

interface Message {
title: string;
message: string;
severity: SeverityEnum;
}

interface Response {
redirect: string;
messages: Array<Message>;
hasErrors: boolean;
}

/**
* Module: TYPO3/CMS/Backend/AjaxDataHandler
* AjaxDataHandler - Javascript functions to work with AJAX and interacting with tce_db.php
Expand Down Expand Up @@ -63,7 +53,7 @@ class AjaxDataHandler {
* @returns {JQueryPromise<any>}
*/
public process(parameters: Object): JQueryPromise<any> {
return this._call(parameters).done((result: Response): void => {
return this._call(parameters).done((result: ResponseInterface): void => {
if (result.hasErrors) {
this.handleErrors(result);
}
Expand All @@ -83,7 +73,7 @@ class AjaxDataHandler {
this._showSpinnerIcon($iconElement);

// make the AJAX call to toggle the visibility
this._call(params).done((result: Response): void => {
this._call(params).done((result: ResponseInterface): void => {
// print messages on errors
if (result.hasErrors) {
this.handleErrors(result);
Expand Down Expand Up @@ -193,7 +183,7 @@ class AjaxDataHandler {
this._showSpinnerIcon($iconElement);

// make the AJAX call to toggle the visibility
this._call(params).done((result: Response): void => {
this._call(params).done((result: ResponseInterface): void => {
// revert to the old class
Icons.getIcon('actions-edit-delete', Icons.sizes.small).done((icon: string): void => {
$iconElement = $anchorElement.find(Identifiers.icon);
Expand Down Expand Up @@ -237,8 +227,8 @@ class AjaxDataHandler {
*
* @param {Object} result
*/
private handleErrors(result: Response): void {
$.each(result.messages, (position: number, message: Message): void => {
private handleErrors(result: ResponseInterface): void {
$.each(result.messages, (position: number, message: MessageInterface): void => {
Notification.error(message.title, message.message);
});
}
Expand Down
@@ -0,0 +1,18 @@
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

export default interface MessageInterface {
title: string;
message: string;
severity: number;
}
@@ -0,0 +1,20 @@
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

import MessageInterface from './MessageInterface';

export default interface ResponseInterface {
redirect: string;
messages: Array<MessageInterface>;
hasErrors: boolean;
}
@@ -0,0 +1,13 @@
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
define(["require","exports"],function(e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0})});
@@ -0,0 +1,13 @@
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
define(["require","exports"],function(e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0})});

0 comments on commit ecce565

Please sign in to comment.