diff --git a/app/assets/javascripts/application/collections.coffee b/app/assets/javascripts/application/collections.coffee index 3dc93bc7f8bc010afb059000f4ee3a9177b3d5a9..0289e4e56c771c88f98948a2259740103a4cf2af 100644 --- a/app/assets/javascripts/application/collections.coffee +++ b/app/assets/javascripts/application/collections.coffee @@ -91,20 +91,23 @@ $(document).on 'ready page:load', -> $(document).on 'add_collection_selector', (e) -> $('.learning-object-vertical').each (e) -> loid = $(this).data('loid') - $('.learning-object-thumbnail', this).append '<input class="collection-selector" type="checkbox" value="' + loid + '"></input>' + type = $(this).data('type') + $('.learning-object-thumbnail', this).append '<input class="collection-selector" type="checkbox" value="' + loid + '" data-type="' + type + '" ></input>' return # add/remove object to array when click checkbox $(document).on 'click', '.collection-selector', -> if this.checked if selected_objects.indexOf(this.value) < 0 - selected_objects.push this.value + selected_objects.push { "class" : $(this).attr('data-type'), "value" : this.value} $(document).trigger('check_selected_collection') return else - index = selected_objects.indexOf(this.value) - if !!(~index) - selected_objects.splice(index, 1) + i = 0 + while i < selected_objects.length + if (selected_objects[i].value == this.value) + selected_objects.splice(i, 1) + i++ $(document).trigger('check_selected_collection') return @@ -113,11 +116,16 @@ $(document).on 'mark_all_collections', -> selected_objects = [] $('.collection-selector').prop('checked', true) $('.collection-selector').each () -> - selected_objects.push this.value + selected_objects.push { "class" : $(this).attr('data-type'), "value" : this.value} + console.log(selected_objects) $(document).trigger('check_selected_collection') -$(document).on 'click', '.count-collections-objects', -> - $(document).trigger('mark_all_collections') +$(document).on 'change', '.count-collections-objects', -> + if ($(this).prop('checked')) + $(document).trigger('mark_all_collections') + else + $(document).trigger('clear_collections') + # clear selected objects $(document).on 'clear_collections', -> @@ -125,21 +133,33 @@ $(document).on 'clear_collections', -> $('.collection-selector').attr('checked', false) $(document).trigger('check_selected_collection') -$(document).on 'click', '.collection-show-select-nav .navbar-brand', -> - $(document).trigger('clear_collections') - # manipulation buttons $(document).on 'click', '.collection-button', -> collection = $('.collection-show-page').data('cid') index = permitted_types.indexOf($(this).data('action')) + urls = [] + learning_objects = [] if permitted_types[index] == 'remove' - url = '/collections/' + encodeURIComponent(collection) + '/learning_objects/' + encodeURIComponent(selected_objects.join()) + if ($('.collection-button').data('class') == 'collections') + i = 0 + while i < selected_objects.length + learning_objects.push selected_objects[i]["value"] + i++ + urls.push '/collections/' + encodeURIComponent(collection) + '/learning_objects/' + encodeURIComponent(learning_objects.join(',')) + else + i = 0 + while i < selected_objects.length + urls.push '/bookmarks/' + encodeURIComponent(selected_objects[i]["class"]) + '/' + encodeURIComponent(selected_objects[i]["value"]) + i++ if confirm('Você tem certeza?') - $.ajax { method: 'DELETE', url: url } - .done -> - $(document).trigger 'refresh_comments' - else - $(document).trigger('open_collections_modal', [collection: collection, type: permitted_types[index], learning_object: selected_objects ]) if !!(~index) + i = 0 + while i < urls.length + $.ajax { method: 'DELETE', url: urls[i] } + .done -> + $(document).trigger 'refresh_comments' + i++ + else + $(document).trigger('open_collections_modal', [collection: collection, type: permitted_types[index], learning_object: selected_objects ]) if !!(~index) # refresh comments via ajax $(document).on 'refresh_comments', (e) -> @@ -159,6 +179,7 @@ $(document).on 'refresh_comments', (e) -> $(document).on 'check_selected_collection', (e) -> length = selected_objects.length if length == 0 + $('.count-collections-objects').prop('checked',false) return $('.collection-show-select-nav').slideUp('slow') else if (length == 1) html = "1 objeto selecionado" diff --git a/app/controllers/bookmarks_controller.rb b/app/controllers/bookmarks_controller.rb index 487cbfd5baed5cfd16afd3755b2da4525d926e55..0dccaf5650ce3f19e62f7958053fe880caca1741 100644 --- a/app/controllers/bookmarks_controller.rb +++ b/app/controllers/bookmarks_controller.rb @@ -9,6 +9,7 @@ class BookmarksController < ApplicationController # GET /bookmarks/1 # GET /bookmarks/1.json def show + render partial: 'list' if params[:list] == 'true' end # POST /bookmarks/1/learning_object @@ -19,10 +20,14 @@ class BookmarksController < ApplicationController render json: { status: true } if request.xhr? end + def list + render layout: false + end + # DELETE /bookmarks/1/learning_object def remove_object authorize @object - Bookmark.destroy(user: @user, bookmarkable: @object) + Bookmark.destroy Bookmark.where(user: @user, bookmarkable: @object) render json: { status: true } if request.xhr? end diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index 86489177db78044d1650583bea381767497346c6..d4aee9e51cf831e20da805bc0db77e8362173dd3 100644 --- a/app/controllers/collections_controller.rb +++ b/app/controllers/collections_controller.rb @@ -118,10 +118,11 @@ class CollectionsController < ApplicationController @new_collection = Collection.new @publishers = publishers_for current_user + @bookmark = (current_user.bookmarks.nil? || current_user.bookmarks.first.nil?) ? [] : [current_user.bookmarks.first] @groups = [ CollectionsGroup.new(title: 'Coleções Automáticas', - collections: [current_user.bookmarks.first]), + collections: @bookmark ), CollectionsGroup.new(title: 'Coleções Adicionadas', collections: current_user.collections.includes(:owner)) ] diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e721429a17d2d91c07125608879877053217d595..cbc5a878c07baa6e6e5c1bb038c2a901a49d1839 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -13,8 +13,8 @@ class UsersController < ApplicationController if @user == current_user @publishers = @user.institutions - @bookmarks = @user.bookmarks.first - @groups.unshift(CollectionsGroup.new(title: 'Coleções Automáticas', collections: [@bookmarks])) + @bookmarks = (@user.bookmarks.nil? || @user.bookmarks.first.nil?) ? [] : [@user.bookmarks.first] + @groups.unshift(CollectionsGroup.new(title: 'Coleções Automáticas', collections: @bookmarks)) end end diff --git a/app/views/bookmarks/_list.html.erb b/app/views/bookmarks/_list.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..622dcb1d1f55703db09a2a9e315e1f770c67e8cb --- /dev/null +++ b/app/views/bookmarks/_list.html.erb @@ -0,0 +1,3 @@ +<% @user.bookmark_learning_objects.each do |object| %> + <%= render object, orientation: 'vertical' %> +<% end %> diff --git a/app/views/bookmarks/show.html.erb b/app/views/bookmarks/show.html.erb index 764dc5519603bfb2874dcebef68a9db16a7093ab..db21f6fefae40a4476214574027cbdbf157b6a8b 100644 --- a/app/views/bookmarks/show.html.erb +++ b/app/views/bookmarks/show.html.erb @@ -6,10 +6,8 @@ <ul class="nav navbar-nav navbar-right collection-header" style="margin-left: 30px;"> <li><h2>Favoritos</h2></li> <li> - <a class="count-collections-objects" data-toggle="tooltip" data-placement="bottom" title="Selecionar todos"> - <%= image_tag image_path("icons/square.png"), class: "logo-image", size: "20x20" %> + <input type="checkbox" class="count-collections-objects" data-toggle="tooltip" data-placement="bottom" title="Selecionar todos"> <%= bookmark_length @user %> - </a> </li> </ul> </div> @@ -18,21 +16,21 @@ </nav> <nav class="navigation navbar-inverse collection-show-select-nav" style="display:none;"> <div class="container-fluid"> - <a class="navbar-brand" href="javascript:void(0);" data-toggle="tooltip" data-placement="bottom" title="Limpar seleção"></a> + <a class="navbar-brand" data-toggle="tooltip" data-placement="bottom" ></a> <ul class="nav navbar-nav navbar-right"> - <li class="set-align collection-button" data-action="download"> + <li class="set-align collection-button" data-action="download" data-class="bookmarks"> <a href="javascript:void(0);"><span class="left-edge1"><%= image_tag image_path("icons/Download_01.png"), class: "logo-image", size: "35x35" %></span><span style="color: white"> Salvar no <br>computador</span></a> </li> - <li class="set-align collection-button" data-action="copy"> + <li class="set-align collection-button" data-action="copy" data-class="bookmarks"> <a href="javascript:void(0);"><span class="left-edge1"><%= image_tag image_path("icons/Copiar_Seleção.png"), class: "logo-image", size: "35x35" %></span><span style="color: white"> Copiar <br>para</span></a> </li> - <li class="set-align collection-button" data-action="move"> + <li class="set-align collection-button" data-action="move" data-class="bookmarks"> <a href="javascript:void(0);"><span class="left-edge1"><%= image_tag image_path("icons/Mover_Seleção.png"), class: "logo-image", size: "35x35" %></span><span style="color: white"> Mover <br>para</span></a> </li> - <li class="set-align collection-button" data-action="remove"> + <li class="set-align collection-button" data-action="remove" data-class="bookmarks"> <a href="javascript:void(0);"><span class="left-edge1"><%= image_tag image_path("icons/Remover_da_Coleção_Seleção.png"), class: "logo-image", size: "35x35" %></span><span style="color: white"> Remover da <br>coleção</span></a> </li> @@ -40,11 +38,9 @@ </div> </nav> -<div class= "row"> +<div class="row"> <div class="learning-object-columns"> <br/> - <% @user.bookmark_learning_objects.each do |object| %> - <%= render object, orientation: 'vertical' %> - <% end %> + <%= render partial: 'list' %> </div> </div> diff --git a/app/views/collections/show.html.erb b/app/views/collections/show.html.erb index dbcbb382e780785aac38462b6ab1b717cadf207e..3e6359ec6c75b3f5a19ffbaf4979325c0f9a7dfa 100644 --- a/app/views/collections/show.html.erb +++ b/app/views/collections/show.html.erb @@ -26,8 +26,7 @@ <ul class="nav navbar-nav navbar-right collection-header" style="margin-left: 30px;"> <li><h2><%= (@collection.class != Bookmark) ? @collection.name : "Favoritos" %></h2></li> <li> - <a class="count-collections-objects" data-toggle="tooltip" data-placement="bottom" title="Selecionar todos"> - <%= image_tag image_path("icons/square.png"), class: "logo-image", size: "20x20" %> + <input type="checkbox" class="count-collections-objects" data-toggle="tooltip" data-placement="bottom" title="Selecionar todos"> <%= collection_length @collection %> </a> </li> @@ -38,24 +37,24 @@ </nav> <nav class="navigation navbar-inverse collection-show-select-nav" style="display:none;"> <div class="container-fluid"> - <a class="navbar-brand" href="javascript:void(0);" data-toggle="tooltip" data-placement="bottom" title="Limpar seleção"></a> + <a class="navbar-brand" data-toggle="tooltip" data-placement="bottom" ></a> <ul class="nav navbar-nav navbar-right"> - <li class="set-align collection-button" data-action="download"> + <li class="set-align collection-button" data-action="download" data-class="collections"> <a href="javascript:void(0);"><span class="left-edge1"><%= image_tag image_path("icons/Download_01.png"), class: "logo-image", size: "35x35" %></span><span style="color: white"> Salvar no <br>computador</span></a> </li> <% if user_signed_in? %> - <li class="set-align collection-button" data-action="copy"> + <li class="set-align collection-button" data-action="copy" data-class="collections"> <a href="javascript:void(0);"><span class="left-edge1"><%= image_tag image_path("icons/Copiar_Seleção.png"), class: "logo-image", size: "35x35" %></span><span style="color: white"> Copiar <br>para</span></a> </li> <% end %> <% if @own %> - <li class="set-align collection-button" data-action="move"> + <li class="set-align collection-button" data-action="move" data-class="collections"> <a href="javascript:void(0);"><span class="left-edge1"><%= image_tag image_path("icons/Mover_Seleção.png"), class: "logo-image", size: "35x35" %></span><span style="color: white"> Mover <br>para</span></a> </li> - <li class="set-align collection-button" data-action="remove"> + <li class="set-align collection-button" data-action="remove" data-class="collections"> <a href="javascript:void(0);"><span class="left-edge1"><%= image_tag image_path("icons/Remover_da_Coleção_Seleção.png"), class: "logo-image", size: "35x35" %></span><span style="color: white"> Remover da <br>coleção</span></a> </li> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index 01d3d53a8683c88e9a71a230441933c4bca79f1f..5eca08657ad41165b2a2ceb551823ff224eba1b1 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -57,17 +57,17 @@ $('.Facebook-button').click(function(){ $('#social-modal-continue').empty(); $('#social-modal-continue').append('<button type="button" class="btn btn-danger" style="float:left;" data-dismiss="modal">Recusar</button>'); - $('#social-modal-continue').append('<%= button_to "Aceitar", user_omniauth_authorize_path(:facebook), class: 'btn btn-primary' %>'); + $('#social-modal-continue').append('<%= button_to "Aceitar", user_omniauth_authorize_path(:facebook), class: 'btn btn-success' %>'); }); $('.Google-button').click(function(){ $('#social-modal-continue').empty(); $('#social-modal-continue').append('<button type="button" class="btn btn-danger" style="float:left;" data-dismiss="modal">Recusar</button>'); - $('#social-modal-continue').append('<%= button_to "Aceitar", user_omniauth_authorize_path(:google_oauth2), class: 'btn btn-primary' %>'); + $('#social-modal-continue').append('<%= button_to "Aceitar", user_omniauth_authorize_path(:google_oauth2), class: 'btn btn-success' %>'); }); $('.Twitter-button').click(function(){ $('#social-modal-continue').empty(); $('#social-modal-continue').append('<button type="button" class="btn btn-danger" style="float:left;" data-dismiss="modal">Recusar</button>'); - $('#social-modal-continue').append('<%= button_to "Aceitar", user_omniauth_authorize_path(:twitter), class: 'btn btn-primary' %>'); + $('#social-modal-continue').append('<%= button_to "Aceitar", user_omniauth_authorize_path(:twitter), class: 'btn btn-success' %>'); }); </script> diff --git a/app/views/learning_objects/_learning_object_vertical.erb b/app/views/learning_objects/_learning_object_vertical.erb index 91f12fba15cb7f9f8bce04a6ea82eec8426d25b5..5319ca6735e835e96ae00b41db508fa07681cd81 100644 --- a/app/views/learning_objects/_learning_object_vertical.erb +++ b/app/views/learning_objects/_learning_object_vertical.erb @@ -1,4 +1,4 @@ -<div class="learning-object-vertical" data-loid="<%= learning_object.id %>"> +<div class="learning-object-vertical" data-loid="<%= learning_object.id %>" data-type="LearningObject" > <div class="panel"> <div class="learning-object-thumbnail"> <%= link_to learning_object_path(id: learning_object.id) do diff --git a/app/views/shared/application/_search.erb b/app/views/shared/application/_search.erb index da844e70f8941b027f89828617add63475ed9553..e239aa2859cdbd26ddca883903044f91c9141e3a 100644 --- a/app/views/shared/application/_search.erb +++ b/app/views/shared/application/_search.erb @@ -1,7 +1,7 @@ <div class="search-input"> <form action="/search" method="get"> <div class="input-group" id="search"> - <input type="text" data-lo="<%=number_with_delimiter(LearningObject.count, delimiter: ".") %>" data-user="<%= number_with_delimiter(User.count, delimiter: ".") %>" data-collection="<%= number_with_delimiter(Collection.count, delimiter: ".") %>" placeholder="" class="form-control" name="query" id="main_search"> + <input type="text" data-lo="<%=number_with_delimiter(LearningObject.count, delimiter: ".") %>" data-user="<%= number_with_delimiter(User.count, delimiter: ".") %>" data-collection="<%= number_with_delimiter(Collection.where(privacy: 'public').count, delimiter: ".") %>" placeholder="" class="form-control" name="query" id="main_search"> <select name="search_class" id="search_class" class="form-control"> <option value="LearningObject" selected>Conteúdos Educacionais</option> <option value="Collection">Coleções</option> diff --git a/config/routes.rb b/config/routes.rb index 47da59df4fc0cc5d82eb98d0e445f283c7980015..3a6aa06ca2fa0df06f61e6a951b020bbb5bc468f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -110,6 +110,7 @@ Rails.application.routes.draw do end get '/bookmarks' => 'bookmarks#show', as: 'bookmark' + get '/bookmarks/list' => 'bookmarks#list', as: 'list' post '/bookmarks/:type/:id' => 'bookmarks#add_object', as: :bookmark_add delete '/bookmarks/:type/:id' => 'bookmarks#remove_object', as: :bookmark_remove