Skip to content

Commit

Permalink
adds tags
Browse files Browse the repository at this point in the history
  • Loading branch information
cearto committed Jul 24, 2014
1 parent 7f9f18d commit e5ab73a
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 14 deletions.
25 changes: 25 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,32 @@
$(function(){
$('textarea').unbind();
})
function removeTag(id, self){
console.log("/tags/" + id);
$.ajax({
url: "/tags/" + id,
type: "DELETE"
});
$(self).parent().remove();
}

function createTag(model, model_id, tag){
var value = $(tag).parent().siblings('input').val();
tag = {};
tag[model + "_id"] = model_id;
tag["content"] = value
// console.log(tag);
$.ajax({
url: "/tags",
type: "POST",
data: {tag: tag, commit:"Create Tag"},
success: function(html){
console.log(html);
$('.tag-list').append(html.tag);
},
dataType: "json"
});
}

function DOM(){}
DOM.tag = function(t){
Expand Down
6 changes: 5 additions & 1 deletion app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
*/


.tag-list > span{
margin-bottom: 5px;
display: inline-block;
margin-bottom: 4px;
}
.nav-row > *{
margin: 2px;
}
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/account_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@ def login
def register
render layout: "custom"
end

def tagify(content, options)
tag = "<span class='tag-label label-gap'>#{content} "
if options[:removable]
tag = tag + '<span class="glyphicon glyphicon-remove-circle"></span>'
end
tag = tag + '</span>'
tag.html_safe
end
end
15 changes: 7 additions & 8 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ def human_boolean(boolean)
boolean ? 'Yes' : 'No'
end

def tagify(content)
# tag << eos
# <span class="tag-label label-gap">brainstorming
# <span class="glyphicon glyphicon-remove-circle"></span>
# </span>
# eos
tag = content
tag.html_safe
def tagify(id, content, options)
tag = "<span class='tag-label label-gap'>#{content} "
if options[:removable]
tag = tag + '<span onclick="removeTag('+ (id.to_s) +', this);" class="glyphicon glyphicon-remove-circle"></span>'
end
tag = tag + '</span>'
tag.html_safe
end

end
Expand Down
20 changes: 16 additions & 4 deletions app/views/design_methods/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<script>
$(function(){
adjustSaveBar();
});

function adjustSaveBar(){
var pH = $('#publish-btn').parent().height()
var eH = $('#publish-btn').height()
$('#publish-btn').css('margin-top', (pH - eH)/2)
Expand All @@ -11,7 +15,7 @@
pH = $('#auto-saved-text').parent().height()
eH = $('#auto-saved-text').height()
$('#auto-saved-text').css('margin-top', (pH - eH)/2)
});
}
</script>
<%= form_for @design_method, :html => {:multipart => true} do |f| %>
<!-- ERROR MESSAGES -->
Expand Down Expand Up @@ -92,9 +96,17 @@
<!-- TAGS -->
<div class="row">
<h4>Tags</h4>
<input type="text" class="form-control" placeholder="Tag">
<p>
<%= tagify("test") %>
<div class="input-group">
<input type="text" class="form-control">
<span class="input-group-btn">
<button class="btn btn-default" type="button" onclick="createTag('design_method', <%=params[:id]%>, this);">Add Tag</button>
</span>
</div>
<br>
<p class='tag-list'>
<% @design_method.tags.each do |t| %>
<%= tagify(t.id, t.content, {:removable => true}) %>
<% end %>
</p>
</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion app/views/design_methods/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@
<div class="row">
<h4>Tags</h4>
<p>
No tags available
<% @method.tags.each do |t| %>
<%= tagify(t.id, t.content, {:removable => false}) %>
<% end %>
<%= "No tags available" unless not @method.tags.empty? %>
</p>
<!-- END TAGS -->
</div>
Expand Down

0 comments on commit e5ab73a

Please sign in to comment.