diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-01-31 18:28:26 +0100 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-02-01 07:56:38 +0100 |
commit | 4846aea9517d1bda4293e3064179f777c1d07aa1 (patch) | |
tree | 8e4b8152b20e054b4998f304a93b16f6bb2afa88 /core/src | |
parent | 4fcadd27b05f0b2c2d1e56a15235670ade12e888 (diff) | |
download | nextcloud-server-4846aea9517d1bda4293e3064179f777c1d07aa1.tar.gz nextcloud-server-4846aea9517d1bda4293e3064179f777c1d07aa1.zip |
Move OC.msg to the server bundle
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/OC/index.js | 2 | ||||
-rw-r--r-- | core/src/OC/msg.js | 117 |
2 files changed, 119 insertions, 0 deletions
diff --git a/core/src/OC/index.js b/core/src/OC/index.js index c4c283ad332..f79fd5755e6 100644 --- a/core/src/OC/index.js +++ b/core/src/OC/index.js @@ -25,6 +25,7 @@ import Backbone from './backbone' import ContactsMenu from './contactsmenu' import EventSource from './eventsource' import L10N from './l10n' +import msg from './msg' import Notification from './notification' /** @namespace OC */ @@ -35,5 +36,6 @@ export default { ContactsMenu, EventSource, L10N, + msg, Notification, } diff --git a/core/src/OC/msg.js b/core/src/OC/msg.js new file mode 100644 index 00000000000..1d43b4375e7 --- /dev/null +++ b/core/src/OC/msg.js @@ -0,0 +1,117 @@ +/* global t */ + +/* + * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @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 $ from 'jquery'; + +/** + * A little class to manage a status field for a "saving" process. + * It can be used to display a starting message (e.g. "Saving...") and then + * replace it with a green success message or a red error message. + * + * @namespace OC.msg + */ +export default { + /** + * Displayes a "Saving..." message in the given message placeholder + * + * @param {Object} selector Placeholder to display the message in + */ + startSaving: function (selector) { + this.startAction(selector, t('core', 'Saving...')); + }, + + /** + * Displayes a custom message in the given message placeholder + * + * @param {Object} selector Placeholder to display the message in + * @param {string} message Plain text message to display (no HTML allowed) + */ + startAction: function (selector, message) { + $(selector).text(message) + .removeClass('success') + .removeClass('error') + .stop(true, true) + .show(); + }, + + /** + * Displayes an success/error message in the given selector + * + * @param {Object} selector Placeholder to display the message in + * @param {Object} response Response of the server + * @param {Object} response.data Data of the servers response + * @param {string} response.data.message Plain text message to display (no HTML allowed) + * @param {string} response.status is being used to decide whether the message + * is displayed as an error/success + */ + finishedSaving: function (selector, response) { + this.finishedAction(selector, response); + }, + + /** + * Displayes an success/error message in the given selector + * + * @param {Object} selector Placeholder to display the message in + * @param {Object} response Response of the server + * @param {Object} response.data Data of the servers response + * @param {string} response.data.message Plain text message to display (no HTML allowed) + * @param {string} response.status is being used to decide whether the message + * is displayed as an error/success + */ + finishedAction: function (selector, response) { + if (response.status === "success") { + this.finishedSuccess(selector, response.data.message); + } else { + this.finishedError(selector, response.data.message); + } + }, + + /** + * Displayes an success message in the given selector + * + * @param {Object} selector Placeholder to display the message in + * @param {string} message Plain text success message to display (no HTML allowed) + */ + finishedSuccess: function (selector, message) { + $(selector).text(message) + .addClass('success') + .removeClass('error') + .stop(true, true) + .delay(3000) + .fadeOut(900) + .show(); + }, + + /** + * Displayes an error message in the given selector + * + * @param {Object} selector Placeholder to display the message in + * @param {string} message Plain text error message to display (no HTML allowed) + */ + finishedError: function (selector, message) { + $(selector).text(message) + .addClass('error') + .removeClass('success') + .show(); + } +} |