Create the folders recursively if a new pad path doesn't exist

pull/1/head
yflory 5 years ago
parent b8ec7178da
commit f0f91b7ab2

@ -438,14 +438,24 @@ define([
parentEl.push(id); parentEl.push(id);
return; return;
} }
// Add to root if path is ROOT or if no path // Add to root if no path
var filesList = exp.getFiles([ROOT, TRASH, 'hrefArray']); var filesList = exp.getFiles([ROOT, TRASH, 'hrefArray']);
if (path && exp.isPathIn(newPath, [ROOT]) || filesList.indexOf(id) === -1) { if (filesList.indexOf(id) === -1 && !newPath) {
parentEl = exp.find(newPath || [ROOT]); newPath = [ROOT];
}
// Add to root
if (path && exp.isPathIn(newPath, [ROOT])) {
var parentEl = exp.find(newPath);
if (parentEl) { if (parentEl) {
var newName = exp.getAvailableName(parentEl, Hash.createChannelId()); var newName = exp.getAvailableName(parentEl, Hash.createChannelId());
parentEl[newName] = id; parentEl[newName] = id;
return; return;
} else {
parentEl = exp.find([ROOT]);
newPath.slice(1).forEach(function (folderName) {
parentEl = parentEl[folderName] = parentEl[folderName] || {};
});
parentEl[Hash.createChannelId()] = id;
} }
} }
}; };

Loading…
Cancel
Save