diff --git a/app/assets/javascripts/application/collections.coffee b/app/assets/javascripts/application/collections.coffee index 1b1645ce35a6329a224a684bb300fb857f31f848..2c60bd6e74aedc37d6d54319e2c2508dac2f5a01 100644 --- a/app/assets/javascripts/application/collections.coffee +++ b/app/assets/javascripts/application/collections.coffee @@ -55,9 +55,6 @@ mount_modal_params = (e) -> $(document).on 'submit', '#collections-modal-form', (evt, params) -> evt.preventDefault() - - refreshable_type = ['move'] - data = mount_modal_params(this) return false if (data.learning_objects_ids.length < 1) || (data.collections_ids.length < 1) || (permitted_types.indexOf(data.type) < 0) @@ -69,9 +66,10 @@ $(document).on 'submit', '#collections-modal-form', (evt, params) -> if (data.type == "move") url = '/collections/' + encodeURIComponent(data.collection_id) + '/learning_objects/' + encodeURIComponent(data.learning_objects_ids.join()) $.ajax {method: "DELETE", url: url, data: data } + .done -> + $(document).trigger('refresh_comments') $(document).trigger 'flash_notice', {text: 'Operação efetuada com sucesso!', type: 'notice'} $(document).trigger('clear_collections') - location.reload(true) if !(refreshable_type.indexOf(data.type) < 0) $('#collections-modal').modal('hide') return @@ -87,11 +85,14 @@ permitted_types = ['add', 'download', 'copy', 'move', 'remove'] $(document).on 'ready page:load', -> if $('.collection-show-page').val() != undefined - # add selectors - $('.learning-object-vertical').each (e) -> - loid = $(this).data('loid') - $('.learning-object-thumbnail', this).append '<input class="collection-selector" type="checkbox" value="' + loid + '"></input>' - return + $(document).trigger('add_collection_selector') + +# add selectors to learning objects +$(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>' + return # add/remove object to array when click checkbox $(document).on 'click', '.collection-selector', -> @@ -120,15 +121,29 @@ $(document).on 'click', '.collection-show-select-nav .navbar-brand', -> $(document).on 'click', '.collection-button', -> collection = $('.collection-show-page').data('cid') index = permitted_types.indexOf($(this).data('action')) - if permitted_types[index] == 'remove' url = '/collections/' + encodeURIComponent(collection) + '/learning_objects/' + encodeURIComponent(selected_objects.join()) if confirm('Você tem certeza?') $.ajax { method: 'DELETE', url: url } - location.reload(true) + .done -> + $(document).trigger 'refresh_comments' 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) -> + selected_objects = [] + $(document).trigger 'check_selected_collection' + + $parent = $('.learning-object-columns') + url = window.location.pathname + '?list=true' + $parent.html('Carregando...') + + $.get url, (data) -> + $parent.html('<br>' + data) + $(document).trigger 'create-learning-object-columns' + $(document).trigger 'add_collection_selector' + # update interface when add/remove an object $(document).on 'check_selected_collection', (e) -> length = selected_objects.length diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index 330b2f4fcf50a5e1cb40f6986c874c2453e50003..f28894396a3b2758e534a10c9567a59c7517ac1f 100644 --- a/app/controllers/collections_controller.rb +++ b/app/controllers/collections_controller.rb @@ -29,6 +29,8 @@ class CollectionsController < ApplicationController @user = @collection.owner @own = user_signed_in? ? @collection.owner?(current_user) : false + + render partial: 'list' if params[:list] == "true" end # POST /collections/1/like diff --git a/app/views/collections/_list.html.erb b/app/views/collections/_list.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..4eb2767808042bd7d8f7e8d1478cd16aa356cc0a --- /dev/null +++ b/app/views/collections/_list.html.erb @@ -0,0 +1,3 @@ +<% @collection.learning_objects.each do |learning_object| %> + <%= render learning_object, orientation: 'vertical' %> +<% end %> diff --git a/app/views/collections/show.html.erb b/app/views/collections/show.html.erb index 06a2cdf90b953349e02f4d2da88b3843ff14c341..73f1f9ed016df68069449138081e9ecd6093772c 100644 --- a/app/views/collections/show.html.erb +++ b/app/views/collections/show.html.erb @@ -61,8 +61,6 @@ <div class= "row"> <div class="learning-object-columns"> <br/> - <% @collection.learning_objects.each do |learning_object| %> - <%= render learning_object, orientation: 'vertical' %> - <% end %> + <%= render partial: 'list' %> </div> </div> diff --git a/app/views/learning_objects/show.html.erb b/app/views/learning_objects/show.html.erb index eb976e03fbb6cf36d87a7bcba72b386d60fe47f2..b563888f8da704e7e064e11efb9424b8fcfcbebc 100644 --- a/app/views/learning_objects/show.html.erb +++ b/app/views/learning_objects/show.html.erb @@ -52,7 +52,7 @@ </a> </div> <div class="col-sm-3 action"> - <a tabindex="0" class="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"> + <a tabindex="0" class="add-to-collection" role="button" title="Adicionar as coleções" data-loid="<%= @learning_object.id %>"> <%= image_tag "icons/collection-add.png", alt: "Adicionar à coleção" %> <h6>adicionar à coleção</h6> </a>