1616 * marking the object for deletion.
1717 * @param {removeCallback } removeCallback the function to be called after
1818 * successful delete.
19+ * @param {undoCallback } undoCallback called after "undo" was clicked
1920 */
20- function DeleteHandler ( endpoint , paramID , markCallback , removeCallback ) {
21+ function DeleteHandler ( endpoint , paramID , markCallback , removeCallback , undoCallback ) {
2122 this . oidToDelete = false ;
2223 this . canceled = false ;
2324
@@ -26,69 +27,8 @@ function DeleteHandler(endpoint, paramID, markCallback, removeCallback) {
2627
2728 this . markCallback = markCallback ;
2829 this . removeCallback = removeCallback ;
29- this . undoCallback = false ;
30-
31- this . notifier = false ;
32- this . notificationDataID = false ;
33- this . notificationMessage = false ;
34- this . notificationPlaceholder = '%oid' ;
35- }
36-
37- /**
38- * Number of milliseconds after which the operation is performed.
39- */
40- DeleteHandler . TIMEOUT_MS = 7000 ;
41-
42- /**
43- * Timer after which the action will be performed anyway.
44- */
45- DeleteHandler . prototype . _timeout = null ;
46-
47- /**
48- * enabled the notification system. Required for undo UI.
49- *
50- * @param {object } notifier Usually OC.Notification
51- * @param {string } dataID an identifier for the notifier, e.g. 'deleteuser'
52- * @param {string } message the message that should be shown upon delete. %oid
53- * will be replaced with the affected id of the item to be deleted
54- * @param {undoCallback } undoCallback called after "undo" was clicked
55- */
56- DeleteHandler . prototype . setNotification = function ( notifier , dataID , message , undoCallback ) {
57- this . notifier = notifier ;
58- this . notificationDataID = dataID ;
59- this . notificationMessage = message ;
6030 this . undoCallback = undoCallback ;
61-
62- var dh = this ;
63-
64- $ ( '#notification' )
65- . off ( 'click.deleteHandler_' + dataID )
66- . on ( 'click.deleteHandler_' + dataID , '.undo' , function ( ) {
67- if ( $ ( '#notification' ) . data ( dh . notificationDataID ) ) {
68- var oid = dh . oidToDelete ;
69- dh . cancel ( ) ;
70- if ( typeof dh . undoCallback !== 'undefined' ) {
71- dh . undoCallback ( oid ) ;
72- }
73- }
74- dh . notifier . hide ( ) ;
75- } ) ;
76- } ;
77-
78- /**
79- * shows the Undo Notification (if configured)
80- */
81- DeleteHandler . prototype . showNotification = function ( ) {
82- if ( this . notifier !== false ) {
83- if ( ! this . notifier . isHidden ( ) ) {
84- this . hideNotification ( ) ;
85- }
86- $ ( '#notification' ) . data ( this . notificationDataID , true ) ;
87- var msg = this . notificationMessage . replace (
88- this . notificationPlaceholder , escapeHTML ( decodeURIComponent ( this . oidToDelete ) ) ) ;
89- this . notifier . showHtml ( msg ) ;
90- }
91- } ;
31+ }
9232
9333/**
9434 * initializes the delete operation for a given object id
@@ -105,20 +45,14 @@ DeleteHandler.prototype.mark = function(oid) {
10545 * initialized by mark(). On error, it will show a message via
10646 * OC.dialogs.alert. On success, a callback is fired so that the client can
10747 * update the web interface accordingly.
108- *
109- * @param {boolean } [keepNotification] true to keep the notification, false to hide
110- * it, defaults to false
11148 */
112- DeleteHandler . prototype . deleteEntry = function ( keepNotification ) {
49+ DeleteHandler . prototype . deleteEntry = function ( ) {
11350 var deferred = $ . Deferred ( ) ;
11451 if ( this . oidToDelete === false ) {
11552 return deferred . resolve ( ) . promise ( ) ;
11653 }
11754
11855 var dh = this ;
119- if ( ! keepNotification && $ ( '#notification' ) . data ( this . notificationDataID ) === true ) {
120- dh . hideNotification ( ) ;
121- }
12256
12357 var payload = { } ;
12458 payload [ dh . ajaxParamID ] = dh . oidToDelete ;
@@ -134,9 +68,12 @@ DeleteHandler.prototype.deleteEntry = function(keepNotification) {
13468 dh . removeCallback ( dh . oidToDelete ) ;
13569 } ,
13670 error : function ( jqXHR ) {
137- OC . dialogs . alert ( jqXHR . responseJSON . data . message , t ( 'settings' , 'Unable to delete {objName}' , { objName : decodeURIComponent ( dh . oidToDelete ) } ) ) ;
71+ var msg = 'Unknown error' ;
72+ if ( jqXHR . responseJSON && jqXHR . responseJSON . data && jqXHR . responseJSON . data . message ) {
73+ msg = jqXHR . responseJSON . data . message ;
74+ }
75+ OC . dialogs . alert ( msg , t ( 'settings' , 'Unable to delete {objName}' , { objName : decodeURIComponent ( dh . oidToDelete ) } ) ) ;
13876 dh . undoCallback ( dh . oidToDelete ) ;
139-
14077 }
14178 } ) ;
14279} ;
0 commit comments