TagSpaces is an offline, open source, document manager with tagging support
- Refactoring of the js files in terms of require js
uggrockdac78ad26a90
diff --git a/data/index.html b/data/index.htmlindex da485351c..e2d9a9dd7 100644--- a/data/index.html+++ b/data/index.html@@ -24,19 +24,7 @@<script type="text/javascript" src="libs/dynatree/jquery.dynatree-1.2.2.js"></script><script type="text/javascript" src="libs/jsoneditor/jsoneditor.js"></script><script type="text/javascript" src="libs/datatables/jquery.dataTables.js"></script>- <script type="text/javascript" src="libs/requirejs/require.js"></script><!-- data-main="loader" -->-- <script type="text/javascript" src="js/misc.ui.js"></script>- <script type="text/javascript" src="js/ioapi.chrome.js"></script>- <script type="text/javascript" src="js/ioapi.mozilla.js"></script>- <script type="text/javascript" src="js/settings.api.js"></script>- <script type="text/javascript" src="js/tagspace.api.js"></script>- <script type="text/javascript" src="js/tags.ui.js"></script>- <script type="text/javascript" src="js/basicviews.ui.js"></script>- <script type="text/javascript" src="js/directories.ui.js"></script>- <script type="text/javascript" src="js/settings.ui.js"></script>- <script type="text/javascript" src="js/main.ui.js"></script>-+ <script type="text/javascript" data-main="loader" src="libs/requirejs/require.js"></script></head><body><div id="container">@@ -290,7 +278,7 @@<ul class="contextMenu" id="fileMenu"><li action="openFile" title=""><a href="javascript:void(0);"><span class="ui-icon ui-icon-plus"></span>Open File</a></li>- <li action="editFile" title=""><a href="javascript:void(0);"><span class="ui-icon ui-icon-wrench"></span>Edit File</a></li>+ <!--li action="editFile" title=""><a href="javascript:void(0);"><span class="ui-icon ui-icon-wrench"></span>Edit File</a></li--><li action="renameFile" title=""><a href="javascript:void(0);"><span class="ui-icon ui-icon-pencil"></span>Raname File</a></li><li action="deleteFile" title=""><a href="javascript:void(0);"><span class="ui-icon ui-icon-trash"></span>Delete File</a></li><li><hr></li>diff --git a/data/js/basicview_reworked b/data/js/basicview_reworkednew file mode 100644index 000000000..0f865f982--- /dev/null+++ b/data/js/basicview_reworked@@ -0,0 +1,605 @@+/* Copyright (c) 2012 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";++console.debug("Loading BasicViewsUI...");++exports.initFileTagViews = function() {+ UIAPI.fileTable = $('#fileTable').dataTable( {+ "bJQueryUI": false,+ "bPaginate": false,+ "bLengthChange": false,+ "bFilter": true,+ "bSort": true,+ "bInfo": false,+ "bAutoWidth": false,+ "aoColumns": [+ { "sTitle": "Filename", "sClass": "right" },+ { "sTitle": "Size(bytes)" },+ { "sTitle": "Date Modified" },+ { "sTitle": "Title" },+ { "sTitle": "Tags" },+ { "sTitle": "Ext" },+ // { "sTitle": "Selection", "mData": null }+ ],+ "aoColumnDefs": [+ {+ "mRender": function ( data, type, row ) { return this.buttonizeFileName(data) },+ "aTargets": [ 0 ]+ },+ {+ "mRender": function ( data, type, row ) { return this.buttonizeTitle(data,row[0]) },+ "aTargets": [ 3 ]+ },+ {+ "mRender": function ( data, type, row ) { return this.generateTagButtons(data,row[5],row[0]) },+ "aTargets": [ 4 ]+ },+ {+ "mRender": function ( data, type, row ) { return TSAPI.formatDateTime(data, true) },+ "aTargets": [ 2 ]+ },+ { "bVisible": false, "aTargets": [ 5 ] },+// { "bSearchable": false, "aTargets": [ 0 ] },+// { "sClass": "center", "aTargets": [ 0 ] }+ ]+ } );+++ // Disable alerts in datatable+ UIAPI.fileTable.dataTableExt.sErrMode = 'throw';++ // Makes the body of the fileTable selectable+ $("tbody", $(UIAPI.fileTable)).selectable({+ filter: 'tr',+ start: function() {+ console.debug("Start selecting");+ UIAPI.hideAllContextMenus();+ UIAPI.selectedFiles = [];+ $("#fileTable tbody tr").each(function(){+ $(this).removeClass('selectedRow');+ });+ },+ stop: function(){+ $(".ui-selected", this).each(function(){+ var index = $("#fileTable tr").index(this) - 1;+ $('#fileTable tbody tr:eq('+index+')').toggleClass('selectedRow');+ $('#fileTable tbody tr:eq('+index+')').toggleClass('ui-selected');+ var rowData = UIAPI.fileTable.fnGetData( this );+ // Add the filename which is located in the first column to the list of selected filenames+ UIAPI.selectedFiles.push(rowData[0]);+ });+/* if(UIAPI.selectedFiles.length == 1) {+ var dirSep = UIAPI.getDirSeparator();+ if(dirSep == "\\\\") { dirSep = "\" }+ $("#selectedFilePath").val(UIAPI.currentPath+dirSep+UIAPI.selectedFiles[0]);+ } else {+ $("#selectedFilePath").val("");+ } */+ console.debug("Selected files: "+UIAPI.selectedFiles);+ UIAPI.handleElementActivation();+ }+ })++ // Filter search functionality+ // TODO Consider Thumb and other views by filtering+ $("#filterBox").keyup(function() {+ UIAPI.fileTable.fnFilter(this.value);+ console.debug("Filter to value: "+this.value);+ });++ $('#filterBox').wrap('<span id="resetFilter" />').after($('<span/>').click(function() {+ $(this).prev('input').val('').focus();+ UIAPI.fileTable.fnFilter( "" );+ }));+}++exports.initThumbView = function() {+// Managing the selection of files in the thumb view+ $( "#selectableFiles" ).selectable({+ stop: function() {+ UIAPI.selectedFiles = [];+ $( ".ui-selected", this ).each(function() {+ // var index = $( "#selectableFiles li" ).index( this );+ // console.debug( "Selected #:" + ( index + 1 ) );+ // console.debug( "Selected file: "+$( "#selectableFiles li" )[index].innerHTML);+ UIAPI.selectedFiles.push($(this).attr("title"));+ });+ console.debug("Selected files: "+UIAPI.selectedFiles);+ UIAPI.handleElementActivation();++ // On selecting only one file opens it in the viewer+ if(UIAPI.selectedFiles.length == 1) {+ FileViewer.openFile(UIAPI.selectedFiles[0]);+ }+ }+ });+}++exports.clearSelectedFiles = function() {+ // Clear selected files in the model+ UIAPI.selectedFiles = [];++ // Deselect all+ $(".selectedRow", $(UIAPI.fileTable)).each(function(){+ $(this).toggleClass('selectedRow');+ });+}++exports.openFileTitleMenu = function(tagButton, fileName) {+ BasicViewsUI.clearSelectedFiles();+ $(tagButton).parent().parent().toggleClass("selectedRow");++ UIAPI.currentFilename = fileName;+ UIAPI.selectedFiles.push(UIAPI.currentFilename);++ var menu = $("#fileTitleMenu").show().position({+ my: "left top",+ at: "left bottom",+ of: tagButton+ });+ // TODO Hide menu+ // $( document ).one( "click", function() { menu.hide(); });+}++exports.openFileMenu = function(tagButton, fileName) {+ BasicViewsUI.clearSelectedFiles();+ $(tagButton).parent().parent().toggleClass("selectedRow");++ UIAPI.currentFilename = fileName;+ UIAPI.selectedFiles.push(UIAPI.currentFilename);++ var menu = $("#fileMenu").show().position({+ my: "left top",+ at: "left bottom",+ of: tagButton+ });+ // TODO Hide menu+ // $( document ).one( "click", function() { menu.hide(); });+}++exports.initButtons = function() {+// Layout Buttons+ $( "#toggleLeftPanel" ).button({+ text: false,+ icons: {+ primary: "ui-icon-triangle-2-e-w"+ }+ })+ .click(function() {+ layoutContainer.toggle("west");+ });++ $( "#toggleRightPanel" ).button({+ text: false,+ icons: {+ primary: "ui-icon-triangle-2-e-w"+ }+ })+ .click(function() {+ layoutContainer.toggle("east");+ });++// Change View buttons+ $( "#viewsRadio" ).buttonset();++ $( "#fileViewButton" ).button({+ text: true,+ icons: {+ primary: "ui-icon-note"+ }+ })+ .click(function() {+ UIAPI.changeView("fileView");+ });++ $( "#tagViewButton" ).button({+ text: true,+ icons: {+ primary: "ui-icon-tag"+ }+ })+ .click(function() {+ UIAPI.changeView("tagView");+ });++ $( "#thumbViewButton" ).button({+ text: true,+ icons: {+ primary: "ui-icon-image"+ }+ })+ .click(function() {+ UIAPI.changeView("thumbView");+ });++ $( "#riverViewButton" ).click(function() {+ UIAPI.changeView("riverView");+ });++// Sort buttons - Deprecated+/*+ $( "#fileSortRadio" ).buttonset();++ $( "#sortByNameButton" ).click(function() {+ UIAPI.setFileSortCriteria("name");+ UIAPI.changeFileView();+ });++ $( "#sortByDateButton" ).click(function() {+ UIAPI.setFileSortCriteria("lmdt");+ UIAPI.changeFileView();+ });++ $( "#sortBySizeButton" ).click(function() {+ UIAPI.setFileSortCriteria("size");+ UIAPI.changeFileView();+ });+*/++// Initialize file buttons+ $( "#createFileButton" ).button({+ text: true,+ icons: {+ primary: "ui-icon-document"+ }+ })+ .click(function() {+ $( "#dialog-filecreate" ).dialog( "open" );+ });++ $( "#openFileButton" ).button({+ text: true,+ disabled: true+ })+ .click(function() {+ FileViewer.openFile(UIAPI.selectedFiles[0]);+ });++ $( "#editFileButton" ).button({+ text: true,+ disabled: true+ })+ .click(function() {+ UIAPI.editFile(UIAPI.selectedFiles[0]);+ });++ $( "#deleteFileButton" ).button({+ text: true,+ disabled: true,+ icons: {+ primary: "ui-icon-trash"+ }+ })+ .click(function() {+ $( "#dialog-confirmdelete" ).dialog( "open" );+ });++ $( "#renameFileButton" ).button({+ text: true,+ disabled: true+ })+ .click(function() {+ $( "#dialog-filerename" ).dialog( "open" );+ });++ $( "#clearFilterButton" ).button({+ text: false,+ disabled: false,+ icons: {+ primary: "ui-icon-close"+ }+ })+ .click(function() {+ $( "#filterBox" ).val( "" );+ UIAPI.fileTable.fnFilter( "" );+ });++}++exports.initContextMenus = function() {+ $( "#fileMenu" ).menu({+ select: function( event, ui ) {+ var commandName = ui.item.attr( "action" );+ switch (commandName) {+ case "openFile":+ $( this ).hide();+ console.debug("Opening file...");+ FileViewer.openFile(UIAPI.selectedFiles[0]);+ break;+ case "editFile":+ $( this ).hide();+ console.debug("Editing file...");+ UIAPI.editFile(UIAPI.selectedFiles[0]);+ break;+ case "renameFile":+ $( this ).hide();+ console.debug("Renaming file...");+ $( "#dialog-filerename" ).dialog( "open" );+ break;+ case "deleteFile":+ $( this ).hide();+ console.debug("Deleting file...");+ $( "#dialog-confirmdelete" ).dialog( "open" );+ break;+ case "closeMenu":+ $( this ).hide();+ break;+ default:+ break;+ }+ $( this ).hide();+ }+ });++ $( "#fileTitleMenu" ).menu({+ select: function( event, ui ) {+ var commandName = ui.item.attr( "action" );+ switch (commandName) {+ case "openFile":+ $( this ).hide();+ console.debug("Opening file...");+ FileViewer.openFile(UIAPI.selectedFiles[0]);+ break;+ case "editFile":+ $( this ).hide();+ console.debug("Editing file...");+ UIAPI.editFile(UIAPI.selectedFiles[0]);+ break;+ case "addTag":+ $( this ).hide();+ console.debug("Adding tag...");+ $("#tags").val("");+ $( "#dialogAddTags" ).dialog( "open" );+ break;+ case "closeMenu":+ $( this ).hide();+ break;+ default:+ break;+ }+ }+ });++}++exports.initDialogs = function() {+ var newDirName = $( "#dirname" );+ var newFileName = $( "#newFileName" );+ var renamedFileName = $( "#renamedFileName" );++ // TODO evtl add smarttag and the others...+ var allFields = $( [] ).add( newDirName );++ var tips = $( ".validateTips" );++ function updateTips( t ) {+ tips+ .text( t )+ .addClass( "ui-state-highlight" );+ setTimeout(function() {+ tips.removeClass( "ui-state-highlight", 1500 );+ }, 500 );+ }++ function checkLength( o, n, min, max ) {+ if ( o.val().length > max || o.val().length < min ) {+ o.addClass( "ui-state-error" );+ updateTips( "Length of " + n + " must be between " ++ min + " and " + max + "." );+ return false;+ } else {+ return true;+ }+ }++ function checkRegexp( o, regexp, n ) {+ if ( !( regexp.test( o.val() ) ) ) {+ o.addClass( "ui-state-error" );+ updateTips( n );+ return false;+ } else {+ return true;+ }+ }++ $( "#fileTypeRadio" ).buttonset();++ var fileContent = undefined;++ $( "#txtFileTypeButton" ).click(function() {+ // TODO Add to config options+ fileContent = TSSETTINGS.getNewTextFileContent();+ //Leave the filename as it is by no extension+ if(newFileName.val().lastIndexOf(".")>=0) {+ newFileName.val(newFileName.val().substring(0,newFileName.val().lastIndexOf("."))+".txt");+ }+ });++ $( "#htmlFileTypeButton" ).click(function() {+ // TODO Add to config options+ fileContent = TSSETTINGS.getNewHTMLFileContent();+ //Leave the filename as it is by no extension+ if(newFileName.val().lastIndexOf(".")>=0) {+ newFileName.val(newFileName.val().substring(0,newFileName.val().lastIndexOf("."))+".html");+ }+ });++ $( "#mdFileTypeButton" ).click(function() {+ // TODO Add to config options+ fileContent = TSSETTINGS.getNewMDFileContent();+ //Leave the filename as it is by no extension+ if(newFileName.val().lastIndexOf(".")>=0) {+ newFileName.val(newFileName.val().substring(0,newFileName.val().lastIndexOf("."))+".md");+ }+ });++ $( "#dialog-filecreate" ).dialog({+ autoOpen: false,+ height: 250,+ width: 450,+ modal: true,+ buttons: {+ "Create": function() {+ var bValid = true;+ allFields.removeClass( "ui-state-error" );++ bValid = bValid && checkLength( newFileName, "filename", 4, 200 );+ // bValid = bValid && checkRegexp( renamedFileName, /^[a-z]([0-9a-z_.])+$/i, "Filename may consist of a-z, 0-9, underscores, begin with a letter." );+ if(UIAPI.fileExists(newFileName.val())) {+ updateTips("File already exists.");+ bValid = false;+ }+ if ( bValid ) {+ IOAPI.saveTextFile(UIAPI.currentPath+UIAPI.getDirSeparator()+$( "#newFileName" ).val(),fileContent);+ $( this ).dialog( "close" );+ IOAPI.listDirectory(UIAPI.currentPath);+ }+ },+ Cancel: function() {+ $( this ).dialog( "close" );+ }+ },+ close: function() {+ allFields.val( "" ).removeClass( "ui-state-error" );+ },+ open: function() {+ fileContent = TSSETTINGS.getNewTextFileContent(); // Default new file in text file+ $( "#newFileName" ).val(".txt");+ }+ });++ $( "#dialog-filerename" ).dialog({+ autoOpen: false,+ height: 220,+ width: 450,+ modal: true,+ buttons: {+ "Rename": function() {+ var bValid = true;+ allFields.removeClass( "ui-state-error" );++ bValid = bValid && checkLength( renamedFileName, "filename", 3, 200 );+ // bValid = bValid && checkRegexp( renamedFileName, /^[a-z]([0-9a-z_.])+$/i, "Filename may consist of a-z, 0-9, underscores, begin with a letter." );+ if ( bValid ) {+ IOAPI.renameFile(+ UIAPI.currentPath+UIAPI.getDirSeparator()+UIAPI.selectedFiles[0],+ UIAPI.currentPath+UIAPI.getDirSeparator()+renamedFileName.val()+ );+ $( this ).dialog( "close" );+ IOAPI.listDirectory(UIAPI.currentPath);+ }+ },+ Cancel: function() {+ $( this ).dialog( "close" );+ }+ },+ close: function() {+ allFields.val( "" ).removeClass( "ui-state-error" );+ },+ open: function() {+ $( "#renamedFileName" ).val(UIAPI.selectedFiles[0]);+ }+ });++ $( "#dialog-confirmdelete" ).dialog({+ autoOpen: false,+ resizable: false,+ height:140,+ modal: true,+ buttons: {+ "Delete all items": function() {+ IOAPI.deleteElement(UIAPI.currentPath+UIAPI.getDirSeparator()+UIAPI.selectedFiles[0]);+ $( this ).dialog( "close" );+ IOAPI.listDirectory(UIAPI.currentPath);+ },+ Cancel: function() {+ $( this ).dialog( "close" );+ }+ }+ });++ $( "#dialogAddTags" ).dialog({+ autoOpen: false,+ resizable: false,+ height:240,+ modal: true,+ buttons: {+ "Add tags": function() {+ var tags = $("#tags").val().split(",");+ TSAPI.writeTagsToFile(UIAPI.selectedFiles[0], tags);+ IOAPI.listDirectory(UIAPI.currentPath);+ $( this ).dialog( "close" );+ },+ Cancel: function() {+ $( this ).dialog( "close" );+ }+ }+ });++ $( "#tagTypeRadio" ).buttonset();++ $( "#plainTagTypeButton" ).click(function() {+ UIAPI.selectedTag, $( "#newTag" ).val("")+ });++ $( "#dateTagTypeButton" ).click(function() {+ UIAPI.selectedTag, $( "#newTag" ).val("201YMMDD")+ });++ $( "#currencyTagTypeButton" ).click(function() {+ UIAPI.selectedTag, $( "#newTag" ).val("XEUR")+ });++ $( "#dialogEditTag" ).dialog({+ autoOpen: false,+ resizable: false,+ height:240,+ modal: true,+ buttons: {+ "Edit tag": function() {+ TSAPI.renameTag(UIAPI.selectedFiles[0], UIAPI.selectedTag, $( "#newTag" ).val());+ IOAPI.listDirectory(UIAPI.currentPath);+ $( this ).dialog( "close" );+ },+ Cancel: function() {+ $( this ).dialog( "close" );+ }+ }+ });++}++this.generateTagButtons = function(commaSeparatedTags, fileExtension, fileName) {+ console.debug("Creating tags...");+ var htmlOutput = "";+ var tagString = ""+commaSeparatedTags;+ if(fileExtension.length > 0) {+ htmlOutput += ('<button title="Opens context menu for '+fileExtension+'" tag="'+fileExtension+'" filename="'+fileName+'" class="extTagButton">'+fileExtension+'</button>');+ }+ if(tagString.length > 0) {+ var tags = tagString.split(",");+ for (var i=0; i < tags.length; i++) {+ htmlOutput += ('<button title="Opens context menu for '+tags[i]+'" tag="'+tags[i]+'" filename="'+fileName+'" class="tagButton">'+tags[i]+'</button>');+ }+ }+ return htmlOutput;+}++this.buttonizeTitle = function(title, fileName) {+ var htmlOutput = "";+ htmlOutput += '<button title="'+fileName+'" class="fileTitleButton">'+title+' </button>';+ return htmlOutput;+}++this.buttonizeFileName = function(fileName) {+ var htmlOutput = "";+ htmlOutput += '<button title="'+fileName+'" class="fileButton">'+fileName+'</button>';+ return htmlOutput;+}++});+diff --git a/data/js/basicviews.ui.js b/data/js/basicviews.ui.jsindex 3054dfcde..9761c5a6a 100644--- a/data/js/basicviews.ui.js+++ b/data/js/basicviews.ui.js@@ -1,579 +1,599 @@-/* Copyright (c) 2012 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. */-console.debug("Loading BasicViewsUI...");--var BasicViewsUI = (typeof BasicViewsUI == 'object' && BasicViewsUI != null) ? BasicViewsUI : {};--BasicViewsUI.initFileTagViews = function() {- UIAPI.fileTable = $('#fileTable').dataTable( {- "bJQueryUI": false,- "bPaginate": false,- "bLengthChange": false,- "bFilter": true,- "bSort": true,- "bInfo": false,- "bAutoWidth": false,- "aoColumns": [- { "sTitle": "Filename", "sClass": "right" },- { "sTitle": "Size(bytes)" },- { "sTitle": "Date Modified" },- { "sTitle": "Title" },- { "sTitle": "Tags" },- { "sTitle": "Ext" },- // { "sTitle": "Selection", "mData": null }- ],- "aoColumnDefs": [- {- "mRender": function ( data, type, row ) { return BasicViewsUI.buttonizeFileName(data) },- "aTargets": [ 0 ]- },- {- "mRender": function ( data, type, row ) { return BasicViewsUI.buttonizeTitle(data,row[0]) },- "aTargets": [ 3 ]- },- {- "mRender": function ( data, type, row ) { return BasicViewsUI.generateTagButtons(data,row[5],row[0]) },- "aTargets": [ 4 ]- },- {- "mRender": function ( data, type, row ) { return TSAPI.formatDateTime(data, true) },- "aTargets": [ 2 ]- },- { "bVisible": false, "aTargets": [ 5 ] },-// { "bSearchable": false, "aTargets": [ 0 ] },-// { "sClass": "center", "aTargets": [ 0 ] }- ]- } );--- // Disable alerts in datatable- UIAPI.fileTable.dataTableExt.sErrMode = 'throw';-- // Makes the body of the fileTable selectable- $("tbody", $(UIAPI.fileTable)).selectable({- filter: 'tr',- start: function() {- console.debug("Start selecting");- UIAPI.hideAllContextMenus();- UIAPI.selectedFiles = [];- $("#fileTable tbody tr").each(function(){- $(this).removeClass('selectedRow');- });- },- stop: function(){- $(".ui-selected", this).each(function(){- var index = $("#fileTable tr").index(this) - 1;- $('#fileTable tbody tr:eq('+index+')').toggleClass('selectedRow');- $('#fileTable tbody tr:eq('+index+')').toggleClass('ui-selected');- var rowData = UIAPI.fileTable.fnGetData( this );- // Add the filename which is located in the first column to the list of selected filenames- UIAPI.selectedFiles.push(rowData[0]);- });-/* if(UIAPI.selectedFiles.length == 1) {- var dirSep = UIAPI.getDirSeparator();- if(dirSep == "\\\\") { dirSep = "\" }- $("#selectedFilePath").val(UIAPI.currentPath+dirSep+UIAPI.selectedFiles[0]);- } else {- $("#selectedFilePath").val("");- } */- console.debug("Selected files: "+UIAPI.selectedFiles);- UIAPI.handleElementActivation();- }- })-- // Filter search functionality- // TODO Consider Thumb and other views by filtering- $("#filterBox").keyup(function() {- UIAPI.fileTable.fnFilter(this.value);- console.debug("Filter to value: "+this.value);- });-- $('#filterBox').wrap('<span id="resetFilter" />').after($('<span/>').click(function() {- $(this).prev('input').val('').focus();- UIAPI.fileTable.fnFilter( "" );- }));-}--BasicViewsUI.initThumbView = function() {-// Managing the selection of files in the thumb view- $( "#selectableFiles" ).selectable({- stop: function() {- UIAPI.selectedFiles = [];- $( ".ui-selected", this ).each(function() {- // var index = $( "#selectableFiles li" ).index( this );- // console.debug( "Selected #:" + ( index + 1 ) );- // console.debug( "Selected file: "+$( "#selectableFiles li" )[index].innerHTML);- UIAPI.selectedFiles.push($(this).attr("title"));- });- console.debug("Selected files: "+UIAPI.selectedFiles);- UIAPI.handleElementActivation();-- // On selecting only one file opens it in the viewer- if(UIAPI.selectedFiles.length == 1) {- UIAPI.openFile(UIAPI.selectedFiles[0]);- }- }- });-}--BasicViewsUI.generateTagButtons = function(commaSeparatedTags, fileExtension, fileName) {- console.debug("Creating tags...");- var htmlOutput = "";- var tagString = ""+commaSeparatedTags;- if(fileExtension.length > 0) {- htmlOutput += ('<button title="Opens context menu for '+fileExtension+'" tag="'+fileExtension+'" filename="'+fileName+'" class="extTagButton">'+fileExtension+'</button>');- }- if(tagString.length > 0) {- var tags = tagString.split(",");- for (var i=0; i < tags.length; i++) {- htmlOutput += ('<button title="Opens context menu for '+tags[i]+'" tag="'+tags[i]+'" filename="'+fileName+'" class="tagButton">'+tags[i]+'</button>');- }- }- return htmlOutput;-}--BasicViewsUI.clearSelectedFiles = function() {- // Clear selected files in the model- UIAPI.selectedFiles = [];-- // Deselect all- $(".selectedRow", $(UIAPI.fileTable)).each(function(){- $(this).toggleClass('selectedRow');- });-}--BasicViewsUI.buttonizeTitle = function(title, fileName) {- var htmlOutput = "";- htmlOutput += '<button title="'+fileName+'" class="fileTitleButton">'+title+' </button>';- return htmlOutput;-}--BasicViewsUI.openFileTitleMenu = function(tagButton, fileName) {- BasicViewsUI.clearSelectedFiles();- $(tagButton).parent().parent().toggleClass("selectedRow");-- UIAPI.currentFilename = fileName;- UIAPI.selectedFiles.push(UIAPI.currentFilename);-- var menu = $("#fileTitleMenu").show().position({- my: "left top",- at: "left bottom",- of: tagButton- });- // TODO Hide menu- // $( document ).one( "click", function() { menu.hide(); });-}--BasicViewsUI.buttonizeFileName = function(fileName) {- var htmlOutput = "";- htmlOutput += '<button title="'+fileName+'" class="fileButton">'+fileName+'</button>';- return htmlOutput;-}--BasicViewsUI.openFileMenu = function(tagButton, fileName) {- BasicViewsUI.clearSelectedFiles();- $(tagButton).parent().parent().toggleClass("selectedRow");-- UIAPI.currentFilename = fileName;- UIAPI.selectedFiles.push(UIAPI.currentFilename);-- var menu = $("#fileMenu").show().position({- my: "left top",- at: "left bottom",- of: tagButton- });- // TODO Hide menu- // $( document ).one( "click", function() { menu.hide(); });-}--BasicViewsUI.initButtons = function() {-// Change View buttons- $( "#viewsRadio" ).buttonset();-- $( "#fileViewButton" ).button({- text: true,- icons: {- primary: "ui-icon-note"- }- })- .click(function() {- UIAPI.changeView("fileView");- });-- $( "#tagViewButton" ).button({- text: true,- icons: {- primary: "ui-icon-tag"- }- })- .click(function() {- UIAPI.changeView("tagView");- });-- $( "#thumbViewButton" ).button({- text: true,- icons: {- primary: "ui-icon-image"- }- })- .click(function() {- UIAPI.changeView("thumbView");- });-- $( "#riverViewButton" ).click(function() {- UIAPI.changeView("riverView");- });--// Sort buttons - Deprecated-/*- $( "#fileSortRadio" ).buttonset();-- $( "#sortByNameButton" ).click(function() {- UIAPI.setFileSortCriteria("name");- UIAPI.changeFileView();- });-- $( "#sortByDateButton" ).click(function() {- UIAPI.setFileSortCriteria("lmdt");- UIAPI.changeFileView();- });-- $( "#sortBySizeButton" ).click(function() {- UIAPI.setFileSortCriteria("size");- UIAPI.changeFileView();- });-*/--// Initialize file buttons- $( "#createFileButton" ).button({- text: true,- icons: {- primary: "ui-icon-document"- }- })- .click(function() {- $( "#dialog-filecreate" ).dialog( "open" );- });-- $( "#openFileButton" ).button({- text: true,- disabled: true- })- .click(function() {- UIAPI.openFile(UIAPI.selectedFiles[0]);- });-- $( "#editFileButton" ).button({- text: true,- disabled: true- })- .click(function() {- UIAPI.editFile(UIAPI.selectedFiles[0]);- });-- $( "#deleteFileButton" ).button({- text: true,- disabled: true,- icons: {- primary: "ui-icon-trash"- }- })- .click(function() {- $( "#dialog-confirmdelete" ).dialog( "open" );- });-- $( "#renameFileButton" ).button({- text: true,- disabled: true- })- .click(function() {- $( "#dialog-filerename" ).dialog( "open" );- });-- $( "#clearFilterButton" ).button({- text: false,- disabled: false,- icons: {- primary: "ui-icon-close"- }- })- .click(function() {- $( "#filterBox" ).val( "" );- UIAPI.fileTable.fnFilter( "" );- });--}--BasicViewsUI.initContextMenus = function() {- $( "#fileMenu" ).menu({- select: function( event, ui ) {- var commandName = ui.item.attr( "action" );- switch (commandName) {- case "openFile":- $( this ).hide();- console.debug("Opening file...");- UIAPI.openFile(UIAPI.selectedFiles[0]);- break;- case "editFile":- $( this ).hide();- console.debug("Editing file...");- UIAPI.editFile(UIAPI.selectedFiles[0]);- break;- case "renameFile":- $( this ).hide();- console.debug("Renaming file...");- $( "#dialog-filerename" ).dialog( "open" );- break;- case "deleteFile":- $( this ).hide();- console.debug("Deleting file...");- $( "#dialog-confirmdelete" ).dialog( "open" );- break;- case "closeMenu":- $( this ).hide();- break;- default:- break;- }- $( this ).hide();- }- });-- $( "#fileTitleMenu" ).menu({- select: function( event, ui ) {- var commandName = ui.item.attr( "action" );- switch (commandName) {- case "openFile":- $( this ).hide();- console.debug("Opening file...");- UIAPI.openFile(UIAPI.selectedFiles[0]);- break;- case "editFile":- $( this ).hide();- console.debug("Editing file...");- UIAPI.editFile(UIAPI.selectedFiles[0]);- break;- case "addTag":- $( this ).hide();- console.debug("Adding tag...");- $("#tags").val("");- $( "#dialogAddTags" ).dialog( "open" );- break;- case "closeMenu":- $( this ).hide();- break;- default:- break;- }- }- });--}--BasicViewsUI.initDialogs = function() {- var newDirName = $( "#dirname" );- var newFileName = $( "#newFileName" );- var renamedFileName = $( "#renamedFileName" );-- // TODO evtl add smarttag and the others...- var allFields = $( [] ).add( newDirName );-- var tips = $( ".validateTips" );-- function updateTips( t ) {- tips- .text( t )- .addClass( "ui-state-highlight" );- setTimeout(function() {- tips.removeClass( "ui-state-highlight", 1500 );- }, 500 );- }-- function checkLength( o, n, min, max ) {- if ( o.val().length > max || o.val().length < min ) {- o.addClass( "ui-state-error" );- updateTips( "Length of " + n + " must be between " +- min + " and " + max + "." );- return false;- } else {- return true;- }- }-- function checkRegexp( o, regexp, n ) {- if ( !( regexp.test( o.val() ) ) ) {- o.addClass( "ui-state-error" );- updateTips( n );- return false;- } else {- return true;- }- }-- $( "#fileTypeRadio" ).buttonset();-- var fileContent = undefined;-- $( "#txtFileTypeButton" ).click(function() {- // TODO Add to config options- fileContent = TSSETTINGS.getNewTextFileContent();- //Leave the filename as it is by no extension- if(newFileName.val().lastIndexOf(".")>=0) {- newFileName.val(newFileName.val().substring(0,newFileName.val().lastIndexOf("."))+".txt");- }- });-- $( "#htmlFileTypeButton" ).click(function() {- // TODO Add to config options- fileContent = TSSETTINGS.getNewHTMLFileContent();- //Leave the filename as it is by no extension- if(newFileName.val().lastIndexOf(".")>=0) {- newFileName.val(newFileName.val().substring(0,newFileName.val().lastIndexOf("."))+".html");- }- });-- $( "#mdFileTypeButton" ).click(function() {- // TODO Add to config options- fileContent = TSSETTINGS.getNewMDFileContent();- //Leave the filename as it is by no extension- if(newFileName.val().lastIndexOf(".")>=0) {- newFileName.val(newFileName.val().substring(0,newFileName.val().lastIndexOf("."))+".md");- }- });-- $( "#dialog-filecreate" ).dialog({- autoOpen: false,- height: 250,- width: 450,- modal: true,- buttons: {- "Create": function() {- var bValid = true;- allFields.removeClass( "ui-state-error" );-- bValid = bValid && checkLength( newFileName, "filename", 4, 200 );- // bValid = bValid && checkRegexp( renamedFileName, /^[a-z]([0-9a-z_.])+$/i, "Filename may consist of a-z, 0-9, underscores, begin with a letter." );- if(UIAPI.fileExists(newFileName.val())) {- updateTips("File already exists.");- bValid = false;- }- if ( bValid ) {- IOAPI.saveTextFile(UIAPI.currentPath+UIAPI.getDirSeparator()+$( "#newFileName" ).val(),fileContent);- $( this ).dialog( "close" );- IOAPI.listDirectory(UIAPI.currentPath);- }- },- Cancel: function() {- $( this ).dialog( "close" );- }- },- close: function() {- allFields.val( "" ).removeClass( "ui-state-error" );- },- open: function() {- fileContent = TSSETTINGS.getNewTextFileContent(); // Default new file in text file- $( "#newFileName" ).val(".txt");- }- });-- $( "#dialog-filerename" ).dialog({- autoOpen: false,- height: 220,- width: 450,- modal: true,- buttons: {- "Rename": function() {- var bValid = true;- allFields.removeClass( "ui-state-error" );-- bValid = bValid && checkLength( renamedFileName, "filename", 3, 200 );- // bValid = bValid && checkRegexp( renamedFileName, /^[a-z]([0-9a-z_.])+$/i, "Filename may consist of a-z, 0-9, underscores, begin with a letter." );- if ( bValid ) {- IOAPI.renameFile(- UIAPI.currentPath+UIAPI.getDirSeparator()+UIAPI.selectedFiles[0],- UIAPI.currentPath+UIAPI.getDirSeparator()+renamedFileName.val()- );- $( this ).dialog( "close" );- IOAPI.listDirectory(UIAPI.currentPath);- }- },- Cancel: function() {- $( this ).dialog( "close" );- }- },- close: function() {- allFields.val( "" ).removeClass( "ui-state-error" );- },- open: function() {- $( "#renamedFileName" ).val(UIAPI.selectedFiles[0]);- }- });-- $( "#dialog-confirmdelete" ).dialog({- autoOpen: false,- resizable: false,- height:140,- modal: true,- buttons: {- "Delete all items": function() {- IOAPI.deleteElement(UIAPI.currentPath+UIAPI.getDirSeparator()+UIAPI.selectedFiles[0]);- $( this ).dialog( "close" );- IOAPI.listDirectory(UIAPI.currentPath);- },- Cancel: function() {- $( this ).dialog( "close" );- }- }- });-- $( "#dialogAddTags" ).dialog({- autoOpen: false,- resizable: false,- height:240,- modal: true,- buttons: {- "Add tags": function() {- var tags = $("#tags").val().split(",");- TSAPI.writeTagsToFile(UIAPI.selectedFiles[0], tags);- IOAPI.listDirectory(UIAPI.currentPath);- $( this ).dialog( "close" );- },- Cancel: function() {- $( this ).dialog( "close" );- }- }- });-- $( "#tagTypeRadio" ).buttonset();-- $( "#plainTagTypeButton" ).click(function() {- UIAPI.selectedTag, $( "#newTag" ).val("")- });-- $( "#dateTagTypeButton" ).click(function() {- UIAPI.selectedTag, $( "#newTag" ).val("201YMMDD")- });-- $( "#currencyTagTypeButton" ).click(function() {- UIAPI.selectedTag, $( "#newTag" ).val("XEUR")- });-- $( "#dialogEditTag" ).dialog({- autoOpen: false,- resizable: false,- height:240,- modal: true,- buttons: {- "Edit tag": function() {- TSAPI.renameTag(UIAPI.selectedFiles[0], UIAPI.selectedTag, $( "#newTag" ).val());- IOAPI.listDirectory(UIAPI.currentPath);- $( this ).dialog( "close" );- },- Cancel: function() {- $( this ).dialog( "close" );- }- }- });-+/* Copyright (c) 2012 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. */+console.debug("Loading BasicViewsUI...");++var BasicViewsUI = (typeof BasicViewsUI == 'object' && BasicViewsUI != null) ? BasicViewsUI : {};++BasicViewsUI.initFileTagViews = function() {+ UIAPI.fileTable = $('#fileTable').dataTable( {+ "bJQueryUI": false,+ "bPaginate": false,+ "bLengthChange": false,+ "bFilter": true,+ "bSort": true,+ "bInfo": false,+ "bAutoWidth": false,+ "aoColumns": [+ { "sTitle": "Filename", "sClass": "right" },+ { "sTitle": "Size(bytes)" },+ { "sTitle": "Date Modified" },+ { "sTitle": "Title" },+ { "sTitle": "Tags" },+ { "sTitle": "Ext" },+ // { "sTitle": "Selection", "mData": null }+ ],+ "aoColumnDefs": [+ {+ "mRender": function ( data, type, row ) { return BasicViewsUI.buttonizeFileName(data) },+ "aTargets": [ 0 ]+ },+ {+ "mRender": function ( data, type, row ) { return BasicViewsUI.buttonizeTitle(data,row[0]) },+ "aTargets": [ 3 ]+ },+ {+ "mRender": function ( data, type, row ) { return BasicViewsUI.generateTagButtons(data,row[5],row[0]) },+ "aTargets": [ 4 ]+ },+ {+ "mRender": function ( data, type, row ) { return TSAPI.formatDateTime(data, true) },+ "aTargets": [ 2 ]+ },+ { "bVisible": false, "aTargets": [ 5 ] },+// { "bSearchable": false, "aTargets": [ 0 ] },+// { "sClass": "center", "aTargets": [ 0 ] }+ ]+ } );+++ // Disable alerts in datatable+ UIAPI.fileTable.dataTableExt.sErrMode = 'throw';++ // Makes the body of the fileTable selectable+ $("tbody", $(UIAPI.fileTable)).selectable({+ filter: 'tr',+ start: function() {+ console.debug("Start selecting");+ UIAPI.hideAllContextMenus();+ UIAPI.selectedFiles = [];+ $("#fileTable tbody tr").each(function(){+ $(this).removeClass('selectedRow');+ });+ },+ stop: function(){+ $(".ui-selected", this).each(function(){+ var index = $("#fileTable tr").index(this) - 1;+ $('#fileTable tbody tr:eq('+index+')').toggleClass('selectedRow');+ $('#fileTable tbody tr:eq('+index+')').toggleClass('ui-selected');+ var rowData = UIAPI.fileTable.fnGetData( this );+ // Add the filename which is located in the first column to the list of selected filenames+ UIAPI.selectedFiles.push(rowData[0]);+ });+/* if(UIAPI.selectedFiles.length == 1) {+ var dirSep = UIAPI.getDirSeparator();+ if(dirSep == "\\\\") { dirSep = "\" }+ $("#selectedFilePath").val(UIAPI.currentPath+dirSep+UIAPI.selectedFiles[0]);+ } else {+ $("#selectedFilePath").val("");+ } */+ console.debug("Selected files: "+UIAPI.selectedFiles);+ UIAPI.handleElementActivation();+ }+ })++ // Filter search functionality+ // TODO Consider Thumb and other views by filtering+ $("#filterBox").keyup(function() {+ UIAPI.fileTable.fnFilter(this.value);+ console.debug("Filter to value: "+this.value);+ });++ $('#filterBox').wrap('<span id="resetFilter" />').after($('<span/>').click(function() {+ $(this).prev('input').val('').focus();+ UIAPI.fileTable.fnFilter( "" );+ }));+}++BasicViewsUI.initThumbView = function() {+// Managing the selection of files in the thumb view+ $( "#selectableFiles" ).selectable({+ stop: function() {+ UIAPI.selectedFiles = [];+ $( ".ui-selected", this ).each(function() {+ // var index = $( "#selectableFiles li" ).index( this );+ // console.debug( "Selected #:" + ( index + 1 ) );+ // console.debug( "Selected file: "+$( "#selectableFiles li" )[index].innerHTML);+ UIAPI.selectedFiles.push($(this).attr("title"));+ });+ console.debug("Selected files: "+UIAPI.selectedFiles);+ UIAPI.handleElementActivation();++ // On selecting only one file opens it in the viewer+ if(UIAPI.selectedFiles.length == 1) {+ FileViewer.openFile(UIAPI.selectedFiles[0]);+ }+ }+ });+}++BasicViewsUI.generateTagButtons = function(commaSeparatedTags, fileExtension, fileName) {+ console.debug("Creating tags...");+ var htmlOutput = "";+ var tagString = ""+commaSeparatedTags;+ if(fileExtension.length > 0) {+ htmlOutput += ('<button title="Opens context menu for '+fileExtension+'" tag="'+fileExtension+'" filename="'+fileName+'" class="extTagButton">'+fileExtension+'</button>');+ }+ if(tagString.length > 0) {+ var tags = tagString.split(",");+ for (var i=0; i < tags.length; i++) {+ htmlOutput += ('<button title="Opens context menu for '+tags[i]+'" tag="'+tags[i]+'" filename="'+fileName+'" class="tagButton">'+tags[i]+'</button>');+ }+ }+ return htmlOutput;+}++BasicViewsUI.clearSelectedFiles = function() {+ // Clear selected files in the model+ UIAPI.selectedFiles = [];++ // Deselect all+ $(".selectedRow", $(UIAPI.fileTable)).each(function(){+ $(this).toggleClass('selectedRow');+ });+}++BasicViewsUI.buttonizeTitle = function(title, fileName) {+ var htmlOutput = "";+ htmlOutput += '<button title="'+fileName+'" class="fileTitleButton">'+title+' </button>';+ return htmlOutput;+}++BasicViewsUI.openFileTitleMenu = function(tagButton, fileName) {+ BasicViewsUI.clearSelectedFiles();+ $(tagButton).parent().parent().toggleClass("selectedRow");++ UIAPI.currentFilename = fileName;+ UIAPI.selectedFiles.push(UIAPI.currentFilename);++ var menu = $("#fileTitleMenu").show().position({+ my: "left top",+ at: "left bottom",+ of: tagButton+ });+ // TODO Hide menu+ // $( document ).one( "click", function() { menu.hide(); });+}++BasicViewsUI.buttonizeFileName = function(fileName) {+ var htmlOutput = "";+ htmlOutput += '<button title="'+fileName+'" class="fileButton">'+fileName+'</button>';+ return htmlOutput;+}++BasicViewsUI.openFileMenu = function(tagButton, fileName) {+ BasicViewsUI.clearSelectedFiles();+ $(tagButton).parent().parent().toggleClass("selectedRow");++ UIAPI.currentFilename = fileName;+ UIAPI.selectedFiles.push(UIAPI.currentFilename);++ var menu = $("#fileMenu").show().position({+ my: "left top",+ at: "left bottom",+ of: tagButton+ });+ // TODO Hide menu+ // $( document ).one( "click", function() { menu.hide(); });+}++BasicViewsUI.initButtons = function() {+// Layout Buttons+ $( "#toggleLeftPanel" ).button({+ text: false,+ icons: {+ primary: "ui-icon-triangle-2-e-w"+ }+ })+ .click(function() {+ layoutContainer.toggle("west");+ });++ $( "#toggleRightPanel" ).button({+ text: false,+ icons: {+ primary: "ui-icon-triangle-2-e-w"+ }+ })+ .click(function() {+ layoutContainer.toggle("east");+ });++// Change View buttons+ $( "#viewsRadio" ).buttonset();++ $( "#fileViewButton" ).button({+ text: true,+ icons: {+ primary: "ui-icon-note"+ }+ })+ .click(function() {+ UIAPI.changeView("fileView");+ });++ $( "#tagViewButton" ).button({+ text: true,+ icons: {+ primary: "ui-icon-tag"+ }+ })+ .click(function() {+ UIAPI.changeView("tagView");+ });++ $( "#thumbViewButton" ).button({+ text: true,+ icons: {+ primary: "ui-icon-image"+ }+ })+ .click(function() {+ UIAPI.changeView("thumbView");+ });++ $( "#riverViewButton" ).click(function() {+ UIAPI.changeView("riverView");+ });++// Sort buttons - Deprecated+/*+ $( "#fileSortRadio" ).buttonset();++ $( "#sortByNameButton" ).click(function() {+ UIAPI.setFileSortCriteria("name");+ UIAPI.changeFileView();+ });++ $( "#sortByDateButton" ).click(function() {+ UIAPI.setFileSortCriteria("lmdt");+ UIAPI.changeFileView();+ });++ $( "#sortBySizeButton" ).click(function() {+ UIAPI.setFileSortCriteria("size");+ UIAPI.changeFileView();+ });+*/++// Initialize file buttons+ $( "#createFileButton" ).button({+ text: true,+ icons: {+ primary: "ui-icon-document"+ }+ })+ .click(function() {+ $( "#dialog-filecreate" ).dialog( "open" );+ });++ $( "#openFileButton" ).button({+ text: true,+ disabled: true+ })+ .click(function() {+ FileViewer.openFile(UIAPI.selectedFiles[0]);+ });++ $( "#editFileButton" ).button({+ text: true,+ disabled: true+ })+ .click(function() {+ UIAPI.editFile(UIAPI.selectedFiles[0]);+ });++ $( "#deleteFileButton" ).button({+ text: true,+ disabled: true,+ icons: {+ primary: "ui-icon-trash"+ }+ })+ .click(function() {+ $( "#dialog-confirmdelete" ).dialog( "open" );+ });++ $( "#renameFileButton" ).button({+ text: true,+ disabled: true+ })+ .click(function() {+ $( "#dialog-filerename" ).dialog( "open" );+ });++ $( "#clearFilterButton" ).button({+ text: false,+ disabled: false,+ icons: {+ primary: "ui-icon-close"+ }+ })+ .click(function() {+ $( "#filterBox" ).val( "" );+ UIAPI.fileTable.fnFilter( "" );+ });++}++BasicViewsUI.initContextMenus = function() {+ $( "#fileMenu" ).menu({+ select: function( event, ui ) {+ var commandName = ui.item.attr( "action" );+ switch (commandName) {+ case "openFile":+ $( this ).hide();+ console.debug("Opening file...");+ FileViewer.openFile(UIAPI.selectedFiles[0]);+ break;+ case "editFile":+ $( this ).hide();+ console.debug("Editing file...");+ UIAPI.editFile(UIAPI.selectedFiles[0]);+ break;+ case "renameFile":+ $( this ).hide();+ console.debug("Renaming file...");+ $( "#dialog-filerename" ).dialog( "open" );+ break;+ case "deleteFile":+ $( this ).hide();+ console.debug("Deleting file...");+ $( "#dialog-confirmdelete" ).dialog( "open" );+ break;+ case "closeMenu":+ $( this ).hide();+ break;+ default:+ break;+ }+ $( this ).hide();+ }+ });++ $( "#fileTitleMenu" ).menu({+ select: function( event, ui ) {+ var commandName = ui.item.attr( "action" );+ switch (commandName) {+ case "openFile":+ $( this ).hide();+ console.debug("Opening file...");+ FileViewer.openFile(UIAPI.selectedFiles[0]);+ break;+ case "editFile":+ $( this ).hide();+ console.debug("Editing file...");+ UIAPI.editFile(UIAPI.selectedFiles[0]);+ break;+ case "addTag":+ $( this ).hide();+ console.debug("Adding tag...");+ $("#tags").val("");+ $( "#dialogAddTags" ).dialog( "open" );+ break;+ case "closeMenu":+ $( this ).hide();+ break;+ default:+ break;+ }+ }+ });++}++BasicViewsUI.initDialogs = function() {+ var newDirName = $( "#dirname" );+ var newFileName = $( "#newFileName" );+ var renamedFileName = $( "#renamedFileName" );++ // TODO evtl add smarttag and the others...+ var allFields = $( [] ).add( newDirName );++ var tips = $( ".validateTips" );++ function updateTips( t ) {+ tips+ .text( t )+ .addClass( "ui-state-highlight" );+ setTimeout(function() {+ tips.removeClass( "ui-state-highlight", 1500 );+ }, 500 );+ }++ function checkLength( o, n, min, max ) {+ if ( o.val().length > max || o.val().length < min ) {+ o.addClass( "ui-state-error" );+ updateTips( "Length of " + n + " must be between " ++ min + " and " + max + "." );+ return false;+ } else {+ return true;+ }+ }++ function checkRegexp( o, regexp, n ) {+ if ( !( regexp.test( o.val() ) ) ) {+ o.addClass( "ui-state-error" );+ updateTips( n );+ return false;+ } else {+ return true;+ }+ }++ $( "#fileTypeRadio" ).buttonset();++ var fileContent = undefined;++ $( "#txtFileTypeButton" ).click(function() {+ // TODO Add to config options+ fileContent = TSSETTINGS.getNewTextFileContent();+ //Leave the filename as it is by no extension+ if(newFileName.val().lastIndexOf(".")>=0) {+ newFileName.val(newFileName.val().substring(0,newFileName.val().lastIndexOf("."))+".txt");+ }+ });++ $( "#htmlFileTypeButton" ).click(function() {+ // TODO Add to config options+ fileContent = TSSETTINGS.getNewHTMLFileContent();+ //Leave the filename as it is by no extension+ if(newFileName.val().lastIndexOf(".")>=0) {+ newFileName.val(newFileName.val().substring(0,newFileName.val().lastIndexOf("."))+".html");+ }+ });++ $( "#mdFileTypeButton" ).click(function() {+ // TODO Add to config options+ fileContent = TSSETTINGS.getNewMDFileContent();+ //Leave the filename as it is by no extension+ if(newFileName.val().lastIndexOf(".")>=0) {+ newFileName.val(newFileName.val().substring(0,newFileName.val().lastIndexOf("."))+".md");+ }+ });++ $( "#dialog-filecreate" ).dialog({+ autoOpen: false,+ height: 250,+ width: 450,+ modal: true,+ buttons: {+ "Create": function() {+ var bValid = true;+ allFields.removeClass( "ui-state-error" );++ bValid = bValid && checkLength( newFileName, "filename", 4, 200 );+ // bValid = bValid && checkRegexp( renamedFileName, /^[a-z]([0-9a-z_.])+$/i, "Filename may consist of a-z, 0-9, underscores, begin with a letter." );+ if(UIAPI.fileExists(newFileName.val())) {+ updateTips("File already exists.");+ bValid = false;+ }+ if ( bValid ) {+ IOAPI.saveTextFile(UIAPI.currentPath+UIAPI.getDirSeparator()+$( "#newFileName" ).val(),fileContent);+ $( this ).dialog( "close" );+ IOAPI.listDirectory(UIAPI.currentPath);+ }+ },+ Cancel: function() {+ $( this ).dialog( "close" );+ }+ },+ close: function() {+ allFields.val( "" ).removeClass( "ui-state-error" );+ },+ open: function() {+ fileContent = TSSETTINGS.getNewTextFileContent(); // Default new file in text file+ $( "#newFileName" ).val(".txt");+ }+ });++ $( "#dialog-filerename" ).dialog({+ autoOpen: false,+ height: 220,+ width: 450,+ modal: true,+ buttons: {+ "Rename": function() {+ var bValid = true;+ allFields.removeClass( "ui-state-error" );++ bValid = bValid && checkLength( renamedFileName, "filename", 3, 200 );+ // bValid = bValid && checkRegexp( renamedFileName, /^[a-z]([0-9a-z_.])+$/i, "Filename may consist of a-z, 0-9, underscores, begin with a letter." );+ if ( bValid ) {+ IOAPI.renameFile(+ UIAPI.currentPath+UIAPI.getDirSeparator()+UIAPI.selectedFiles[0],+ UIAPI.currentPath+UIAPI.getDirSeparator()+renamedFileName.val()+ );+ $( this ).dialog( "close" );+ IOAPI.listDirectory(UIAPI.currentPath);+ }+ },+ Cancel: function() {+ $( this ).dialog( "close" );+ }+ },+ close: function() {+ allFields.val( "" ).removeClass( "ui-state-error" );+ },+ open: function() {+ $( "#renamedFileName" ).val(UIAPI.selectedFiles[0]);+ }+ });++ $( "#dialog-confirmdelete" ).dialog({+ autoOpen: false,+ resizable: false,+ height:140,+ modal: true,+ buttons: {+ "Delete all items": function() {+ IOAPI.deleteElement(UIAPI.currentPath+UIAPI.getDirSeparator()+UIAPI.selectedFiles[0]);+ $( this ).dialog( "close" );+ IOAPI.listDirectory(UIAPI.currentPath);+ },+ Cancel: function() {+ $( this ).dialog( "close" );+ }+ }+ });++ $( "#dialogAddTags" ).dialog({+ autoOpen: false,+ resizable: false,+ height:240,+ modal: true,+ buttons: {+ "Add tags": function() {+ var tags = $("#tags").val().split(",");+ TSAPI.writeTagsToFile(UIAPI.selectedFiles[0], tags);+ IOAPI.listDirectory(UIAPI.currentPath);+ $( this ).dialog( "close" );+ },+ Cancel: function() {+ $( this ).dialog( "close" );+ }+ }+ });++ $( "#tagTypeRadio" ).buttonset();++ $( "#plainTagTypeButton" ).click(function() {+ UIAPI.selectedTag, $( "#newTag" ).val("")+ });++ $( "#dateTagTypeButton" ).click(function() {+ UIAPI.selectedTag, $( "#newTag" ).val("201YMMDD")+ });++ $( "#currencyTagTypeButton" ).click(function() {+ UIAPI.selectedTag, $( "#newTag" ).val("XEUR")+ });++ $( "#dialogEditTag" ).dialog({+ autoOpen: false,+ resizable: false,+ height:240,+ modal: true,+ buttons: {+ "Edit tag": function() {+ TSAPI.renameTag(UIAPI.selectedFiles[0], UIAPI.selectedTag, $( "#newTag" ).val());+ IOAPI.listDirectory(UIAPI.currentPath);+ $( this ).dialog( "close" );+ },+ Cancel: function() {+ $( this ).dialog( "close" );+ }+ }+ });}\ No newline at end of filediff --git a/data/js/fileviewer.ui.js b/data/js/fileviewer.ui.jsnew file mode 100644index 000000000..3bcf5f08b--- /dev/null+++ b/data/js/fileviewer.ui.js@@ -0,0 +1,234 @@+/* Copyright (c) 2012 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";++console.debug("Loading FileViewer...");++var tsEditor = undefined;++exports.updateTextEditorContent = function(fileContent) {+ console.debug("Updating edtitor"); // with data: "+fileContent);+ tsEditor.setContent(fileContent);+}++exports.openFile = function(fileName) {+ console.debug("Opening file: "+fileName);++ var openedFilePath = UIAPI.currentPath+UIAPI.getDirSeparator()+fileName;+ // TODO replace \\ to \ in filenames+ openedFilePath.replace("\\\\","\\");+ $("#selectedFilePath").val(openedFilePath);++ var fileExt = fileName.substring(fileName.lastIndexOf(".")+1,fileName.length).toLowerCase();+ var filePath = "file:///"+UIAPI.currentPath+UIAPI.getDirSeparator()+fileName;++ this.constructFileViewerUI(fileName, filePath);++ // Getting the viewer for the file extension/type+ var viewerExt = TSSETTINGS.getFileTypeViewer(fileExt);+ console.debug("File Viewer: "+viewerExt);++ // TODO Consider page width by opening, e.g. responsive design+ layoutContainer.open("east");+ // layoutContainer.close("west");++ UIAPI.isFileOpened = true;++ $( "#viewer" ).empty();+ if(!viewerExt) {+ $( "#viewer" ).html("File type not supported for viewing.");+ return;+ } else {+ require(["ext/"+viewerExt+"/extension"], function(viewer) {+ tsEditor = viewer;+ tsEditor.init("viewer");+ // tsEditor.setFileType(fileExt);+ tsEditor.setContent(filePath);+ });+// IOAPI.loadTextFile(filePath);+ }+}++exports.editFile = function(fileName) {+ console.debug("Editing file: "+filePath);+ var filePath = UIAPI.currentPath+UIAPI.getDirSeparator()+fileName;+ var fileExt = fileName.substring(fileName.lastIndexOf(".")+1,fileName.length).toLowerCase();++ // Getting the editor for the file extension/type+ var editorExt = TSSETTINGS.getFileTypeEditor(fileExt);+ console.debug("File Editor: "+editorExt);++ $( "#viewer" ).empty();+ if(!editorExt) {+ $( "#viewer" ).html("File type not supported for editing.");+ return;+ } else {+ $( "#viewer" ).html('<div id="generalEditor" style="width: 100%; height: 100%"></div>');+ require(["ext/"+editorExt+"/extension"], function(editr) {+ tsEditor = editr;+ tsEditor.init("generalEditor");+ tsEditor.setFileType(fileExt);+ });+ IOAPI.loadTextFile(filePath);+ }+}++this.constructFileViewerUI = function(fileName, filePath) {+ // Adding tag buttons to the filetoolbox+ var tags = TSAPI.extractTags(fileName);++ $( "#fileTitle" ).html(TSAPI.extractTitle(fileName));++ // Generate tag buttons+ $( "#fileTags" ).html("");+ for (var i=0; i < tags.length; i++) {+ $( "#fileTags" ).append('<button title="Opens context menu for '+tags[i]+'" tag="'+tags[i]+'" filename="'+fileName+'" class="tagButton">'+tags[i]+'</button>');+ };++ // Activate tagButtons in file view+ $('.tagButton', $( "#fileTags" )).click( function() {+ TagsUI.openTagMenu(this, $(this).attr("tag"), $(this).attr("filename"));+ });++ // Clear filetoolbox+ $( "#filetoolbox" ).html("");++ // TODO Fullscreen disabled due a fullscreen issue+ //this.addFullScreenButton("#filetoolbox");++ this.addEditButton("#filetoolbox", fileName);++ this.addOpenInWindowButton("#filetoolbox", filePath);++ // TODO Tag suggestion disabled due menu init issue+ //this.initTagSuggestionMenu(fileName, tags);+ //this.addTagSuggestionButton("#filetoolbox");++ this.addCloseButton("#filetoolbox");+}+++this.initTagSuggestionMenu = function(fileName, tags) {+ // Adding buttons for creating tags according to the suggested tags+ var suggTags = TSAPI.suggestTags(fileName);++ // $( "#tagSuggestionsMenu" ).menu();+ // $( "#tagSuggestionsMenu" ).menu("disable");+ $( "#tagSuggestionsMenu" ).html("");++ for (var i=0; i < suggTags.length; i++) {+ // Ignoring the tags already assigned to a file+ if(tags.indexOf(suggTags[i]) < 0) {+ $( "#tagSuggestionsMenu" ).append('<li name="'+suggTags[i]+'" title="Add tag '+suggTags[i]+' to current file">Tag with "'+suggTags[i]+'"</li>');+ }+ };++ // TODO menu does not initialize+ $( "#tagSuggestionsMenu" ).menu({ // menu("destroy").+ select: function( event, ui ) {+ var tagName = ui.item.attr( "name" );+ TSAPI.writeTagsToFile(fileName, [tagName]);+ IOAPI.listDirectory(UIAPI.currentPath);+ }+ });+}++this.addEditButton = function(container, fileName) {+ // TODO implement disabled check+ var buttonDisabled = false;+ $( ""+container ).append('<button id="editDocument">Edit</button>');+ $( "#editDocument" ).button({+ text: true,+ icons: {+ primary: "ui-icon-wrench"+ },+ disabled: buttonDisabled+ })+ .click(function() {+ exports.editFile(fileName);+ });+}++this.addOpenInWindowButton = function(container, filePath) {+ $( ""+container ).append('<button id="openInNewWindow">Open in new tab</button>');+ $( "#openInNewWindow" ).button({+ text: false,+ icons: {+ primary: "ui-icon-newwin"+ },+ disabled: false+ })+ .click(function() {+ window.open(filePath);+ });+}++this.addCloseButton = function(container) {+ $( ""+container ).append('<button id="closeOpenedFile">Close</button>');+ $( "#closeOpenedFile" ).button({+ text: false,+ icons: {+ primary: "ui-icon-circle-close"+ },+ disabled: false+ })+ .click(function() {+ UIAPI.isFileOpened = false;+ layoutContainer.open("west");+ layoutContainer.close("east");+ });+}+++this.addFullScreenButton = function(container) {+ $( ""+container ).append('<button id="startFullscreen">Fullscreen</button>');+ $( "#startFullscreen" ).button({+ text: false,+ icons: {+ primary: "ui-icon-arrow-4-diag"+ },+ disabled: false+ })+ .click(function() {+ var docElm = $("#container");+ docElm.mozRequestFullScreen();+/* alert(docElm.webkitRequestFullScreen);+ if (docElm.requestFullscreen) {+ docElm.requestFullscreen();+ }+ else if (docElm.mozRequestFullScreen) {+ docElm.mozRequestFullScreen();+ }+ else if (docElm.webkitRequestFullScreen) {+ alert(docElm);+ docElm.webkitRequestFullScreen();+ }*/+ });+}++this.addTagSuggestionButton = function(container) {+ $( ""+container ).append('<button id="openTagSuggestionMenu">Tag Suggestion</button>');+ $( "#openTagSuggestionMenu" ).button({+ text: false,+ icons: {+ primary: "ui-icon-suitcase"+ },+ disabled: false+ })+ .click(function() {+ UIAPI.selectedTag = this.id;+ var menu = $("#tagSuggestionsMenu").show().position({+ my: "left top",+ at: "left bottom",+ of: $( this )+ });+ $( document ).one( "click", function() {+ menu.hide();+ });+ return false;+ });+}++});\ No newline at end of filediff --git a/data/js/layout.ui.js b/data/js/layout.ui.jsnew file mode 100644index 000000000..c597cd1e3--- /dev/null+++ b/data/js/layout.ui.js@@ -0,0 +1,97 @@+/* Copyright (c) 2012 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. */+console.debug("Loading LayoutUI...");++$(document).ready(function () {+ layoutContainer = $('#container').layout(+ {+ fxName: "none"++ // some resizing/toggling settings+ , north__resizable: false // OVERRIDE the pane-default of 'slidable=true'+ , north__spacing_open: 0 // no resizer-bar when open (zero height)+ // , north__togglerLength_closed: '100%' // toggle-button is full-width of resizer-bar+ // , north__spacing_closed: 20 // big resizer-bar when open (zero height)+ , north__size: 33++ , south__resizable: false // OVERRIDE the pane-default of 'resizable=true'+ , south__spacing_open: 0 // no resizer-bar when open (zero height)+ // , south__spacing_closed: 20 // big resizer-bar when open (zero height)++ // west settings+ , west__resizable: true+ , west__minSize: .1+// , west__maxSize: .4+ , west__size: 200+ , west__spacing_open: 3++ // east settings+ , east__resizable: true+ , east__size: .45+ , east__minSize: .2+// , east__maxSize: .8 // 80% of layout width+ , east__spacing_open: 3++ // center settings+ , center__resizable: true+ , center__minSize: 0.5++ // enable showOverflow on west-pane so CSS popups will overlap north pane+ , west__showOverflowOnHover: true++ // enable state management+ , stateManagement__enabled: false // automatic cookie load & save enabled by default++ , showDebugMessages: true // log and/or display messages from debugging & testing code+ }++ );++ var westLayout = $('div.ui-layout-west').layout({+ minSize: 50 // ALL panes+ , center__paneSelector: ".west-center"+ , south__paneSelector: ".west-south"+ , south__size: .5+ , south__spacing_open: 3+ });++ var centerLayout = $('div.ui-layout-center').layout({+ name: "middle"+ , north__paneSelector: ".middle-north"+ , center__paneSelector: ".middle-center"+ , south__paneSelector: ".middle-south"+ , minSize: 0 // ALL panes+ , center__minSize: 300+ , north__size: 32+ , north__resizable: false+ , north__spacing_open: 0+ , south__spacing_open: 0+ , south__size: 1+ });++ // File Viewer / Editor+ var eastLayout = $('div.ui-layout-east').layout({+ minSize: 30 // ALL panes+ , north__paneSelector: ".east-north"+ , center__paneSelector: ".east-center"+ , south__paneSelector: ".east-south"+ , north__size: 80+ , north__resizable: false+ , north__spacing_open: 0+ , south__size: 25+ , south__spacing_open: 0+ });++ var dirNavigationLayout = $('#directoryNavigator').layout({+ minSize: 30 // ALL panes+ , north__paneSelector: "#directoryNavigatorNorth"+ , center__paneSelector: "#dirTree"+ , north__size: 30+ , north__resizable: false+ , north__spacing_open: 0+ });++ // Hide Document Viewer by default+ layoutContainer.toggle("east");+});\ No newline at end of filediff --git a/data/js/loader.js b/data/js/loader.jsdeleted file mode 100644index f3065fab2..000000000--- a/data/js/loader.js+++ /dev/null@@ -1,13 +0,0 @@-require([- //"js/misc.ui.js",- "js/ioapi.chrome.js",- "js/ioapi.mozilla.js",- "js/settings.api.js",- "js/tagspace.api.js",- "js/tags.ui.js",- "js/basicviews.ui.js",- "js/directories.ui.js",- "js/settings.ui.js",- "js/main.ui.js"-], function($) {-});\ No newline at end of filediff --git a/data/js/messaging.mozilla.js b/data/js/messaging.mozilla.jsnew file mode 100644index 000000000..492a9e3bd--- /dev/null+++ b/data/js/messaging.mozilla.js@@ -0,0 +1,106 @@+/* Copyright (c) 2012 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. */+// Activating browser specific IOAPI modul+define(function(require, exports, module) {+"use strict";++console.debug("Loading messaging.mozilla.js..");+document.documentElement.addEventListener("addon-message1", function(event) {+ console.debug("Message received in page script from content script: "+JSON.stringify(event.detail));+ UIAPI.hideLoadingAnimation();+ var message = event.detail;+ switch (message.command) {+ case "loadSettings":+ if(message.success) {+ try {+ console.debug("Loading settings...: "+JSON.stringify(message.content));+ TSSETTINGS.updateSettingMozillaPreferences(message.content);+ } catch (ex) {+ console.debug("Exception while getting setting from firefox failed "+ex)+ }+ } else {+ console.debug("Getting setting from firefox failed")+ }+ break;+ case "saveSettings":+ if(message.success) {+ console.debug("Saving setting as native mozilla preference successfull!")+ } else {+ console.debug("Saving setting as native mozilla preference failed!")+ }+ break;+ case "updateDefaultPath":+ if(message.content.length > 1) {+ UIAPI.setCurrentPath(message.content);+ }+ break;+ case "rename":+ if(message.success){+ UIAPI.updateLogger("Rename success");+ // message.content contains the name of the file after the rename+ UIAPI.selectedFiles[0] = message.content;+ if(UIAPI.isFileOpened) {+ FileViewer.openFile(UIAPI.selectedFiles[0]);+ }+ } else {+ UIAPI.updateLogger("Rename failed");+ }+ break;+ case "saveTextFile":+ if(message.success){+ UIAPI.updateLogger("Save success");+ } else {+ UIAPI.updateLogger("Save failed");+ }+ break;+ case "createDirectory":+ if(message.success){+ UIAPI.updateLogger("Create dir success");+ DirectoriesUI.openFavorite(TSSETTINGS.Settings["tagspacesList"][0].path, TSSETTINGS.Settings["tagspacesList"][0].name);+ } else {+ UIAPI.updateLogger("Create dir failed");+ }+ break;+ case "loadTextFile":+ if(message.success){+ UIAPI.updateTextEditorContent(message.content);+ } else {+ UIAPI.updateLogger("File loading failed");+ }+ break;+ case "listDirectory":+ if(message.success){+ UIAPI.updateFileBrowserData(message.content);+ } else {+ UIAPI.updateLogger("List directory failed");+ }+ break;+ case "getSubdirs":+ if(message.success){+ var dirListing = [];+ for (var i=0; i < message.content.length; i++) {+ dirListing.push(message.content[i]);+ }+ // TODO JSON functions are a workarround for a bug....+ UIAPI.updateTree(JSON.parse( JSON.stringify(dirListing)));+ //if(!extConnected) {+ // initUI();+ //}+ //extConnected = true;+ } else {+ UIAPI.updateLogger("Getting subdirs failed");+ }+ break;+ case "delete":+ if(message.success){+ UIAPI.updateLogger("Delete success");+ } else {+ UIAPI.updateLogger("Delete failed");+ }+ break;+ default:+ break;+ }+}, false);+});\ No newline at end of filediff --git a/data/js/misc.ui.js b/data/js/misc.ui.jsindex 6ec13fdf4..c57c2550e 100644--- a/data/js/misc.ui.js+++ b/data/js/misc.ui.js@@ -111,9 +111,7 @@ UIAPI.updateFileBrowserData = function(dirList) {UIAPI.fileList.push(entry);}}- }--+ }UIAPI.changeView(UIAPI.currentView);}@@ -144,7 +142,7 @@ UIAPI.initFileTagView = function(viewType) {console.debug("Opening file...");var rowData = UIAPI.fileTable.fnGetData( this );$("#selectedFilePath").val(UIAPI.currentPath+UIAPI.getDirSeparator()+rowData[0]);- UIAPI.openFile(rowData[0]);+ FileViewer.openFile(rowData[0]);UIAPI.hideAllContextMenus();} );@@ -305,207 +303,6 @@ UIAPI.changeDirectory = function(newDir) {UIAPI.selectedTag = "";}-UIAPI.openFile = function(fileName) {- console.debug("Opening file: "+fileName);-- // TODO Consider page width by opening, e.g. responsive design- layoutContainer.open("east");- // layoutContainer.close("west");-- UIAPI.isFileOpened = true;-- var openedFilePath = UIAPI.currentPath+UIAPI.getDirSeparator()+fileName;- // TODO replace \\ to \ in filenames- openedFilePath.replace("\\\\","\\");- $("#selectedFilePath").val(openedFilePath);-- var fileExt = fileName.substring(fileName.lastIndexOf(".")+1,fileName.length).toLowerCase();-// console.debug("Ext: "+fileExt);- var filePath = "file:///"+UIAPI.currentPath+UIAPI.getDirSeparator()+fileName;-- $( "#viewer" ).show();- if(TSSETTINGS.getSupportedFileExt4Viewing().indexOf(fileExt) >= 0) {- $( "#viewer" ).html('<iframe id="idFrameViewer" src="'+filePath+'" />');- } else {- $( "#viewer" ).html('File type/extension not supported for viewing');- }--- // Adding tag buttons to the filetoolbox- var tags = TSAPI.extractTags(fileName);-- $( "#fileTitle" ).html(TSAPI.extractTitle(fileName));-- // Generate tag buttons- $( "#fileTags" ).html("");- for (var i=0; i < tags.length; i++) {- $( "#fileTags" ).append('<button title="Opens context menu for '+tags[i]+'" tag="'+tags[i]+'" filename="'+fileName+'" class="tagButton">'+tags[i]+'</button>');- };-- // Activate tagButtons in file view- $('.tagButton', $( "#fileTags" )).click( function() {- TagsUI.openTagMenu(this, $(this).attr("tag"), $(this).attr("filename"));- } );-- // Clear filetoolbox- $( "#filetoolbox" ).html("");-- // TODO Fullscreen disabled due a fullscreen issue- //UIAPI.addFullScreenButton("#filetoolbox");-- UIAPI.addOpenInWindowButton("#filetoolbox", filePath);-- // TODO Tag suggestion disabled due menu init issue- //UIAPI.initTagSuggestionMenu(fileName, tags);- //UIAPI.addTagSuggestionButton("#filetoolbox");-- UIAPI.addCloseButton("#filetoolbox");-}--UIAPI.initTagSuggestionMenu = function(fileName, tags) {- // Adding buttons for creating tags according to the suggested tags- var suggTags = TSAPI.suggestTags(fileName);-- // $( "#tagSuggestionsMenu" ).menu();- // $( "#tagSuggestionsMenu" ).menu("disable");- $( "#tagSuggestionsMenu" ).html("");-- for (var i=0; i < suggTags.length; i++) {- // Ignoring the tags already assigned to a file- if(tags.indexOf(suggTags[i]) < 0) {- $( "#tagSuggestionsMenu" ).append('<li name="'+suggTags[i]+'" title="Add tag '+suggTags[i]+' to current file">Tag with "'+suggTags[i]+'"</li>');- }- };-- // TODO menu does not initialize- $( "#tagSuggestionsMenu" ).menu({ // menu("destroy").- select: function( event, ui ) {- var tagName = ui.item.attr( "name" );- TSAPI.writeTagsToFile(fileName, [tagName]);- IOAPI.listDirectory(UIAPI.currentPath);- }- });-}--UIAPI.addOpenInWindowButton = function(container, filename) {- $( ""+container ).append('<button id="openInNewWindow">Open in new tab</button>');- $( "#openInNewWindow" ).button({- text: false,- icons: {- primary: "ui-icon-newwin"- },- disabled: false- })- .click(function() {- window.open(filename);- });-}--UIAPI.addCloseButton = function(container) {- $( ""+container ).append('<button id="closeOpenedFile">Close</button>');- $( "#closeOpenedFile" ).button({- text: false,- icons: {- primary: "ui-icon-circle-close"- },- disabled: false- })- .click(function() {- UIAPI.isFileOpened = false;- layoutContainer.open("west");- layoutContainer.close("east");- });-}---UIAPI.addFullScreenButton = function(container) {- $( ""+container ).append('<button id="startFullscreen">Fullscreen</button>');- $( "#startFullscreen" ).button({- text: false,- icons: {- primary: "ui-icon-arrow-4-diag"- },- disabled: false- })- .click(function() {- var docElm = $("#container");- docElm.mozRequestFullScreen();-/* alert(docElm.webkitRequestFullScreen);- if (docElm.requestFullscreen) {- docElm.requestFullscreen();- }- else if (docElm.mozRequestFullScreen) {- docElm.mozRequestFullScreen();- }- else if (docElm.webkitRequestFullScreen) {- alert(docElm);- docElm.webkitRequestFullScreen();- }*/- });-}--UIAPI.addTagSuggestionButton = function(container) {- $( ""+container ).append('<button id="openTagSuggestionMenu">Tag Suggestion</button>');- $( "#openTagSuggestionMenu" ).button({- text: false,- icons: {- primary: "ui-icon-suitcase"- },- disabled: false- })- .click(function() {- UIAPI.selectedTag = this.id;- var menu = $("#tagSuggestionsMenu").show().position({- my: "left top",- at: "left bottom",- of: $( this )- });- $( document ).one( "click", function() {- menu.hide();- });- return false;- });-}--// TODO handle different file type such as txt or md-UIAPI.updateTextEditorContent = function(fileContent) {- console.debug("Updating edtitor with data: "+fileContent);- aceEditor.setValue(fileContent);-}--UIAPI.editFile = function(fileName) {- console.debug("Editing file: "+fileName);- var fileExt = fileName.substring(fileName.lastIndexOf(".")+1,fileName.length).toLowerCase();-- $( "#viewer" ).empty();-- if(TSSETTINGS.Settings["supportedFileTypeEditing"].indexOf(fileExt) < 0) {- $( "#viewer" ).html("File type not supported for editing.");- return;- }-- var filePath = UIAPI.currentPath+UIAPI.getDirSeparator()+fileName;- if(fileExt == "js") {- $( "#viewer" ).html('<div id="generalEditor" style="width: 100%; height: 100%">'+' '+'</div>');- aceEditor = undefined- require(["ext/editor_text/ace/ace"], function(ace) {- aceEditor = ace.edit("generalEditor");- aceEditor.setTheme("ext/editor_text/ace/theme/monokai");- aceEditor.getSession().setMode("ext/editor_text/ace/mode/javascript");- });- IOAPI.loadTextFile(filePath);- } else if (fileExt == "html" || fileExt == "htm" ) {-- } else if (fileExt == "md" ) {-- } else {- $( "#viewer" ).html("File type not supported for editing.");- }-- layoutContainer.open("east");- UIAPI.isFileOpened = true;- $( "#viewer" ).show();-}UIAPI.handleElementActivation = function() {console.debug("Entering element activation handler...");@@ -556,100 +353,6 @@ UIAPI.reloadUI = function() {location.reload();}-$(document).ready(function () {- layoutContainer = $('#container').layout(- {- fxName: "none"-- // some resizing/toggling settings- , north__resizable: false // OVERRIDE the pane-default of 'slidable=true'- , north__spacing_open: 0 // no resizer-bar when open (zero height)- // , north__togglerLength_closed: '100%' // toggle-button is full-width of resizer-bar- // , north__spacing_closed: 20 // big resizer-bar when open (zero height)- , north__size: 33-- , south__resizable: false // OVERRIDE the pane-default of 'resizable=true'- , south__spacing_open: 0 // no resizer-bar when open (zero height)- // , south__spacing_closed: 20 // big resizer-bar when open (zero height)-- // west settings- , west__resizable: true- , west__minSize: .1-// , west__maxSize: .4- , west__size: 200- , west__spacing_open: 3-- // east settings- , east__resizable: true- , east__size: .45- , east__minSize: .2-// , east__maxSize: .8 // 80% of layout width- , east__spacing_open: 3-- // center settings- , center__resizable: true- , center__minSize: 0.5-- // enable showOverflow on west-pane so CSS popups will overlap north pane- , west__showOverflowOnHover: true-- // enable state management- , stateManagement__enabled: false // automatic cookie load & save enabled by default-- , showDebugMessages: true // log and/or display messages from debugging & testing code- }-- );-- var westLayout = $('div.ui-layout-west').layout({- minSize: 50 // ALL panes- , center__paneSelector: ".west-center"- , south__paneSelector: ".west-south"- , south__size: .5- , south__spacing_open: 3- });-- var centerLayout = $('div.ui-layout-center').layout({- name: "middle"- , north__paneSelector: ".middle-north"- , center__paneSelector: ".middle-center"- , south__paneSelector: ".middle-south"- , minSize: 0 // ALL panes- , center__minSize: 300- , north__size: 32- , north__resizable: false- , north__spacing_open: 0- , south__spacing_open: 0- , south__size: 1- });-- // File Viewer / Editor- var eastLayout = $('div.ui-layout-east').layout({- minSize: 30 // ALL panes- , north__paneSelector: ".east-north"- , center__paneSelector: ".east-center"- , south__paneSelector: ".east-south"- , north__size: 80- , north__resizable: false- , north__spacing_open: 0- , south__size: 25- , south__spacing_open: 0- });-- var dirNavigationLayout = $('#directoryNavigator').layout({- minSize: 30 // ALL panes- , north__paneSelector: "#directoryNavigatorNorth"- , center__paneSelector: "#dirTree"- , north__size: 30- , north__resizable: false- , north__spacing_open: 0- });-- // Hide Document Viewer by default- layoutContainer.toggle("east");-});--/*** Sortingswitch (UIAPI.fileSortCriteria) {diff --git a/data/js/settings.api.js b/data/js/settings.api.jsindex 74ab0801b..82b799f01 100644--- a/data/js/settings.api.js+++ b/data/js/settings.api.js@@ -44,8 +44,6 @@ TSSETTINGS.DefaultSettings = {"appVersion": "@VERSION@beta","appBuild": "@VERSION@.@BUILD@","settingsVersion": 1,- "supportedFileTypeViewing": ['txt','html','htm','md','jpeg','jpg','png','gif','mht','mhtml','pdf','maff'],- "supportedFileTypeEditing": ['txt','html','htm','md'],"supportedFileTypeThumnailing": ['jpg','jpeg','png','gif'],"newTextFileContent": "Text file created with tagspaces(@VERSION@.@BUILD@)...","newHTMLFileContent": "<html><head><meta http-equiv='content-type' content='text/html; charset=utf-8'><title>Tagspaces File</title></head><body>Tag created with tagspaces(@VERSION@.@BUILD@)...</body></html>",@@ -54,9 +52,40 @@ TSSETTINGS.DefaultSettings = {"lastOpenedTSID": 0,"lastOpenedDirectory": "","tagspacesList": [- {name:'Sampe windows place', path:'Z:\\' },- {name:'Sample unix place', path:'/media/' },+ {+ "name":'Sampe windows place',+ "path":'Z:\\'+ },+ {+ "name":'Sample unix place',+ "path":'/media/'+ },],+ "extensions": [+ {+ "id": "editorText", // ID should be equal to the directory name where the ext. is located+ "enabled": true,+ },+ {+ "id": "tsTodo", // ID should be equal to the directory name where the ext. is located+ "enabled": false,+ },+ ],+ "supportedFileTypes": [+ { "type": "jpg", "viewer": "viewerImage", "editor": false },+ { "type": "jpeg", "viewer": "viewerImage", "editor": false },+ { "type": "gif", "viewer": "viewerImage", "editor": false },+ { "type": "png", "viewer": "viewerImage", "editor": false },+ { "type": "pdf", "viewer": "viewerBrowser", "editor": false },+ { "type": "html", "viewer": "viewerBrowser", "editor": false },+ { "type": "htm", "viewer": "viewerBrowser", "editor": false },+ { "type": "mht", "viewer": "viewerBrowser", "editor": false },+ { "type": "mhtml", "viewer": "viewerBrowser", "editor": false },+ { "type": "maff", "viewer": "viewerBrowser", "editor": false },+ { "type": "txt", "viewer": "viewerBrowser", "editor": "editorText" },+ { "type": "js", "viewer": "viewerBrowser", "editor": "editorText" },+ { "type": "md", "viewer": "viewerMD", "editor": "editorText" },+ ],"tagGroups": [{"title":"common",@@ -104,16 +133,26 @@ TSSETTINGS.getNewMDFileContent = function() {return TSSETTINGS.Settings["newMDFileContent"];}-TSSETTINGS.getSupportedFileExt4Thumbnaling = function() {- return TSSETTINGS.Settings["supportedFileTypeViewing"];+TSSETTINGS.getSupportedFileExt4Thumbnailing = function() {+ return TSSETTINGS.Settings["supportedFileTypeThumnailing"];}-TSSETTINGS.getSupportedFileExt4Viewing = function() {- return TSSETTINGS.Settings["supportedFileTypeViewing"];+TSSETTINGS.getFileTypeEditor = function(fileTypeExt) {+ for(var i=0; i < TSSETTINGS.Settings["supportedFileTypes"].length; i++) {+ if(TSSETTINGS.Settings["supportedFileTypes"][i].type == fileTypeExt) {+ return TSSETTINGS.Settings["supportedFileTypes"][i].editor;+ }+ }+ return false;}-TSSETTINGS.getSupportedFileExt4Thumbnailing = function() {- return TSSETTINGS.Settings["supportedFileTypeThumnailing"];+TSSETTINGS.getFileTypeViewer = function(fileTypeExt) {+ for(var i=0; i < TSSETTINGS.Settings["supportedFileTypes"].length; i++) {+ if(TSSETTINGS.Settings["supportedFileTypes"][i].type == fileTypeExt) {+ return TSSETTINGS.Settings["supportedFileTypes"][i].viewer;+ }+ }+ return false;}TSSETTINGS.findTag = function(tagName, tagGroupKey) {diff --git a/data/js/settings.ui.js b/data/js/settings.ui.jsindex e8bf9b1a2..d14768c70 100644--- a/data/js/settings.ui.js+++ b/data/js/settings.ui.js@@ -44,7 +44,7 @@ SettingsUI.initDialogs = function() {modal: true,buttons: {"Back": function() {- $("#aboutIframe").attr("src","aboutbox.html");+ $("#aboutIframe").attr("src","about.html");},"Close": function() {$( this ).dialog( "close" );diff --git a/data/js/tags.ui.js b/data/js/tags.ui.jsindex 5010cbfef..53150e522 100644--- a/data/js/tags.ui.js+++ b/data/js/tags.ui.js@@ -1,11 +1,12 @@/* Copyright (c) 2012 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. */-console.debug("Loading TagsUI...");+define(function(require, exports, module) {+"use strict";-var TagsUI = (typeof TagsUI == 'object' && TagsUI != null) ? TagsUI : {};+console.debug("Loading TagsUI...");-TagsUI.initContextMenus = function() {+exports.initContextMenus = function() {// $( "#tagSuggestionsMenu" ).menu({// select: function( event, ui ) {@@ -35,7 +36,6 @@ TagsUI.initContextMenus = function() {case "removeTag":$( this ).hide();TSAPI.removeTag(UIAPI.selectedTag);- //UIAPI.openFile(UIAPI.selectedFiles[0]);break;case "closeMenu":$( this).hide();@@ -101,7 +101,7 @@ TagsUI.initContextMenus = function() {});}-TagsUI.initDialogs = function() {+exports.initDialogs = function() {var newDirName = $( "#dirname" );@@ -298,14 +298,14 @@ TagsUI.initDialogs = function() {});}-TagsUI.updateTagGroups = function() {+exports.updateTagGroups = function() {console.debug("Updating TagGroups tree..."); //+JSON.stringify(TSSETTINGS.Settings["tagGroups"]));$("#tagGroups").dynatree("getRoot").removeChildren();$("#tagGroups").dynatree("getRoot").addChild(TSSETTINGS.Settings["tagGroups"]);}-TagsUI.initTagTree = function() {+exports.initTagTree = function() {// Init the tag tree / taggroups module$("#tagGroups").dynatree({clickFolderMode: 1,@@ -347,7 +347,7 @@ TagsUI.initTagTree = function() {});}-TagsUI.openTagMenu = function(tagButton, tag, fileName) {+exports.openTagMenu = function(tagButton, tag, fileName) {BasicViewsUI.clearSelectedFiles();$(tagButton).parent().parent().toggleClass("selectedRow");@@ -366,4 +366,6 @@ TagsUI.openTagMenu = function(tagButton, tag, fileName) {menu.hide();});return false;*/-}\ No newline at end of file+}++});\ No newline at end of filediff --git a/data/loader.js b/data/loader.jsnew file mode 100644index 000000000..afdcb5fb4--- /dev/null+++ b/data/loader.js@@ -0,0 +1,68 @@+/* Copyright (c) 2012 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. */+console.debug("Loading Loader...");++// Init layout+require(["js/layout.ui"]);++// Setting up the communication between the extension and tagspace app+if( $.browser.mozilla) {+ require(["js/messaging.mozilla"]);+}++FileViewer = undefined;+TagsUI = undefined;+//BasicViewsUI = undefined;++jQuery(function($) {+ require([+ "js/fileviewer.ui",+ "js/tags.ui",+ "js/basicviews.ui.js",+ "js/misc.ui.js",+ "js/ioapi.chrome.js",+ "js/ioapi.mozilla.js",+ "js/settings.api.js",+ "js/tagspace.api.js",+ "js/directories.ui.js",+ "js/settings.ui.js"+ ],+ function(viewer,tags) {+ FileViewer = viewer;++ TagsUI = tags;+ TagsUI.initContextMenus();+ TagsUI.initDialogs();+ TagsUI.initTagTree();++ //BasicViewsUI = basicviews;+ BasicViewsUI.initContextMenus();+ BasicViewsUI.initFileTagViews();+ BasicViewsUI.initDialogs();+ BasicViewsUI.initButtons();+ BasicViewsUI.initThumbView();++ DirectoriesUI.initDialogs();+ DirectoriesUI.initButtons();+ DirectoriesUI.initDirectoryTree();++ SettingsUI.initButtons();+ SettingsUI.initDialogs();+ SettingsUI.initJSONEditor();++ TSSETTINGS.loadSettingsLocalStorage();++ // By empty local storage and a mozilla browser, trying to load from mozilla preferences+ if(TSSETTINGS.Settings == undefined && $.browser.mozilla) {+ setTimeout(IOAPI.loadSettings, 1000); // executes initUI and updateSettingMozillaPreferences by success+ console.debug("Loading setting with from mozilla pref execured with delay...");+ }++ if(TSSETTINGS.Settings == undefined) {+ TSSETTINGS.Settings = TSSETTINGS.DefaultSettings;+ }++ UIAPI.initUI();+ });+});\ No newline at end of file