@@ -265,32 +265,75 @@ 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 ( ) ;
272
+ if ( positionBefore ) {
273
+ parentNode . children . forEach ( ( node ) => {
274
+ if ( node . data . position >= responseData . descriptors . position ) {
275
+ node . data . position ++ ;
276
+ }
277
+ } ) ;
278
+ }
273
279
parentNode . addChildren ( requestNodeToFancytreeNode ( responseData ) ) ;
274
280
} ;
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 ) ;
281
+
282
+ let setIcon = ( nodeToSetOn , icon ) => {
283
+ nodeToSetOn . icon = icon ;
284
+ dropedNode . renderTitle ( ) ;
285
+ } ;
286
+
287
+ setIcon ( dropedNode , 'fa fa-spinner fa-spin' )
288
+
289
+ let onError = ( jqxhr ) => {
290
+ let message = 'Failed to move node' ;
291
+ let formerLabel = dropedNode . title ;
292
+ if ( jqxhr . hasOwnProperty ( 'responseJSON' ) && jqxhr . responseJSON . hasOwnProperty ( 'message' ) ) {
293
+ message += ': ' + jqxhr . responseJSON . message ;
294
+ }
295
+ let details = null ;
296
+ if ( jqxhr . hasOwnProperty ( 'responseJSON' ) ) {
297
+ details = jqxhr . responseJSON ;
298
+ }
299
+ dropedNode . _error = { message : message , details : details } ;
300
+ dropedNode . renderStatus ( ) ;
301
+
302
+ dropedNode . title += '[' + message + ']' ;
303
+ dropedNode . renderTitle ( ) ;
304
+
305
+ console . error ( message ) ;
306
+ setIcon ( dropedNode , formerIcon ) ;
307
+
308
+ setTimeout ( function ( ) {
309
+ dropedNode . _error = null ;
310
+ dropedNode . title = formerLabel ;
311
+ dropedNode . renderTitle ( ) ;
312
+ dropedNode . renderStatus ( ) ;
313
+ } , 1000 ) ;
284
314
} ;
285
315
this . requestData . move ( dropNodePath , targetPath ) . done ( ( responseData ) => {
286
- if ( this . dndOptions . reorder ) {
316
+ if ( positionBefore && this . dndOptions . reorder ) {
287
317
this . requestData . reorder ( parenPath , dropedAtPath , targetPath , data . hitMode ) . done ( ( responseData ) => {
288
318
moveNodeInTree ( responseData ) ;
289
319
if ( fancytreeOptions . hasOwnProperty ( 'sortChildren' ) ) {
290
- parentNode . sortChildren ( fancytreeOptions . sortChildren , true ) ;
320
+ parentNode . sortChildren ( fancytreeOptions . sortChildren , true ) ;
291
321
}
292
- } ) . fail ( onError ) ;
322
+ setIcon ( dropedNode , formerIcon ) ;
323
+ } ) . fail ( ( jqxhr ) => {
324
+ onError ( jqxhr ) ;
325
+ setTimeout ( ( ) => {
326
+ this . requestData . move ( targetPath , dropNodePath ) . done ( ( responseData ) => {
327
+ if ( fancytreeOptions . hasOwnProperty ( 'sortChildren' ) ) {
328
+ parentNode . sortChildren ( fancytreeOptions . sortChildren , true ) ;
329
+ }
330
+ setIcon ( dropedNode , formerIcon ) ;
331
+ } ) ;
332
+ } , 1000 ) ;
333
+
334
+ } ) ;
293
335
} else {
336
+ dropedNode . icon = formerIcon ;
294
337
moveNodeInTree ( responseData ) ;
295
338
}
296
339
} ) . fail ( onError ) ;
0 commit comments