Permalink
Browse files

tag delete in.

  • Loading branch information...
1 parent d6992db commit 90863751f9d39bc87b730e3d10d2bdd79b4972ee @zk committed Oct 23, 2010
Showing with 30 additions and 8 deletions.
  1. +22 −0 app/controllers/cdtags_controller.rb
  2. +2 −3 app/views/main/function.html.erb
  3. +1 −0 config/routes.rb
  4. +5 −5 public/javascripts/cd.js
@@ -43,4 +43,26 @@ def add
}
end
+
+ def delete
+
+ @function = Function.find_by_id(params[:function_id])
+ @tag = Tag.find_by_id(params[:tag_id])
+
+ render json_fail "Couldn't find function." and return unless @function
+ render json_fail "Couldn't find tag." and return unless @tag
+
+ #really should only be max of one, but what the hell
+ taggings = Tagging.find_all_by_tag_id_and_taggable_type_and_taggable_id(@tag.id, 'Function', @function.id)
+
+ raise [@tag.id, 'Function', @function.id].to_yaml
+
+ all_succeeded = tagging.map {|t|
+ t.delete
+ }.reduce{|a,b| a && b}
+
+ render json_fail "There was a problem removing tag #{@tag.name} from #{@function.name}." and return unless all_succeeded
+
+ render :json => {:success => true}
+ end
end
@@ -301,11 +301,11 @@ $(document).ready(function() {
<h2>Tags</h2>
<ul>
<% @function.all_tags.each do |t| %>
- <li>
+ <li class="tag_item" id="tag_item_<%= t.id %>">
<a href="" class="tag">
<%= t.name %>
</a>
- <a href="" class='delete'>
+ <a href="" class="delete" id="tag_delete_<%= t.id %>">
<%= image_tag 'x_alt_12x12.png', :width => 12, :height => 12 %>
</a>
</li>
@@ -316,4 +316,3 @@ $(document).ready(function() {
</div>
</div>
-
View
@@ -73,6 +73,7 @@
map.connect '/tags/lookup', :controller => 'cdtags', :action => 'lookup'
map.connect '/tags/add', :controller => 'cdtags', :action => 'add'
+ map.connect '/tags/delete', :controller => 'cdtags', :action => 'delete'
map.connect '/v/:id', :controller => 'main', :action => 'function_short_link'
View
@@ -490,14 +490,13 @@ CD.SeeAlsos = function() {
CD.Tags = function() {
function deleteItem() {
- if(confirm("Are you sure you want to delete this see also? There is no undo!")) {
+ if(confirm("Are you sure you want to remove this tag? There is no undo!")) {
var id = $(this).attr("id").split("_")[2]
params = {id: id}
- alert('delete ' + id)
- $.getJSON("/tag/delete", params, function(data) {
- $("#see_also_item_" + id).slideUp(500)
+ $.getJSON("/tags/delete", params, function(data) {
+ $("#tag_item_" + id).slideUp(500)
})
- $("#see_also_item_" + id + " .controls .delete img").attr("src", "/images/ajax-loader.gif")
+ $("#tag_item_" + id + " .controls .delete img").attr("src", "/images/ajax-loader.gif")
}
return false
@@ -577,6 +576,7 @@ CD.Tags = function() {
init: function(args) {
var varId = args.varId
initAutoComplete(varId)
+ $(".function_tags .delete").click(deleteItem)
$("#tag_name_search").keyup(function(e) {
if(e.keyCode != 13) return;

0 comments on commit 9086375

Please sign in to comment.