summaryrefslogtreecommitdiffstats
path: root/settings/js
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-09-11 15:56:00 +0200
committerLukas Reschke <lukas@owncloud.com>2014-09-15 14:04:44 +0200
commit0d9f24a0efef20b9041e40817b10822a4700532d (patch)
tree17d9640bcb15229cfe964ac53e82b40946d79e57 /settings/js
parent31898aa63548be8492b826b9bac6dc0f8bca8dee (diff)
downloadnextcloud-server-0d9f24a0efef20b9041e40817b10822a4700532d.tar.gz
nextcloud-server-0d9f24a0efef20b9041e40817b10822a4700532d.zip
Add timeout to user and group deletion notification
Added timeout in DeleteHandler to auto-delete after a delay. Fixed issue where OC.Notification.hide() was called twice in a row when deleting multiple entries, causing the second notification to disappear. Fixed issue where "undo" click event handler was registered multiple times when calling setNotifications() twice. Added JS unit tests for the DeleteHandler class. Refix undo users, groups feature Timeout is now cleared in cancel(). Fixed click handler name for "undo" to be able to work with multiple DeleteHandler instances (in our case one for users and one for groups) so that there is no conflict.
Diffstat (limited to 'settings/js')
-rw-r--r--settings/js/users/deleteHandler.js47
1 files changed, 43 insertions, 4 deletions
diff --git a/settings/js/users/deleteHandler.js b/settings/js/users/deleteHandler.js
index d4736d88701..c89a844044e 100644
--- a/settings/js/users/deleteHandler.js
+++ b/settings/js/users/deleteHandler.js
@@ -35,6 +35,16 @@ function DeleteHandler(endpoint, paramID, markCallback, removeCallback) {
}
/**
+ * Number of milliseconds after which the operation is performed.
+ */
+DeleteHandler.TIMEOUT_MS = 7000;
+
+/**
+ * Timer after which the action will be performed anyway.
+ */
+DeleteHandler.prototype._timeout = null;
+
+/**
* The function to be called after successfully marking the object for deletion
* @callback markCallback
* @param {string} oid the ID of the specific user or group
@@ -72,7 +82,9 @@ DeleteHandler.prototype.setNotification = function(notifier, dataID, message, un
var dh = this;
- $('#notification').on('click', '.undo', function () {
+ $('#notification')
+ .off('click.deleteHandler_' + dataID)
+ .on('click.deleteHandler_' + dataID, '.undo', function () {
if ($('#notification').data(dh.notificationDataID)) {
var oid = dh.oidToDelete;
dh.cancel();
@@ -116,18 +128,36 @@ DeleteHandler.prototype.hideNotification = function() {
*/
DeleteHandler.prototype.mark = function(oid) {
if(this.oidToDelete !== false) {
- this.deleteEntry();
+ // passing true to avoid hiding the notification
+ // twice and causing the second notification
+ // to disappear immediately
+ this.deleteEntry(true);
}
this.oidToDelete = oid;
this.canceled = false;
this.markCallback(oid);
this.showNotification();
+ if (this._timeout) {
+ clearTimeout(this._timeout);
+ this._timeout = null;
+ }
+ if (DeleteHandler.TIMEOUT_MS > 0) {
+ this._timeout = window.setTimeout(
+ _.bind(this.deleteEntry, this),
+ DeleteHandler.TIMEOUT_MS
+ );
+ }
};
/**
* cancels a delete operation
*/
DeleteHandler.prototype.cancel = function() {
+ if (this._timeout) {
+ clearTimeout(this._timeout);
+ this._timeout = null;
+ }
+
this.canceled = true;
this.oidToDelete = false;
};
@@ -137,22 +167,31 @@ DeleteHandler.prototype.cancel = function() {
* initialized by mark(). On error, it will show a message via
* OC.dialogs.alert. On success, a callback is fired so that the client can
* update the web interface accordingly.
+ *
+ * @param {boolean} [keepNotification] true to keep the notification, false to hide
+ * it, defaults to false
*/
-DeleteHandler.prototype.deleteEntry = function() {
+DeleteHandler.prototype.deleteEntry = function(keepNotification) {
if(this.canceled || this.oidToDelete === false) {
return false;
}
var dh = this;
- if($('#notification').data(this.notificationDataID) === true) {
+ if(!keepNotification && $('#notification').data(this.notificationDataID) === true) {
dh.hideNotification();
}
+ if (this._timeout) {
+ clearTimeout(this._timeout);
+ this._timeout = null;
+ }
+
var payload = {};
payload[dh.ajaxParamID] = dh.oidToDelete;
$.ajax({
type: 'POST',
url: OC.filePath('settings', 'ajax', dh.ajaxEndpoint),
+ // FIXME: do not use synchronous ajax calls as they block the browser !
async: false,
data: payload,
success: function (result) {
eight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
SPDX-License-Identifier: MIT
SPDX-License-Identifier: ISC
SPDX-License-Identifier: GPL-3.0-or-later
SPDX-License-Identifier: BSD-3-Clause
SPDX-License-Identifier: AGPL-3.0-or-later
SPDX-License-Identifier: (MPL-2.0 OR Apache-2.0)
SPDX-FileCopyrightText: inherits developers
SPDX-FileCopyrightText: escape-html developers
SPDX-FileCopyrightText: debounce developers
SPDX-FileCopyrightText: assert developers
SPDX-FileCopyrightText: Varun A P
SPDX-FileCopyrightText: Tobias Koppers @sokra
SPDX-FileCopyrightText: T. Jameson Little <t.jameson.little@gmail.com>
SPDX-FileCopyrightText: Roman Shtylman <shtylman@gmail.com>
SPDX-FileCopyrightText: Raynos <raynos2@gmail.com>
SPDX-FileCopyrightText: Nextcloud GmbH and Nextcloud contributors
SPDX-FileCopyrightText: Matt Zabriskie
SPDX-FileCopyrightText: Joyent
SPDX-FileCopyrightText: Jordan Harband <ljharb@gmail.com>
SPDX-FileCopyrightText: Jordan Harband
SPDX-FileCopyrightText: John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)
SPDX-FileCopyrightText: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
SPDX-FileCopyrightText: Guillaume Chau <guillaume.b.chau@gmail.com>
SPDX-FileCopyrightText: GitHub Inc.
SPDX-FileCopyrightText: Feross Aboukhadijeh
SPDX-FileCopyrightText: Evan You
SPDX-FileCopyrightText: Dr.-Ing. Mario Heiderich, Cure53 <mario@cure53.de> (https://cure53.de/)
SPDX-FileCopyrightText: Denis Pushkarev
SPDX-FileCopyrightText: David Clark
SPDX-FileCopyrightText: Christoph Wurst
SPDX-FileCopyrightText: Anthony Fu <https://github.com/antfu>
SPDX-FileCopyrightText: Andris Reinman
SPDX-FileCopyrightText: @nextcloud/password-confirmation developers
SPDX-FileCopyrightText: @nextcloud/dialogs developers


This file is generated from multiple sources. Included packages:
- @nextcloud/auth
	- version: 2.3.0
	- license: GPL-3.0-or-later
- @nextcloud/axios
	- version: 2.5.0
	- license: GPL-3.0-or-later
- @nextcloud/dialogs
	- version: 5.3.1
	- license: GPL-3.0-or-later
- semver
	- version: 7.6.2
	- license: ISC
- @nextcloud/event-bus
	- version: 3.3.1
	- license: GPL-3.0-or-later
- @nextcloud/initial-state
	- version: 2.1.0
	- license: GPL-3.0-or-later
- @nextcloud/router
	- version: 2.2.0
	- license: GPL-3.0-or-later
- @nextcloud/l10n
	- version: 2.2.0
	- license: GPL-3.0-or-later
- @nextcloud/password-confirmation
	- version: 5.1.0
	- license: MIT
- @nextcloud/router
	- version: 3.0.1
	- license: GPL-3.0-or-later
- @nextcloud/logger
	- version: 2.7.0
	- license: GPL-3.0-or-later
- core-js
	- version: 3.33.0
	- license: MIT
- debounce
	- version: 2.0.0
	- license: MIT
- @nextcloud/vue
	- version: 8.11.2
	- license: AGPL-3.0-or-later
- @vueuse/core
	- version: 10.9.0
	- license: MIT
- @vueuse/shared
	- version: 10.9.0
	- license: MIT
- assert
	- version: 2.1.0
	- license: MIT
- available-typed-arrays
	- version: 1.0.7
	- license: MIT
- axios
	- version: 1.6.8
	- license: MIT
- base64-js
	- version: 1.5.1
	- license: MIT
- buffer
	- version: 6.0.3
	- license: MIT
- call-bind
	- version: 1.0.7
	- license: MIT
- console-browserify
	- version: 1.2.0
	- license: MIT
- css-loader
	- version: 6.10.0
	- license: MIT
- define-data-property
	- version: 1.1.4
	- license: MIT
- define-properties
	- version: 1.2.1
	- license: MIT
- dompurify
	- version: 3.1.4
	- license: (MPL-2.0 OR Apache-2.0)
- es-define-property
	- version: 1.0.0
	- license: MIT
- es-errors
	- version: 1.3.0
	- license: MIT
- escape-html
	- version: 1.0.3
	- license: MIT
- floating-vue
	- version: 1.0.0-beta.19
	- license: MIT
- focus-trap
	- version: 7.5.4
	- license: MIT
- for-each
	- version: 0.3.3
	- license: MIT
- function-bind
	- version: 1.1.2
	- license: MIT
- get-intrinsic
	- version: 1.2.4
	- license: MIT
- gopd
	- version: 1.0.1
	- license: MIT
- has-property-descriptors
	- version: 1.0.2
	- license: MIT
- has-proto
	- version: 1.0.3
	- license: MIT
- has-symbols
	- version: 1.0.3
	- license: MIT
- has-tostringtag
	- version: 1.0.2
	- license: MIT
- hasown
	- version: 2.0.1
	- license: MIT
- ieee754
	- version: 1.2.1
	- license: BSD-3-Clause
- inherits
	- version: 2.0.4
	- license: ISC
- is-arguments
	- version: 1.1.1
	- license: MIT
- is-callable
	- version: 1.2.7
	- license: MIT
- is-generator-function
	- version: 1.0.10
	- license: MIT
- is-nan
	- version: 1.3.2
	- license: MIT
- is-typed-array
	- version: 1.1.13
	- license: MIT
- lodash.get
	- version: 4.4.2
	- license: MIT
- node-gettext
	- version: 3.0.0
	- license: MIT
- object-is
	- version: 1.1.5
	- license: MIT
- object-keys
	- version: 1.1.1
	- license: MIT
- object.assign
	- version: 4.1.5
	- license: MIT
- inherits
	- version: 2.0.3
	- license: ISC
- util
	- version: 0.10.4
	- license: MIT
- path
	- version: 0.12.7
	- license: MIT
- possible-typed-array-names
	- version: 1.0.0
	- license: MIT
- process
	- version: 0.11.10
	- license: MIT
- set-function-length
	- version: 1.2.1
	- license: MIT
- style-loader
	- version: 3.3.4
	- license: MIT
- tabbable
	- version: 6.2.0
	- license: MIT
- toastify-js
	- version: 1.12.0
	- license: MIT
- util
	- version: 0.12.5
	- license: MIT
- vue-loader
	- version: 15.11.1
	- license: MIT
- vue
	- version: 2.7.16
	- license: MIT
- webpack
	- version: 5.91.0
	- license: MIT
- which-typed-array
	- version: 1.1.14
	- license: MIT
- nextcloud
	- version: 1.0.0
	- license: AGPL-3.0-or-later