Skip to content

TagSpaces is an offline, open source, document manager with tagging support

new promise api implementation

Borislav Sapundzhievacbb0f7d8f6f
diff --git a/data/js/directories.ui.js b/data/js/directories.ui.js
index 50c5e92d1..3518e6fab 100644
--- a/data/js/directories.ui.js
+++ b/data/js/directories.ui.js
@@ -433,8 +433,18 @@ define(function(require, exports, module) {
}
function listDirectory(dirPath) {
+ //TSCORE.IO.listDirectory(dirPath);
+ TSCORE.IO.listDirectoryPromise(dirPath).then(
+ function(entries) {
+ TSPOSTIO.listDirectory(entries);
+ console.log("Listing: " + dirPath + " done!");
+ },
+ function(err) {
+ TSPOSTIO.errorOpeningPath();
+ console.log("Error listing directory" + err);
+ }
+ );
- TSCORE.IO.listDirectory(dirPath);
if (TSCORE.PRO) {
TSCORE.IO.createMetaFolder(dirPath);
}
@@ -466,7 +476,15 @@ define(function(require, exports, module) {
TSCORE.showConfirmDialog($.i18n.t('ns.dialogs:deleteDirectoryTitleConfirm'), $.i18n.t(dlgConfirmMsgId, {
dirPath: dir4ContextMenu
}), function() {
- TSCORE.IO.deleteDirectory(dir4ContextMenu);
+ TSCORE.IO.deleteDirectoryPromise(dir4ContextMenu).then(function() {
+ TSPOSTIO.deleteDirectory(dir4ContextMenu);
+ },
+ function(error) {
+ TSCORE.hideLoadingAnimation();
+ console.error("Deleting directory " + dir4ContextMenu + " failed " + error);
+ TSPOSTIO.deleteDirectoryFailed(dir4ContextMenu);
+ }
+ );
});
});
$('#directoryMenuOpenDirectory').click(function() {
@@ -680,7 +698,16 @@ define(function(require, exports, module) {
var uiTemplate = Handlebars.compile(uiTPL);
$('body').append(uiTemplate());
$('#renameDirectoryButton').on('click', function() {
- TSCORE.IO.renameDirectory($('#renameDirectoryButton').attr('path'), $('#directoryNewName').val());
+ var dirPath = $('#renameDirectoryButton').attr('path');
+ var newDirPath = $('#directoryNewName').val();
+ TSCORE.IO.renameDirectoryPromise(dirPath, newDirPath)
+ .then(function(newDirName) {
+ TSCORE.hideWaitingDialog();
+ TSPOSTIO.renameDirectory(dirPath, newDirName);
+ }, function(err) {
+ TSCORE.hideWaitingDialog();
+ TSCORE.showAlertDialog(err);
+ });
});
}
$('#formDirectoryRename').validator();
diff --git a/data/node-webkit/node-webkit.api.js b/data/node-webkit/node-webkit.api.js
index b535a660c..af4cf0d56 100644
--- a/data/node-webkit/node-webkit.api.js
+++ b/data/node-webkit/node-webkit.api.js
@@ -519,7 +519,8 @@ define(function(require, exports, module) {
}
- function renameDirectoryPromise(dirPath, newDirPath) {
+ function renameDirectoryPromise(dirPath, newDirName) {
+ var newDirPath = TSCORE.TagUtils.extractParentDirectoryPath(dirPath) + TSCORE.dirSeparator + newDirName;
console.log("Renaming dir: " + dirPath + " to " + newDirPath);
return new Promise(function(resolve, reject) {
if (dirPath === newDirPath) {
@@ -535,7 +536,7 @@ define(function(require, exports, module) {
console.error("Renaming directory failed " + error);
reject("Renaming " + dirPath + " failed.");
}
- resolve(true);
+ resolve(newDirPath);
});
} else {
reject($.i18n.t("ns.common:pathIsNotDirectory", {dirName:dirPath}), $.i18n.t("ns.common:directoryRenameFailed"));
@@ -545,14 +546,15 @@ define(function(require, exports, module) {
/** @deprecated */
function renameDirectory(dirPath, newDirName) {
- var newDirPath = TSCORE.TagUtils.extractParentDirectoryPath(dirPath) + TSCORE.dirSeparator + newDirName;
+ alert("Not implemented");
+ /*var newDirPath = TSCORE.TagUtils.extractParentDirectoryPath(dirPath) + TSCORE.dirSeparator + newDirName;
renameDirectoryPromise(dirPath, newDirPath).then(function() {
TSCORE.hideWaitingDialog();
TSPOSTIO.renameDirectory(dirPath, newDirPath);
}, function(err) {
TSCORE.hideWaitingDialog();
TSCORE.showAlertDialog(err);
- });
+ });*/
}
@@ -754,6 +756,11 @@ define(function(require, exports, module) {
function deleteDirectoryPromise(path) {
+
+ if (TSCORE.PRO && TSCORE.Config.getUseTrashCan()) {
+ return trash([path]);
+ }
+
return new Promise(function(resolve, reject) {
fs.rmdir(path, function(error) {
if (error) {
@@ -767,9 +774,9 @@ define(function(require, exports, module) {
/** @deprecated */
function deleteDirectory(path) {
- if (TSCORE.PRO && TSCORE.Config.getUseTrashCan()) {
- return trash([path]);
- }
+ //if (TSCORE.PRO && TSCORE.Config.getUseTrashCan()) {
+ // return trash([path]);
+ //}
deleteDirectoryPromise(path).then(function() {
TSPOSTIO.deleteDirectory(path);
@@ -782,7 +789,6 @@ define(function(require, exports, module) {
);
}
-
function selectDirectory() {
if (document.getElementById('folderDialogNodeWebkit') === null) {
$("body").append('<input style="display:none;" id="folderDialogNodeWebkit" type="file" nwdirectory />');