diff --git a/app/assets/javascripts/problems.js.coffee b/app/assets/javascripts/problems.js.coffee index 72a85259..82f5ce00 100644 --- a/app/assets/javascripts/problems.js.coffee +++ b/app/assets/javascripts/problems.js.coffee @@ -2,6 +2,24 @@ # All this logic will automatically be available in application.js. # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ +$(document).ready -> + $('.dropdown-menu input, .dropdown-menu label').click (event) -> + event.stopPropagation() + + $('.dropdown-menu input').change (event) -> + $btnGroup = $(this).closest(".btn-group") + $menuItems = $btnGroup.find(".dropdown-menu input:checked") + selected = [] + $menuItems.each (index, item) -> + selected.push($(item).val()) + title = "" + if selected.length > 0 + title = selected.join(", ") + else + title = "Please select" + + $btnGroup.find(".btn").text(title) + @myfunction = (problemid, collectionid) -> $.ajax({url: "/add_problem?collection_id=#{collectionid}&id=#{problemid}"}).done (data) -> diff --git a/app/views/shared/_problems_table.html.haml b/app/views/shared/_problems_table.html.haml index f2d75ff1..e8f80a78 100644 --- a/app/views/shared/_problems_table.html.haml +++ b/app/views/shared/_problems_table.html.haml @@ -23,6 +23,9 @@ %td -if problems_index / =link_to "add to #{Collection.find(@current_user.current_collection).name} (current)", add_problem_path(:id => problem.id, :collection_id => @current_user.current_collection), {:id => "problem_#{problem.id}"} - %a{:class => "addlink", :id => "problem#{problem.id}", :onclick => "myfunction('#{problem.id}', #{@current_user.current_collection}); return false"} current collection + / %a{:class => "addlink", :id => "problem#{problem.id}", :onclick => "myfunction('#{problem.id}', #{@current_user..topbar-wrapper{:style => "z-index: 5;"} + = select_tag "dropdown", options_from_collection_for_select(Collection.all, "id", "name"), :onchange => "myfunction(id, '2')" + + -else =link_to "remove from this collection", remove_problem_path( :id => problem.id, :collection_id => collection), {:id => "problem_#{problem.id}"}