Convert folder into shared folders now working

pull/1/head
ClemDee 5 years ago
parent 4a93d1829a
commit 1cddd99baa

@ -461,6 +461,62 @@ define([
cb(id); cb(id);
}); });
}; };
// convert a folder to a Shared Folder
var _convertFolderToSharedFolder = function (Env, data, cb) {
var path = data.path;
var folderElement = Env.user.userObject.find(path);
if (data.path.length <= 1) { return; }
if (_isInSharedFolder(Env, path)) { return; }
if (Env.user.userObject.hasSubSharedFolder(folderElement)) { return; }
var parentPath = path.slice(0, -1);
var parentFolder = Env.user.userObject.find(parentPath);
var folderName = path[path.length - 1];
var SFId;
var sharedFolderElement;
nThen(function (waitFor) {
// create shared folder
_addSharedFolder(Env, {
path: parentPath,
name: folderName,
owned: true,
password: '',
}, waitFor(function (id) { SFId = id; }));
}).nThen(function (waitFor) {
// move everything from folder to SF
if (!SFId) { return void cb(); }
var paths = [];
for (var el in folderElement) {
if (Env.user.userObject.isFolder(folderElement[el]) || Env.user.userObject.isFile(folderElement[el])) {
paths.push(path.concat(el));
}
}
var SFKey = Object.keys(parentFolder).find(function (el) {
return parentFolder[el] === SFId;
});
var newPath = parentPath.concat(SFKey).concat(UserObject.ROOT);
sharedFolderElement = Env.user.proxy[UserObject.SHARED_FOLDERS][SFId];
_move(Env, {
paths: paths,
newPath: newPath,
copy: false,
}, waitFor());
}).nThen(function (waitFor) {
// migrate metadata
var metadata = Env.user.userObject.getFolderData(folderElement);
for (var key in metadata) {
if (key === "metadata") { continue; }
sharedFolderElement[key] = metadata[key];
}
}).nThen(function (waitFor) {
// remove folder
Env.user.userObject.delete([path], waitFor());
}).nThen(function () {
// call callback
cb();
});
}
// Delete permanently some pads or folders // Delete permanently some pads or folders
var _delete = function (Env, data, cb) { var _delete = function (Env, data, cb) {
data = data || {}; data = data || {};
@ -598,6 +654,8 @@ define([
_addFolder(Env, data, cb); break; _addFolder(Env, data, cb); break;
case 'addSharedFolder': case 'addSharedFolder':
_addSharedFolder(Env, data, cb); break; _addSharedFolder(Env, data, cb); break;
case 'convertFolderToSharedFolder':
_convertFolderToSharedFolder(Env, data, cb); break;
case 'delete': case 'delete':
_delete(Env, data, cb); break; _delete(Env, data, cb); break;
case 'emptyTrash': case 'emptyTrash':
@ -914,6 +972,14 @@ define([
} }
}, cb); }, cb);
}; };
var convertFolderToSharedFolderInner = function (Env, path, cb) {
return void Env.sframeChan.query("Q_DRIVE_USEROBJECT", {
cmd: "convertFolderToSharedFolder",
data: {
path: path
}
}, cb);
};
var deleteInner = function (Env, paths, cb) { var deleteInner = function (Env, paths, cb) {
return void Env.sframeChan.query("Q_DRIVE_USEROBJECT", { return void Env.sframeChan.query("Q_DRIVE_USEROBJECT", {
cmd: "delete", cmd: "delete",
@ -1117,6 +1183,7 @@ define([
emptyTrash: callWithEnv(emptyTrashInner), emptyTrash: callWithEnv(emptyTrashInner),
addFolder: callWithEnv(addFolderInner), addFolder: callWithEnv(addFolderInner),
addSharedFolder: callWithEnv(addSharedFolderInner), addSharedFolder: callWithEnv(addSharedFolderInner),
convertFolderToSharedFolder: callWithEnv(convertFolderToSharedFolderInner),
delete: callWithEnv(deleteInner), delete: callWithEnv(deleteInner),
restore: callWithEnv(restoreInner), restore: callWithEnv(restoreInner),
setFolderData: callWithEnv(setFolderDataInner), setFolderData: callWithEnv(setFolderDataInner),

@ -158,13 +158,13 @@ define([
} }
}; };
exp.hasSubSharedFolder = function (folder) { var hasSubSharedFolder = exp.hasSubSharedFolder = function (folder) {
for (var el in folder) { for (var el in folder) {
if (isSharedFolder(folder[el])) { if (isSharedFolder(folder[el])) {
return true; return true;
} }
else if (isFolder(folder[el])) { else if (isFolder(folder[el])) {
if (exp.hasSubSharedFolder(folder[el])) { if (hasSubSharedFolder(folder[el])) {
return true; return true;
} }
} }

@ -3601,7 +3601,7 @@ define([
UI.confirm(Messages.convertFolderToSF_confirm || "In order to be shared, this folder must be converted into a shared folder. Proceed ?", function(res) { UI.confirm(Messages.convertFolderToSF_confirm || "In order to be shared, this folder must be converted into a shared folder. Proceed ?", function(res) {
if (!res) { return; } if (!res) { return; }
if (paths[0].path.length <= 1) { return; } // if root if (paths[0].path.length <= 1) { return; } // if root
// convert folder to Shared Folder manager.convertFolderToSharedFolder(paths[0].path, refresh);
}); });
} }
} else { // File } else { // File

Loading…
Cancel
Save