Refresh the directory if needed when the object has changed
This commit is contained in:
parent
118829617f
commit
d6e1215166
@ -71,12 +71,6 @@ define(function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Store.addPad = function () {};
|
|
||||||
|
|
||||||
Store.forgetPad = function (href, cb) {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
var changeHandlers = Store.changeHandlers = [];
|
var changeHandlers = Store.changeHandlers = [];
|
||||||
|
|
||||||
Store.change = function (f) {
|
Store.change = function (f) {
|
||||||
|
|||||||
@ -20,6 +20,12 @@ define([
|
|||||||
*/
|
*/
|
||||||
var $ = window.jQuery;
|
var $ = window.jQuery;
|
||||||
|
|
||||||
|
// When set to true, USE_FS_STORE becomes the default store, but the localStorage store is
|
||||||
|
// still loaded for migration purpose. When false, the localStorage is used.
|
||||||
|
var USE_FS_STORE = true;
|
||||||
|
|
||||||
|
var storeToUse = USE_FS_STORE ? FS : Store;
|
||||||
|
|
||||||
var common = {
|
var common = {
|
||||||
User: User,
|
User: User,
|
||||||
};
|
};
|
||||||
@ -36,8 +42,8 @@ define([
|
|||||||
|
|
||||||
var getStore = common.getStore = function (legacy) {
|
var getStore = common.getStore = function (legacy) {
|
||||||
if (!legacy && userStore) { return userStore; }
|
if (!legacy && userStore) { return userStore; }
|
||||||
if (legacy) { return store; }
|
if ((!USE_FS_STORE || legacy) && store) { return store; }
|
||||||
if (!legacy && fsStore) { return fsStore; }
|
if (USE_FS_STORE && !legacy && fsStore) { return fsStore; }
|
||||||
throw new Error("Store is not ready!");
|
throw new Error("Store is not ready!");
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -379,6 +385,9 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
// STORAGE
|
// STORAGE
|
||||||
|
var forgetFSPad = function (href, cb) {
|
||||||
|
getStore().forgetPad(href, cb);
|
||||||
|
};
|
||||||
var forgetPad = common.forgetPad = function (href, cb, legacy) {
|
var forgetPad = common.forgetPad = function (href, cb, legacy) {
|
||||||
var parsed = parsePadUrl(href);
|
var parsed = parsePadUrl(href);
|
||||||
|
|
||||||
@ -389,6 +398,10 @@ define([
|
|||||||
}
|
}
|
||||||
|
|
||||||
getStore(legacy).keys(function (err, keys) {
|
getStore(legacy).keys(function (err, keys) {
|
||||||
|
if (err) {
|
||||||
|
cb(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
var toRemove = keys.filter(function (k) {
|
var toRemove = keys.filter(function (k) {
|
||||||
return k.indexOf(parsed.hash) === 0;
|
return k.indexOf(parsed.hash) === 0;
|
||||||
});
|
});
|
||||||
@ -403,6 +416,26 @@ define([
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (USE_FS_STORE && !legacy) {
|
||||||
|
// TODO implement forgetPad in store.js
|
||||||
|
forgetFSPad(href, callback);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
getRecentPads(function (err, recentPads) {
|
||||||
|
setRecentPads(recentPads.filter(function (pad) {
|
||||||
|
var p = parsePadUrl(pad.href);
|
||||||
|
// find duplicates
|
||||||
|
if (parsed.hash === p.hash && parsed.type === p.type) {
|
||||||
|
console.log("Found a duplicate");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}), callback, legacy);
|
||||||
|
}, legacy);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (typeof(getStore(legacy).forgetPad) === "function") {
|
if (typeof(getStore(legacy).forgetPad) === "function") {
|
||||||
// TODO implement forgetPad in store.js
|
// TODO implement forgetPad in store.js
|
||||||
getStore(legacy).forgetPad(href, callback);
|
getStore(legacy).forgetPad(href, callback);
|
||||||
@ -457,8 +490,7 @@ define([
|
|||||||
if (!contains) {
|
if (!contains) {
|
||||||
var data = makePad(href, name);
|
var data = makePad(href, name);
|
||||||
renamed.push(data);
|
renamed.push(data);
|
||||||
if (typeof(getStore(legacy).addPad) === "function") {
|
if (USE_FS_STORE && typeof(getStore().addPad) === "function") {
|
||||||
//TODO implement addPad in store.js
|
|
||||||
getStore().addPad(href);
|
getStore().addPad(href);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -533,8 +565,11 @@ define([
|
|||||||
f(void 0, env);
|
f(void 0, env);
|
||||||
};
|
};
|
||||||
|
|
||||||
FS.ready(function (err, store) {
|
storeToUse.ready(function (err, store) {
|
||||||
fsStore = common.store = env.store = store;
|
common.store = env.store = store;
|
||||||
|
if (USE_FS_STORE) {
|
||||||
|
fsStore = store;
|
||||||
|
}
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
// Race condition : if document.body is undefined when alertify.js is loaded, Alertify
|
// Race condition : if document.body is undefined when alertify.js is loaded, Alertify
|
||||||
|
|||||||
@ -86,11 +86,7 @@ li {
|
|||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
#tree #trashTree {
|
#tree #trashTree, #tree #unsortedTree, #tree #allfilesTree {
|
||||||
margin-top: 2em;
|
|
||||||
}
|
|
||||||
|
|
||||||
#tree #unsortedTree {
|
|
||||||
margin-top: 2em;
|
margin-top: 2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -322,6 +322,7 @@ define([
|
|||||||
appStatus._onReady.forEach(function (h) {
|
appStatus._onReady.forEach(function (h) {
|
||||||
h();
|
h();
|
||||||
});
|
});
|
||||||
|
_onReady = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -857,6 +858,28 @@ define([
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var displayAllFiles = function ($container) {
|
||||||
|
var allfiles = files[FILES_DATA];
|
||||||
|
if (allfiles.length === 0) { return; }
|
||||||
|
var $fileHeader = getFileListHeader(false);
|
||||||
|
$container.append($fileHeader);
|
||||||
|
allfiles.forEach(function (file, idx) {
|
||||||
|
var $icon = $fileIcon.clone();
|
||||||
|
var $name = $('<span>', { 'class': 'file-element element' });
|
||||||
|
addFileData(file.href, file.title, $name, false);
|
||||||
|
var $element = $('<li>', {
|
||||||
|
draggable: false
|
||||||
|
}).append($icon).append($name).dblclick(function () {
|
||||||
|
openFile(file.href);
|
||||||
|
});
|
||||||
|
$element.click(function(e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
onElementClick($element);
|
||||||
|
});
|
||||||
|
$container.append($element);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
var displayTrashRoot = function ($list, $folderHeader, $fileHeader) {
|
var displayTrashRoot = function ($list, $folderHeader, $fileHeader) {
|
||||||
// Elements in the trash are JS arrays (several elements can have the same name)
|
// Elements in the trash are JS arrays (several elements can have the same name)
|
||||||
[true,false].forEach(function (folder) {
|
[true,false].forEach(function (folder) {
|
||||||
@ -890,7 +913,8 @@ define([
|
|||||||
|
|
||||||
// Display the selected directory into the content part (rightside)
|
// Display the selected directory into the content part (rightside)
|
||||||
// NOTE: Elements in the trash are not using the same storage structure as the others
|
// NOTE: Elements in the trash are not using the same storage structure as the others
|
||||||
var displayDirectory = module.displayDirectory = function (path) {
|
var displayDirectory = module.displayDirectory = function (path, force) {
|
||||||
|
if (!appStatus.isReady && !force) { return; }
|
||||||
appStatus.ready(false);
|
appStatus.ready(false);
|
||||||
currentPath = path;
|
currentPath = path;
|
||||||
$content.html("");
|
$content.html("");
|
||||||
@ -899,6 +923,7 @@ define([
|
|||||||
}
|
}
|
||||||
var isTrashRoot = filesOp.comparePath(path, [TRASH]);
|
var isTrashRoot = filesOp.comparePath(path, [TRASH]);
|
||||||
var isUnsorted = filesOp.comparePath(path, [UNSORTED]);
|
var isUnsorted = filesOp.comparePath(path, [UNSORTED]);
|
||||||
|
var isAllFiles = filesOp.comparePath(path, [FILES_DATA]);
|
||||||
|
|
||||||
var root = filesOp.findElement(files, path);
|
var root = filesOp.findElement(files, path);
|
||||||
if (typeof(root) === "undefined") {
|
if (typeof(root) === "undefined") {
|
||||||
@ -906,7 +931,7 @@ define([
|
|||||||
debug("Unable to locate the selected directory: ", path);
|
debug("Unable to locate the selected directory: ", path);
|
||||||
var parentPath = path.slice();
|
var parentPath = path.slice();
|
||||||
parentPath.pop();
|
parentPath.pop();
|
||||||
displayDirectory(parentPath);
|
displayDirectory(parentPath, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -938,6 +963,8 @@ define([
|
|||||||
|
|
||||||
if (isUnsorted) {
|
if (isUnsorted) {
|
||||||
displayUnsorted($list);
|
displayUnsorted($list);
|
||||||
|
} else if (isAllFiles) {
|
||||||
|
displayAllFiles($list);
|
||||||
} else if (isTrashRoot) {
|
} else if (isTrashRoot) {
|
||||||
displayTrashRoot($list, $folderHeader, $fileHeader);
|
displayTrashRoot($list, $folderHeader, $fileHeader);
|
||||||
} else {
|
} else {
|
||||||
@ -1075,6 +1102,15 @@ define([
|
|||||||
$container.append($unsortedList);
|
$container.append($unsortedList);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var createAllFiles = function ($container, path) {
|
||||||
|
var $icon = $unsortedIcon.clone();
|
||||||
|
var isOpened = filesOp.comparePath(path, currentPath);
|
||||||
|
var $allfilesElement = createTreeElement(FILES_DATA_NAME, $icon, [FILES_DATA], false, false, isOpened);
|
||||||
|
$allfilesElement.addClass('root');
|
||||||
|
var $allfilesList = $('<ul>', { id: 'allfilesTree' }).append($allfilesElement);
|
||||||
|
$container.append($allfilesList);
|
||||||
|
};
|
||||||
|
|
||||||
var createTrash = function ($container, path) {
|
var createTrash = function ($container, path) {
|
||||||
var $icon = filesOp.isFolderEmpty(files[TRASH]) ? $trashEmptyIcon.clone() : $trashIcon.clone();
|
var $icon = filesOp.isFolderEmpty(files[TRASH]) ? $trashEmptyIcon.clone() : $trashIcon.clone();
|
||||||
var isOpened = filesOp.comparePath(path, currentPath);
|
var isOpened = filesOp.comparePath(path, currentPath);
|
||||||
@ -1099,10 +1135,9 @@ define([
|
|||||||
$tree.html('');
|
$tree.html('');
|
||||||
createTree($tree, [ROOT]);
|
createTree($tree, [ROOT]);
|
||||||
createUnsorted($tree, [UNSORTED]);
|
createUnsorted($tree, [UNSORTED]);
|
||||||
|
createAllFiles($tree, [FILES_DATA]);
|
||||||
createTrash($tree, [TRASH]);
|
createTrash($tree, [TRASH]);
|
||||||
};
|
};
|
||||||
module.displayDirectory(currentPath);
|
|
||||||
//resetTree(); //already called by displayDirectory
|
|
||||||
|
|
||||||
var hideMenu = module.hideMenu = function () {
|
var hideMenu = module.hideMenu = function () {
|
||||||
$contextMenu.hide();
|
$contextMenu.hide();
|
||||||
@ -1251,6 +1286,31 @@ define([
|
|||||||
moveElements(paths, [TRASH], false, refresh);
|
moveElements(paths, [TRASH], false, refresh);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
files.on('change', [], function () {
|
||||||
|
var path = arguments[2];
|
||||||
|
if ((filesOp.isPathInUnsorted(currentPath) && filesOp.isPathInUnsorted(path)) ||
|
||||||
|
(path.length >= currentPath.length && filesOp.isSubpath(path, currentPath)) ||
|
||||||
|
(filesOp.isPathInTrash(currentPath) && filesOp.isPathInTrash(path))) {
|
||||||
|
// Reload after 50ms to make sure all the change events have been received
|
||||||
|
window.setTimeout(function () {
|
||||||
|
module.displayDirectory(currentPath);
|
||||||
|
}, 50);
|
||||||
|
}
|
||||||
|
module.resetTree();
|
||||||
|
}).on('remove', [], function () {
|
||||||
|
var path = arguments[1];
|
||||||
|
if ((filesOp.isPathInUnsorted(currentPath) && filesOp.isPathInUnsorted(path)) ||
|
||||||
|
(path.length >= currentPath.length && filesOp.isSubpath(path, currentPath)) ||
|
||||||
|
(filesOp.isPathInTrash(currentPath) && filesOp.isPathInTrash(path))) {
|
||||||
|
// Reload after 50ms to make sure all the change events have been received
|
||||||
|
window.setTimeout(function () {
|
||||||
|
module.displayDirectory(currentPath);
|
||||||
|
}, 50); }
|
||||||
|
module.resetTree();
|
||||||
|
});
|
||||||
|
|
||||||
|
module.displayDirectory(currentPath);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user