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/>.
19 # Link to some item in the application or to the outside.
22 # reader to init value
27 # For :type see #types on whats possible. Giving an unknown type will raise
30 # The :target parameter is whatever makes sense for the given type.
31 # Usually its the numerical id.
32 def initialize(type, target)
33 raise 'given :type is not supported' unless types.has_value? type
42 'External Link' => :url,
43 'Asset Position' => :position,
44 'Cash Deposit' => :cashposition,
46 'Blog Commentary' => :comment,
47 'Edit Blog Commentary' => :comment_edit,
48 'Security' => :security,
49 'Organization' => :organization,
50 # 'Document' => :document
58 # URL String to the destination of this link
60 url_helpers = Rails.application.routes.url_helpers
62 when :url then @target
63 when :position then url_helpers.position_path :id=>@target
64 when :cashposition then url_helpers.cashposition_path :id=>@target
65 when :order then url_helpers.order_path :id=>@target
66 when :comment then url_helpers.blog_path :id=>@target
67 when :comment_edit then url_helpers.new_blog_path :id=>@target # FIXME: the :new action should not do this
68 when :security then url_helpers.portrait_security_path :id=>@target
69 when :organization then url_helpers.portrait_organization_path :id=>@target
74 # String to present this link to humans.
77 @target.to_s # do something better here
78 else '%s #%i' % [types.key(@type), @target] end