infopark_fiona_connector 6.8.0.110.6570b45 → 6.8.0.210.ed204b0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,363 @@
1
+ module RailsConnector
2
+
3
+ # This module contains helpers that can be used to build markers for the preview.
4
+ #
5
+ # The helpers will not render anyhing if not in editor mode!
6
+ # See RailsConnector::Configuration for information on modes.
7
+ #
8
+ # All helpers have the following <em>options</em>, unknown options are passed
9
+ # to the HTML element which is being created:
10
+ #
11
+ # [:context] the context object that will be shown in the preview after editing
12
+ # [:size] the symbolic size of the target window to open
13
+ # [:target] the target frame in which the edit window is to be opened.
14
+ #
15
+ # You can specify the size of the edit window by means of the <tt>:size</tt> option:
16
+ #
17
+ # [<tt>'n'</tt>] normal browser window
18
+ # [<tt>'udl'</tt>] undecorated large browser window
19
+ # [<tt>'uds'</tt>] undecorated small browser window
20
+ # [<tt>'udt'</tt>] undecorated tiny browser window
21
+ #
22
+ # The <tt>:target</tt> option becomes the <tt>target</tt> attribute of the <tt><a></tt> tag.
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 :marker => false.
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 (display:none),
42
+ # otherwise they cannot be displayed correctly.
43
+ def edit_marker(obj, attr, options = {}, &block)
44
+ if Configuration.editor_interface_enabled? && !session[:hide_editmarkers]
45
+ context = (options.delete :context) || @obj
46
+ default_value = options.delete(:default_value)
47
+
48
+ if block_given?
49
+ content = block.call(obj, attr)
50
+ content = default_value || raw("&nbsp;") if content.blank?
51
+ else
52
+ content = attr.to_s.humanize
53
+ content = obj.name + ": " + content if obj != context
54
+ end
55
+
56
+ marker_id = store_marker_definition(
57
+ :obj_id => obj.id,
58
+ :attribute => format_attribute_name_for_gui(attr),
59
+ :context_id => context ? context.id : nil,
60
+ :size => options.delete(:size),
61
+ :target => options.delete(:target),
62
+ :memberships => required_memberships_for_editing(obj, attr)
63
+ )
64
+
65
+ store_edit_marker_markup(content_tag(:a, "",
66
+ :class => "nps_edit_marker nps_marker_id_#{marker_id}"))
67
+
68
+ tag_type = options.delete(:tag) || :span
69
+ content_tag(
70
+ tag_type,
71
+ content.to_s,
72
+ options.merge(:class => "#{options[:class]}", :id => "nps_marker_id_#{marker_id}")
73
+ )
74
+ else
75
+ block_given? ? block.call(obj, attr) : nil
76
+ end
77
+ end
78
+
79
+ # Renders a link which the editor can use to toggle on/off the editmarkers shown
80
+ # in the preview.
81
+ # This link will only be shown if the Rails Connector is in <tt>editor</tt> mode.
82
+ # <em>value</em> the link text or e.g. an image_tag
83
+ def toggle_edit_marker_link(value)
84
+ if Configuration.editor_interface_enabled?
85
+ link_to value, toggle_markers_url(@obj)
86
+ end
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
+ def action_marker(action, objs, options = {}, &block)
102
+ return unless Configuration.editor_interface_enabled?
103
+
104
+ context = (options.delete :context) || @obj
105
+ size = options.delete(:size)
106
+ target = options.delete(:target) || "_blank"
107
+ params = options.delete(:params)
108
+ permissions = options.delete(:permissions) || [:read]
109
+
110
+ if objs.size == 1
111
+ memberships = required_memberships_for_permissions(objs.first, permissions)
112
+ else
113
+ memberships = []
114
+ end
115
+
116
+ marker_id = store_marker_definition(
117
+ :memberships => memberships
118
+ )
119
+
120
+ link_to(
121
+ block_given? ? block.call : action.to_s.humanize,
122
+ uri_for_action_marker(action, objs, context, size, target, params),
123
+ options.merge(:class => ["nps_action_marker", "nps_marker_id_#{marker_id}", options[:class]].compact.join(' '))
124
+ )
125
+ end
126
+
127
+ # Generates an edit marker link.
128
+ #
129
+ # [name] the link caption.
130
+ # [obj] the object for which the edit dialog will be generated.
131
+ # [attr] the attribute for which the edit dialog will be generated.
132
+ # [options] options for the edit dialog (see +edit_marker+).
133
+ def link_to_edit(name, obj, attr, options = {})
134
+ if Configuration.editor_interface_enabled?
135
+ context = (options.delete :context) || @obj
136
+ size = options.delete(:size)
137
+ target = options.delete(:target) || "_blank"
138
+
139
+ link_to_function(name.to_s,
140
+ "inline_editing.openEditDialog('#{obj.id}', '#{attr}', '#{context.id || 'null'}', '#{size || 'null'}', '#{target || 'null'}')"
141
+ )
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
+ def marker_menu(left=0, top=0, &block)
165
+ self.current_marker_menu_id = store_marker_definition(
166
+ :offset_left => left,
167
+ :offset_top => top
168
+ )
169
+ store_marker_markup(content_tag(
170
+ :div,
171
+ marker_menu_markup(capture(&block)),
172
+ :class => "nps_marker_menu nps_marker_id_#{current_marker_menu_id}",
173
+ :id => "nps_marker_menu_#{current_marker_menu_id}"
174
+ ))
175
+ nil
176
+ end
177
+
178
+ # Marks the given content to display the previous defined marker menu.
179
+ #
180
+ # [tag_name] the tag in which the content will be displayed.
181
+ # [options] the options for the tag.
182
+ # [&block] the content which will be displayed with the menu.
183
+ #
184
+ # See +marker_menu+ for an example.
185
+ def marker_menu_target(tag_name, options = {}, &block)
186
+ content_tag(
187
+ tag_name,
188
+ capture(&block),
189
+ options.merge(:class => "#{marker_menu_target_class} #{options[:class]}")
190
+ )
191
+ end
192
+
193
+ # Returns the css class used for the target element where the marker menu
194
+ # should be displayed.
195
+ #
196
+ # Will be used automatically if you use the helpers +marker_menu+ and
197
+ # +marker_menu_target+. But if you want to set a marker menu manually to
198
+ # an element (e.g. an image) you need to supply this css class.
199
+ def marker_menu_target_class
200
+ "nps_marker_menu_target nps_marker_menu_target_#{current_marker_menu_id}" if Configuration.editor_interface_enabled?
201
+ end
202
+
203
+ # Renders the necessary JavaScript and CSS includes to use the edit markers.
204
+ def include_edit_marker_support # :nodoc:
205
+ if Configuration.editor_interface_enabled?
206
+ raw <<-EOF
207
+ #{stylesheet_link_tag :editmarker}
208
+ #{javascript_include_tag :editmarker}
209
+ #{content_tag(:script, :type => 'text/javascript') { 'inline_editing.init();' }}
210
+ EOF
211
+ end
212
+ end
213
+
214
+ # Renders the necessary marker code to use edit markers and marker menus.
215
+ def render_marker_code # :nodoc:
216
+ return unless Configuration.editor_interface_enabled?
217
+ html = raw("#{render_marker_definitions}\n#{render_marker_menus}\n#{render_edit_markers}")
218
+ reset_marker_code
219
+ html
220
+ end
221
+
222
+ # This helper method can be used in +marker_menu+ to generate a list with
223
+ # actions using +edit_item+ or +action_item+. For each action a icon and
224
+ # title will be shown.
225
+ #
226
+ # Usage:
227
+ # <%= marker_menu do %>
228
+ # <%= iconlist do %>
229
+ # <%= edit_item("edit title", "css_class", @obj, :image) %>
230
+ # <%= action_item("edit image", "css_class", [@obj], :editImage) %>
231
+ # <% end %>
232
+ # <% end %>
233
+ def iconlist(&block)
234
+ content_tag(:ul, capture(&block)) if block_given?
235
+ end
236
+
237
+ # Creates an edit marker item for the list generated by +iconlist+.
238
+ #
239
+ # [title] the title which will be displayed.
240
+ # [css_class] the css-class can be used to display a different icon.
241
+ # [obj] the object for which the edit dialog will be generated.
242
+ # [attribute] the attribute for which the edit dialog will be generated.
243
+ # [options] options that will be delegated to the +link_to_edit+ helper.
244
+ def edit_item(title, css_class, obj, attribute, options = {})
245
+ edit_link = link_to_edit(content_tag(:span, title, :class => css_class), obj, attribute, options)
246
+ content_tag(:li, edit_link)
247
+ end
248
+
249
+ # Creates an action marker item for the list generated by +iconlist+.
250
+ #
251
+ # [title] the title which will be displayed.
252
+ # [css_class] the css-class can be used to display a different icon.
253
+ # [objs] the array of objects for which the action dialog will be generated.
254
+ # [action] the action for which the action dialog will be generated.
255
+ # [options] options that will be delegated to the +action_marker+ helper.
256
+ def action_item(title, css_class, objs, action, options = {})
257
+ action_link = action_marker(action, objs, options) { content_tag(:span, title, :class => css_class) }
258
+ content_tag(:li, action_link)
259
+ end
260
+
261
+ private
262
+
263
+ attr_accessor :current_marker_menu_id
264
+
265
+ def current_marker_menu_id
266
+ @current_marker_menu_id or raise "Tried to create a marker menu target before a marker menu was created!"
267
+ end
268
+
269
+ JS_HEADER = <<ENDOFSTRING
270
+ <script type="text/javascript">
271
+ // <![CDATA[
272
+ ENDOFSTRING
273
+
274
+ JS_FOOTER = <<ENDOFSTRING
275
+ // ]]>
276
+ </script>
277
+ ENDOFSTRING
278
+
279
+ def store_marker_definition(definition)
280
+ @marker_definitions ||= {}
281
+ marker_id = random_marker_id
282
+ @marker_definitions[marker_id] = definition
283
+ marker_id
284
+ end
285
+
286
+ def random_marker_id
287
+ rand(1_000_000_000)
288
+ end
289
+
290
+ def render_marker_definitions
291
+ return unless @marker_definitions.present?
292
+ "#{JS_HEADER}inline_editing.storeMarkerDefinitions(#{@marker_definitions.to_json});" +
293
+ "#{JS_FOOTER}"
294
+ end
295
+
296
+ def store_marker_markup(markup)
297
+ @marker_markup ||= []
298
+ @marker_markup << markup
299
+ end
300
+
301
+ def store_edit_marker_markup(markup)
302
+ @edit_marker_markup ||= []
303
+ @edit_marker_markup << markup
304
+ end
305
+
306
+ def reset_marker_code
307
+ @marker_definitions = @marker_markup = @edit_marker_markup = nil
308
+ end
309
+
310
+ def render_marker_menus
311
+ (@marker_markup || []).join
312
+ end
313
+
314
+ def render_edit_markers
315
+ (@edit_marker_markup || []).join
316
+ end
317
+
318
+ def required_memberships_for_editing(obj, attr)
319
+ permissions = [:read]
320
+ if [:name, :obj_class, :workflow, :suppressexport, :permalink].include?(attr.to_sym)
321
+ permissions << :root
322
+ else
323
+ permissions << :write
324
+ end
325
+
326
+ required_memberships_for_permissions(obj, permissions)
327
+ end
328
+
329
+ def required_memberships_for_permissions(obj, permissions)
330
+ permissions.map { |perm| obj.permissions.__send__(perm) }
331
+ end
332
+
333
+ def uri_for_action_marker(action, objects, context = nil, size = nil, target = nil, params = nil) #:nodoc:
334
+ action = action.to_s
335
+ objectIds = objects.collect(&:id).to_json
336
+ contextId = context.nil? ? 'null' : context.id
337
+ size = size.nil? ? 'null' : "'#{size}'"
338
+ target = target.nil? ? 'null' : "'#{target}'"
339
+ params = params.blank? ? 'null' : "'#{escape_javascript(params.to_json.gsub('"','%22'))}'"
340
+ "javascript:parent.openActionDialog('#{action}',#{objectIds},#{contextId},#{params},#{size},#{target})"
341
+ end
342
+
343
+ def format_attribute_name_for_gui(attr)
344
+ attr = attr.to_s
345
+ attr = 'blob' if attr == 'body'
346
+ attr = attr.camelize(:lower) if %w{ valid_from valid_until obj_class }.include? attr
347
+ attr
348
+ end
349
+
350
+ def marker_menu_markup(content)
351
+ raw %Q{<a class="nps_marker_menu_button" name="nps_marker_menu_button" href="#">MENU</a>
352
+ <div class="nps_marker_menu_content" style="display:none;">
353
+ <div class="b1"></div><div class="b2"></div><div class="b3"></div><div class="b4"></div>
354
+ <div class="core">
355
+ #{content}
356
+ </div>
357
+ <div class="b4"></div><div class="b3"></div><div class="b2"></div><div class="b1"></div>
358
+ </div>}
359
+ end
360
+
361
+ end
362
+
363
+ end
@@ -21,3 +21,5 @@ end
21
21
 
