TagSpaces is an offline, open source, document manager with tagging support
A new default perspective added with the aim of replacing basic, search and thumb perspectives
uggrock482d354fb30a
diff --git a/data/ext/perspectiveDefault/extension.js b/data/ext/perspectiveDefault/extension.jsnew file mode 100644index 000000000..72b6aa0f6--- /dev/null+++ b/data/ext/perspectiveDefault/extension.js@@ -0,0 +1,227 @@+/* 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";++ var extensionTitle = "Default"+ var extensionID = "perspectiveDefault"; // ID should be equal to the directory name where the ext. is located+ var extensionType = "view";+ var extensionIcon = "ui-icon-tag";+ var extensionVersion = "1.0";+ var extensionManifestVersion = 1;+ var extensionLicense = "AGPL";++ console.debug("Loading "+extensionID);++ var TSCORE = require("tscore");++ var extensionDirectory = TSCORE.Config.getExtensionPath()+"/"+extensionID;+ var UI = undefined;++ function init() {+ console.debug("Initializing perspective "+extensionID);++ // TODO use css require extension for loading 'css!datatablescss'+ require([+ extensionDirectory+'/perspectiveUI',+ 'datatables'+ ], function(extUI) {+ UI = new extUI.ExtUI(extensionID);+ UI.buildUI();+ UI.initTable();+ UI.initFileFilter();+ UI.initButtons();+ });+ }++ var load = function () {+ console.debug("Loading perspective "+extensionID);++ $('#'+extensionID+"FileTable_wrapper").hide();++ updateIndexData(TSCORE.fileList);++ $( "#"+extensionID+"ReIndexButton" ).button( "enable" );+ TSCORE.hideLoadingAnimation();+ }++ var enhanceIndexData = function(index) {+ console.debug("Enhancing directory index...");+ var enhancedIndex = [];+ var tags = undefined;+ var ext = undefined;+ var title = undefined;+ var fileSize = undefined;+ var fileLMDT = undefined;+ var path = undefined;+ var filename = undefined;+ for (var i=0; i < index.length; i++) {+ if (index[i].type == "file"){+ // Considering Unix HiddenEntries (. in the beginning of the filename)+ if (TSCORE.Config.Settings["showUnixHiddenEntries"] ||+ (!TSCORE.Config.Settings["showUnixHiddenEntries"] && (index[i].name.indexOf(".") != 0))) {+ filename = index[i].name;+ path = index[i].path;+ tags = TSCORE.TagUtils.extractTags(path);+ title = TSCORE.TagUtils.extractTitle(path);+ ext = TSCORE.TagUtils.extractFileExtension(path)+ fileSize = index[i].size;+ fileLMDT = index[i].lmdt;++ if(fileSize == undefined) fileSize = "";+ if(fileLMDT == undefined) fileLMDT = "";+ var entry = [title,tags,fileSize,fileLMDT,path,filename,ext];+ enhancedIndex.push(entry);+ }+ }+ }+ return enhancedIndex;+ }++ var updateIndexData = function (index) {+ console.debug("Updating index data.");++ // Clearing the old data+ UI.fileTable.fnClearTable();++ UI.fileTable.fnAddData( enhanceIndexData(index) );+ //UI.fileTable.fnAddData(index);+++ UI.fileTable.$('tr')+ .droppable({+ accept: ".tagButton",+ hoverClass: "activeRow",+ drop: function( event, ui ) {+ var tagName = ui.draggable.attr("tag");+ var targetFilePath = UI.fileTable.fnGetData( this )[4];+ console.log("Tagging file: "+tagName+" to "+targetFilePath);++ $(this).toggleClass("ui-selected");++ clearSelectedFiles();+ TSCORE.selectedFiles.push(targetFilePath);+ UI.handleElementActivation();++ TSCORE.TagUtils.addTag(TSCORE.selectedFiles, [tagName]);+ }+ })+ .dblclick( function() {+ console.debug("Opening file...");+ var rowData = UI.fileTable.fnGetData( this );++ TSCORE.FileOpener.openFile(rowData[4]); // 4 is the filePath+ } );++ UI.fileTable.$('.fileTitleButton')+ .draggable({+ cancel:false,+ appendTo: "body",+ helper: "clone",+ revert: true,+ start: function() {+ selectFile(this, $(this).attr("filepath"));+ }+ })+ .click( function() {+ selectFile(this, $(this).attr("filepath"));+ } )+ .dropdown( 'attach' , '#fileMenu' );++ UI.fileTable.$('.extTagButton')+ .click( function() {+ selectFile(this, $(this).attr("fileName"));+ TSCORE.openTagMenu(this, $(this).attr("tag"), $(this).attr("filepath"));+ } )+ .dropdown( 'attach' , '#extensionMenu' );++ UI.fileTable.$('.tagButton')+ .click( function() {+ selectFile(this, $(this).attr("fileName"));+ TSCORE.openTagMenu(this, $(this).attr("tag"), $(this).attr("filepath"));+ } )+ .dropdown( 'attach' , '#tagMenu' );++ $('#'+extensionID+"FileTable_wrapper").show();++ $( "#"+extensionID+"ReIndexButton" ).button( "enable" );++ TSCORE.hideLoadingAnimation();+ }++ var setFileFilter = function (filter) {+ $( "#"+extensionID+"FilterBox").val(filter);+ UI.fileTable.fnFilter(filter);+ }++ var clearSelectedFiles = function() {+ TSCORE.selectedFiles = [];+ $('#'+extensionID+'FileTable tbody tr').each(function(){+ $(this).removeClass('ui-selected');+ });+ }++ var getNextFile = function (filePath) {+ var nextFilePath = undefined;+ var data = UI.fileTable._('tr', {"filter":"applied"});+ data.forEach(function(entry, index) {+ if(entry[4] == filePath) {+ var nextIndex = index+1;+ if(nextIndex < data.length) {+ nextFilePath = data[nextIndex][4];+ } else {+ nextFilePath = data[0][4];+ }+ }+ console.log("Path: "+entry[4]);+ });+ console.debug("Next file: "+nextFilePath);+ return nextFilePath;+ }++ var getPrevFile = function (filePath) {+ var prevFilePath = undefined;+ var data = UI.fileTable._('tr', {"filter":"applied"});+ data.forEach(function(entry, index) {+ if(entry[4] == filePath) {+ var prevIndex = index-1;+ if(prevIndex >= 0) {+ prevFilePath = data[prevIndex][4];+ } else {+ prevFilePath = data[data.length-1][4];+ }+ }+ console.log("Path: "+entry[4]);+ });+ console.debug("Prev file: "+prevFilePath);+ return prevFilePath;+ }++ var selectFile = function(tagButton, filePath) {+ clearSelectedFiles();+ $(tagButton).parent().parent().toggleClass("ui-selected");+ TSCORE.selectedFiles.push(filePath);+ UI.handleElementActivation();+ }++ // Vars+ exports.Title = extensionTitle;+ exports.ID = extensionID;+ exports.Type = extensionType;+ exports.Icon = extensionIcon;+ exports.Version = extensionVersion;+ exports.ManifestVersion = extensionManifestVersion;+ exports.License = extensionLicense;++ // Methods+ exports.init = init;+ exports.load = load;+ exports.updateIndexData = updateIndexData;+ exports.setFileFilter = setFileFilter;+ exports.clearSelectedFiles = clearSelectedFiles;+ exports.getNextFile = getNextFile;+ exports.getPrevFile = getPrevFile;++});\ No newline at end of filediff --git a/data/ext/perspectiveDefault/perspectiveUI.js b/data/ext/perspectiveDefault/perspectiveUI.jsnew file mode 100644index 000000000..41cf5dbca--- /dev/null+++ b/data/ext/perspectiveDefault/perspectiveUI.js@@ -0,0 +1,261 @@+/* 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";++console.debug("Loading UI for perspectiveDefault");++ var TSCORE = require("tscore");++ function ExtUI(extID) {+ this.extensionID = extID;+ this.viewContainer = $("#"+this.extensionID+"Container").empty();+ this.viewToolbar = $("#"+this.extensionID+"Toolbar").empty();+ this.viewFooter = $("#"+this.extensionID+"Footer").empty();+ }++ ExtUI.prototype.buildUI = function() {+ console.debug("Init UI module");++ this.viewToolbar.append($("<button>", {+ text: "Subdirs",+ disabled: true,+ title: "Include subdirectories",+ id: this.extensionID+"ReIndexButton",+ }));++ this.viewToolbar.append($("<button>", {+ text: "Add Tag",+ disabled: true,+ title: "TagSelectedFiles",+ id: this.extensionID+"TagButton",+ }));++ this.viewToolbar.append($("<input>", {+ type: "checkbox",+ disabled: false,+ title: "TagSelectedFiles",+ id: this.extensionID+"ShowTmbButton",+ }));++ this.viewToolbar.append($("<label>", {+ for: this.extensionID+"ShowTmbButton",+ text: "Thumbnails",+ title: "Some file thumbnails",+ }));++ this.viewToolbar.append($("<input>", {+ type: "checkbox",+ disabled: false,+ title: "TagSelectedFiles",+ id: this.extensionID+"ShowFileDetailsButton",+ }));++ this.viewToolbar.append($("<label>", {+ for: this.extensionID+"ShowFileDetailsButton",+ text: "File Details",+ title: "Some file details",+ }));++ this.viewToolbar.append($("<input>", {+ type: "checkbox",+ disabled: false,+ title: "TagSelectedFiles",+ id: this.extensionID+"ShowTagsButton",+ }));++ this.viewToolbar.append($("<label>", {+ for: this.extensionID+"ShowTagsButton",+ text: "Tags",+ title: "Some file details",+ }));++ this.viewToolbar.append($("<span>", {+ style: "float: right; margin: 0px; padding: 0px;",+ }).append($("<input>", {+ type: "filter",+ // autocomplete: "off", // Error: cannot call methods on autocomplete prior to initialization; attempted to call method 'off'+ title: "This filter applies to current directory without subdirectories.",+ id: this.extensionID+"FilterBox",+ })));++ this.viewContainer.append($("<table>", {+ cellpadding: "0",+ cellspacing: "0",+ border: "0",+ style: "width: 100%",+ id: this.extensionID+"FileTable",+ }));++ }++ ExtUI.prototype.initTable = function() {+ // Column order in json [title(0),tags(1),fileSize(2),fileLMDT(3),path(4),filename(5),extension(6)];+ this.fileTable = $('#'+this.extensionID+"FileTable").dataTable( {+ "bJQueryUI": false,+ "bPaginate": false,+ "bLengthChange": false,+ "bFilter": true,+ "bSort": true,+ "bInfo": false,+ "bAutoWidth": false,+ "aoColumns": [+ { "sTitle": "Title", "sClass": "right" },+ { "sTitle": "Tags" },+ { "sTitle": "Size(bytes)" },+ { "sTitle": "Date Modified" },+ { "sTitle": "Path" },+ ],+ "aoColumnDefs": [+ { // Title column+ "mRender": function ( data, type, row ) { return TSCORE.buttonizeTitle(data,row[0],row[4]) },+ "aTargets": [ 0 ]+ },+ { // Tags column+ "mRender": function ( data, type, row ) { return TSCORE.generateTagButtons(data,row[6],row[5],row[4]) },+ "aTargets": [ 1 ]+ },+ { // Filesize column+ "mRender": function ( data, type, row ) { return TSCORE.TagUtils.formatFileSize(data) },+ "aTargets": [ 2 ]+ },+ { // Last changed date column+ "mRender": function ( data, type, row ) { return TSCORE.TagUtils.formatDateTime(data, true) },+ "aTargets": [ 3 ]+ },+ // { "bVisible": false, "aTargets": [ 5 ] },+ // { "bSearchable": false, "aTargets": [ 0 ] },+ // { "sClass": "center", "aTargets": [ 0 ] }+ ]+ } );++ // Disable alerts in datatable+ this.fileTable.dataTableExt.sErrMode = 'throw';++ var myTable = this.fileTable;+ var myHandleActivateion = this.handleElementActivation;++ // Makes the body of the fileTable selectable+ $("tbody", $(myTable)).selectable({+ filter: 'tr',+ start: function() {+ console.debug("Start selecting");+ TSCORE.hideAllDropDownMenus();+ TSCORE.ViewManager.clearSelectedFiles();+ },+ stop: function(){+ $(".ui-selected", this).each(function(){+ var rowData = myTable.fnGetData( this );+ // Add the filename which is located in the first column to the list of selected filenames+ TSCORE.selectedFiles.push(rowData[4]);+ myHandleActivateion();+ });+ console.debug("Selected files: "+TSCORE.selectedFiles);+ }+ })+ }++ ExtUI.prototype.toggleThumbnails = function() {+ console.debug("thumbs toggled");+ }++ ExtUI.prototype.initButtons = function() {+ var self = this;+ // Initialize file buttons+ $( "#"+this.extensionID+"ReIndexButton" ).button({+ text: true,+ icons: {+ primary: "ui-icon-refresh"+ }+ })+ .click(function() {+ $( "#"+self.extensionID+"ReIndexButton" ).button( "disable" );+ TSCORE.IO.createDirectoryIndex(TSCORE.currentPath);+ });++ $( "#"+this.extensionID+"TagButton" ).button({+ text: true,+ icons: {+ primary: "ui-icon-tag"+ }+ })+ .click(function() {+ TSCORE.showAddTagsDialog();+ });++ $( "#"+this.extensionID+"ShowTmbButton" ).button({+ text: true,+ icons: {+ primary: "ui-icon-image"+ }+ })+ .click(function() {+ self.toggleThumbnails();+ });++ $( "#"+this.extensionID+"ShowFileDetailsButton" ).button({+ text: true,+ icons: {+ primary: "ui-icon-contact"+ }+ })+ .click(function() {+ // self.toggleThumbnails();+ });++ $( "#"+this.extensionID+"ShowTagsButton" ).button({+ text: true,+ icons: {+ primary: "ui-icon-tag"+ }+ })+ .click(function() {+ // self.toggleThumbnails();+ });++ $( "#clearFilterButton" ).button({+ text: false,+ disabled: false,+ icons: {+ primary: "ui-icon-close"+ }+ })+ .click(function() {+ $( "#filterBox" ).val( "" );+ self.fileTable.fnFilter( "" );+ });+ }++ ExtUI.prototype.initFileFilter = function() {+ var self = this;++ // Filter functionality+ $("#"+this.extensionID+"FilterBox").keyup(function() {+ self.fileTable.fnFilter(this.value);+ console.debug("Filter to value: "+this.value);+ });++ $('#'+this.extensionID+"FilterBox").wrap('<span id="resetFilter" />').after($('<span/>').click(function() {+ $(this).prev('input').val('').focus();+ self.fileTable.fnFilter( "" );+ }));+ }++ ExtUI.prototype.handleElementActivation = function() {+ console.debug("Entering element activation handler...");++ var tabButton = $( "#"+this.extensionID+"TagButton" );++ if (TSCORE.selectedFiles.length > 1) {+ tabButton.button( "enable" );+ } else if (TSCORE.selectedFiles.length == 1) {+ tabButton.button( "enable" );+ } else {+ tabButton.button( "disable" );+ }+ }++ exports.ExtUI = ExtUI;+});\ No newline at end of file