5 * 1. User clicks "delete"
6 * 2. Notification appears for 5 seconds
7 * 3. Token row is faded out
8 * 4a User clicks on notification:
9 * - Action is cancelled
10 * - Token row is faded in
11 * 4b User does not click on notification:
12 * - Action gets executed 5 seconds after the delete click
13 * - Token row gets removed
17 * 1. User clicks "delete"
18 * 2. Notification appears for 5 seconds
19 * 3. User clicks "delete"
20 * 4. Notification appears for 5 seconds
21 * 5a User clicks on notification: All pending actions are cancelled
22 * 5b User does not click on notification
23 * - Action 1 gets executed 5 seconds after the first click
24 * - Action 2 gets executed 5 seconds after the second click
27 simpleUndo: function(undoTask) {
28 var notifier = $('#notification');
30 notifier.off('click');
31 notifier.text('Token has been deleted. Click to undo.');
34 $('#' + undoTask.elementId).fadeOut();
36 OC.grauphel.startGuiTimer(timeout, notifier);
37 var timer = setTimeout(
39 var dataid = timer.toString();
40 OC.grauphel.executeTask(notifier.data(dataid), true);
41 notifier.removeData(dataid);
45 var dataid = timer.toString();
46 notifier.data(dataid, undoTask);
48 notifier.on('click', function() {
49 for (var id in notifier.data()) {
50 clearTimeout(parseInt(id));
51 notifier.off('click');
52 OC.grauphel.restore(notifier.data(id));
53 notifier.removeData(id);
58 executeTask: function(task, async) {
59 //console.log("execute task: ", task);
67 restore: function(undoTask) {
68 $('#' + undoTask.elementId).fadeIn();
70 var notifier = $('#notification');
72 notifier.off('click');
73 notifier.text('Token has been restored.');
75 OC.grauphel.startGuiTimer(timeout, notifier);
76 notifier.on('click', function() {
77 clearTimeout(OC.grauphel.guiTimer);
82 executeAllTasks: function() {
83 var notifier = $('#notification');
84 for (var id in notifier.data()) {
85 clearTimeout(parseInt(id));
86 OC.grauphel.executeTask(notifier.data(id), false);
87 notifier.removeData(id);
93 startGuiTimer: function(timeout, notifier) {
94 if (OC.grauphel.guiTimer !== null) {
95 clearTimeout(OC.grauphel.guiTimer);
97 OC.grauphel.guiTimer = setTimeout(
100 notifier.off('click');
107 $(document).ready(function() {
108 $('#grauphel-tokens .delete').click(
110 event.preventDefault();
114 'url': $(this).parent('form').attr('action'),
115 'elementId': $(this).data('token')
117 OC.grauphel.simpleUndo(undoTask);
122 //in case a user deletes tokens and leaves the page within the 5 seconds
123 window.onbeforeunload = function(e) {
124 OC.grauphel.executeAllTasks();