Example #1
0
    function generateTagGroups() {
        console.log("Generating TagGroups...");
        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",
                "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
        for(var k=0; k < tagGroups.length; k++) {
            if(tagGroups[k].key.indexOf(locationTagGroupKey) === 0 || tagGroups[k].key === calculatedTagGroupKey) {
                console.log("Deleting:"+tagGroups[k].key+" "+k);
                tagGroups.splice(k, 1);
                k--;
            }
        }

        // Adding tags to the calculated tag group
        if(TSCORE.Config.getCalculateTags() && TSCORE.calculatedTags !== null) {
            tagGroups.push({
                "title": $.i18n.t("ns.common:tagsFromCurrentFolder"),
                "key": calculatedTagGroupKey,
                "expanded": true,
                "children": TSCORE.calculatedTags
            });
        }

        // Adding tag groups from the current location
        if(TSCORE.Config.getLoadLocationMeta() && TSCORE.locationTags !== null) {
            TSCORE.locationTags.forEach(function(data) {
                tagGroups.push({
                    "title": data.title+" (imported)",
                    "key": locationTagGroupKey+TSCORE.TagUtils.formatDateTime4Tag(new Date(),true, true),
                    "expanded": true,
                    "children": data.children
                });
            });

        }

        // 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++) {
                tag = tagGroups[i].children[j];

                if(tag.description !== undefined) {
                    tag.titleUI = tag.description;
                } else {
                    tag.titleUI = tag.title;
                }

                tag.icon = "";
                if(tag.type === "smart"){
                    tag.icon = "fa fa-flask";
                }

                // Add keybinding to tags
                if(tag.keyBinding !== undefined && tag.keyBinding.length > 0) {
                    tag.icon = "fa fa-keyboard-o";
                    tag.titleUI = tag.titleUI + " [" +tag.keyBinding+ "]";
                    Mousetrap.unbind(tag.keyBinding);
                    Mousetrap.bind(
                        tag.keyBinding,
                        (function(innerTag) {
                            return function( e ) {
                                TSCORE.TagUtils.addTag(TSCORE.selectedFiles, [innerTag]);
                            };
                        })(tag.title)
                    );
                }
                tag.style = generateTagStyle(tag);
            }
        }

        $tagGroupsContent.html(tagGroupsTmpl({
             "tagGroups":           tagGroups,
             "toggleTagGroup":      $.i18n.t("ns.common:toggleTagGroup"),
             "tagGroupOperations":  $.i18n.t("ns.common:tagGroupOperations")
         }));

        $tagGroupsContent.find(".tagButton").each(function() {
            $(this).draggable({
                    "appendTo":   "body",
                    "helper":     "clone",
                    "revert":     'invalid',
                    "start":     function() {
                        console.log("Start dragging..........");
                        TSCORE.selectedTagData = TSCORE.Config.getTagData($(this).attr("tag"), $(this).attr("parentKey"));
                        TSCORE.selectedTag = generateTagValue(TSCORE.selectedTagData);
                        TSCORE.selectedTagData.parentKey = $(this).attr("parentKey");
                    }
                })
        });

        $tagGroupsContent.find(".tagGroupTitle").each(function() {
            $(this)
                .droppable({
                    accept: '.tagButton',
                    hoverClass: "dirButtonActive",
                    drop: function( event, ui ) {
                        //ui.draggable.detach();
                        var tagGroupData = TSCORE.Config.getTagData(ui.draggable.attr("tag"), ui.draggable.attr("parentKey"));
                        tagGroupData.parentKey = ui.draggable.attr("parentKey");
                        var targetTagGroupKey = $(this).attr("key");
                        console.log("Moving tag: "+tagGroupData.title+" to "+targetTagGroupKey);
                        TSCORE.Config.moveTag(tagGroupData, targetTagGroupKey);
                        generateTagGroups();
                        $(ui.helper).remove();
                    }
                })
        });

        $tagGroupsContent.on("contextmenu click", ".tagGroupActions", function () {
            TSCORE.hideAllDropDownMenus();
            TSCORE.selectedTag = $(this).attr("tag");
            TSCORE.selectedTagData = TSCORE.Config.getTagGroupData($(this).attr("key"));
            TSCORE.selectedTagData.parentKey = undefined;
            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"));
            TSCORE.selectedTag = generateTagValue(TSCORE.selectedTagData);
            TSCORE.selectedTagData.parentKey = $(this).attr("parentKey");
            TSCORE.showContextMenu("#tagTreeMenu", $(this));
            return false;
        });
    }
