Skip to content

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

utilization of postioapi

uggrock18da441fdd4a
diff --git a/data/js/ioapi.chrome.js b/data/js/ioapi.chrome.js
index dea2d99a8..57392f07c 100644
--- a/data/js/ioapi.chrome.js
+++ b/data/js/ioapi.chrome.js
@@ -8,7 +8,8 @@ define(function(require, exports, module) {
console.log("Loading ioapi.chrome.js..");
var TSCORE = require("tscore");
-
+
+ var TSPOSTIO = require("tspostioapi");
/**
API of npapifileioforchrome:
@@ -118,7 +119,7 @@ Still Missing:
type: 'GET',
})
.done(function(data) {
- TSCORE.updateNewVersionData(data);
+ TSPOSTIO.checkNewVersion(data);
})
.fail(function(data) {
console.log("AJAX failed "+data);
@@ -141,7 +142,7 @@ Still Missing:
b.size = size;
var reader = new FileReader();
reader.onload = function (e) {
- TSCORE.FileOpener.updateEditorContent(e.target.result);
+ TSPOSTIO.loadTextFile(e.target.result);
}
reader.readAsText(b);
} else {
@@ -167,7 +168,7 @@ Still Missing:
"path": path
});
}
- TSCORE.PerspectiveManager.updateFileBrowserData(anotatedDirList);
+ TSPOSTIO.listDirectory(anotatedDirList);
} catch(ex) {
console.error("Directory listing failed "+ex);
}
@@ -193,7 +194,7 @@ Still Missing:
});
}
}
- TSCORE.updateSubDirs(anotatedDirList);
+ TSPOSTIO.getSubdirs(anotatedDirList);
} catch(ex) {
console.error("Directory listing failed "+ex);
}
@@ -205,7 +206,8 @@ Still Missing:
exports.deleteElement = function(path) {
console.log("Deleting: "+path);
try {
- nativeIO.removeRecursively(path);
+ nativeIO.removeRecursively(path);
+ TSPOSTIO.deleteElement();
} catch(ex) {
console.error("Deleting file failed "+ex);
}
@@ -216,14 +218,14 @@ Still Missing:
var directoryIndex = [];
directoryIndex = scanDirectory(dirPath, directoryIndex);
//console.log(JSON.stringify(directoryIndex));
- TSCORE.PerspectiveManager.updateFileBrowserData(directoryIndex);
+ TSPOSTIO.createDirectoryIndex(directoryIndex);
}
exports.createDirectoryTree = function(dirPath) {
console.log("Creating directory index for: "+dirPath);
var directoyTree = generateDirectoryTree(dirPath);
//console.log(JSON.stringify(directoyTree));
- TSCORE.PerspectiveManager.updateTreeData(directoyTree);
+ TSPOSTIO.createDirectoryTree(directoyTree);
}
exports.saveTextFile = function(filePath,content) {
@@ -239,11 +241,7 @@ Still Missing:
reader.onloadend = function(e){
var data = Array.prototype.slice.call(new Uint8Array(reader.result), 0);
nativeIO.saveBlobToFile(filePath, data);
- TSCORE.PerspectiveManager.refreshFileListContainer();
- if(TSCORE.FileOpener.isFileOpened()) {
- // TODO Automatically reopening of the file is not desirable in every case ...
- TSCORE.FileOpener.openFile(message.content);
- }
+ TSPOSTIO.saveTextFile();
}
reader.readAsArrayBuffer(blob);
}
@@ -252,6 +250,7 @@ Still Missing:
console.log("Creating directory: "+dirPath);
try {
nativeIO.createDirectory(dirPath);
+ TSPOSTIO.createDirectory();
} catch(ex) {
console.error("Deleting file failed "+ex);
}
@@ -280,7 +279,7 @@ Still Missing:
if(nativeIO.fileExists(newFilePath)) {
nativeIO.removeRecursively(filePath);
}
- TSCORE.PerspectiveManager.refreshFileListContainer();
+ TSPOSTIO.renameFile();
}
reader.readAsArrayBuffer(b);
} else {
@@ -293,7 +292,7 @@ Still Missing:
console.log("Select directory!");
nativeIO.launchFolderSelect(function(dirPath){
if (dirPath && dirPath.length){
- $("#folderLocation").val(dirPath);
+ TSPOSTIO.selectDirectory(dirPath);
}
});
}
diff --git a/data/js/ioapi.mozilla.js b/data/js/ioapi.mozilla.js
index 5683c16a1..2960aa641 100644
--- a/data/js/ioapi.mozilla.js
+++ b/data/js/ioapi.mozilla.js
@@ -10,7 +10,9 @@ console.log("Loading ioapi.mozilla.js..");
var TSCORE = require("tscore");
-document.documentElement.addEventListener("addon-message1", function(event) {
+var TSPOSTIO = require("tspostioapi");
+
+document.documentElement.addEventListener("tsMessage", function(event) {
console.log("Message received in page script from content script: "); //+JSON.stringify(event.detail));
TSCORE.hideLoadingAnimation();
var message = event.detail;
@@ -40,55 +42,42 @@ document.documentElement.addEventListener("addon-message1", function(event) {
break;
case "rename":
if(message.success){
- TSCORE.updateLogger("Rename success");
- // message.content contains the name of the file after the rename
- if(TSCORE.FileOpener.isFileOpened()) {
- TSCORE.FileOpener.openFile(message.content);
- }
- // TODO to be replaced with a function which replaced the
- // renamed file in the model of the perspective
- TSCORE.PerspectiveManager.refreshFileListContainer();
+ TSPOSTIO.renameFile();
} else {
TSCORE.updateLogger("Rename failed");
}
break;
case "saveTextFile":
if(message.success){
- TSCORE.PerspectiveManager.refreshFileListContainer();
- if(TSCORE.FileOpener.isFileOpened()) {
- // TODO Automatically reopening of the file is not desirable in every case ...
- TSCORE.FileOpener.openFile(message.content);
- }
+ TSPOSTIO.saveTextFile();
} else {
TSCORE.updateLogger("Save failed");
}
break;
case "createDirectory":
if(message.success){
- TSCORE.updateLogger("Create dir success");
- TSCORE.openFavorite(TSCORE.Config.Settings["tagspacesList"][0].path, TSCORE.Config.Settings["tagspacesList"][0].name);
+ TSPOSTIO.createDirectory();
} else {
TSCORE.updateLogger("Create dir failed");
}
break;
case "loadTextFile":
if(message.success){
- TSCORE.FileOpener.updateEditorContent(message.content);
+ TSPOSTIO.loadTextFile(message.content);
} else {
TSCORE.updateLogger("File loading failed");
}
break;
case "listDirectory":
if(message.success){
- TSCORE.PerspectiveManager.updateFileBrowserData(message.content);
+ TSPOSTIO.listDirectory(message.content);
} else {
TSCORE.updateLogger("List directory failed");
}
break;
case "indexDirectory":
if(message.success){
- //console.log("Directory Index: "+JSON.stringify(message.content));
- TSCORE.PerspectiveManager.updateFileBrowserData(message.content);
+ TSPOSTIO.createDirectoryIndex(message.content);
} else {
TSCORE.updateLogger("Indexing directory failed");
}
@@ -96,7 +85,7 @@ document.documentElement.addEventListener("addon-message1", function(event) {
case "createDirectoryTree":
if(message.success){
console.log("Directory tree: "+JSON.stringify(message.content));
- TSCORE.PerspectiveManager.updateTreeData(message.content);
+ TSPOSTIO.createDirectoryTree(message.content);
} else {
TSCORE.updateLogger("Indexing directory failed");
}
@@ -108,31 +97,28 @@ document.documentElement.addEventListener("addon-message1", function(event) {
dirListing.push(message.content[i]);
}
// TODO JSON functions are a workarround for a bug....
- TSCORE.updateSubDirs(JSON.parse( JSON.stringify(dirListing)));
+ TSPOSTIO.getSubdirs(JSON.parse( JSON.stringify(dirListing)));
} else {
TSCORE.updateLogger("Getting subdirs failed");
}
break;
case "delete":
if(message.success){
- TSCORE.updateLogger("Delete success");
- TSCORE.PerspectiveManager.refreshFileListContainer();
+ TSPOSTIO.deleteElement();
} else {
TSCORE.updateLogger("Delete failed");
}
break;
case "selectDirectory":
if(message.success){
- // TODO make the use of this function more general
- $("#folderLocation").val(message.content);
+ TSPOSTIO.selectDirectory(message.content);
} else {
TSCORE.updateLogger("Selecting directory failed.");
}
break;
case "checkNewVersion":
if(message.success){
- TSCORE.updateLogger("Getting New Version Information Successfull");
- TSCORE.updateNewVersionData(message.content);
+ TSPOSTIO.checkNewVersion(message.content);
} else {
TSCORE.updateLogger("Create dir failed");
}
diff --git a/data/js/postioapi.js b/data/js/postioapi.js
new file mode 100644
index 000000000..a425f4434
--- /dev/null
+++ b/data/js/postioapi.js
@@ -0,0 +1,78 @@
+/* Copyright (c) 2012-2013 The TagSpaces Authors. All rights reserved.
+ * Use of this source code is governed by a AGPL3 license that
+ * can be found in the LICENSE file. */
+define(function(require, exports, module) {
+"use strict";
+
+ // Activating browser specific exports modul
+ console.log("Loading post ioapi ...");
+
+ var TSCORE = require("tscore");
+
+ exports.createDirectoryIndex = function(directoryIndex) {
+ TSCORE.PerspectiveManager.updateFileBrowserData(directoryIndex);
+ }
+
+ exports.createDirectoryTree = function(directoyTree) {
+ TSCORE.PerspectiveManager.updateTreeData(directoyTree);
+ }
+
+ exports.createDirectory = function() {
+ //TODO refresh the directory area
+ // TSCORE.openFavorite(TSCORE.Config.Settings["tagspacesList"][0].path, TSCORE.Config.Settings["tagspacesList"][0].name);
+ }
+
+ exports.renameFile = function() {
+ // message.content contains the name of the file after the rename
+ //if(TSCORE.FileOpener.isFileOpened()) {
+ // TSCORE.FileOpener.openFile(message.content);
+ //}
+ // TODO to be replaced with a function which replaced the
+ // renamed file in the model of the perspective
+ TSCORE.PerspectiveManager.refreshFileListContainer();
+ }
+
+ exports.loadTextFile = function(content) {
+ TSCORE.FileOpener.updateEditorContent(content);
+ }
+
+ exports.saveTextFile = function() {
+ TSCORE.PerspectiveManager.refreshFileListContainer();
+ if(TSCORE.FileOpener.isFileOpened()) {
+ // TODO Automatically reopening of the file is not desirable in every case ...
+ //TSCORE.FileOpener.openFile(message.content);
+ }
+ }
+
+ exports.listDirectory = function(anotatedDirList) {
+ TSCORE.PerspectiveManager.updateFileBrowserData(anotatedDirList);
+ }
+
+ exports.getSubdirs = function(anotatedDirList) {
+ TSCORE.updateSubDirs(anotatedDirList);
+ }
+
+ exports.deleteElement = function() {
+ TSCORE.PerspectiveManager.refreshFileListContainer();
+ }
+
+ exports.checkNewVersion = function(data) {
+ TSCORE.updateNewVersionData(data);
+ }
+
+ exports.selectDirectory = function(dirPath) {
+ // TODO make the use of this function more general
+ $("#folderLocation").val(dirPath);
+ }
+
+ exports.openDirectory = function(dirPath) {
+
+ }
+
+ exports.selectFile = function() {
+ console.log("File selected: "+$(this).val());
+ }
+
+ exports.openExtensionsDirectory = function() {
+ }
+});
\ No newline at end of file