22
22
  autoload :Comment, "comment"
23
23
  autoload :Rating, "rating"
24
+
25
+ require "rails_connector/fiona_engine" if defined?(Rails)
@@ -0,0 +1,5 @@
1
+ module ::RailsConnector
2
+ class FionaEngine < Rails::Engine #:nodoc:
3
+ end
4
+ end
5
+
@@ -0,0 +1,69 @@
1
+ module RailsConnector::LiquidSupport
2
+
3
+ # Usage example for actionmarkers in Liquid templates:
4
+ # {% actionmarker obj.images[0] editImageWizard param_a:value_a param_b:value_b %}
5
+ # [Edit image]
6
+ # {% endactionmarker %}
7
+ #
8
+ # The first parameter may be an instance of +ObjDrop+ (usually +obj+ in Liquid templates),
9
+ # +Array+ (such as a +LinkList+ field), or +LinkDrop+ (as in the example above).
10
+ #
11
+ # The second parameter is the action to be run on the target objects.
12
+ # Additional parameters to be forwarded to the action can be added as <tt>key:value</tt> pairs.
13
+ # All parameters are evaluated in the current Liquid context and thus may contain,
14
+ # for example, method calls on objects.
15
+ #
16
+ # Internally, the parameter <tt>:context</tt> is always set to the currently viewed object (+obj+)
17
+ # and can not be overwritten.
18
+ #
19
+ # The Liquid actionmarker uses RailsConnector::MarkerHelper#action_marker.
20
+ class ActionMarker < Liquid::Block
21
+ def initialize(tag_name, markup, tokens)
22
+ @obj_name, @method_name = markup.to_s.split(/\s+/)
23
+ unless @obj_name && @method_name
24
+ raise Liquid::SyntaxError.new("Syntax Error in 'actionmarker' - Valid syntax: actionmarker obj [action] [foo:bar]")
25
+ end
26
+ @params = {}
27
+ markup.scan(/#{Liquid::TagAttributes}(#{Liquid::SpacelessFilter})?/) do |key, value, spaceless_filter|
28
+ @params[key] = spaceless_filter.blank? ? value : "#{value}|#{spaceless_filter}"
29
+ end
30
+ super
31
+ end
32
+
33
+ def render(context)
34
+ context.registers[:action_view].action_marker(
35
+ (context[@method_name] || @method_name).to_s,
36
+ target_objs(context),
37
+ :params => params(context),
38
+ :context => context['obj'].__drop_content
39
+ ) do
40
+ context.stack { render_all(@nodelist, context) }
41
+ end
42
+ end
43
+
44
+ protected
45
+
46
+ def target_objs(context)
47
+ [ context[@obj_name] ].flatten.map do |item|
48
+ case item
49
+ when RailsConnector::Link
50
+ item.destination_object
51
+ when LinkDrop
52
+ item.destination.__drop_content
53
+ else
54
+ item.__drop_content
55
+ end
56
+ end
57
+ end
58
+
59
+ def params(context)
60
+ result = {}
61
+ @params.each do |key, value|
62
+ result[(context[key] || key).to_s] = (context[value] || value).to_s
63
+ end
64
+ result
65
+ end
66
+ end
67
+
68
+ Liquid::Template.register_tag('actionmarker', ActionMarker)
69
+ end
metadata CHANGED
@@ -1,17 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infopark_fiona_connector
3
3
  version: !ruby/object:Gem::Version
4
- hash: -727788260
5
- prerelease: 14
4
+ hash: -712075784
5
+ prerelease: 10
6
6
  segments:
7
7
  - 6
8
8
  - 8
9
9
  - 0
10
- - 110
11
- - 6570
10
+ - 210
11
+ - ed
12
+ - 204
12
13
  - b
13
- - 45
14
- version: 6.8.0.110.6570b45
14
+ - 0
15
+ version: 6.8.0.210.ed204b0
15
16
  platform: ruby
16
17
  authors:
17
18
  - Infopark AG
@@ -19,7 +20,7 @@ autorequire:
19
20
  bindir: bin
20
21
  cert_chain: []
21
22
 
22
- date: 2012-10-26 00:00:00 +02:00
23
+ date: 2012-11-06 00:00:00 +01:00
23
24
  default_executable:
24
25
  dependencies:
25
26
  - !ruby/object:Gem::Dependency
@@ -78,6 +79,7 @@ extensions: []
78
79
  extra_rdoc_files:
79
80
  - README
80
81
  files:
82
+ - app/helpers/rails_connector/marker_helper.rb
81
83
  - lib/comment.rb
82
84
  - lib/infopark_fiona_connector.rb
83
85
  - lib/rails_connector/attr_dict.rb
@@ -93,7 +95,9 @@ files:
93
95
  - lib/rails_connector/date_attribute.rb
94
96
  - lib/rails_connector/default_search_request.rb
95
97
  - lib/rails_connector/errors.rb
98
+ - lib/rails_connector/fiona_engine.rb
96
99
  - lib/rails_connector/link.rb
100
+ - lib/rails_connector/liquid_support/action_marker.rb
97
101
  - lib/rails_connector/lucene_search_request.rb
98
102
  - lib/rails_connector/named_link.rb
99
103
  - lib/rails_connector/news.rb