From b933eae8a602c58334ba562af8404b56fda00009 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 8 Dec 2013 21:53:05 +0400 Subject: [PATCH] first trivial tag editing... Signed-off-by: Alex A. Naanou --- ui/index.html | 1 + ui/tags.js | 33 +++++++++++++++++++++------------ ui/ui.js | 22 ++++++++++++++++++++-- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/ui/index.html b/ui/index.html index 261fa95c..b4790a1d 100755 --- a/ui/index.html +++ b/ui/index.html @@ -38,6 +38,7 @@ + diff --git a/ui/tags.js b/ui/tags.js index c9c2cca1..0dabadeb 100755 --- a/ui/tags.js +++ b/ui/tags.js @@ -25,11 +25,16 @@ function buildTagsFromImages(images){ /*********************************************************************/ function addTag(tags, gid, tagset, images){ - tags = typeof(tag) == typeof('str') ? [ tags ] : tag + tags = typeof(tags) == typeof('str') ? [ tags ] : tags gid = gid == null ? getImageGID() : gid tagset = tagset == null ? TAGS : tagset images = images == null ? IMAGES : images - + + var img = images[gid] + if(img.tags == null){ + img.tags = [] + } + // add tags to tagset... tags.map(function(tag){ var set = tagset[tag] @@ -37,13 +42,15 @@ function addTag(tags, gid, tagset, images){ set = [] tagset[tag] = set } - set.push(tag) - set.sort() - }) + if(set.indexOf(tag) < 0){ + set.push(tag) + set.sort() + } - // add tag to image... - var img = images[gid] - img.tags = img.tags == null ? tags : img.tags.concat(tags) + if(img.tags.indexOf(tag) < 0){ + img.tags.push(tag) + } + }) // XXX hardcoded and not customizable... IMAGES_UPDATED.push(gid) @@ -51,7 +58,7 @@ function addTag(tags, gid, tagset, images){ function removeTag(tags, gid, tagset, images){ - tags = typeof(tag) == typeof('str') ? [ tags ] : tag + tags = typeof(tags) == typeof('str') ? [ tags ] : tags gid = gid == null ? getImageGID() : gid tagset = tagset == null ? TAGS : tagset images = images == null ? IMAGES : images @@ -63,9 +70,10 @@ function removeTag(tags, gid, tagset, images){ tags.map(function(tag){ var set = tagset[tag] if(set != null && set.indexOf(tag) >= 0){ - updated = true - set.splice(set.indexOf(tag), 1) + } + if(img.tags != null && img.tags.indexOf(tag) >= 0){ + updated = true img.tags.splice(img.tags.indexOf(tag), 1) // clear the tags... @@ -116,10 +124,11 @@ function selectByTags(tags, tagset){ } -function getTags(){ +function getTags(gid){ } +// XXX don't remember the semantics... function getRelatedTags(){ } diff --git a/ui/ui.js b/ui/ui.js index 587006cf..64362d6e 100755 --- a/ui/ui.js +++ b/ui/ui.js @@ -1203,6 +1203,8 @@ function showImageInfo(){ var comment = data.comment comment = comment == null ? '' : comment comment = comment.replace(/\n/g, '
') + var tags = data.tags + tags = tags == null ? '' : tags.join(', ') return formDialog(null, ('
'+ @@ -1225,6 +1227,7 @@ function showImageInfo(){ // XXX this expanding to a too big size will mess up the screen... // add per editable and global dialog max-height and overflow 'Comment: '+ comment +''+ + 'Tags: '+ tags +''+ ''+ '
'+ '
'), @@ -1246,8 +1249,23 @@ function showImageInfo(){ IMAGES_UPDATED.push(gid) } - // XXX tags... - // XXX + // tags... + var ntags = form.find('.tags').text().trim() + if(ntags != tags){ + ntags = ntags.split(/\s*,\s*/) + + // remove... + var rtags = [] + data.tags.map(function(tag){ + if(ntags.indexOf(tag) < 0){ + rtags.push(tag) + } + }) + removeTag(rtags, gid) + + // add... + addTag(ntags, gid) + } }) }