Skip to content

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

moving tag import and tag group create functionalities out from the context menu

uggrock2818e949c42e
diff --git a/data/index.html b/data/index.html
index 77a5851fc..fb056d998 100644
--- a/data/index.html
+++ b/data/index.html
@@ -1002,12 +1002,12 @@
<li class="divider"></li>
<li><a id="tagGroupMenuCreateNewTag" data-i18n="[title]ns.common:addTagsTooltip">
<i class="fa fa-tag fa-lg fa-fw"></i>&nbsp;<span data-i18n="ns.common:addTags"></span></a></li>
- <li><a id="tagGroupMenuImportTags" data-i18n="[title]ns.common:importTagsTooltip">
+ <!--li><a id="tagGroupMenuImportTags" data-i18n="[title]ns.common:importTagsTooltip">
<span class="fa-stack fa-fw">
<i class="fa fa-tag fa-stack-2x fa-fw"></i><i class="fa fa-arrow-right fa-stack-1x fa-inverse"></i>
- </span>&nbsp;<span data-i18n="ns.common:importTags"></span></a></li>
- <li><a id="tagGroupMenuCreateTagGroup" data-i18n="[title]ns.common:createTagGroupTooltip">
- <i class="fa fa-tags fa-lg fa-fw"></i>&nbsp;<span data-i18n="ns.common:createTagGroup"></span></a></li>
+ </span>&nbsp;<span data-i18n="ns.common:importTags"></span></a></li-->
+ <!--li><a id="tagGroupMenuCreateTagGroup" data-i18n="[title]ns.common:createTagGroupTooltip">
+ <i class="fa fa-tags fa-lg fa-fw"></i>&nbsp;<span data-i18n="ns.common:createTagGroup"></span></a></li-->
<li><a id="tagGroupMenuMoveUp" data-i18n="[title]ns.common:moveTagGroupUpTooltip">
<i class="fa fa-arrow-up fa-lg fa-fw"></i>&nbsp;<span data-i18n="ns.common:moveTagGroupUp"></span></a></li>
<li><a id="tagGroupMenuMoveDown" data-i18n="[title]ns.common:moveTagGroupDownTooltip">
diff --git a/data/js/tags.ui.js b/data/js/tags.ui.js
index c7f55e99f..bfe94822b 100644
--- a/data/js/tags.ui.js
+++ b/data/js/tags.ui.js
@@ -56,89 +56,82 @@ define(function(require, exports, module) {
function initUI() {
$('#extMenuAddTagAsFilter').click(function() {});
+
// Context menu for the tags in the file table and the file viewer
$('#tagMenuAddTagAsFilter').click(function() {
TSCORE.searchForTag(TSCORE.selectedTag);
});
+
$('#tagMenuEditTag').click(function() {
TSCORE.showTagEditDialog();
});
+
$('#tagMenuRemoveTag').click(function() {
TSCORE.TagUtils.removeTag(TSCORE.selectedFiles[0], TSCORE.selectedTag);
});
+
$('#tagMenuMoveTagFirst').click(function() {
TSCORE.TagUtils.moveTagLocation(TSCORE.selectedFiles[0], TSCORE.selectedTag, 'first');
});
+
$('#tagMenuMoveTagRight').click(function() {
TSCORE.TagUtils.moveTagLocation(TSCORE.selectedFiles[0], TSCORE.selectedTag, 'next');
});
+
$('#tagMenuMoveTagLeft').click(function() {
TSCORE.TagUtils.moveTagLocation(TSCORE.selectedFiles[0], TSCORE.selectedTag, 'prev');
});
+
// Context menu for the tags in the tag tree
$('#tagTreeMenuAddTagToFile').click(function() {
TSCORE.TagUtils.addTag(TSCORE.Utils.getUniqueSelectedFiles(), [TSCORE.selectedTag]);
});
+
$('#tagTreeMenuAddTagAsFilter').click(function() {
TSCORE.searchForTag(TSCORE.selectedTag);
});
+
$('#tagTreeMenuEditTag').click(function() {
TSCORE.showTagEditInTreeDialog();
});
+
$('#tagTreeMenuDeleteTag').click(function() {
TSCORE.showConfirmDialog('Delete Tag', 'Do you want to delete this tag from the taggroup?', function() {
TSCORE.Config.deleteTag(TSCORE.selectedTagData);
generateTagGroups();
});
});
+
// Context menu for the tags groups
$('#tagGroupMenuCreateNewTag').click(function() {
TSCORE.showDialogTagCreate();
});
- $('#tagGroupMenuImportTags').click(function() {
- //var addFileInputName;
- console.log("tagGroupMenuImportTags");
- $('#jsonImportFileInput').click();
- $('#jsonImportFileInput').on('change', function(selection) {
-
- var file = selection.currentTarget.files[0];
- //addFileInputName = decodeURIComponent(file.name);
- var reader = new FileReader();
- reader.onload = function() {
- try {
- var jsonObj = JSON.parse(reader.result);
- if ($.isArray(jsonObj.tagGroups)) {
- showImportTagsDialog(jsonObj.tagGroups);
- } else {
- TSCORE.showAlertDialog($.i18n.t("ns.dialogs:invalidImportFile"));
- }
- } catch (e) {
- console.log(e);
- TSCORE.showAlertDialog($.i18n.t("ns.dialogs:invalidImportFile"));
- }
- };
- reader.readAsText(file);
- });
- });
+ $('#tagGroupMenuImportTags').on('click', importTagGroups);
+
$('#tagGroupMenuCreateTagGroup').click(function() {
TSCORE.showDialogTagGroupCreate();
});
+
$('#tagGroupSort').click(function() {
TSCORE.Config.sortTagGroup(TSCORE.selectedTagData);
generateTagGroups();
});
+
$('#tagGroupMenuMoveUp').click(function() {
TSCORE.Config.moveTagGroup(TSCORE.selectedTagData, 'up');
generateTagGroups();
});
+
$('#tagGroupMenuMoveDown').click(function() {
TSCORE.Config.moveTagGroup(TSCORE.selectedTagData, 'down');
generateTagGroups();
});
+
$('#tagGroupMenuEdit').click(function() {
TSCORE.showDialogEditTagGroup();
});
+
$('#tagGroupMenuDelete').click(function() {
TSCORE.showConfirmDialog($.i18n.t('ns.dialogs:deleteTagGroupTitleConfirm'), $.i18n.t('ns.dialogs:deleteTagGroupContentConfirm', {
tagGroup: TSCORE.selectedTagData.title
@@ -147,25 +140,30 @@ define(function(require, exports, module) {
generateTagGroups();
});
});
+
// Dialogs
$('#editTagInTreeButton').click(function() {
TSCORE.Config.editTag(TSCORE.selectedTagData, $('#tagInTreeName').val(), $('#tagColor').val(), $('#tagTextColor').val(), $('#tagInTreeKeyBinding').val());
generateTagGroups();
TSCORE.PerspectiveManager.refreshFileListContainer();
});
+
$('#cleanTagsButton').click(function() {
TSCORE.showConfirmDialog($.i18n.t('ns.dialogs:cleanFilesTitleConfirm'), $.i18n.t('ns.dialogs:cleanFilesContentConfirm'), function() {
TSCORE.TagUtils.cleanFilesFromTags(TSCORE.Utils.getUniqueSelectedFiles());
});
});
+
$('#addTagsButton').click(function() {
var tags = $('#tags').val().split(',');
TSCORE.TagUtils.addTag(TSCORE.Utils.getUniqueSelectedFiles(), tags);
});
+
$('#removeTagsButton').click(function() {
var tags = $('#tags').val().split(',');
TSCORE.TagUtils.removeTags(TSCORE.Utils.getUniqueSelectedFiles(), tags);
});
+
$('#createTagButton').click(function() {
var tags = $('#newTagTitle').val().split(',');
tags.forEach(function(value) {
@@ -173,13 +171,39 @@ define(function(require, exports, module) {
});
generateTagGroups();
});
+
$('#createTagGroupButton').on("click", createTagGroup);
+
$('#editTagGroupButton').click(function() {
TSCORE.Config.editTagGroup(TSCORE.selectedTagData, $('#tagGroupName').val());
generateTagGroups();
});
}
+ function importTagGroups() {
+ console.log("tagGroupMenuImportTags");
+ $('#jsonImportFileInput').click();
+ $('#jsonImportFileInput').on('change', function(selection) {
+ var file = selection.currentTarget.files[0];
+ //addFileInputName = decodeURIComponent(file.name);
+ var reader = new FileReader();
+ reader.onload = function() {
+ try {
+ var jsonObj = JSON.parse(reader.result);
+ if ($.isArray(jsonObj.tagGroups)) {
+ showImportTagsDialog(jsonObj.tagGroups);
+ } else {
+ TSCORE.showAlertDialog($.i18n.t("ns.dialogs:invalidImportFile"));
+ }
+ } catch (e) {
+ console.log(e);
+ TSCORE.showAlertDialog($.i18n.t("ns.dialogs:invalidImportFile"));
+ }
+ };
+ reader.readAsText(file);
+ });
+ }
+
function createTagGroup() {
TSCORE.Config.createTagGroup(TSCORE.selectedTagData, $('#newTagGroupName').val());
generateTagGroups();
@@ -190,18 +214,7 @@ define(function(require, exports, module) {
var $tagGroupsContent = $('#tagGroupsContent');
$tagGroupsContent.children().remove();
$tagGroupsContent.addClass('accordion');
- // Show TagGroup create button if no taggroup exist
- if (TSCORE.Config.Settings.tagGroups.length < 1) {
- $tagGroupsContent.append($('<button>', {
- 'class': 'btn btn-default',
- 'style': 'margin-top: 5px; margin-left: 7px;',
- 'text': $.i18n.t('ns.common:createTagGroup'),
- 'data-i18n': 'ns.common:createTagGroup'
- }).click(function() {
- TSCORE.showDialogTagGroupCreate();
- }));
- return true; // quit the taggroup generation
- }
+
var tagGroups = TSCORE.Config.Settings.tagGroups;
var tag;
// Cleaning Special TagGroups
@@ -212,6 +225,7 @@ define(function(require, exports, module) {
k--;
}
}
+
// Adding tags to the calculated tag group
if (TSCORE.Config.getCalculateTags() && TSCORE.calculatedTags !== null) {
tagGroups.push({
@@ -221,6 +235,7 @@ define(function(require, exports, module) {
'children': TSCORE.calculatedTags
});
}
+
// Adding tag groups from the current location
if (TSCORE.Config.getLoadLocationMeta() && TSCORE.locationTags !== null) {
TSCORE.locationTags.forEach(function(data) {
@@ -232,6 +247,7 @@ define(function(require, exports, module) {
});
});
}
+
// ehnances the taggroups with addition styling information
for (var i = 0; i < tagGroups.length; i++) {
for (var j = 0; j < tagGroups[i].children.length; j++) {
@@ -263,17 +279,6 @@ define(function(require, exports, module) {
'tagGroupOperations': $.i18n.t('ns.common:tagGroupOperations')
}));
- $tagGroupsContent.find('.tagGroupTitle').each(function() {
- $(this).on('click', function() {
- var areaId = $(this).attr('data-target');
- if (areaId) {
- var index = areaId.substring(areaId.length - 1);
- tagGroups[index].collapse = $(areaId).is(':visible');
- TSCORE.Config.saveSettings();
- }
- });
- });
-
$tagGroupsContent.find('.tagGroupIcon').each(function() {
$(this).on('click', function() {
var areaId = $(this).attr('data-target');
@@ -303,8 +308,18 @@ define(function(require, exports, module) {
TSCORE.TagUtils.addTag(TSCORE.Utils.getUniqueSelectedFiles(), [TSCORE.selectedTag]);
});
});
+
$tagGroupsContent.find('.tagGroupTitle').each(function() {
- $(this).droppable({
+ $(this)
+ .on('click', function() {
+ var areaId = $(this).attr('data-target');
+ if (areaId) {
+ var index = areaId.substring(areaId.length - 1);
+ tagGroups[index].collapse = $(areaId).is(':visible');
+ TSCORE.Config.saveSettings();
+ }
+ })
+ .droppable({
accept: '.tagButton',
hoverClass: 'dirButtonActive',
drop: function(event, ui) {
@@ -325,6 +340,7 @@ define(function(require, exports, module) {
}
});
});
+
$tagGroupsContent.on('contextmenu click', '.tagGroupActions', function() {
TSCORE.hideAllDropDownMenus();
TSCORE.selectedTag = $(this).attr('tag');
@@ -333,6 +349,7 @@ define(function(require, exports, module) {
TSCORE.showContextMenu('#tagGroupMenu', $(this));
return false;
});
+
$tagGroupsContent.on('contextmenu click', '.tagButton', function() {
TSCORE.hideAllDropDownMenus();
TSCORE.selectedTagData = TSCORE.Config.getTagData($(this).attr('tag'), $(this).attr('parentKey'));
@@ -341,6 +358,20 @@ define(function(require, exports, module) {
TSCORE.showContextMenu('#tagTreeMenu', $(this));
return false;
});
+
+ $tagGroupsContent.append($('<button>', {
+ 'class': 'btn btn-link',
+ 'style': 'margin-top: 15px; margin-left: -8px; display: block',
+ 'text': $.i18n.t('ns.common:createTagGroup'),
+ 'data-i18n': 'ns.common:createTagGroup;[title]ns.common:createTagGroupTooltip'
+ }).on('click', TSCORE.showDialogTagGroupCreate));
+
+ $tagGroupsContent.append($('<button>', {
+ 'class': 'btn btn-link',
+ 'style': 'margin-top: 0px; display: block; margin-left: -8px;',
+ 'text': $.i18n.t('ns.common:importTags'),
+ 'data-i18n': 'ns.common:importTags;[title]ns.common:importTagsTooltip'
+ }).on('click', importTagGroups));
}
function generateTagValue(tagData) {