ownCloud follows the design principle of Never Use a Warning When you Mean Undo : Instead of showing a popup dialog that you have to confirm to e.g. delete a file, the action is taken immediately. ownCloud does however show a small notice that something has been deleted. Clicking the notice will restore the deleted items.
When the user clicks "delete", a request is sent to the server and the token's database row gets the "deleted" flag set. A notification is shown, telling the user that he can restore the token by clicking on the notice.
When the user clicks "undo", another request is sent to the server and the deleted flag gets reset.
This also implies a way to clean the database of deleted tokens.
- A possible solution is a trash view in which all deleted tokens are shown. There they can be deleted permanently.
- Another solution is to send another request to the server after the "you deleted the token" message disappears. This is non-deterministic since the user may leave the page earlier.
- One could run a cronjob every day to permanently remove deleted tokens.
If the user clicks the notification within the 5 seconds, the timer is stopped. The token row in the HTML table is made visible again.
When the user leaves the page within the 5 seconds, the delete action requests are immediately sent to the server via an onbeforeunload event handler. You have to send the requests in synchronous mode, since the browser tab will be closed before the request reaches the server in async mode.
You also have to take care of multiple timeouts: What happens if the user deletes 2 tokens and then clicks undo? I chose to restore both tokens.