infopark_fiona_connector 7.0.1.5.2.3.rc8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +5 -0
- data/app/assets/images/admin/minus.gif +0 -0
- data/app/assets/images/bg80.png +0 -0
- data/app/assets/images/edit.png +0 -0
- data/app/assets/images/icons/mm_generic.png +0 -0
- data/app/assets/images/icons/mm_menu.png +0 -0
- data/app/assets/javascripts/editmarker.js +240 -0
- data/app/assets/javascripts/infopark_rails_connector.js.erb +0 -0
- data/app/assets/stylesheets/editmarker.css +70 -0
- data/app/assets/stylesheets/infopark_rails_connector.css.erb +0 -0
- data/app/controllers/cms_controller.rb +7 -0
- data/app/controllers/rails_connector/default_cms_controller.rb +41 -0
- data/app/helpers/cms_helper.rb +7 -0
- data/app/helpers/cms_routing_helper.rb +7 -0
- data/app/helpers/rails_connector/cms_asset_helper.rb +54 -0
- data/app/helpers/rails_connector/cms_tag_helper.rb +4 -0
- data/app/helpers/rails_connector/default_cms_helper.rb +21 -0
- data/app/helpers/rails_connector/default_cms_routing_helper.rb +119 -0
- data/app/helpers/rails_connector/display_helper.rb +124 -0
- data/app/helpers/rails_connector/editing_helper.rb +7 -0
- data/app/helpers/rails_connector/layout_helper.rb +26 -0
- data/app/helpers/rails_connector/marker_helper.rb +371 -0
- data/app/helpers/rails_connector/table_of_contents_helper.rb +20 -0
- data/app/models/named_link.rb +2 -0
- data/app/views/cms/_index.html.erb +7 -0
- data/app/views/cms/index.html.erb +1 -0
- data/app/views/errors/403_forbidden.html.erb +3 -0
- data/app/views/errors/410_gone.html.erb +7 -0
- data/config/cms_routes.rb +17 -0
- data/config/locales/de.rails_connector.errors.yml +11 -0
- data/config/locales/de.rails_connector.lib.yml +6 -0
- data/config/locales/de.rails_connector.views.yml +9 -0
- data/config/locales/en.rails_connector.errors.yml +10 -0
- data/config/locales/en.rails_connector.lib.yml +6 -0
- data/config/locales/en.rails_connector.views.yml +9 -0
- data/lib/gem_dependencies.rb +68 -0
- data/lib/generators/rails_connector/install/install_generator.rb +37 -0
- data/lib/generators/rails_connector/install/templates/app/models/obj.rb.erb +5 -0
- data/lib/generators/rails_connector/install/templates/initializers/rails_connector.rb +2 -0
- data/lib/generators/rails_connector/install/templates/local/configuration.rb +2 -0
- data/lib/infopark_fiona_connector.rb +44 -0
- data/lib/meta_eager_loader.rb +1 -0
- data/lib/obj.rb +3 -0
- data/lib/rails_connector/attr_dict.rb +169 -0
- data/lib/rails_connector/attr_value_provider.bundle +0 -0
- data/lib/rails_connector/attr_value_provider.so +0 -0
- data/lib/rails_connector/attr_value_provider64.so +0 -0
- data/lib/rails_connector/attribute.rb +93 -0
- data/lib/rails_connector/authenticable.rb +37 -0
- data/lib/rails_connector/basic_obj.rb +571 -0
- data/lib/rails_connector/blob.rb +75 -0
- data/lib/rails_connector/blob_mapping.rb +15 -0
- data/lib/rails_connector/blob_mysql.rb +30 -0
- data/lib/rails_connector/blob_oracle.rb +37 -0
- data/lib/rails_connector/cache_middleware.rb +13 -0
- data/lib/rails_connector/channel.rb +18 -0
- data/lib/rails_connector/cms_accessible.rb +111 -0
- data/lib/rails_connector/cms_base_model.rb +62 -0
- data/lib/rails_connector/cms_dispatch_controller.rb +43 -0
- data/lib/rails_connector/cms_env.rb +65 -0
- data/lib/rails_connector/cms_test_request.rb +8 -0
- data/lib/rails_connector/configuration.rb +174 -0
- data/lib/rails_connector/content.rb +7 -0
- data/lib/rails_connector/core_extensions.rb +1 -0
- data/lib/rails_connector/core_extensions/time.rb +17 -0
- data/lib/rails_connector/date_attribute.rb +26 -0
- data/lib/rails_connector/default_search_request.rb +6 -0
- data/lib/rails_connector/engine.rb +65 -0
- data/lib/rails_connector/errors.rb +6 -0
- data/lib/rails_connector/fiona_datetime.rb +14 -0
- data/lib/rails_connector/fiona_engine.rb +8 -0
- data/lib/rails_connector/html_string.rb +17 -0
- data/lib/rails_connector/job.rb +10 -0
- data/lib/rails_connector/link.rb +148 -0
- data/lib/rails_connector/link_list.rb +28 -0
- data/lib/rails_connector/link_resolvable.rb +5 -0
- data/lib/rails_connector/lucene_search_request.rb +102 -0
- data/lib/rails_connector/markdown_string.rb +17 -0
- data/lib/rails_connector/meta.rb +143 -0
- data/lib/rails_connector/meta/eager_loader.rb +84 -0
- data/lib/rails_connector/named_link.rb +90 -0
- data/lib/rails_connector/news.rb +20 -0
- data/lib/rails_connector/obj_class.rb +138 -0
- data/lib/rails_connector/obj_class_attr.rb +5 -0
- data/lib/rails_connector/object_with_meta_data.rb +13 -0
- data/lib/rails_connector/permission.rb +37 -0
- data/lib/rails_connector/rack_middlewares.rb +5 -0
- data/lib/rails_connector/ses.rb +78 -0
- data/lib/rails_connector/ses/verity_accessor.rb +127 -0
- data/lib/rails_connector/string_tagging.rb +26 -0
- data/lib/rails_connector/verity_search_request.rb +86 -0
- data/lib/search_request.rb +2 -0
- data/lib/version.rb +7 -0
- metadata +277 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
module RailsConnector
|
2
|
+
# This is a wrapper module for the default set of Rails Connector helper modules.
|
3
|
+
#
|
4
|
+
# To make autoloading from +CmsController+ work, this module must be wrapped
|
5
|
+
# by a module named +CmsHelper+:
|
6
|
+
#
|
7
|
+
# module CmsHelper
|
8
|
+
# include RailsConnector::DefaultCmsHelper
|
9
|
+
# end
|
10
|
+
# @api public
|
11
|
+
module DefaultCmsHelper
|
12
|
+
include DisplayHelper
|
13
|
+
include MarkerHelper
|
14
|
+
include CmsAssetHelper
|
15
|
+
include RailsConnector::CmsAssetHelper
|
16
|
+
include RailsConnector::TableOfContentsHelper
|
17
|
+
include RailsConnector::EditingHelper
|
18
|
+
include RailsConnector::LayoutHelper
|
19
|
+
include RailsConnector::CmsTagHelper
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
module RailsConnector
|
2
|
+
# @api public
|
3
|
+
module DefaultCmsRoutingHelper
|
4
|
+
# Returns the path for +target+ using the +CmsController+ routes.
|
5
|
+
# +target+ can be an +Obj+ or a +Link+ or a +LinkList+.
|
6
|
+
# If +target+ is a +Linklist+, it must be non-empty. The first +Link+ from the +LinkList+ will be used.
|
7
|
+
# +options+ are optional and include url settings such as path parameters or protocol.
|
8
|
+
# @return [String]
|
9
|
+
# @api public
|
10
|
+
def cms_path(target, options = {})
|
11
|
+
cms_path_or_url(target, "path", options)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns the absolute URL for target using the +CmsController+ routes.
|
15
|
+
# +target+ can be an +Obj+ or a +Link+ or a +LinkList+.
|
16
|
+
# If +target+ is a +Linklist+, it must be non-empty. The first +Link+ from the +LinkList+ will be used.
|
17
|
+
# +options+ are optional and include url settings such as path parameters or protocol.
|
18
|
+
# @return [String]
|
19
|
+
# @api public
|
20
|
+
def cms_url(target, options = {})
|
21
|
+
cms_path_or_url(target, "url", options)
|
22
|
+
end
|
23
|
+
|
24
|
+
LINK_TO_UNREACHABLE = "#__target_object_not_reachable".freeze
|
25
|
+
LINK_TO_EMPTY_LINKLIST = "#__empty_linklist".freeze
|
26
|
+
|
27
|
+
def cms_path_or_url(target, path_or_url, options = {})
|
28
|
+
if target.is_a?(Link)
|
29
|
+
cms_path_or_url_for_links(target, path_or_url, options)
|
30
|
+
elsif target.is_a?(Obj)
|
31
|
+
cms_path_or_url_for_objs(target, path_or_url, options)
|
32
|
+
elsif target.respond_to?(:first)
|
33
|
+
if target.first.is_a?(Link)
|
34
|
+
cms_path_or_url_for_links(target.first, path_or_url, options)
|
35
|
+
else
|
36
|
+
LINK_TO_EMPTY_LINKLIST
|
37
|
+
end
|
38
|
+
else
|
39
|
+
raise "cms_path or cms_url was called with an instance of #{target.class}. " +
|
40
|
+
"It must only be called with an Obj or a Link or a non-empty LinkList."
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def cms_path_or_url_for_links(link, path_or_url, options = {})
|
45
|
+
return LINK_TO_UNREACHABLE if link.internal? && link.destination_object.nil?
|
46
|
+
|
47
|
+
url = basic_url_or_path_for_link(link, path_or_url, options)
|
48
|
+
url = append_search(url, link) if options.empty?
|
49
|
+
|
50
|
+
append_fragment(url, link)
|
51
|
+
end
|
52
|
+
|
53
|
+
def cms_path_or_url_for_objs(obj, path_or_url, options = {})
|
54
|
+
permalink = obj.permalink
|
55
|
+
ignore_body_data_url = options.delete(:ignore_body_data_url)
|
56
|
+
if permalink && !Configuration.editor_interface_enabled?
|
57
|
+
__send__("cms_permalink_#{path_or_url}", options.merge(permalink: permalink))
|
58
|
+
elsif obj.homepage? && !Configuration.editor_interface_enabled?
|
59
|
+
__send__("root_#{path_or_url}", options)
|
60
|
+
else
|
61
|
+
if obj.body_data_url && !ignore_body_data_url
|
62
|
+
enforce_protocol_from_request(obj.body_data_url)
|
63
|
+
elsif obj.binary? && !obj.file_extension.blank?
|
64
|
+
__send__("cms_id_#{path_or_url}",
|
65
|
+
options.merge(id: obj.id, slug: obj.slug.presence, format: obj.file_extension))
|
66
|
+
else
|
67
|
+
routing_options = options.merge(id: obj.id, slug: obj.slug.presence)
|
68
|
+
__send__("cms_id_#{path_or_url}", routing_options)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def basic_url_or_path_for_link(link, path_or_url, options = {})
|
76
|
+
if link.internal?
|
77
|
+
__send__("cms_#{path_or_url}", link.destination_object, options)
|
78
|
+
else
|
79
|
+
url = if link.external_prefix?
|
80
|
+
remove_external_prefix(link.url)
|
81
|
+
else
|
82
|
+
link.url
|
83
|
+
end
|
84
|
+
|
85
|
+
options.delete(:ignore_body_data_url)
|
86
|
+
url = merge_options(url, options) if options.any?
|
87
|
+
url
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def remove_external_prefix(link)
|
92
|
+
link.gsub(/external:/, "").strip
|
93
|
+
end
|
94
|
+
|
95
|
+
def append_search(url, link)
|
96
|
+
url += "?#{link.search}" unless link.search.blank?
|
97
|
+
url
|
98
|
+
end
|
99
|
+
|
100
|
+
def append_fragment(url, link)
|
101
|
+
url += "##{link.fragment}" unless link.fragment.blank?
|
102
|
+
url
|
103
|
+
end
|
104
|
+
|
105
|
+
def merge_options(url, options)
|
106
|
+
parsed_url = URI.parse(url)
|
107
|
+
|
108
|
+
search = Rack::Utils.parse_query(parsed_url.query)
|
109
|
+
merged_search = search.merge(options.stringify_keys)
|
110
|
+
parsed_url.query = merged_search.to_query
|
111
|
+
|
112
|
+
parsed_url.to_s
|
113
|
+
end
|
114
|
+
|
115
|
+
def enforce_protocol_from_request(url)
|
116
|
+
request.ssl? && !url.starts_with?("https") ? url.gsub(/^http/, "https") : url
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module RailsConnector
|
2
|
+
# This module contains a helper that can be used to render attributes of the CMS models.
|
3
|
+
# @api public
|
4
|
+
module DisplayHelper
|
5
|
+
# For a consistent look of your site and easy maintenance, only the display helpers
|
6
|
+
# should be used to render an attribute <em>value</em> of a CMS model.
|
7
|
+
#
|
8
|
+
# <%= display_value @obj.title %>
|
9
|
+
# Renders the value, taking its type into account.
|
10
|
+
# * An HtmlString will be exported by converting its links
|
11
|
+
# * A Time will be exported in an international form: Year-Month-Day Hour:Minutes
|
12
|
+
# * A non-HTML String will be quoted
|
13
|
+
# * other values will be rendered unchanged
|
14
|
+
#
|
15
|
+
# @api public
|
16
|
+
def display_value(value)
|
17
|
+
case value
|
18
|
+
when MarkdownString then markdown(convert_links(value)).html_safe
|
19
|
+
when HtmlString then convert_links(value).html_safe
|
20
|
+
when String then html_escape_once(value).html_safe
|
21
|
+
when Time then html_escape_once(l(value)).html_safe
|
22
|
+
else value
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def display_original_value(value)
|
27
|
+
case value
|
28
|
+
when HtmlString then convert_links(value, ignore_body_data_url: true).html_safe
|
29
|
+
else display_value(value)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Renders a field from the CMS, including an edit marker for the preview
|
34
|
+
# If the option :marker is +false+, no edit marker will be rendered.
|
35
|
+
#
|
36
|
+
# <%= display_field @obj, :title %>
|
37
|
+
#
|
38
|
+
# When creating an edit marker, all options except :marker are passed to {MarkerHelper#edit_marker}.
|
39
|
+
#
|
40
|
+
# @api public
|
41
|
+
def display_field(obj, attr, options = {})
|
42
|
+
options.reverse_merge!({
|
43
|
+
marker: !%i(id path created last_changed version).include?(attr.to_sym)
|
44
|
+
})
|
45
|
+
if options.delete :marker
|
46
|
+
edit_marker(obj, attr, options) do |obj, attr|
|
47
|
+
display_value obj[attr]
|
48
|
+
end
|
49
|
+
else
|
50
|
+
display_value obj[attr]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Legacy method - deprecated
|
55
|
+
#
|
56
|
+
# Use display_value and display_field instead
|
57
|
+
def display(*args)
|
58
|
+
options = if args.last.is_a? Hash
|
59
|
+
args.pop
|
60
|
+
else
|
61
|
+
{}
|
62
|
+
end
|
63
|
+
return display_value(args.first) if args.size == 1
|
64
|
+
|
65
|
+
display_field(args[0], args[1], options)
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def markdown(string)
|
71
|
+
require "maruku"
|
72
|
+
Maruku.new(string).to_html
|
73
|
+
end
|
74
|
+
|
75
|
+
LINK_PATTERN = '<?\binternallink:(\d+)\b>?'.freeze
|
76
|
+
LINK_EXPRESSION = /#{LINK_PATTERN}/.freeze
|
77
|
+
|
78
|
+
def convert_links(content_attribute, cms_path_options = {})
|
79
|
+
return content_attribute unless content_attribute =~ LINK_EXPRESSION
|
80
|
+
|
81
|
+
link_map = content_attribute.source.text_links.each_with_object({}) do |link, map|
|
82
|
+
map[link.id.to_s] = link
|
83
|
+
end
|
84
|
+
content_attribute.gsub(/#{LINK_PATTERN}(['"]?)/) do
|
85
|
+
link = link_map[Regexp.last_match(1).to_s]
|
86
|
+
if link.blank?
|
87
|
+
"#{CmsRoutingHelper::LINK_TO_UNREACHABLE}#{Regexp.last_match(2)}"
|
88
|
+
else
|
89
|
+
uri = "#{cms_path(link, cms_path_options)}#{Regexp.last_match(2)}"
|
90
|
+
if link.markdown?
|
91
|
+
markdown_link(link, uri)
|
92
|
+
else
|
93
|
+
html_link(link, uri)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def html_link(link, uri)
|
100
|
+
subst = uri
|
101
|
+
name, value =
|
102
|
+
case link.tag_name
|
103
|
+
when "img", "input"
|
104
|
+
["alt", link.title || ""]
|
105
|
+
when "a", "link"
|
106
|
+
["title", begin link.title unless link.title.blank? end]
|
107
|
+
end
|
108
|
+
subst << %( #{name}="#{html_escape_once(value)}") if value
|
109
|
+
subst << %( target="#{html_escape_once(link.target)}") unless link.target.blank?
|
110
|
+
subst
|
111
|
+
end
|
112
|
+
|
113
|
+
def markdown_link(link, uri)
|
114
|
+
subst = "<#{uri}>"
|
115
|
+
unless link.title.blank?
|
116
|
+
case link.markdown_type
|
117
|
+
when "inline", "reference"
|
118
|
+
subst << %( "#{html_escape_once(link.title)}")
|
119
|
+
end
|
120
|
+
end
|
121
|
+
subst
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module RailsConnector
|
2
|
+
# This module contains helpers that render tags for the html head
|
3
|
+
# and the end of the html body.
|
4
|
+
# @api public
|
5
|
+
module LayoutHelper
|
6
|
+
# Renders all tags needed in the html head.
|
7
|
+
# @api public
|
8
|
+
def rails_connector_header_tags
|
9
|
+
html = "".html_safe
|
10
|
+
html += tag("meta", name: "generator",
|
11
|
+
content: "Rails Connector for Infopark CMS Fiona by Infopark AG (www.infopark.de)")
|
12
|
+
html += include_edit_marker_support
|
13
|
+
html += include_editing_stylesheet
|
14
|
+
html
|
15
|
+
end
|
16
|
+
|
17
|
+
# Renders all tags needed at the end of the body tag.
|
18
|
+
# @api public
|
19
|
+
def rails_connector_after_content_tags
|
20
|
+
html = "".html_safe
|
21
|
+
html += render_marker_code
|
22
|
+
html += include_editing_javascript
|
23
|
+
html
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,371 @@
|
|
1
|
+
module RailsConnector
|
2
|
+
# This module contains helpers that can be used to build markers for the preview.
|
3
|
+
#
|
4
|
+
# The helpers will not render anything if not in editor mode!
|
5
|
+
# See {RailsConnector::Configuration} for information on modes.
|
6
|
+
#
|
7
|
+
# All helpers have the following <em>options</em>, unknown options are passed
|
8
|
+
# to the HTML element which is being created:
|
9
|
+
#
|
10
|
+
# [:context] the context object that will be shown in the preview after editing
|
11
|
+
# [:size] the symbolic size of the target window to open
|
12
|
+
# [:target] the target frame in which the edit window is to be opened.
|
13
|
+
#
|
14
|
+
# You can specify the size of the edit window by means of the <tt>:size</tt> option:
|
15
|
+
#
|
16
|
+
# [<tt>'n'</tt>] normal browser window
|
17
|
+
# [<tt>'udl'</tt>] undecorated large browser window
|
18
|
+
# [<tt>'uds'</tt>] undecorated small browser window
|
19
|
+
# [<tt>'udt'</tt>] undecorated tiny browser window
|
20
|
+
#
|
21
|
+
# The <tt>:target</tt> option becomes the <tt>target</tt> attribute of the <tt><a></tt> tag.
|
22
|
+
# @api public
|
23
|
+
module MarkerHelper
|
24
|
+
# Renders an edit marker for a named attribute of an active object in the preview.
|
25
|
+
# <em>obj</em> is the Obj to edit, <em>attr</em> the attribute as a Symbol or String.
|
26
|
+
# The helper will render nothing if the object is inactive! The :context defaults to obj.
|
27
|
+
#
|
28
|
+
# The following code will render an edit marker for the title attribute of the current object:
|
29
|
+
#
|
30
|
+
# <%= edit_marker @obj, :title %>
|
31
|
+
#
|
32
|
+
# By passing a block, the evaluated block will be included in the marker:
|
33
|
+
# <%= edit_marker @obj, :title do |obj, attr|
|
34
|
+
# display_value obj[attr]
|
35
|
+
# end %>
|
36
|
+
#
|
37
|
+
# The last form is the default of {DisplayHelper#display_field} without the option <code>:marker => false</code>.
|
38
|
+
# When the blob evaluates to nil, an empty string or array, the markup of the option +:default_value+
|
39
|
+
# will be rendered.
|
40
|
+
#
|
41
|
+
# Hint: You should not render edit markers within elements that are hidden via CSS (<code>display:none</code>),
|
42
|
+
# otherwise they cannot be displayed correctly.
|
43
|
+
# @api public
|
44
|
+
def edit_marker(obj, attr, options = {})
|
45
|
+
if Configuration.editor_interface_enabled? && !session[:hide_editmarkers]
|
46
|
+
context = (options.delete :context) || @obj
|
47
|
+
default_value = options.delete(:default_value)
|
48
|
+
|
49
|
+
if block_given?
|
50
|
+
content = yield(obj, attr)
|
51
|
+
content = default_value || raw(" ") if content.blank?
|
52
|
+
else
|
53
|
+
content = attr.to_s.humanize
|
54
|
+
content = obj.name + ": " + content if obj != context
|
55
|
+
end
|
56
|
+
|
57
|
+
marker_id = store_marker_definition(
|
58
|
+
obj_id: obj.id,
|
59
|
+
attribute: format_attribute_name_for_gui(attr),
|
60
|
+
context_id: context ? context.id : nil,
|
61
|
+
size: options.delete(:size),
|
62
|
+
target: options.delete(:target),
|
63
|
+
memberships: required_memberships_for_editing(obj, attr)
|
64
|
+
)
|
65
|
+
|
66
|
+
store_edit_marker_markup(content_tag(:a, "",
|
67
|
+
class: "nps_edit_marker nps_marker_id_#{marker_id}"))
|
68
|
+
|
69
|
+
tag_type = options.delete(:tag) || :span
|
70
|
+
content_tag(
|
71
|
+
tag_type,
|
72
|
+
content.to_s,
|
73
|
+
options.merge(class: (options[:class]).to_s, id: "nps_marker_id_#{marker_id}")
|
74
|
+
)
|
75
|
+
else
|
76
|
+
block_given? ? yield(obj, attr) : nil
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Renders a link which the editor can use to toggle on/off the editmarkers shown
|
81
|
+
# in the preview.
|
82
|
+
# This link will only be shown if the Rails Connector is in <tt>editor</tt> mode.
|
83
|
+
# <em>value</em> the link text or e.g. an image_tag
|
84
|
+
# @api public
|
85
|
+
def toggle_edit_marker_link(value)
|
86
|
+
link_to value, toggle_markers_url(@obj) if Configuration.editor_interface_enabled?
|
87
|
+
end
|
88
|
+
|
89
|
+
# Renders a marker for an action to be performed with any number of objects.
|
90
|
+
# <em>action</em> the attribute as a Symbol or String.
|
91
|
+
# <em>objs</em> is an Array containing a single, none or more than one Obj.
|
92
|
+
# The helper has additional options:
|
93
|
+
# [:permissions] is an Array of permissions the current user needs to use
|
94
|
+
# the marker: :read, :write, :root, :create_children - defaults to [:read].
|
95
|
+
# This option is available for a single Obj passed to <em>objs</em>.
|
96
|
+
# [:params] a hash of parameters to be passed to the action.
|
97
|
+
#
|
98
|
+
# The following code will render an action marker for the release action of the current object:
|
99
|
+
#
|
100
|
+
# <%= action_marker :workflow_release, [@obj] %>
|
101
|
+
# @api public
|
102
|
+
def action_marker(action, objs, options = {})
|
103
|
+
return unless Configuration.editor_interface_enabled?
|
104
|
+
|
105
|
+
context = (options.delete :context) || @obj
|
106
|
+
size = options.delete(:size)
|
107
|
+
target = options.delete(:target) || "_blank"
|
108
|
+
params = options.delete(:params)
|
109
|
+
permissions = options.delete(:permissions) || [:read]
|
110
|
+
|
111
|
+
memberships = if objs.size == 1
|
112
|
+
required_memberships_for_permissions(objs.first, permissions)
|
113
|
+
else
|
114
|
+
[]
|
115
|
+
end
|
116
|
+
|
117
|
+
marker_id = store_marker_definition(
|
118
|
+
memberships: memberships
|
119
|
+
)
|
120
|
+
|
121
|
+
link_to(
|
122
|
+
block_given? ? yield : action.to_s.humanize,
|
123
|
+
uri_for_action_marker(action, objs, context, size, target, params),
|
124
|
+
options.merge(class: ["nps_action_marker", "nps_marker_id_#{marker_id}", options[:class]].compact.join(" "))
|
125
|
+
)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Generates an edit marker link.
|
129
|
+
#
|
130
|
+
# [name] the link caption.
|
131
|
+
# [obj] the object for which the edit dialog will be generated.
|
132
|
+
# [attr] the attribute for which the edit dialog will be generated.
|
133
|
+
# [options] options for the edit dialog (see {MarkerHelper#edit_marker}).
|
134
|
+
# @api public
|
135
|
+
def link_to_edit(name, obj, attr, options = {})
|
136
|
+
if Configuration.editor_interface_enabled?
|
137
|
+
context = (options.delete :context) || @obj
|
138
|
+
size = options.delete(:size)
|
139
|
+
target = options.delete(:target) || "_blank"
|
140
|
+
|
141
|
+
link_to name.to_s, "#", onclick: "inline_editing.openEditDialog('#{obj.id}', '#{attr}', '#{context.id || "null"}', '#{size || "null"}', '#{target || "null"}'); return false;"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# Renders a folding menu which can be used to insert various edit actions or
|
146
|
+
# informations.
|
147
|
+
#
|
148
|
+
# [left] the left offset.
|
149
|
+
# [top] the top offset.
|
150
|
+
# [&block] the content which will be displayed in the menu.
|
151
|
+
#
|
152
|
+
# To generate a menu you have to create one using the {#marker_menu} helper.
|
153
|
+
# Than you have to mark the target for which the menu should be displayed
|
154
|
+
# using the {#marker_menu_target} helper.
|
155
|
+
#
|
156
|
+
# Usage:
|
157
|
+
# <%= marker_menu do %>
|
158
|
+
# Menu
|
159
|
+
# <% end %>
|
160
|
+
#
|
161
|
+
# <%= marker_menu_target(:div) do %>
|
162
|
+
# Content
|
163
|
+
# <% end %>
|
164
|
+
# @api public
|
165
|
+
def marker_menu(left = 0, top = 0, &block)
|
166
|
+
self.current_marker_menu_id = store_marker_definition(
|
167
|
+
offset_left: left,
|
168
|
+
offset_top: top
|
169
|
+
)
|
170
|
+
store_marker_markup(content_tag(
|
171
|
+
:div,
|
172
|
+
marker_menu_markup(capture(&block)),
|
173
|
+
class: "nps_marker_menu nps_marker_id_#{current_marker_menu_id}",
|
174
|
+
id: "nps_marker_menu_#{current_marker_menu_id}"
|
175
|
+
))
|
176
|
+
nil
|
177
|
+
end
|
178
|
+
|
179
|
+
# Marks the given content to display the previous defined marker menu.
|
180
|
+
#
|
181
|
+
# [tag_name] the tag in which the content will be displayed.
|
182
|
+
# [options] the options for the tag.
|
183
|
+
# [&block] the content which will be displayed with the menu.
|
184
|
+
#
|
185
|
+
# See {#marker_menu} for an example.
|
186
|
+
# @api public
|
187
|
+
def marker_menu_target(tag_name, options = {}, &block)
|
188
|
+
content_tag(
|
189
|
+
tag_name,
|
190
|
+
capture(&block),
|
191
|
+
options.merge(class: "#{marker_menu_target_class} #{options[:class]}")
|
192
|
+
)
|
193
|
+
end
|
194
|
+
|
195
|
+
# Returns the css class used for the target element where the marker menu
|
196
|
+
# should be displayed.
|
197
|
+
#
|
198
|
+
# Will be used automatically if you use the helpers {#marker_menu} and
|
199
|
+
# {#marker_menu_target}. But if you want to set a marker menu manually to
|
200
|
+
# an element (e.g. an image) you need to supply this css class.
|
201
|
+
# @api public
|
202
|
+
def marker_menu_target_class
|
203
|
+
if Configuration.editor_interface_enabled?
|
204
|
+
"nps_marker_menu_target nps_marker_menu_target_#{current_marker_menu_id}"
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
# Renders the necessary JavaScript and CSS includes to use the edit markers.
|
209
|
+
def include_edit_marker_support
|
210
|
+
if Configuration.editor_interface_enabled?
|
211
|
+
raw <<-EOF
|
212
|
+
#{stylesheet_link_tag :editmarker}
|
213
|
+
#{javascript_include_tag :editmarker}
|
214
|
+
#{content_tag(:script, type: "text/javascript") { "inline_editing.init();" }}
|
215
|
+
EOF
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
# Renders the necessary marker code to use edit markers and marker menus.
|
220
|
+
def render_marker_code
|
221
|
+
return unless Configuration.editor_interface_enabled?
|
222
|
+
|
223
|
+
html = raw("#{render_marker_definitions}\n#{render_marker_menus}\n#{render_edit_markers}")
|
224
|
+
reset_marker_code
|
225
|
+
html
|
226
|
+
end
|
227
|
+
|
228
|
+
# This helper method can be used in {#marker_menu} to generate a list with
|
229
|
+
# actions using {#edit_item} or {#action_item}. For each action a icon and
|
230
|
+
# title will be shown.
|
231
|
+
#
|
232
|
+
# Usage:
|
233
|
+
# <%= marker_menu do %>
|
234
|
+
# <%= iconlist do %>
|
235
|
+
# <%= edit_item("edit title", "css_class", @obj, :image) %>
|
236
|
+
# <%= action_item("edit image", "css_class", [@obj], :editImage) %>
|
237
|
+
# <% end %>
|
238
|
+
# <% end %>
|
239
|
+
# @api public
|
240
|
+
def iconlist(&block)
|
241
|
+
content_tag(:ul, capture(&block)) if block_given?
|
242
|
+
end
|
243
|
+
|
244
|
+
# Creates an edit marker item for the list generated by {#iconlist}.
|
245
|
+
#
|
246
|
+
# [title] the title which will be displayed.
|
247
|
+
# [css_class] the css-class can be used to display a different icon.
|
248
|
+
# [obj] the object for which the edit dialog will be generated.
|
249
|
+
# [attribute] the attribute for which the edit dialog will be generated.
|
250
|
+
# [options] options that will be delegated to the {#link_to_edit} helper.
|
251
|
+
# @api public
|
252
|
+
def edit_item(title, css_class, obj, attribute, options = {})
|
253
|
+
edit_link = link_to_edit(content_tag(:span, title, class: css_class), obj, attribute, options)
|
254
|
+
content_tag(:li, edit_link)
|
255
|
+
end
|
256
|
+
|
257
|
+
# Creates an action marker item for the list generated by {#iconlist}.
|
258
|
+
#
|
259
|
+
# [title] the title which will be displayed.
|
260
|
+
# [css_class] the css-class can be used to display a different icon.
|
261
|
+
# [objs] the array of objects for which the action dialog will be generated.
|
262
|
+
# [action] the action for which the action dialog will be generated.
|
263
|
+
# [options] options that will be delegated to the {#action_marker} helper.
|
264
|
+
# @api public
|
265
|
+
def action_item(title, css_class, objs, action, options = {})
|
266
|
+
action_link = action_marker(action, objs, options) { content_tag(:span, title, class: css_class) }
|
267
|
+
content_tag(:li, action_link)
|
268
|
+
end
|
269
|
+
|
270
|
+
private
|
271
|
+
|
272
|
+
attr_writer :current_marker_menu_id
|
273
|
+
|
274
|
+
def current_marker_menu_id
|
275
|
+
@current_marker_menu_id or raise "Tried to create a marker menu target before a marker menu was created!"
|
276
|
+
end
|
277
|
+
|
278
|
+
JS_HEADER = <<~ENDOFSTRING.freeze
|
279
|
+
<script type="text/javascript">
|
280
|
+
// <![CDATA[
|
281
|
+
ENDOFSTRING
|
282
|
+
|
283
|
+
JS_FOOTER = <<~ENDOFSTRING.freeze
|
284
|
+
// ]]>
|
285
|
+
</script>
|
286
|
+
ENDOFSTRING
|
287
|
+
|
288
|
+
def store_marker_definition(definition)
|
289
|
+
@marker_definitions ||= {}
|
290
|
+
marker_id = random_marker_id
|
291
|
+
@marker_definitions[marker_id] = definition
|
292
|
+
marker_id
|
293
|
+
end
|
294
|
+
|
295
|
+
def random_marker_id
|
296
|
+
rand(1_000_000_000)
|
297
|
+
end
|
298
|
+
|
299
|
+
def render_marker_definitions
|
300
|
+
return unless @marker_definitions.present?
|
301
|
+
|
302
|
+
"#{JS_HEADER}inline_editing.storeMarkerDefinitions(#{@marker_definitions.to_json});" +
|
303
|
+
JS_FOOTER.to_s
|
304
|
+
end
|
305
|
+
|
306
|
+
def store_marker_markup(markup)
|
307
|
+
@marker_markup ||= []
|
308
|
+
@marker_markup << markup
|
309
|
+
end
|
310
|
+
|
311
|
+
def store_edit_marker_markup(markup)
|
312
|
+
@edit_marker_markup ||= []
|
313
|
+
@edit_marker_markup << markup
|
314
|
+
end
|
315
|
+
|
316
|
+
def reset_marker_code
|
317
|
+
@marker_definitions = @marker_markup = @edit_marker_markup = nil
|
318
|
+
end
|
319
|
+
|
320
|
+
def render_marker_menus
|
321
|
+
(@marker_markup || []).join
|
322
|
+
end
|
323
|
+
|
324
|
+
def render_edit_markers
|
325
|
+
(@edit_marker_markup || []).join
|
326
|
+
end
|
327
|
+
|
328
|
+
def required_memberships_for_editing(obj, attr)
|
329
|
+
permissions = [:read]
|
330
|
+
permissions << if %i(name obj_class workflow suppressexport permalink).include?(attr.to_sym)
|
331
|
+
:root
|
332
|
+
else
|
333
|
+
:write
|
334
|
+
end
|
335
|
+
|
336
|
+
required_memberships_for_permissions(obj, permissions)
|
337
|
+
end
|
338
|
+
|
339
|
+
def required_memberships_for_permissions(obj, permissions)
|
340
|
+
permissions.map { |perm| obj.permissions.__send__(perm) }
|
341
|
+
end
|
342
|
+
|
343
|
+
def uri_for_action_marker(action, objects, context = nil, size = nil, target = nil, params = nil)
|
344
|
+
action = action.to_s
|
345
|
+
objectIds = objects.collect(&:id).to_json
|
346
|
+
contextId = context.nil? ? "null" : context.id
|
347
|
+
size = size.nil? ? "null" : "'#{size}'"
|
348
|
+
target = target.nil? ? "null" : "'#{target}'"
|
349
|
+
params = params.blank? ? "null" : "'#{escape_javascript(params.to_json.gsub('"', "%22"))}'"
|
350
|
+
"javascript:parent.openActionDialog('#{action}',#{objectIds},#{contextId},#{params},#{size},#{target})"
|
351
|
+
end
|
352
|
+
|
353
|
+
def format_attribute_name_for_gui(attr)
|
354
|
+
attr = attr.to_s
|
355
|
+
attr = "blob" if attr == "body"
|
356
|
+
attr = attr.camelize(:lower) if %w(valid_from valid_until obj_class).include? attr
|
357
|
+
attr
|
358
|
+
end
|
359
|
+
|
360
|
+
def marker_menu_markup(content)
|
361
|
+
raw %(<a class="nps_marker_menu_button" name="nps_marker_menu_button" href="#">MENU</a>
|
362
|
+
<div class="nps_marker_menu_content" style="display:none;">
|
363
|
+
<div class="b1"></div><div class="b2"></div><div class="b3"></div><div class="b4"></div>
|
364
|
+
<div class="core">
|
365
|
+
#{content}
|
366
|
+
</div>
|
367
|
+
<div class="b4"></div><div class="b3"></div><div class="b2"></div><div class="b1"></div>
|
368
|
+
</div>)
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|