Remove add link when maximum tags is reached

This commit is contained in:
Kyle Drake 2017-03-03 10:52:43 -08:00
parent 460dea3f5e
commit 019ceff01c
2 changed files with 9 additions and 5 deletions

View file

@ -128,6 +128,8 @@ class Site < Sequel::Model
BLOCK_JERK_THRESHOLD = 3
MAXIMUM_TAGS = 5
def self.newsletter_sites
Site.select(:email).
exclude(email: 'nil').exclude(is_banned: true).
@ -962,8 +964,8 @@ class Site < Sequel::Model
end
end
if ((new? ? 0 : tags_dataset.count) + new_tags.length > 5)
errors.add :new_tags_string, 'Cannot have more than 5 tags for your site.'
if ((new? ? 0 : tags_dataset.count) + new_tags.length > MAXIMUM_TAGS)
errors.add :new_tags_string, "Cannot have more than #{MAXIMUM_TAGS} tags for your site."
end
new_tags.each do |tag|

View file

@ -9,13 +9,15 @@
<% if is_current_site %>
<div class="clear">
<a href="#addTag" data-toggle="modal">Add</a>
<% if is_current_site && current_site.tags_dataset.count < Site::MAXIMUM_TAGS %>
<a href="#addTag" data-toggle="modal">Add</a>
<% end %>
&nbsp;&nbsp;&nbsp;
<a href="#removeTag" data-toggle="modal">Remove</a>
</div>
<% end %>
<% end %>
<% end %>
<% end %>
<div class="modal hide fade" id="addTag" tabindex="-1" role="dialog" aria-labelledby="addTagLabel" aria-hidden="true">
<form method="POST" action="/tags/add">
@ -58,4 +60,4 @@
<button type="submit" class="btn-Action">Remove Tag(s)</button>
</div>
</form>
</div>
</div>