TagSpaces is an offline, open source, document manager with tagging support
finalizing directory browser
Ilianbbc258e4fa4e
diff --git a/data/js/core.api.js b/data/js/core.api.jsindex 4cc0a85a4..0750c4527 100644--- a/data/js/core.api.js+++ b/data/js/core.api.js@@ -40,6 +40,8 @@ define(function(require, exports, module) {var startTime = undefined;var subfoldersDirBrowser = undefined;++ var directoryBrowser = undefined;function initApp() {console.log("Init application");@@ -253,7 +255,7 @@ define(function(require, exports, module) {console.log("Current orientation: "+window.orientation);}, false);- $( window ).on('resize', onWindowResize);+ //$( window ).on('resize', onWindowResize);function onWindowResize() {console.log("Window was resized to W:"+window.innerWidth+" H:"+window.innerHeight);@@ -516,6 +518,7 @@ define(function(require, exports, module) {exports.showLocationsPanel = tsCoreUI.showLocationsPanel;exports.showTagsPanel = tsCoreUI.showTagsPanel;exports.showContextMenu = tsCoreUI.showContextMenu;+ exports.showDirectoryBrowserDialog = tsCoreUI.showDirectoryBrowserDialog;// Proxying functions from tsTagsUIexports.generateTagButtons = tsTagsUI.generateTagButtons;@@ -546,6 +549,7 @@ define(function(require, exports, module) {exports.selectedTagData = selectedTagData;exports.startTime = startTime;exports.subfoldersDirBrowser = subfoldersDirBrowser;+ exports.directoryBrowser = directoryBrowser;exports.fileListFILEEXT = 0;exports.fileListTITLE = 1;diff --git a/data/js/core.ui.js b/data/js/core.ui.jsindex 0157c43de..ec229be33 100644--- a/data/js/core.ui.js+++ b/data/js/core.ui.js@@ -99,8 +99,31 @@ define(function(require, exports, module) {var showTagEditDialog = function() {$( "#newTagName" ).val(TSCORE.selectedTag);++ /* $( "#newTagName" ).select2('data', null);+ $( "#newTagName" ).select2({+ //minimumInputLength: 1,+ multiple: false,+ tags: TSCORE.Config.getAllTags(),+ }); */+$( '#dialogEditTag' ).modal({show: true});- };+ };++ var showDirectoryBrowserDialog = function(path) {+ require([+ "text!templates/DirectoryBrowserDialog.html",+ "tsdirectorybrowser"+ ], function(uiTPL, controller) {+ TSCORE.directoryBrowser = controller;+ if($("#directoryBrowserDialog").length < 1) {+ var uiTemplate = Handlebars.compile( uiTPL );+ $('body').append(uiTemplate());+ TSCORE.directoryBrowser.initUI();+ }+ TSCORE.IO.listSubDirectories(path);+ });+ };var showOptionsDialog = function() {require([@@ -278,7 +301,11 @@ define(function(require, exports, module) {$( "#fileMenuDeleteFile" ).click( function() {TSCORE.showFileDeleteDialog(TSCORE.selectedFiles[0]);- });+ });++ $( "#fileOpenProperties" ).click( function() {+ //TSCORE.showFilePropertiesDialog(TSCORE.selectedFiles[0]);+ });// End File Menu$('#switchLang').click(function(e) {@@ -408,16 +435,14 @@ define(function(require, exports, module) {$("#directoryMenuOpenDirectory").parent().hide();$("#fileMenuOpenDirectory").parent().hide();$("#fullscreenFile").parent().hide();- //$("#openDirectory").parent().hide();+ $("#openDirectory").parent().hide();$("#advancedSettings").hide();$("#openFileInNewWindow").hide();-}if(isChrome) {$("#directoryMenuOpenDirectory").parent().hide();$("#fileMenuOpenDirectory").parent().hide();$("#openDirectory").parent().hide();- //$("#advancedSettings").hide();$("#openFileInNewWindow").hide();$("#openNatively").hide();}@@ -472,16 +497,17 @@ define(function(require, exports, module) {};// Public API definition- exports.showContextMenu = showContextMenu;- exports.initUI = initUI;- exports.showAlertDialog = showAlertDialog;- exports.showConfirmDialog = showConfirmDialog;- exports.showFileRenameDialog = showFileRenameDialog;- exports.showFileCreateDialog = showFileCreateDialog;- exports.showFileDeleteDialog = showFileDeleteDialog;- exports.showTagEditDialog = showTagEditDialog;- exports.showLocationsPanel = showLocationsPanel;- exports.showTagsPanel = showTagsPanel;- exports.hideAllDropDownMenus = hideAllDropDownMenus;+ exports.showContextMenu = showContextMenu;+ exports.initUI = initUI;+ exports.showAlertDialog = showAlertDialog;+ exports.showConfirmDialog = showConfirmDialog;+ exports.showFileRenameDialog = showFileRenameDialog;+ exports.showFileCreateDialog = showFileCreateDialog;+ exports.showFileDeleteDialog = showFileDeleteDialog;+ exports.showTagEditDialog = showTagEditDialog;+ exports.showLocationsPanel = showLocationsPanel;+ exports.showDirectoryBrowserDialog = showDirectoryBrowserDialog;+ exports.showTagsPanel = showTagsPanel;+ exports.hideAllDropDownMenus = hideAllDropDownMenus;});\ No newline at end of filediff --git a/data/js/directories.ui.js b/data/js/directories.ui.jsindex 2ab9cbceb..287396275 100644--- a/data/js/directories.ui.js+++ b/data/js/directories.ui.js@@ -77,25 +77,42 @@ define(function(require, exports, module) {"style": "overflow-y: auto; max-height: 500px; width: 250px; padding: 5px;","class": "dropdown-menu"})- .append('<li class="dropdown-header"><span>Subfolders of:</span><button type="button" class="close">×</button></li>')- .append($("<li>")- .append($("<button>", {- "class": "btn btn-sm dirButton",- "key": directoryHistory[i].path,- "title": directoryHistory[i].path,- "style": "margin: 1px;",- "text": " "+directoryHistory[i].name- })- .prepend("<i class='fa fa-folder-o'></i>")- .click( function() {- navigateToDirectory($(this).attr("key"));- })- )+ .append($("<li>", { "text": 'Actions for '+directoryHistory[i].name, "class": 'dropdown-header' })+ .append($('<button type="button" class="close">×</button>')))- .append('<li class="divider"></li>');+ .append($("<li>", {} )+ .append($("<div>", { "class": "btn-group"} )+ .append($("<button>", {+ "class": "btn btn-default",+ "path": directoryHistory[i].path,+ "title": "Open or Reopen "+directoryHistory[i].name,+ "style": "margin: 1px; font-size: 13px",+ "text": " (Re)Open"+ })+ .prepend("<i class='fa fa-refresh'></i>")+ .click( function() {+ navigateToDirectory($(this).attr("path"));+ })+ )+ .append($("<button>", {+ "class": "btn btn-default",+ "path": directoryHistory[i].path,+ "title": "Create Subdirectory",+ "style": "margin: 1px; font-size: 13px",+ "text": " New Directory"+ })+ .prepend("<i class='fa fa-folder'></i>")+ .click( function() {+ showCreateDirectoryDialog($(this).attr("path"));+ })+ )+ )+ )+ .append($("<li>", { "text": 'Subfolders of : '+directoryHistory[i].name, "class": 'dropdown-header' }));+ //.append('<li class="divider"></li>');if(directoryHistory[i]["children"].length <= 0) {- subfolders.append("<div class='alert'><span> No subfolders found</span></div>");+ subfolders.append("<div class='alert alert-warning'>No subfolders found</div>");} else {for(var j=0; j < directoryHistory[i]["children"].length; j++) {if (TSCORE.Config.getShowUnixHiddenEntries() ||@@ -409,21 +426,8 @@ define(function(require, exports, module) {}function selectLocalDirectory() {- if(isChrome) { // isCordova- require([- "text!templates/DirectoryBrowserDialog.html",- "tsdirectorybrowser"- ], function(uiTPL, controller) {- if($("#directoryBrowserDialog").length < 1) {- var uiTemplate = Handlebars.compile( uiTPL );- $('body').append(uiTemplate());- controller.initUI();- }- controller.reInitUI();- });- } else {- TSCORE.IO.selectDirectory();- }+ TSCORE.IO.selectDirectory();+ //TSCORE.showDirectoryBrowserDialog("/media");}function showLocationEditDialog(name,path) {@@ -501,7 +505,7 @@ define(function(require, exports, module) {});}- function showCreateDirectoryDialog() {+ function showCreateDirectoryDialog(dirPath) {require(["text!templates/DirectoryCreateDialog.html",], function(uiTPL) {@@ -510,19 +514,20 @@ define(function(require, exports, module) {$('body').append(uiTemplate());$( "#createNewDirectoryButton" ).on("click", function() {+ // TODO validate folder namevar bValid = true;//bValid = bValid && checkLength( newDirName, "directory name", 3, 100 );-//bValid = bValid && checkRegexp( newDirName, /^[a-z]([0-9a-z_])+$/i, "Directory name may consist of a-z, 0-9, underscores, begin with a letter." );- // From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/- // bValid = bValid && checkRegexp( email, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "eg. [email protected]" );- // bValid = bValid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );if ( bValid ) {- TSCORE.IO.createDirectory(dir4ContextMenu+TSCORE.dirSeparator+$( "#newDirectoryName" ).val());- //navigateToDirectory(dir4ContextMenu);+ TSCORE.IO.createDirectory($( "#createNewDirectoryButton" ).attr("path")+TSCORE.dirSeparator+$( "#newDirectoryName" ).val());}});}+ // TODO remove use dir4ContextMenu+ if(dirPath == undefined) {+ dirPath = dir4ContextMenu;+ }+ $( "#createNewDirectoryButton" ).attr("path", dirPath);$("#newDirectoryName").val("");$('#dialogDirectoryCreate').modal({show: true});});@@ -555,6 +560,7 @@ define(function(require, exports, module) {"Do you want to delete the connection "+$("#connectionName2").attr("oldName")+"?",function() {deleteLocation($("#connectionName2").attr("oldName"));+ $("#dialogLocationEdit").modal('hide');});}@@ -610,7 +616,6 @@ define(function(require, exports, module) {$( "#createNewLocation" ).click(function() {showLocationCreateDialog();});-}// Public API definitiondiff --git a/data/js/directorybrowser.js b/data/js/directorybrowser.jsindex 4fd4bf0e5..0f210551b 100644--- a/data/js/directorybrowser.js+++ b/data/js/directorybrowser.js@@ -7,29 +7,9 @@ define(function(require, exports, module) {console.log("Loading directorybrowser.js ...");var TSCORE = require("tscore");-- function addPerspective(parent, perspectiveId) {- var perspectiveControl = $("<div class='form-inline'>")- .append($("<div class='input-group' style='width: 90%'>")- //.append($("<button class='btn btn-default' style='width: 10%' title='Remove Perspective'><i class='fa fa-ellipsis-v'></i></button>"))- .append($("<select class='form-control' style='width: 70%'></select>"))- .append($("<button class='btn btn-default' style='width: 40px' title='Remove Perspective'><i class='fa fa-times'></button>")- .click(function() {- $(this).parent().parent().remove();- })- )- );- //.append($("<button class='btn' title='Remove this extension'><i class='icon-arrow-up'></button>"))- //.append($("<button class='btn' title='Remove this extension'><i class='icon-arrow-down'></button>"))-- generateSelectOptions(perspectiveControl.find("select"), TSCORE.Config.getPerspectiveExtensions(), perspectiveId);- parent.append(perspectiveControl);- }--+ var TSPOSTIO = require("tspostioapi");function initUI() {-$('#addPerspectiveButton').click(function(e) {// Fixes reloading of the application by clicke.preventDefault();@@ -37,27 +17,47 @@ define(function(require, exports, module) {addPerspective($('#perspectiveList'), "");});- $( "#startDir" ).click(function() {- TSCORE.IO.listSubDirectories("/media/z/TagSpaces");+ $( "#gotoParentDirButton" ).click(function() {+ var parent = TSCORE.TagUtils.extractParentDirectoryPath($("#directoryPath").val());+ TSCORE.IO.listSubDirectories(parent);});$( "#selectDirectoryButton" ).click(function() {-+ TSPOSTIO.selectDirectory($("#directoryPath").val());});-}function reInitUI(dirPath) {- // $("#extensionsPathInput").val(TSCORE.Config.getExtensionPath());-- $('#directoryPath').empty();+ $('#directoryPath').val(dirPath);- $('#subdirectoriesArea').empty();+ var subfolders = $('#subdirectoriesArea').empty();+ if(TSCORE.subfoldersDirBrowser == undefined || TSCORE.subfoldersDirBrowser.length <= 0) {+ subfolders.append("<div class='alert alert-warning'>No subfolders found</div>");+ } else {+ for(var j=0; j < TSCORE.subfoldersDirBrowser.length; j++) {+ if (TSCORE.Config.getShowUnixHiddenEntries() ||+ (!TSCORE.Config.getShowUnixHiddenEntries()+ && (TSCORE.subfoldersDirBrowser[j].name.indexOf(".") != 0)+ )+ ) {+ subfolders.append($("<button>", {+ "class": "btn btn-sm dirButton",+ "path": TSCORE.subfoldersDirBrowser[j].path,+ //"title": TSCORE.subfoldersDirBrowser[j].path,+ "style": "margin: 1px;",+ "text": " "+TSCORE.subfoldersDirBrowser[j].name+ })+ .prepend("<i class='fa fa-folder-o'></i>")+ .click( function() {+ TSCORE.IO.listSubDirectories($(this).attr("path"));+ })+ );+ }+ }+ }$('#directoryBrowserDialog').modal('show');- }--+ }// Public Methodsexports.initUI = initUI;diff --git a/data/js/ioapi.chrome.js b/data/js/ioapi.chrome.jsindex 850fb4668..5c9986245 100644--- a/data/js/ioapi.chrome.js+++ b/data/js/ioapi.chrome.js@@ -203,7 +203,7 @@ IO-API});}}- TSPOSTIO.listSubDirectories(anotatedDirList);+ TSPOSTIO.listSubDirectories(anotatedDirList, dirPath);} else {//TSPOSTIO.errorOpeningPath();console.log("Directory does not exists.");diff --git a/data/js/ioapi.cordova.js b/data/js/ioapi.cordova.jsindex 490352fce..074ae92c2 100644--- a/data/js/ioapi.cordova.js+++ b/data/js/ioapi.cordova.js@@ -150,10 +150,11 @@ define(function (require, exports, module) {};var listSubDirectories = function (dirPath) {+ console.log("Listing sub directories of: " + dirPath);// directory path format DCIM/Camera/ !dirPath = dirPath+"/"; // TODO make it platform independentdirPath = normalizePath(dirPath);- console.log("Listing sub directories of: " + dirPath);+ console.log("Listing sub directories of : " + dirPath + " normalized.");TSCORE.showLoadingAnimation();fsRoot.getDirectory(dirPath, {create: false, exclusive: false},@@ -174,7 +175,7 @@ define(function (require, exports, module) {}}//console.log("Dir content: " + JSON.stringify(entries));- TSPOSTIO.listSubDirectories(anotatedDirList);+ TSPOSTIO.listSubDirectories(anotatedDirList, dirPath);}, function (error) { // error get file system//TSPOSTIO.errorOpeningPath();console.log("Listing sub directories failed: " + error.code);@@ -385,8 +386,9 @@ define(function (require, exports, module) {};var selectDirectory = function() {- console.log("Operation selectDirectory not supported on Android yet!");- TSCORE.showAlertDialog("Selecting directory not supported on Android yet, please enter the desired directory path manually in the textbox!");+ console.log("Open select directory dialog.");+ //file:///storage/emulated/0/DCIM/Camera/+ TSCORE.showDirectoryBrowserDialog(fsRoot.fullPath);};var selectFile = function() {diff --git a/data/js/postioapi.js b/data/js/postioapi.jsindex 02b3e1e52..65da064bc 100644--- a/data/js/postioapi.js+++ b/data/js/postioapi.js@@ -70,9 +70,12 @@ define(function(require, exports, module) {TSCORE.updateSubDirs(anotatedDirList);};- exports.listSubDirectories = function(dirList) {+ exports.listSubDirectories = function(dirList, dirPath) {console.log("Listing Subdirs: "+JSON.stringify(dirList));TSCORE.subfoldersDirBrowser = dirList;+ if(TSCORE.directoryBrowser != undefined) {+ TSCORE.directoryBrowser.reInitUI(dirPath);+ }};exports.errorOpeningPath = function() {@@ -94,10 +97,12 @@ define(function(require, exports, module) {exports.selectDirectory = function(dirPath) {// TODO make the use of this function more general- var dirName = TSCORE.TagUtils.extractContainingDirectoryName(dirPath+TSCORE.dirSeparator);+ if(!TSCORE.TagUtils.stringEndsWith(dirPath, TSCORE.dirSeparator)) {+ dirPath = dirPath + TSCORE.dirSeparator;+ }+ var dirName = TSCORE.TagUtils.extractContainingDirectoryName(dirPath);$("#connectionName").val(dirName);$("#folderLocation").val(dirPath);- //$("#connectionName2").val(dirName);$("#folderLocation2").val(dirPath);};diff --git a/data/js/tagutils.js b/data/js/tagutils.jsindex 208f348af..8a0d810d0 100644--- a/data/js/tagutils.js+++ b/data/js/tagutils.js@@ -29,11 +29,22 @@ define(function(require, exports, module) {return fileName;}}++ function stringEndsWith(str, suffix) {+ return str.indexOf(suffix, str.length - suffix.length) !== -1;+ }function extractContainingDirectoryPath(filePath) {return filePath.substring(0, filePath.lastIndexOf(TSCORE.dirSeparator));}+ function extractParentDirectoryPath(dirPath) {+ if(stringEndsWith(dirPath, TSCORE.dirSeparator)) {+ dirPath = dirPath.substring(0, dirPath.lastIndexOf(TSCORE.dirSeparator));+ }+ return dirPath.substring(0, dirPath.lastIndexOf(TSCORE.dirSeparator));+ }+function extractContainingDirectoryName(filePath) {var tmpStr = filePath.substring(0, filePath.lastIndexOf(TSCORE.dirSeparator));return tmpStr.substring(tmpStr.lastIndexOf(TSCORE.dirSeparator)+1,tmpStr.length);@@ -391,6 +402,7 @@ define(function(require, exports, module) {exports.extractFileNameWithoutExt = extractFileNameWithoutExt;exports.extractContainingDirectoryPath = extractContainingDirectoryPath;exports.extractContainingDirectoryName = extractContainingDirectoryName;+ exports.extractParentDirectoryPath = extractParentDirectoryPath;exports.extractFileExtension = extractFileExtension;exports.extractTitle = extractTitle;exports.formatFileSize = formatFileSize;@@ -404,5 +416,6 @@ define(function(require, exports, module) {exports.removeTag = removeTag;exports.addTag = addTag;exports.changeTitle = changeTitle;+ exports.stringEndsWith = stringEndsWith;});\ No newline at end of filediff --git a/data/templates/DirectoryBrowserDialog.html b/data/templates/DirectoryBrowserDialog.htmlindex 83db98f0c..32becba38 100644--- a/data/templates/DirectoryBrowserDialog.html+++ b/data/templates/DirectoryBrowserDialog.html@@ -5,15 +5,23 @@<button class="close" data-dismiss="modal" aria-hidden="true">×</button><h4 id="directoryBrowserDialogTitle">Select Directory</h4></div>- <div class="modal-body">- <div class="row" id="directoryPath">-- </div>- <div class="row" id="subdirectoriesArea">- </div>+ <div class="modal-body" >+ <div class="form-group">+ <label class="control-label" for="directoryPath">Current Path</label>+ <input class="form-control uneditable-input" readonly="true" type="text" name="directoryPath" id="directoryPath" />+ </div>+ <div class="panel panel-default">+ <div class="panel-heading">+ <button class="btn btn-default" title="Go to parent directory" id="gotoParentDirButton">+ <i class="fa fa-mail-reply"></i>+ </button>+ </div>+ <div class="panel-body" id="subdirectoriesArea" style="overflow-y: auto; max-height: 350px">+ Panel content+ </div>+ </div></div><div class="modal-footer">- <button id="startDir" class="btn">Start Dir</button><button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button><button id="selectDirectoryButton" class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Ok</button></div>