first trivial tag editing...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-12-08 21:53:05 +04:00
parent 6bd8e318f0
commit b933eae8a6
3 changed files with 42 additions and 14 deletions

View File

@ -38,6 +38,7 @@
<script src="ui.js"></script>
<script src="setup.js"></script>
<script src="editor.js"></script>
<script src="tags.js"></script>
<script src="keybindings.js"></script>

View File

@ -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(){
}

View File

@ -1203,6 +1203,8 @@ function showImageInfo(){
var comment = data.comment
comment = comment == null ? '' : comment
comment = comment.replace(/\n/g, '<br>')
var tags = data.tags
tags = tags == null ? '' : tags.join(', ')
return formDialog(null,
('<div>'+
@ -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
'<tr><td>Comment: </td><td class="comment" contenteditable>'+ comment +'</td></tr>'+
'<tr><td>Tags: </td><td class="tags" contenteditable>'+ tags +'</td></tr>'+
'</table>'+
'<br>'+
'</div>'),
@ -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)
}
})
}