diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-02-07 10:47:59 +0100 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-04-06 17:00:58 +0200 |
commit | 01a70e5d0f6f369fefd510379994e7f465289421 (patch) | |
tree | 56139424174b1d66587aec8c2323df836a288f2d /core/src | |
parent | 1d62b9786f07474bd6910b04aa905ccf3745690b (diff) | |
download | nextcloud-server-01a70e5d0f6f369fefd510379994e7f465289421.tar.gz nextcloud-server-01a70e5d0f6f369fefd510379994e7f465289421.zip |
Use external Toast implementation and deprecate the OCP API
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/OCP/index.js | 8 | ||||
-rw-r--r-- | core/src/OCP/toast.js | 111 |
2 files changed, 56 insertions, 63 deletions
diff --git a/core/src/OCP/index.js b/core/src/OCP/index.js index d8640b1ff0c..4f2c47f1fa4 100644 --- a/core/src/OCP/index.js +++ b/core/src/OCP/index.js @@ -1,13 +1,10 @@ -/** - * - */ import * as AppConfig from './appconfig' import * as Comments from './comments' import Loader from './loader' import { loadState } from '@nextcloud/initial-state' import Collaboration from './collaboration' -import Toast from './toast' import * as WhatsNew from './whatsnew' +import Toast from './toast' /** @namespace OCP */ export default { @@ -21,6 +18,9 @@ export default { loadState, }, Loader, + /** + * @deprecated 19.0.0 use the `@nextcloud/dialogs` package instead + */ Toast, WhatsNew, } diff --git a/core/src/OCP/toast.js b/core/src/OCP/toast.js index 6bb3b130287..e5331377dc9 100644 --- a/core/src/OCP/toast.js +++ b/core/src/OCP/toast.js @@ -20,70 +20,63 @@ * */ -import Toastify from 'toastify-js' +import { + showError, + showInfo, showMessage, + showSuccess, + showWarning, +} from '@nextcloud/dialogs' -const TOAST_TYPE_CLASES = { - error: 'toast-error', - info: 'toast-info', - warning: 'toast-warning', - success: 'toast-success', - permanent: 'permanent', -} - -const Toast = { - - success(text, options = {}) { - options.type = 'success' - return this.message(text, options) +export default { + /** + * @deprecated 19.0.0 use `showSuccess` from the `@nextcloud/dialogs` package instead + * + * @param {string} text the toast text + * @param {object} options options + * @returns {Toast} + */ + success(text, options) { + return showSuccess(text, options) }, - - warning(text, options = {}) { - options.type = 'warning' - return this.message(text, options) + /** + * @deprecated 19.0.0 use `showWarning` from the `@nextcloud/dialogs` package instead + * + * @param {string} text the toast text + * @param {object} options options + * @returns {Toast} + */ + warning(text, options) { + return showWarning(text, options) }, - - error(text, options = {}) { - options.type = 'error' - return this.message(text, options) + /** + * @deprecated 19.0.0 use `showError` from the `@nextcloud/dialogs` package instead + * + * @param {string} text the toast text + * @param {object} options options + * @returns {Toast} + */ + error(text, options) { + return showError(text, options) }, - - info(text, options = {}) { - options.type = 'info' - return this.message(text, options) + /** + * @deprecated 19.0.0 use `showInfo` from the `@nextcloud/dialogs` package instead + * + * @param {string} text the toast text + * @param {object} options options + * @returns {Toast} + */ + info(text, options) { + return showInfo(text, options) }, - + /** + * @deprecated 19.0.0 use `showMessage` from the `@nextcloud/dialogs` package instead + * + * @param {string} text the toast text + * @param {object} options options + * @returns {Toast} + */ message(text, options) { - options = options || {} - _.defaults(options, { - timeout: 7, - isHTML: false, - type: undefined, - close: true, - callback: () => {}, - }) - if (!options.isHTML) { - text = $('<div/>').text(text).html() - } - let classes = '' - if (options.type) { - classes = TOAST_TYPE_CLASES[options.type] - } - - const toast = Toastify({ - text: text, - duration: options.timeout ? options.timeout * 1000 : null, - callback: options.callback, - close: options.close, - gravity: 'top', - selector: !window.TESTING ? 'content' : 'testArea', - positionLeft: false, - backgroundColor: '', - className: 'toast ' + classes, - }) - toast.showToast() - // add toastify object to the element for reference in legacy OC.Notification - toast.toastElement.toastify = toast - return toast + return showMessage(text, options) }, + } -export default Toast |