2 # This file is part of SMR.
4 # SMR is free software: you can redistribute it and/or modify it under the
5 # terms of the GNU General Public License as published by the Free Software
6 # Foundation, either version 3 of the License, or (at your option) any later
9 # SMR is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # SMR. If not, see <http://www.gnu.org/licenses/>.
18 # handles CRUD on Bookmark records
19 class Objects::BookmarkController < ObjectsController
22 # List all Bookmark records for editing.
25 session[:objects_bookmark_query] = params[:q] if params[:q]
27 @query = Bookmark.ransack(session[:objects_bookmark_query])
28 @bookmarks, @total_pages = smr_paginate(
35 # defines empty Bookmark to #create a new one
37 @securities = smr_securities_list
38 @organizations = smr_organizations_list(:drop_universe=>false)
39 @portfolios = smr_portfolios_list(:show_all=>true)
40 @figure_vars = FigureVar.for_user(current_user.id)
42 @bookmark = Bookmark.new(:id_user=>current_user.id)
46 # retrieve Bookmark for editing
49 @bookmark = Bookmark.for_user(current_user).where(:id=>params[:id]).first
54 # handles creates and updates
58 if params[:bookmark][:id].to_i > 0 then
59 bookmark = Bookmark.for_user(current_user).where(:id=>params[:bookmark][:id]).first
60 bookmark.update(bookmark_params)
61 else bookmark = Bookmark.create(bookmark_params.merge({:id_user=>current_user.id})) end
63 bookmark.id_user = params[:mark_bookmark_private] == '1' ? current_user.id : 0
65 n << bookmark.errors.full_messages.uniq
67 redirect_to objects_bookmark_index_path, :notice=>n.compact.flatten.join(', ')
73 b = Bookmark.find(params[:id])
75 rescue ActiveRecord::DeleteRestrictionError => errors
76 flash[:alert] = errors.to_s
79 redirect_to :action=>:index
85 # internal helper defining parameters acceptable for Bookmark create/update
87 params.require(:bookmark).permit(
89 :id_security, :id_organization, :id_portfolio, :id_figure_var