From f0f91b7ab2c56c8075b0d1fe26f96ba6e13f9e81 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 28 Jan 2020 13:43:31 +0100 Subject: [PATCH] Create the folders recursively if a new pad path doesn't exist --- www/common/outer/userObject.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/www/common/outer/userObject.js b/www/common/outer/userObject.js index 5a2693fd9..004018c12 100644 --- a/www/common/outer/userObject.js +++ b/www/common/outer/userObject.js @@ -438,14 +438,24 @@ define([ parentEl.push(id); 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']); - if (path && exp.isPathIn(newPath, [ROOT]) || filesList.indexOf(id) === -1) { - parentEl = exp.find(newPath || [ROOT]); + if (filesList.indexOf(id) === -1 && !newPath) { + newPath = [ROOT]; + } + // Add to root + if (path && exp.isPathIn(newPath, [ROOT])) { + var parentEl = exp.find(newPath); if (parentEl) { var newName = exp.getAvailableName(parentEl, Hash.createChannelId()); parentEl[newName] = id; return; + } else { + parentEl = exp.find([ROOT]); + newPath.slice(1).forEach(function (folderName) { + parentEl = parentEl[folderName] = parentEl[folderName] || {}; + }); + parentEl[Hash.createChannelId()] = id; } } };