diff --git a/app/assets/javascripts/application/collections.coffee b/app/assets/javascripts/application/collections.coffee index 51855518dc564e05cf8a551eb7182a42c22f951f..009d8567892270bbc1e88c4c4803d46990ff69a0 100644 --- a/app/assets/javascripts/application/collections.coffee +++ b/app/assets/javascripts/application/collections.coffee @@ -92,14 +92,14 @@ $ -> $(document).on 'click', '.collection-selector', -> if this.checked if selected_objects.indexOf(this.value) < 0 - selected_objects.push { name: 'learning_object', value: this.value } - $(document).trigger('check_selected_collection'); + selected_objects.push this.value + $(document).trigger('check_selected_collection') return else - index = selected_objects.indexOf({ name: 'learning_object', value: this.value }) + index = selected_objects.indexOf(this.value) if !!(~index) selected_objects.splice(index, 1) - $(document).trigger('check_selected_collection'); + $(document).trigger('check_selected_collection') return # clear selected objects @@ -114,15 +114,13 @@ $ -> # manipulation buttons $(document).on 'click', '.collection-button', -> index = permitted_types.indexOf($(this).data('action')) - learning_objects = selected_objects.map (o) -> - return o.value if permitted_types[index] == 'remove' - url = '/collections/' + encodeURIComponent(collection) + '/learning_objects/' + encodeURIComponent(learning_objects.join()) + url = '/collections/' + encodeURIComponent(collection) + '/learning_objects/' + encodeURIComponent(selected_objects.join()) $.ajax { method: 'DELETE', url: url } if confirm('Você tem certeza?') location.reload(true) else - $(document).trigger('open_collections_modal', [collection: collection, type: permitted_types[index], learning_object: learning_objects ]) if !!(~index) + $(document).trigger('open_collections_modal', [collection: collection, type: permitted_types[index], learning_object: selected_objects ]) if !!(~index) # update interface when add/remove an object $(document).on 'check_selected_collection', (e) -> diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index 7e68db0ddadd388764323a46deb243cd157b5bf6..330b2f4fcf50a5e1cb40f6986c874c2453e50003 100644 --- a/app/controllers/collections_controller.rb +++ b/app/controllers/collections_controller.rb @@ -83,7 +83,18 @@ class CollectionsController < ApplicationController @collections = collection_repository.all(Collections::UserContext.new(current_user)) @collections.select! { |c| c.id != @collection.id } unless @collection.blank? - @type = params[:type] unless params[:type].blank? + unless params[:type].blank? + @type = params[:type] + + @send = case @type + when 'add' then 'Adicionar' + when 'copy' then 'Copiar' + when 'move' then 'Mover' + else 'Enviar' + end + + @title = (@send == 'Enviar') ? 'Coleções' : @send + ' objeto(s) à s coleções' + end render layout: false end diff --git a/app/views/collections/list.html.erb b/app/views/collections/list.html.erb index 22efd618cacefbf4889ea06ed20bb3e01f028973..3c2f0c010bed078ab48e9a645629b4848375864d 100644 --- a/app/views/collections/list.html.erb +++ b/app/views/collections/list.html.erb @@ -3,7 +3,7 @@ <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> - <h4 class="modal-title">Coleções</h4> + <h4 class="modal-title"><%= @title %></h4> </div> <form id="collections-modal-form"> <div class="modal-body"> @@ -23,7 +23,7 @@ </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button> - <button type="submit" class="btn btn-primary">Enviar</button> + <button type="submit" class="btn btn-primary"><%= @send %></button> </div> </form> </div>