fix a few things, add comments for others

pull/1/head
ansuz 5 years ago
parent 58a3f76464
commit 7d583975b8

@ -466,36 +466,61 @@ define([
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; }
// don't try to convert top-level elements (trash, root, etc) to shared-folders
// TODO also validate that you're in root (not templates, etc)
if (data.path.length <= 1) {
// XXX call back with error and abort nThen
return;
}
if (_isInSharedFolder(Env, path)) {
// XXX call back with error and abort nThen
return;
}
if (Env.user.userObject.hasSubSharedFolder(folderElement)) {
// XXX call back with error and abort nThen
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; }));
owned: true, // FIXME hardcoded preference
password: '', // FIXME hardcoded preference
}, waitFor(function (id) {
// _addSharedFolder can be an id or an error
if (typeof(id) === 'object' && id && id.error) {
// XXX FIXME handle error
} else {
SFId = id;
}
}));
}).nThen(function (waitFor) {
// move everything from folder to SF
if (!SFId) { return void cb(); }
if (!SFId) {
// XXX FIXME callback does not indicate that there is an error
// XXX FIXME does not abort nThen chain
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 SFKey;
// this is basically Array.find, except it works in IE
Object.keys(parentFolder).some(function (el) {
if (parentFolder[el] === SFId) {
SFKey = el;
return true;
}
});
var newPath = parentPath.concat(SFKey).concat(UserObject.ROOT);
sharedFolderElement = Env.user.proxy[UserObject.SHARED_FOLDERS][SFId];
_move(Env, {
paths: paths,
newPath: newPath,
@ -503,17 +528,20 @@ define([
}, waitFor());
}).nThen(function () {
// migrate metadata
var sharedFolderElement = Env.user.proxy[UserObject.SHARED_FOLDERS][SFId];
var metadata = Env.user.userObject.getFolderData(folderElement);
for (var key in metadata) {
// it shouldn't be possible to have nested metadata
// but this is a reasonable sanity check
if (key === "metadata") { continue; }
// copy the metadata from the original folder to the new shared folder
sharedFolderElement[key] = metadata[key];
}
}).nThen(function (waitFor) {
// remove folder
Env.user.userObject.delete([path], waitFor());
}).nThen(function () {
// call callback
cb();
Env.user.userObject.delete([path], function () {
cb();
});
});
};
@ -1137,12 +1165,8 @@ define([
}
return Env.user.userObject.hasSubfolder(el, trashRoot);
};
var hasSubSharedFolder = function (Env, el, trashRoot) {
if (Env.folders[el]) {
var uo = Env.folders[el].userObject;
return uo.hasSubSharedFolder(uo.find[uo.ROOT]);
}
return Env.user.userObject.hasSubSharedFolder(el, trashRoot);
var hasSubSharedFolder = function (Env, el) {
return Env.user.userObject.hasSubSharedFolder(el);
};
var hasFile = function (Env, el, trashRoot) {
if (Env.folders[el]) {

@ -109,7 +109,9 @@ define([
};
exp.isFolderEmpty = function (element) {
if (!isFolder(element)) { return false; }
// if the folder contains nothing, it's empty
if (Object.keys(element).length === 0) { return true; }
// or if it contains one thing and that thing is metadata
if (Object.keys(element).length === 1 && isFolderData(element[Object.keys(element)[0]])) { return true; }
return false;
};

@ -993,7 +993,7 @@ define([
hide.push('collapseall');
}
if (path.length === 1) {
// Can't rename or delete root elements
// Can't rename, share, delete, or change the color of root elements
hide.push('delete');
hide.push('rename');
hide.push('share');
@ -1023,9 +1023,8 @@ define([
}
} else if ($element.is('.cp-app-drive-element-sharedf')) {
if (containsFolder) {
// More than 1 shared folder selected: cannot create a new subfolder
// More than 1 folder selected: cannot create a new subfolder
hide.push('newfolder');
hide.push('share');
hide.push('expandall');
hide.push('collapseall');
}
@ -1038,7 +1037,6 @@ define([
if (containsFolder) {
// More than 1 folder selected: cannot create a new subfolder
hide.push('newfolder');
hide.push('share');
hide.push('expandall');
hide.push('collapseall');
}
@ -3570,7 +3568,7 @@ define([
var parsed, modal;
var friends = common.getFriends();
if (manager.isSharedFolder(el)) { // Shared Folder
if (manager.isSharedFolder(el)) {
data = manager.getSharedFolderData(el);
parsed = Hash.parsePadUrl(data.href);
modal = UIElements.createSFShareModal({
@ -3584,21 +3582,21 @@ define([
editHash: parsed.hash
}
});
UI.openCustomModal(modal, {
return void UI.openCustomModal(modal, {
wide: Object.keys(friends).length !== 0
});
} else if (manager.isFolder(el)) { // Folder
// if folder is inside SF
if (manager.isInSharedFolder(paths[0].path)) {
UI.alert(Messages.convertFolderToSF_SFParent, undefined, true);
return void UI.alert(Messages.convertFolderToSF_SFParent);
}
// if folder already contains SF
else if (manager.hasSubSharedFolder(el)) {
UI.alert(Messages.convertFolderToSF_SFChildren, undefined, true);
return void UI.alert(Messages.convertFolderToSF_SFChildren);
}
// if folder does not contains SF
else {
UI.confirm(Messages.convertFolderToSF_confirm, function(res) {
return void UI.confirm(Messages.convertFolderToSF_confirm, function(res) {
if (!res) { return; }
if (paths[0].path.length <= 1) { return; } // if root
manager.convertFolderToSharedFolder(paths[0].path, refresh);

Loading…
Cancel
Save