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 # Link to some item in the application or to the outside.
21 # reader to init value
23 attr_reader :destination
27 # For :type see #types on whats possible. Giving an unknown type will raise
30 # The :destination parameter is whatever makes sense for the given type.
31 # Usually its the numerical id.
33 # The :name parameter is shown by #to_s if given.
34 def initialize(type, destination, name=false)
35 raise 'given :type=%s is not supported' % type unless types.has_value? type
37 @destination=destination
45 'External Link' => :url,
46 'Asset Position' => :position,
47 'Cash Deposit' => :cashposition,
49 'Blog Commentary' => :comment,
50 'Edit Blog Commentary' => :comment_edit,
51 'Security' => :security,
52 'Organization' => :organization,
53 # 'Document' => :document
54 'Portfolio' => :portfolio,
55 'Figure' => :figurevar,
64 # URL String to the destination of this link
66 url_helpers = Rails.application.routes.url_helpers
68 when :url then @destination
69 when :position then url_helpers.position_path :id=>@destination
70 when :cashposition then url_helpers.cashposition_path :id=>@destination
71 when :order then url_helpers.order_path :id=>@destination
72 when :comment then url_helpers.blog_path :id=>@destination
73 when :comment_edit then url_helpers.new_blog_path :id=>@destination # FIXME: the :new action should not do this
74 when :security then url_helpers.portrait_security_path :id=>@destination
75 when :organization then url_helpers.portrait_organization_path :id=>@destination
76 when :portfolio then url_helpers.show_portfolio_path :id_portfolio=>@destination
77 when :figurevar then url_helpers.figures_path # :id=>@destination - to be implemented
78 when :user then url_helpers.root_path # :id=>@destination - to be implemented
83 # String to present this link to humans.
88 else '%s #%i' % [types.key(@type), @destination] end