Example #2
0
  function generateTagGroups() {
    console.log('Generating TagGroups...');
    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
    for (var k = 0; k < tagGroups.length; k++) {
      if (tagGroups[k].key.indexOf(locationTagGroupKey) === 0 || tagGroups[k].key === calculatedTagGroupKey) {
        console.log('Deleting:' + tagGroups[k].key + ' ' + k);
        tagGroups.splice(k, 1);
        k--;
      }
    }
    // Adding tags to the calculated tag group
    if (TSCORE.Config.getCalculateTags() && TSCORE.calculatedTags !== null) {
      tagGroups.push({
        'title': $.i18n.t('ns.common:tagsFromCurrentFolder'),
        'key': calculatedTagGroupKey,
        'expanded': true,
        'children': TSCORE.calculatedTags
      });
    }
    // Adding tag groups from the current location
    if (TSCORE.Config.getLoadLocationMeta() && TSCORE.locationTags !== null) {
      TSCORE.locationTags.forEach(function(data) {
        tagGroups.push({
          'title': data.title + ' (imported)',
          'key': locationTagGroupKey + TSCORE.TagUtils.formatDateTime4Tag(new Date(), true, true),
          'expanded': true,
          'children': data.children
        });
      });
    }
    // 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++) {
        tag = tagGroups[i].children[j];
        if (!tag.description) {
          tag.description = tag.title;
        }
        tag.icon = '';
        if (tag.type === 'smart') {
          tag.icon = 'fa fa-flask';
        }
        // Add keybinding to tags
        if (tag.keyBinding && tag.keyBinding.length > 0) {
          tag.icon = 'fa fa-keyboard-o';
          tag.description = tag.title + ' [' + tag.keyBinding + ']';
          Mousetrap.unbind(tag.keyBinding);
          Mousetrap.bind(tag.keyBinding, function(innerTag) {
            return function(e) {
              TSCORE.TagUtils.addTag(TSCORE.Utils.getUniqueSelectedFiles(), [innerTag]);
            };
          }(tag.title)); // jshint ignore:line
        }
        tag.style = generateTagStyle(tag);
      }
    }
    $tagGroupsContent.html(tagGroupsTmpl({
      'tagGroups': tagGroups,
      'toggleTagGroup': $.i18n.t('ns.common:toggleTagGroup'),
      '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');
        if (areaId) {
          var index = areaId.substring(areaId.length - 1);
          tagGroups[index].collapse = $(areaId).is(':visible');
          TSCORE.Config.saveSettings();
        }
      });
    });

    $tagGroupsContent.find('.tagButton').each(function() {
      $(this).draggable({
        'appendTo': 'body',
        'helper': 'clone',
        'revert': 'invalid',
        'start': function() {
          console.log('Start dragging..........');
          TSCORE.selectedTagData = TSCORE.Config.getTagData($(this).attr('tag'), $(this).attr('parentKey'));
          TSCORE.selectedTag = generateTagValue(TSCORE.selectedTagData);
          TSCORE.selectedTagData.parentKey = $(this).attr('parentKey');
        }
      }).on('dblclick', function() {
        TSCORE.hideAllDropDownMenus();
        TSCORE.selectedTagData = TSCORE.Config.getTagData($(this).attr('tag'), $(this).attr('parentKey'));
        TSCORE.selectedTag = generateTagValue(TSCORE.selectedTagData);
        TSCORE.TagUtils.addTag(TSCORE.Utils.getUniqueSelectedFiles(), [TSCORE.selectedTag]);
      });
    });
    $tagGroupsContent.find('.tagGroupTitle').each(function() {
      $(this).droppable({
        accept: '.tagButton',
        hoverClass: 'dirButtonActive',
        drop: function(event, ui) {
          //ui.draggable.detach();
          var parentKeyAttr = ui.draggable.attr('parentKey');
          var tagAttr = ui.draggable.attr('tag');
          var targetTagGroupKey = $(this).attr('key');
          if (parentKeyAttr && (targetTagGroupKey !== parentKeyAttr)) { // move from taggroup
            var tagGroupData = TSCORE.Config.getTagData(tagAttr, parentKeyAttr);
            //console.log('Moving tag: ' + tagGroupData.title + ' to ' + targetTagGroupKey);
            TSCORE.Config.moveTag(tagGroupData, targetTagGroupKey);
          } else if (tagAttr && tagAttr.length > 1) { // create from file
            var targetTagGroupData = TSCORE.Config.getTagGroupData(targetTagGroupKey);
            TSCORE.Config.createTag(targetTagGroupData, tagAttr, defaultTagColor, defaultTagTextColor);
          }
          generateTagGroups();
          $(ui.helper).remove();
        }
      });
    });
    $tagGroupsContent.on('contextmenu click', '.tagGroupActions', function() {
      TSCORE.hideAllDropDownMenus();
      TSCORE.selectedTag = $(this).attr('tag');
      TSCORE.selectedTagData = TSCORE.Config.getTagGroupData($(this).attr('key'));
      TSCORE.selectedTagData.parentKey = undefined;
      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'));
      TSCORE.selectedTag = generateTagValue(TSCORE.selectedTagData);
      TSCORE.selectedTagData.parentKey = $(this).attr('parentKey');
      TSCORE.showContextMenu('#tagTreeMenu', $(this));
      return false;
    });
  }