Skip to content

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

Implementing location edit functionality

Ilian6ad109f7c06c
diff --git a/data/js/directories.ui.js b/data/js/directories.ui.js
index f3d87692a..55b93b89c 100644
--- a/data/js/directories.ui.js
+++ b/data/js/directories.ui.js
@@ -12,17 +12,20 @@ define(function(require, exports, module) {
var dir4ContextMenu = null;
- var nameCurrentConnection = undefined;
+ var currentLocationName = undefined;
function openConnection(path) {
console.log("Opening connection in : "+path);
- nameCurrentConnection = TSCORE.Config.getConnectionName(path);
+ currentLocationName = TSCORE.Config.getConnectionName(path);
- document.title = nameCurrentConnection + " | " + TSCORE.Config.DefaultSettings.appName;
+ document.title = currentLocationName + " | " + TSCORE.Config.DefaultSettings.appName;
- $( "#locationName" ).text(nameCurrentConnection);
- $( "#locationName" ).attr("title",path);
+ $( "#locationName" ).text(currentLocationName);
+ $( "#locationName" ).attr("title",path);
+
+ // Open the directory locations panel
+ TSCORE.showLocationsPanel();
// Clears the directory history
directoryHistory = new Array();
@@ -167,7 +170,7 @@ define(function(require, exports, module) {
})
);
}
- }
+ }
}
}
}
@@ -208,9 +211,6 @@ define(function(require, exports, module) {
function navigateToDirectory(directoryPath) {
console.log("Navigating to directory: "+directoryPath);
-
- // Open the directory locations panel
- TSCORE.showLocationsPanel();
// Cleaning the directory path from \\ \ and /
if( (directoryPath.lastIndexOf('/')+1 == directoryPath.length) || (directoryPath.lastIndexOf('\\')+1 == directoryPath.length)) {
@@ -263,7 +263,6 @@ define(function(require, exports, module) {
}
TSCORE.currentPath = directoryPath;
- TSCORE.startTime = new Date().getTime();
TSCORE.IO.listDirectory(directoryPath);
}
@@ -291,11 +290,52 @@ define(function(require, exports, module) {
});
}
+
+ function editLocation() {
+ TSCORE.Config.editConnection(
+ $("#connectionName2").attr("oldName"),
+ $("#connectionName2").val(),
+ $("#folderLocation2").val()
+ );
+ initConnections();
+ openConnection($("#folderLocation2").val());
+ }
+
+ function showLocationEditDialog(name,path) {
+ require([
+ "text!templates/LocationEditDialog.html",
+ ], function(uiTPL) {
+ // Check if dialog already created
+ if($("#dialogLocationEdit").length < 1) {
+ var uiTemplate = Handlebars.compile( uiTPL );
+ $("body").append(uiTemplate());
+
+ $("#selectLocalDirectory2").on("click",function(e) {
+ e.preventDefault();
+ TSCORE.IO.selectDirectory();
+ });
+
+ $( "#saveLocationButton" ).on("click", function() {
+ editLocation();
+ });
+
+ $( "#deleteLocationButton" ).on("click", function() {
+ $("#dialogLocationEdit").modal("hide");
+ showDeleteFolderConnectionDialog();
+ });
+ }
+ $("#connectionName2").val(name);
+ $("#connectionName2").attr("oldName",name);
+ $("#folderLocation2").val(path);
+ $("#dialogLocationEdit").modal({show: true});
+ });
+ }
- function showCreateFolderConnectionDialog() {
+ function showLocationCreateDialog() {
require([
"text!templates/LocationCreateDialog.html",
], function(uiTPL) {
+ // Check if dialog already created
if($("#dialogCreateFolderConnection").length < 1) {
var uiTemplate = Handlebars.compile( uiTPL );
$("body").append(uiTemplate());
@@ -353,37 +393,53 @@ define(function(require, exports, module) {
});
}
- function deleteFolderConnection() {
+ function deleteLocation(name) {
console.log("Deleting folder connection..");
- TSCORE.Config.deleteConnection(nameCurrentConnection);
+ TSCORE.Config.deleteConnection(name);
initConnections();
//Opens the first location in the settings after deleting a location
- if(TSCORE.Config.Settings["tagspacesList"][0] != undefined) {
+ if(TSCORE.Config.Settings["tagspacesList"].length > 0) {
openConnection(TSCORE.Config.Settings["tagspacesList"][0].path);
- }
+ } else {
+ closeCurrentLocation();
+ }
+ }
+
+ function closeCurrentLocation() {
+ console.log("Closing location..");
+ currentLocationName = undefined;
+ $("#locationName").text("Choose Location");
+ $("#locationName").attr("title","");
+ $("#locationContent").empty();
+
}
- function showDeleteFolderConnectionDialog() {
+
+ function showDeleteFolderConnectionDialog(name) {
TSCORE.showConfirmDialog(
"Delete connection to folder",
"Do you want to delete this connection to a folder?",
- deleteFolderConnection
+ function() {
+ deleteLocation($("#connectionName2").attr("oldName"));
+ }
);
}
function initConnections() {
console.log("Creating location menu...");
- $( "#connectionsList" ).empty();
- $( "#connectionsList" ).append('<li class="dropdown-header"><span id="">Your Locations</span><button type="button" class="close">×</button></li>');
- $( "#connectionsList" ).append('<li class="divider"></li>');
+ var $connectionList = $( "#connectionsList" );
+ $connectionList.empty();
+ $connectionList.attr("style","overflow-y: auto; max-height: 500px; width: 238px;");
+ $connectionList.append('<li class="dropdown-header"><span id="">Your Locations</span><button type="button" class="close">×</button></li>');
+ $connectionList.append('<li class="divider"></li>');
var connectionsList = TSCORE.Config.Settings["tagspacesList"];
for (var i=0; i < connectionsList.length; i++) {
// <li><a href="#"><i class="fa fa-dropbox"></i>&nbsp;<span data-i18n="app.test1;">My Dropbox Folder</span>&nbsp;
// <button type="button" class="btn btn-link"><i class="fa fa-edit"></i></button></a></li>
- $( "#connectionsList" ).append(
+ $connectionList.append(
$('<li>', {}).append(
$('<a>', {
title: "Location pointing to "+connectionsList[i].path,
@@ -397,24 +453,26 @@ define(function(require, exports, module) {
.prepend("<i class='fa fa-bookmark'></i>&nbsp;")
.append(
$('<button>', {
- type: "button",
- // path: connectionsList[i].path,
- class: "btn btn-link",
+ type: "button",
+ title: "Edit Location",
+ location: connectionsList[i].name,
+ path: connectionsList[i].path,
+ class: "btn btn-default pull-right",
} )
- // .append("<i class='fa fa-edit'></i>")
- // .click(function(e) {
- // e.preventDefault();
- // alert("Delete location");
- // })
+ .append("<i class='fa fa-pencil'></i>")
+ .click(function(e) {
+ console.log("Edit location");
+ showLocationEditDialog($(this).attr("location"),$(this).attr("path"));
+ return false;
+ })
)
));
};
- $( "#connectionsList" ).append('<li class="divider"></li>');
- $( "#connectionsList" ).append('<li id="deleteConnection"><a><i class="fa fa-trash-o"></i> Remove Current Location</a></li>');
- // $( "#connectionsList" ).hide();
+ //$connectionList.append('<li class="divider"></li>');
+ //$connectionList.append('<li id="deleteConnection"><a><i class="fa fa-trash-o"></i> Remove Current Location</a></li>');
$( "#createNewLocation" ).click(function() {
- showCreateFolderConnectionDialog();
+ showLocationCreateDialog();
});
$( "#deleteConnection" ).click(function() {
@@ -424,6 +482,7 @@ define(function(require, exports, module) {
// Public API definition
exports.openConnection = openConnection;
+ exports.closeCurrentLocation = closeCurrentLocation;
exports.updateSubDirs = updateSubDirs;
exports.initUI = initUI;
exports.initConnections = initConnections;
diff --git a/data/js/settings.api.js b/data/js/settings.api.js
index 0baf9c77b..0b97b2988 100644
--- a/data/js/settings.api.js
+++ b/data/js/settings.api.js
@@ -269,7 +269,6 @@ define(function(require, exports, module) {
}
};
-
var getPerspectiveExtensions = function() {
if(exports.Settings["ootbPerspectives"] == null) {
exports.Settings["ootbPerspectives"] = exports.DefaultSettings["ootbPerspectives"];
@@ -581,7 +580,6 @@ define(function(require, exports, module) {
newConnectionModel.path = location;
var createLocation = true;
exports.Settings["tagspacesList"].forEach(function (value, index) {
- // TODO make this check from the ui dialog
if(value.path == newConnectionModel.path) {
TSCORE.showAlertDialog("Selected path is already used by a location!","Duplicated Location Path");
createLocation = false;
@@ -597,6 +595,33 @@ define(function(require, exports, module) {
}
};
+ var editConnection = function(oldName, newName, newLocation) {
+// name = name.replace("\\", "\\\\");
+// name = name.replace("\\\\\\", "\\\\");
+// name = name.replace("\\\\\\\\", "\\\\");
+ console.log("Old Name: "+oldName+" New Name: "+newName+" New Loc: "+newLocation);
+ var editLocation = true;
+ exports.Settings["tagspacesList"].forEach(function (value, index) {
+ /* if(value.path == newLocation) {
+ TSCORE.showAlertDialog("Selected path is already used by a location!","Duplicated Location Path");
+ editLocation = false;
+ } */
+ if(value.name == newName && value.name != oldName) {
+ TSCORE.showAlertDialog("Selected location name is already used by a location!","Duplicated Location Name");
+ editLocation = false;
+ }
+ });
+ if(editLocation) {
+ exports.Settings["tagspacesList"].forEach(function (value, index) {
+ if(value.name == oldName) {
+ value.name = newName;
+ value.path = newLocation;
+ }
+ });
+ saveSettings();
+ }
+ };
+
var getConnectionName = function(connectionPath) {
var connectionName = undefined;
exports.Settings["tagspacesList"].forEach(function (value, index) {
@@ -712,6 +737,7 @@ define(function(require, exports, module) {
exports.createTagGroup = createTagGroup;
exports.duplicateTagGroup = duplicateTagGroup;
exports.createConnection = createConnection;
+ exports.editConnection = editConnection;
exports.deleteConnection = deleteConnection;
exports.getConnectionName = getConnectionName;
exports.updateSettingMozillaPreferences = updateSettingMozillaPreferences;
diff --git a/data/templates/LocationCreateDialog.html b/data/templates/LocationCreateDialog.html
index 71513f76a..4cb77305e 100644
--- a/data/templates/LocationCreateDialog.html
+++ b/data/templates/LocationCreateDialog.html
@@ -7,7 +7,7 @@
</div>
<div class="modal-body form">
<div class="form-group">
- <label class="control-label" for="folderLocation">Folder Location</label>
+ <label class="control-label" for="folderLocation">Location Path</label>
<div class="input-group">
<input class="form-control" type="text" name="folderLocation" id="folderLocation" placeholder="Example: c:\users\johnsmith\documents" />
<span class="input-group-btn">
@@ -17,7 +17,7 @@
</div><!-- /input-group -->
</div>
<div class="form-group">
- <label class="control-label" for="connectionName">Connection Name</label>
+ <label class="control-label" for="connectionName">Location Name</label>
<input class="form-control" type="text" name="connectionName" id="connectionName" placeholder="Example: My Documents" />
</div>
</div>
diff --git a/data/templates/LocationEditDialog.html b/data/templates/LocationEditDialog.html
index 1bc940c81..ca4d461c0 100644
--- a/data/templates/LocationEditDialog.html
+++ b/data/templates/LocationEditDialog.html
@@ -1,24 +1,24 @@
-<div id="dialogCreateFolderConnection" class="modal" tabindex="-1" role="dialog" aria-hidden="true">
+<div id="dialogLocationEdit" class="modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
- <h4>Edit a Location</h4>
+ <h4>Edit This Location</h4>
</div>
<div class="modal-body form">
<div class="form-group">
- <label class="control-label" for="folderLocation">Folder Location</label>
+ <label class="control-label" for="folderLocation2">Location Path</label>
<div class="input-group">
- <input class="form-control" type="text" name="folderLocation" id="folderLocation" placeholder="Example: c:\users\johnsmith\documents" />
+ <input class="form-control" type="text" name="folderLocation2" id="folderLocation2" placeholder="Example: c:\users\johnsmith\documents" />
<span class="input-group-btn">
- <button class="btn btn-default" id="selectLocalDirectory" title="Select local folder">
+ <button class="btn btn-default" id="selectLocalDirectory2" title="Select local folder">
&nbsp;&nbsp;<i class="fa fa-folder-open"></i>&nbsp;&nbsp;
</button> </span>
</div><!-- /input-group -->
</div>
<div class="form-group">
- <label class="control-label" for="connectionName">Connection Name</label>
- <input class="form-control" type="text" name="connectionName" id="connectionName" placeholder="Example: My Documents" />
+ <label class="control-label" for="connectionName2">Location Name</label>
+ <input class="form-control" type="text" name="connectionName2" id="connectionName2" placeholder="Example: My Documents" />
</div>
</div>
<div class="modal-footer">
@@ -28,7 +28,7 @@
<button class="btn" data-dismiss="modal" aria-hidden="true">
Cancel
</button>
- <button id="createFolderConnectionButton" class="btn btn-primary" data-dismiss="modal" aria-hidden="true">
+ <button id="saveLocationButton" class="btn btn-primary" data-dismiss="modal" aria-hidden="true">
Ok
</button>
</div>