Skip to content

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

using promises for move and copy files functionality

uggrock211207719955
diff --git a/data/js/core.ui.js b/data/js/core.ui.js
index e0089c800..19e194b46 100644
--- a/data/js/core.ui.js
+++ b/data/js/core.ui.js
@@ -24,7 +24,9 @@ define(function(require, exports, module) {
show: true
});
};
+
var hideWaitingDialog = function(message, title) {
+ //
$('#waitingDialog').modal('hide');
};
@@ -88,6 +90,7 @@ define(function(require, exports, module) {
show: true
});*/
};
+
var showConfirmDialog = function(title, message, okCallback, cancelCallback, confirmShowNextTime) {
if (!title) {
title = $.i18n.t('ns.dialogs:titleConfirm');
@@ -123,6 +126,7 @@ define(function(require, exports, module) {
show: true
});
};
+
var showFileCreateDialog = function() {
fileContent = TSCORE.Config.getNewTextFileContent();
// Default new file in text file
@@ -162,6 +166,7 @@ define(function(require, exports, module) {
handle: ".modal-header"
});
};
+
var showFileRenameDialog = function(filePath) {
$('#renamedFileName').attr('filepath', filePath);
$('#renamedFileName').val(TSCORE.TagUtils.extractFileName(filePath));
@@ -190,6 +195,7 @@ define(function(require, exports, module) {
handle: ".modal-header"
});
};
+
var showFileDeleteDialog = function(filePath) {
console.log('Deleting file...');
var dlgConfirmMsgId = 'ns.dialogs:fileDeleteContentConfirm';
@@ -210,6 +216,7 @@ define(function(require, exports, module) {
);
});
};
+
var showTagEditDialog = function() {
$('#newTagName').val(TSCORE.selectedTag);
$('#formEditTag').validator();
@@ -236,6 +243,7 @@ define(function(require, exports, module) {
handle: ".modal-header"
});
};
+
var showDirectoryBrowserDialog = function(path) {
require([
'text!templates/DirectoryBrowserDialog.html',
@@ -251,6 +259,7 @@ define(function(require, exports, module) {
TSCORE.Utils.listSubDirectories(path);
});
};
+
var showOptionsDialog = function() {
require([
'text!templates/OptionsDialog.html',
@@ -266,21 +275,8 @@ define(function(require, exports, module) {
controller.reInitUI();
});
};
- var showWelcomeDialog = function() {
- startGettingStartedTour();
- /*require(['text!templates/WelcomeDialog.html'], function(uiTPL) {
- if ($('#dialogWelcome').length < 1) {
- var uiTemplate = Handlebars.compile(uiTPL);
- $('body').append(uiTemplate());
- $('#welcomeCarosel').carousel();
- }
- $('#dialogWelcome').i18n();
- $('#dialogWelcome').modal({
- backdrop: 'static',
- show: true
- });
- });*/
- };
+
+ var showWelcomeDialog = function() { startGettingStartedTour(); };
var startGettingStartedTour = function() {
var tsGettingStarted = require('tsgettingstarted');
@@ -292,37 +288,46 @@ define(function(require, exports, module) {
if ($('#dialogMoveCopyFiles').length < 1) {
var uiTemplate = Handlebars.compile(uiTPL);
$('body').append(uiTemplate());
+
$('#moveFilesButton').click(function(e) {
e.preventDefault();
- TSCORE.showWaitingDialog('Files are being renaming');
- /*jshint loopfunc: true */
+ TSCORE.showWaitingDialog('Please wait, while files are being renamed.');
+ var newFilePath, filePath;
+ var fileOperations = [];
for (var i = 0; i < TSCORE.selectedFiles.length; i++) {
- var newFilePath = $('#moveCopyDirectoryPath').val() + TSCORE.dirSeparator + TSCORE.TagUtils.extractFileName(TSCORE.selectedFiles[i]);
- var filePath = TSCORE.selectedFiles[i];
- TSCORE.IO.renameFilePromise(filePath, newFilePath).then(function(success) {
- TSCORE.hideWaitingDialog();
- TSPOSTIO.renameFile(filePath, newFilePath);
- }, function(err) {
- TSCORE.hideWaitingDialog();
- TSCORE.showAlertDialog(err);
- });
+ newFilePath = $('#moveCopyDirectoryPath').val() + TSCORE.dirSeparator + TSCORE.TagUtils.extractFileName(TSCORE.selectedFiles[i]);
+ filePath = TSCORE.selectedFiles[i];
+ fileOperations.push(TSCORE.IO.renameFilePromise(filePath, newFilePath));
}
+ Promise.all(fileOperations).then(function(success) {
+ // TODO handle moving sidecar files
+ TSCORE.hideWaitingDialog();
+ TSCORE.navigateToDirectory(TSCORE.currentPath);
+ TSCORE.showSuccessDialog("Files successfully moved");
+ }, function(err) {
+ TSCORE.hideWaitingDialog();
+ TSCORE.showAlertDialog("Renaming files failed");
+ });
});
+
$('#copyFilesButton').click(function(e) {
e.preventDefault();
- TSCORE.showWaitingDialog('Files are being copied');
- /*jshint loopfunc: true */
+ TSCORE.showWaitingDialog('Please wait, while files are being copied.');
+ var newFilePath, filePath;
+ var fileOperations = [];
for (var i = 0; i < TSCORE.selectedFiles.length; i++) {
var newFilePath = $('#moveCopyDirectoryPath').val() + TSCORE.dirSeparator + TSCORE.TagUtils.extractFileName(TSCORE.selectedFiles[i]);
var filePath = TSCORE.selectedFiles[i];
- TSCORE.IO.copyFilePromise(filePath, newFilePath).then(function(success) {
- TSCORE.hideWaitingDialog();
- TSPOSTIO.copyFile(filePath, newFilePath);
- }, function(err) {
- TSCORE.hideWaitingDialog();
- TSCORE.showAlertDialog(err);
- });
+ fileOperations.push(TSCORE.IO.copyFilePromise(filePath, newFilePath));
}
+ Promise.all(fileOperations).then(function(success) {
+ // TODO handle copying sidecar files
+ TSCORE.hideWaitingDialog();
+ TSCORE.showSuccessDialog("Files successfully copied");
+ }, function(err) {
+ TSCORE.hideWaitingDialog();
+ TSCORE.showAlertDialog("Copying files failed");
+ });
});
$('#selectDirectoryMoveCopyDialog').click(function(e) {
e.preventDefault();
@@ -350,6 +355,7 @@ define(function(require, exports, module) {
console.log('Selected files: ' + TSCORE.selectedFiles);
});
};
+
var showAboutDialog = function() {
$('#dialogAboutTS').modal({
backdrop: 'static',
@@ -359,6 +365,7 @@ define(function(require, exports, module) {
handle: ".modal-header"
});
};
+
var initUI = function() {
if (TSCORE.PRO) {
//TSCORE.PRO.sayHi();
@@ -488,12 +495,12 @@ define(function(require, exports, module) {
});
});
$('#renameFileButton').click(function() {
- var filePath = $('#renamedFileName').attr('filepath');
+ var initialFilePath = $('#renamedFileName').attr('filepath');
var containingDir = TSCORE.TagUtils.extractContainingDirectoryPath(initialFilePath);
var newFilePath = containingDir + TSCORE.dirSeparator + $('#renamedFileName').val();
- TSCORE.IO.renameFilePromise(filePath, newFilePath).then(function(success) {
+ TSCORE.IO.renameFilePromise(initialFilePath, newFilePath).then(function(success) {
TSCORE.hideWaitingDialog();
- TSPOSTIO.renameFile(filePath, newFilePath);
+ TSPOSTIO.renameFile(initialFilePath, newFilePath);
}, function(err) {
TSCORE.hideWaitingDialog();
TSCORE.showAlertDialog(err);
@@ -663,9 +670,7 @@ define(function(require, exports, module) {
// Search UI END
$('#perspectiveSwitcherButton').prop('disabled', true);
var $contactUsContent = $('#contactUsContent');
- $contactUsContent.on('click', '#openHints', function() {
- showWelcomeDialog();
- });
+ $contactUsContent.on('click', '#openHints', showWelcomeDialog);
$contactUsContent.on('click', '#openUservoice', function(e) {
e.preventDefault();
openLinkExternally($(this).attr('href'));
@@ -827,6 +832,7 @@ define(function(require, exports, module) {
$('body').addClass('osx');
}
}
+
var showContextMenu = function(menuId, sourceObject) {
var leftPos = sourceObject.offset().left;
var topPos = sourceObject.offset().top;
@@ -843,6 +849,7 @@ define(function(require, exports, module) {
top: topPos
});
};
+
var hideAllDropDownMenus = function() {
$('#tagGroupMenu').hide();
$('#tagTreeMenu').hide();
@@ -851,6 +858,7 @@ define(function(require, exports, module) {
$('#fileMenu').hide();
$('.dirAltNavMenu').hide();
};
+
var showLocationsPanel = function() {
TSCORE.openLeftPanel();
$('#tagGroupsContent').hide();
@@ -860,6 +868,7 @@ define(function(require, exports, module) {
$('#contactUs').removeClass('active');
$('#showLocations').addClass('active');
};
+
var showTagsPanel = function() {
TSCORE.openLeftPanel();
$('#locationContent').hide();
@@ -869,6 +878,7 @@ define(function(require, exports, module) {
$('#contactUs').removeClass('active');
$('#showTagGroups').addClass('active');
};
+
var showContactUsPanel = function() {
TSCORE.openLeftPanel();
$('#locationContent').hide();