Removed a way to repeat a tag in uploaded post

This commit is contained in:
Marcin Kurczewski 2015-06-24 23:51:11 +02:00
parent d20fe3d95a
commit b5d6e4837d

View file

@ -440,6 +440,15 @@ App.Presenters.PostUploadPresenter = function(
};
}
function getTagIndex(post, tag) {
var tags = jQuery.map(post.tags, String.toLowerCase);
return tags.indexOf(tag.toLowerCase());
}
function hasTag(post, tag) {
return getTagIndex(post, tag) !== -1;
}
function getCombinedPost(posts) {
var combinedPost = _.extend({}, getDefaultPost());
if (posts.length === 0) {
@ -449,7 +458,7 @@ App.Presenters.PostUploadPresenter = function(
var tagFilter = function(post) {
return function(tag) {
return post.tags.indexOf(tag) !== -1;
return hasTag(post, tag);
};
};
@ -496,8 +505,7 @@ App.Presenters.PostUploadPresenter = function(
function addTagToPosts(posts, tag) {
jQuery.each(posts, function(i, post) {
var index = post.tags.indexOf(tag);
if (index === -1) {
if (!hasTag(post, tag)) {
post.tags.push(tag);
}
postChanged(post);
@ -506,9 +514,8 @@ App.Presenters.PostUploadPresenter = function(
function removeTagFromPosts(posts, tag) {
jQuery.each(posts, function(i, post) {
var index = post.tags.indexOf(tag);
if (index !== -1) {
post.tags.splice(index, 1);
if (hasTag(post, tag)) {
post.tags.splice(getTagIndex(post, tag), 1);
}
postChanged(post);
});