Convert read-only link to editing link in the drive
This commit is contained in:
parent
8bdc8415ab
commit
c5f983ecd7
@ -630,6 +630,7 @@ define([
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var updateWeaker = [];
|
||||||
var contains;
|
var contains;
|
||||||
var renamed = recent.map(function (pad) {
|
var renamed = recent.map(function (pad) {
|
||||||
var p = parsePadUrl(pad.href);
|
var p = parsePadUrl(pad.href);
|
||||||
@ -663,6 +664,14 @@ define([
|
|||||||
|
|
||||||
// set the name
|
// set the name
|
||||||
pad.title = name;
|
pad.title = name;
|
||||||
|
|
||||||
|
// If we now have a stronger version of a stored href, replace the weaker one by the strong one
|
||||||
|
if (pad && pad.href && href !== pad.href) {
|
||||||
|
updateWeaker.push({
|
||||||
|
o: pad.href,
|
||||||
|
n: href
|
||||||
|
});
|
||||||
|
}
|
||||||
pad.href = href;
|
pad.href = href;
|
||||||
}
|
}
|
||||||
return pad;
|
return pad;
|
||||||
@ -677,6 +686,11 @@ define([
|
|||||||
}
|
}
|
||||||
|
|
||||||
setRecentPads(renamed, function (err, data) {
|
setRecentPads(renamed, function (err, data) {
|
||||||
|
if (updateWeaker.length > 0) {
|
||||||
|
updateWeaker.forEach(function (obj) {
|
||||||
|
getStore().replaceHref(obj.o, obj.n);
|
||||||
|
});
|
||||||
|
}
|
||||||
cb(err, data);
|
cb(err, data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -243,10 +243,9 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
var _findFileInRoot = function (path, href) {
|
var _findFileInRoot = function (path, href) {
|
||||||
if (path[0] !== ROOT) { return []; }
|
if (path[0] !== ROOT && path[0] !== TRASH) { return []; }
|
||||||
var paths = [];
|
var paths = [];
|
||||||
var root = exp.findElement(files, path);
|
var root = exp.findElement(files, path);
|
||||||
|
|
||||||
var addPaths = function (p) {
|
var addPaths = function (p) {
|
||||||
if (paths.indexOf(p) === -1) {
|
if (paths.indexOf(p) === -1) {
|
||||||
paths.push(p);
|
paths.push(p);
|
||||||
@ -254,7 +253,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (isFile(root)) {
|
if (isFile(root)) {
|
||||||
if (compareFiles(href, root[e])) {
|
if (compareFiles(href, root)) {
|
||||||
if (paths.indexOf(path) === -1) {
|
if (paths.indexOf(path) === -1) {
|
||||||
paths.push(path);
|
paths.push(path);
|
||||||
}
|
}
|
||||||
@ -262,16 +261,14 @@ define([
|
|||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
for (var e in root) {
|
for (var e in root) {
|
||||||
if (!isFile(root[e])) {
|
var nPath = path.slice();
|
||||||
var nPath = path.slice();
|
nPath.push(e);
|
||||||
nPath.push(e);
|
_findFileInRoot(nPath, href).forEach(addPaths);
|
||||||
_findFileInRoot(nPath, href).forEach(addPaths);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return paths;
|
return paths;
|
||||||
};
|
};
|
||||||
var _findFileInArray = function (rootName, href) {
|
var _findFileInHrefArray = function (rootName, href) {
|
||||||
var unsorted = files[rootName].slice();
|
var unsorted = files[rootName].slice();
|
||||||
var ret = [];
|
var ret = [];
|
||||||
var i = -1;
|
var i = -1;
|
||||||
@ -322,10 +319,9 @@ define([
|
|||||||
var unsortedpaths = _findFileInHrefArray(UNSORTED, href);
|
var unsortedpaths = _findFileInHrefArray(UNSORTED, href);
|
||||||
var templatepaths = _findFileInHrefArray(TEMPLATE, href);
|
var templatepaths = _findFileInHrefArray(TEMPLATE, href);
|
||||||
var trashpaths = _findFileInTrash([TRASH], href);
|
var trashpaths = _findFileInTrash([TRASH], href);
|
||||||
// TODO return concat all
|
return rootpaths.concat(unsortedpaths, templatepaths, trashpaths);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Remove the selected 'href' from the tree located at 'path', and push its locations to the 'paths' array
|
// Remove the selected 'href' from the tree located at 'path', and push its locations to the 'paths' array
|
||||||
var removeFileFromRoot = function (path, href) {
|
var removeFileFromRoot = function (path, href) {
|
||||||
var paths = [];
|
var paths = [];
|
||||||
@ -458,7 +454,6 @@ define([
|
|||||||
var parentEl = exp.findElement(files, parentPath);
|
var parentEl = exp.findElement(files, parentPath);
|
||||||
// Trash root: we have array here, we can't just splice with the path otherwise we might break the path
|
// Trash root: we have array here, we can't just splice with the path otherwise we might break the path
|
||||||
// of another element in the loop
|
// of another element in the loop
|
||||||
console.log(path);
|
|
||||||
if (path.length === 4) {
|
if (path.length === 4) {
|
||||||
trashRoot.push({
|
trashRoot.push({
|
||||||
name: path[1],
|
name: path[1],
|
||||||
@ -657,7 +652,6 @@ define([
|
|||||||
// Import elements in the file manager
|
// Import elements in the file manager
|
||||||
var importElements = exp.importElements = function (elements, path, cb) {
|
var importElements = exp.importElements = function (elements, path, cb) {
|
||||||
if (!elements || elements.length === 0) { return; }
|
if (!elements || elements.length === 0) { return; }
|
||||||
console.log(elements);
|
|
||||||
var newParent = findElement(files, path);
|
var newParent = findElement(files, path);
|
||||||
if (!newParent) { debug("Trying to import elements into a non-existing folder"); return; }
|
if (!newParent) { debug("Trying to import elements into a non-existing folder"); return; }
|
||||||
elements.forEach(function (e) {
|
elements.forEach(function (e) {
|
||||||
@ -754,7 +748,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Delete permanently (remove from the trash root and from filesData)
|
// Delete permanently (remove from the trash root and from filesData)
|
||||||
var removeFromTrash = exp.removeFromTrash = function (path, cb) {
|
var removeFromTrash = exp.removeFromTrash = function (path, cb, nocheck) {
|
||||||
if (!path || path.length < 4 || path[0] !== TRASH) { return; }
|
if (!path || path.length < 4 || path[0] !== TRASH) { return; }
|
||||||
// Remove the last element from the path to get the parent path and the element name
|
// Remove the last element from the path to get the parent path and the element name
|
||||||
var parentPath = path.slice();
|
var parentPath = path.slice();
|
||||||
@ -775,7 +769,9 @@ define([
|
|||||||
parentEl[name] = undefined;
|
parentEl[name] = undefined;
|
||||||
delete parentEl[name];
|
delete parentEl[name];
|
||||||
}
|
}
|
||||||
checkDeletedFiles();
|
if (!nocheck) {
|
||||||
|
checkDeletedFiles();
|
||||||
|
}
|
||||||
if(cb) { cb(); }
|
if(cb) { cb(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -857,7 +853,7 @@ define([
|
|||||||
pushToTrash(key, href, path);
|
pushToTrash(key, href, path);
|
||||||
};
|
};
|
||||||
|
|
||||||
var addUnsortedPad = exp.addPad = function (href, path, name) {
|
var addPad = exp.addPad = function (href, path, name) {
|
||||||
if (workgroup) { return; }
|
if (workgroup) { return; }
|
||||||
if (!href) { return; }
|
if (!href) { return; }
|
||||||
var unsortedFiles = getUnsortedFiles();
|
var unsortedFiles = getUnsortedFiles();
|
||||||
@ -882,6 +878,7 @@ define([
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (unsortedFiles.indexOf(href) === -1 && rootFiles.indexOf(href) === -1 && templateFiles.indexOf(href) === -1 && trashFiles.indexOf(href) === -1) {
|
if (unsortedFiles.indexOf(href) === -1 && rootFiles.indexOf(href) === -1 && templateFiles.indexOf(href) === -1 && trashFiles.indexOf(href) === -1) {
|
||||||
|
console.log('push', href);
|
||||||
files[UNSORTED].push(href);
|
files[UNSORTED].push(href);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -905,20 +902,27 @@ define([
|
|||||||
|
|
||||||
// Replace a href by a stronger one everywhere in the drive (except FILES_DATA)
|
// Replace a href by a stronger one everywhere in the drive (except FILES_DATA)
|
||||||
var replaceHref = exp.replaceHref = function (o, n) {
|
var replaceHref = exp.replaceHref = function (o, n) {
|
||||||
replaceFile([ROOT], o, n);
|
if (!isFile(o) || !isFile(n)) { return; }
|
||||||
var i = files[UNSORTED].indexOf(o);
|
var paths = findFile(o);
|
||||||
if (i !== -1) {
|
|
||||||
files[UNSORTED].splice(i, 1);
|
// Remove all the occurences in the trash
|
||||||
files[UNSORTED].push(n);
|
// Replace all the occurences not in the trash
|
||||||
}
|
// If all the occurences are in the trash or no occurence, add the pad to unsorted
|
||||||
var j = files[TEMPLATE].indexOf(o);
|
var allInTrash = true;
|
||||||
if (j !== -1) {
|
paths.forEach(function (p) {
|
||||||
files[TEMPLATE].splice(j, 1);
|
if (p[0] === TRASH) {
|
||||||
files[TEMPLATE].push(n);
|
removeFromTrash(p, null, true); // 3rd parameter means skip "checkDeletedFiles"
|
||||||
}
|
return;
|
||||||
var k = getTrashFiles().indexOf(o);
|
} else {
|
||||||
if (k !== -1) {
|
allInTrash = false;
|
||||||
// TODO?
|
var parentPath = p.slice();
|
||||||
|
var key = parentPath.pop();
|
||||||
|
var parentEl = findElement(files, parentPath);
|
||||||
|
parentEl[key] = n;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (allInTrash) {
|
||||||
|
addPad(n);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user