Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit ff3562f

Browse files
committed
#158 fix error handling and move back on failing reorder
1 parent 0cdf15f commit ff3562f

File tree

1 file changed

+49
-13
lines changed

1 file changed

+49
-13
lines changed

src/Resources/assets/js/adapter/fancytree.js

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -265,32 +265,68 @@ export class FancytreeAdapter {
265265
let parenPath = parentNode.data.refPath;
266266
let targetPath = parenPath + '/' + dropNodePath.substr(1 + dropNodePath.lastIndexOf('/'));
267267

268-
dropedNode.icon = 'fa fa-spinner fa-spin';
269-
dropedNode.renderTitle();
268+
let formerIcon = dropedNode.icon;
270269

271270
let moveNodeInTree = (responseData) => {
272271
dropedNode.remove();
273272
parentNode.addChildren(requestNodeToFancytreeNode(responseData));
274273
};
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);
284307
};
285308
this.requestData.move(dropNodePath, targetPath).done((responseData) => {
286309
if (this.dndOptions.reorder) {
287310
this.requestData.reorder(parenPath, dropedAtPath, targetPath, data.hitMode).done((responseData) => {
288311
moveNodeInTree(responseData);
289312
if (fancytreeOptions.hasOwnProperty('sortChildren')) {
290-
parentNode.sortChildren(fancytreeOptions.sortChildren, true);
313+
parentNode.sortChildren(fancytreeOptions.sortChildren, true);
291314
}
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+
});
293328
} else {
329+
dropedNode.icon = formerIcon;
294330
moveNodeInTree(responseData);
295331
}
296332
}).fail(onError);

0 commit comments

Comments
 (0)