Class: FolderItemsActionsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- FolderItemsActionsController
- Defined in:
- app/controllers/folder_items_actions_controller.rb
Overview
use to share folder item actions (email, cite, delete) between folders and bookmarks
Instance Method Summary collapse
Instance Method Details
#folder_item_actions ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/folder_items_actions_controller.rb', line 4 def folder_item_actions @folder = Bpluser::Folder.find(params[:id]) if params[:origin] == "folders" @user = current_or_guest_user if params[:selected] sort = params[:sort] ? params[:sort] : "" per_page = params[:per_page] ? params[:per_page] : "" view = params[:view] ? params[:view] : "" items = params[:selected] case params[:commit] # email when t('blacklight.tools.email') redirect_to email_solr_document_path(:id => items) # cite when t('blacklight.tools.citation') redirect_to citation_solr_document_path(:id => items) # remove when t('blacklight.tools.remove') if params[:origin] == "folders" if @folder.folder_items.where(:document_id => items).delete_all flash[:notice] = I18n.t('blacklight.folders.update_items.remove.success') else flash[:error] = I18n.t('blacklight.folders.update_items.remove.failure') end redirect_to folder_path(:id => @folder, :sort => sort, :per_page => per_page, :view => view) else if current_or_guest_user.bookmarks.where(:document_id => items).delete_all flash[:notice] = I18n.t('blacklight.folders.update_items.remove.success') else flash[:error] = I18n.t('blacklight.folders.update_items.remove.failure') end redirect_to bookmarks_path(:sort => sort, :per_page => per_page, :view => view) end # copy when /#{t('blacklight.tools.copy_to')}/ destination = params[:commit].split(t('blacklight.tools.copy_to') + ' ')[1] if destination == t('blacklight.bookmarks.title') success = items.all? do |item_id| current_or_guest_user.bookmarks.create(:document_id => item_id) unless current_or_guest_user.bookmarks.where(:document_id => item_id).exists? end else folder_to_update = current_user.folders.find(destination) success = items.all? do |item_id| folder_to_update.folder_items.create!(:document_id => item_id) and folder_to_update.touch unless folder_to_update.has_folder_item(item_id) end end redirect_to :back if success folder_display_name = destination == t('blacklight.bookmarks.title') ? t('blacklight.bookmarks.title') : folder_to_update.title flash[:notice] = t('blacklight.folders.update_items.copy.success', :folder_name => folder_display_name) else flash[:error] = t('blacklight.folders.update_items.copy.failure') end end else redirect_to :back flash[:error] = I18n.t('blacklight.folders.update_items.remove.no_items') end end |