From 63549f1cf4df43e7b7eb0321d9d1603fc811f0cc Mon Sep 17 00:00:00 2001 From: Mateus Rambo Strey <mars11@inf.ufpr.br> Date: Wed, 4 Nov 2015 11:56:34 -0200 Subject: [PATCH] add and remove collection from button --- app/assets/javascripts/application/collections.coffee | 11 +++++++++++ .../javascripts/application/learning_objects.coffee | 3 ++- app/assets/stylesheets/application.scss | 5 +++++ .../learning_objects/_collections_button.html.erb | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/application/collections.coffee b/app/assets/javascripts/application/collections.coffee index 46fc726d..fa82b5ea 100644 --- a/app/assets/javascripts/application/collections.coffee +++ b/app/assets/javascripts/application/collections.coffee @@ -6,3 +6,14 @@ $ -> title: -> $('#create_collection_popover_title').html() return + +$ -> + $(document).on 'click', 'input[class=collection-element]', -> + url = '/collections/' + encodeURIComponent($(this).data('cid')) + '/learning_object/' + encodeURIComponent($(this).data('loid')) + if this.checked + $.ajax {method: "POST", url: url }, (d) -> + d + else + $.ajax {method: "DELETE", url: url }, (d) -> + d + return diff --git a/app/assets/javascripts/application/learning_objects.coffee b/app/assets/javascripts/application/learning_objects.coffee index 9730795c..d3d5b5e8 100644 --- a/app/assets/javascripts/application/learning_objects.coffee +++ b/app/assets/javascripts/application/learning_objects.coffee @@ -6,6 +6,7 @@ $ -> all = undefined objects = undefined url = $(this).data('poload') + loid = $(this).data('loid') $.get '/collections.json', (d) -> all = d $.get url, (d) -> @@ -25,7 +26,7 @@ $ -> html = '' while i < len name = 'collection_' + all[i].id.split(':').slice(-1)[0] - html += '<input type="checkbox" id="' + name + '" value="' + all[i].id + '"' + html += '<input type="checkbox" class="collection-element" data-cid="' + all[i].id + '" data-loid="' + loid + '" id="' + name + '" value="' + all[i].id + '"' if lookup[all[i].id] != undefined html += " checked" html += '>' diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index ab180a93..4987e681 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -267,6 +267,11 @@ header { z-index: 999; max-width: 600px; width: auto; + + .popover-content { + max-height: 300px; + overflow: auto; + } } //// FOOTER diff --git a/app/views/learning_objects/_collections_button.html.erb b/app/views/learning_objects/_collections_button.html.erb index b9c2aeaf..c35f0f4e 100644 --- a/app/views/learning_objects/_collections_button.html.erb +++ b/app/views/learning_objects/_collections_button.html.erb @@ -1,3 +1,3 @@ -<a tabindex="0" class="btn btn-default btn-xs add_to_collection" role="button" data-toggle="popover" data-placement="left" title="Adicionar as coleções" data-poload="/learning_objects/<%= ERB::Util.url_encode(learning_object.id) %>/collections.json"> +<a tabindex="0" class="btn btn-default btn-xs add_to_collection" role="button" data-toggle="popover" data-placement="left" title="Adicionar as coleções" data-loid="<%= learning_object.id %>" data-poload="/learning_objects/<%= ERB::Util.url_encode(learning_object.id) %>/collections.json"> <span class="glyphicon glyphicon-list" aria-hidden="true"></span> </a> -- GitLab