summaryrefslogtreecommitdiffstats
path: root/core/src/OCP
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2019-03-01 13:02:12 +0100
committerJulius Härtl <jus@bitgrid.net>2019-06-07 07:32:16 +0200
commit2d0337332d64065c5bf36dfb775c48976c0f730d (patch)
treef863ac28782caf124f68baecffef86576570c6f0 /core/src/OCP
parent07ffe4a34a9b3e63f33603a2e2bd49ea98293d88 (diff)
downloadnextcloud-server-2d0337332d64065c5bf36dfb775c48976c0f730d.tar.gz
nextcloud-server-2d0337332d64065c5bf36dfb775c48976c0f730d.zip
Add toastify js as a OC.Notification replacement
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'core/src/OCP')
-rw-r--r--core/src/OCP/index.js6
-rw-r--r--core/src/OCP/toast.js89
2 files changed, 93 insertions, 2 deletions
diff --git a/core/src/OCP/index.js b/core/src/OCP/index.js
index 67945318362..a4d8f46b88d 100644
--- a/core/src/OCP/index.js
+++ b/core/src/OCP/index.js
@@ -6,14 +6,16 @@ import * as Comments from './comments'
import * as InitialState from './initialstate'
import Loader from './loader'
import Collaboration from './collaboration'
+import Toast from './toast'
import * as WhatsNew from './whatsnew'
/** @namespace OCP */
export default {
AppConfig,
+ Collaboration,
Comments,
InitialState,
Loader,
- WhatsNew,
- Collaboration
+ Toast,
+ WhatsNew
};
diff --git a/core/src/OCP/toast.js b/core/src/OCP/toast.js
new file mode 100644
index 00000000000..a9c96f14a70
--- /dev/null
+++ b/core/src/OCP/toast.js
@@ -0,0 +1,89 @@
+/*
+ * @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import Toastify from 'toastify-js'
+
+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)
+ },
+
+ warning(text, options = {}) {
+ options.type = 'warning';
+ return this.message(text, options)
+ },
+
+ error(text, options = {}) {
+ options.type = 'error';
+ return this.message(text, options)
+ },
+
+ info(text, options = {}) {
+ options.type = 'info';
+ return this.message(text, options)
+ },
+
+ message(text, options) {
+ options = options || {};
+ _.defaults(options, {
+ timeout: 7,
+ showHtml: false,
+ type: undefined,
+ close: true,
+ callback: () => {}
+ });
+ if (!options.showHtml) {
+ 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: 'content',
+ 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
+ }
+}
+export default Toast