@@ -265,32 +265,68 @@ export class FancytreeAdapter {
265
265
let parenPath = parentNode . data . refPath ;
266
266
let targetPath = parenPath + '/' + dropNodePath . substr ( 1 + dropNodePath . lastIndexOf ( '/' ) ) ;
267
267
268
- dropedNode . icon = 'fa fa-spinner fa-spin' ;
269
- dropedNode . renderTitle ( ) ;
268
+ let formerIcon = dropedNode . icon ;
270
269
271
270
let moveNodeInTree = ( responseData ) => {
272
271
dropedNode . remove ( ) ;
273
272
parentNode . addChildren ( requestNodeToFancytreeNode ( responseData ) ) ;
274
273
} ;
275
- let onError = ( jqxhr , textStatus , errorThrown ) => {
276
- node . _error = { message : 'Failed to move the node.' , details : errorThrown } ;
277
- node . renderStatus ( ) ;
278
- console . error ( errorThrown ) ;
279
-
280
- setTimeout ( function ( ) {
281
- node . _error = null ;
282
- node . renderStatus ( ) ;
283
- } , 1000 ) ;
274
+
275
+ let setIcon = ( nodeToSetOn , icon ) => {
276
+ nodeToSetOn . icon = icon ;
277
+ dropedNode . renderTitle ( ) ;
278
+ } ;
279
+
280
+ setIcon ( dropedNode , 'fa fa-spinner fa-spin' )
281
+
282
+ let onError = ( jqxhr ) => {
283
+ let message = 'Failed to move node' ;
284
+ let formerLabel = dropedNode . title ;
285
+ if ( jqxhr . hasOwnProperty ( 'responseJSON' ) && jqxhr . responseJSON . hasOwnProperty ( 'message' ) ) {
286
+ message += ': ' + jqxhr . responseJSON . message ;
287
+ }
288
+ let details = null ;
289
+ if ( jqxhr . hasOwnProperty ( 'responseJSON' ) ) {
290
+ details = jqxhr . responseJSON ;
291
+ }
292
+ dropedNode . _error = { message : message , details : details } ;
293
+ dropedNode . renderStatus ( ) ;
294
+
295
+ dropedNode . title += '[' + message + ']' ;
296
+ dropedNode . renderTitle ( ) ;
297
+
298
+ console . error ( message ) ;
299
+ setIcon ( dropedNode , formerIcon ) ;
300
+
301
+ setTimeout ( function ( ) {
302
+ dropedNode . _error = null ;
303
+ dropedNode . title = formerLabel ;
304
+ dropedNode . renderTitle ( ) ;
305
+ dropedNode . renderStatus ( ) ;
306
+ } , 1000 ) ;
284
307
} ;
285
308
this . requestData . move ( dropNodePath , targetPath ) . done ( ( responseData ) => {
286
309
if ( this . dndOptions . reorder ) {
287
310
this . requestData . reorder ( parenPath , dropedAtPath , targetPath , data . hitMode ) . done ( ( responseData ) => {
288
311
moveNodeInTree ( responseData ) ;
289
312
if ( fancytreeOptions . hasOwnProperty ( 'sortChildren' ) ) {
290
- parentNode . sortChildren ( fancytreeOptions . sortChildren , true ) ;
313
+ parentNode . sortChildren ( fancytreeOptions . sortChildren , true ) ;
291
314
}
292
- } ) . fail ( onError ) ;
315
+ setIcon ( dropedNode , formerIcon ) ;
316
+ } ) . fail ( ( jqxhr ) => {
317
+ onError ( jqxhr ) ;
318
+ setTimeout ( ( ) => {
319
+ this . requestData . move ( targetPath , dropNodePath ) . done ( ( responseData ) => {
320
+ if ( fancytreeOptions . hasOwnProperty ( 'sortChildren' ) ) {
321
+ parentNode . sortChildren ( fancytreeOptions . sortChildren , true ) ;
322
+ }
323
+ setIcon ( dropedNode , formerIcon ) ;
324
+ } ) ;
325
+ } , 1000 ) ;
326
+
327
+ } ) ;
293
328
} else {
329
+ dropedNode . icon = formerIcon ;
294
330
moveNodeInTree ( responseData ) ;
295
331
}
296
332
} ) . fail ( onError ) ;
0 commit comments