drg_cms 0.6.0.6 → 0.6.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +25 -10
  3. data/app/assets/javascripts/drg_cms/drg_cms.js +281 -106
  4. data/app/assets/stylesheets/drg_cms/drg_cms.css +417 -152
  5. data/app/assets/stylesheets/drg_cms/select-multiple.css +9 -12
  6. data/app/assets/stylesheets/drg_cms_cms.css +1 -1
  7. data/app/controllers/cmsedit_controller.rb +247 -175
  8. data/app/controllers/dc_application_controller.rb +251 -173
  9. data/app/controllers/dc_common_controller.rb +81 -48
  10. data/app/controls/dc_help_control.rb +126 -0
  11. data/app/controls/dc_report.rb +223 -0
  12. data/app/forms/all_options.yml +38 -10
  13. data/app/forms/cms_menu.yml +7 -1
  14. data/app/forms/dc_big_table.yml +1 -0
  15. data/app/forms/dc_big_table_value.yml +1 -0
  16. data/app/forms/dc_category.yml +2 -1
  17. data/app/forms/dc_design.yml +1 -0
  18. data/app/forms/dc_help_1.yml +109 -0
  19. data/app/forms/dc_journal.yml +3 -1
  20. data/app/forms/dc_link.yml +1 -1
  21. data/app/forms/dc_menu.yml +2 -0
  22. data/app/forms/dc_menu_item.yml +1 -0
  23. data/app/forms/dc_page.yml +6 -0
  24. data/app/forms/dc_part.yml +1 -0
  25. data/app/forms/dc_piece.yml +1 -0
  26. data/app/forms/dc_poll.yml +15 -5
  27. data/app/forms/dc_poll_item.yml +2 -1
  28. data/app/forms/dc_poll_result.yml +9 -0
  29. data/app/forms/dc_simple_menu.yml +2 -0
  30. data/app/forms/dc_site.yml +4 -12
  31. data/app/forms/dc_user.yml +27 -11
  32. data/app/forms/dc_user_role.yml +3 -0
  33. data/app/helpers/cms_common_helper.rb +375 -0
  34. data/app/helpers/{cmsedit_edit_helper.rb → cms_edit_helper.rb} +109 -65
  35. data/app/helpers/{cmsedit_helper.rb → cms_helper.rb} +93 -48
  36. data/app/helpers/{cmsedit_index_helper.rb → cms_index_helper.rb} +240 -206
  37. data/app/helpers/dc_application_helper.rb +108 -327
  38. data/app/models/concerns/dc_page_concern.rb +14 -4
  39. data/app/models/concerns/dc_piece_concern.rb +1 -1
  40. data/app/models/concerns/dc_policy_rule_concern.rb +20 -8
  41. data/app/models/concerns/dc_site_concern.rb +67 -44
  42. data/app/models/concerns/dc_user_concern.rb +58 -19
  43. data/app/models/dc_design.rb +29 -19
  44. data/app/models/dc_filter.rb +26 -18
  45. data/app/models/dc_key_value_store.rb +1 -0
  46. data/app/models/dc_permission.rb +49 -9
  47. data/app/models/dc_policy.rb +25 -14
  48. data/app/models/dc_policy_role.rb +22 -11
  49. data/app/models/dc_poll.rb +1 -0
  50. data/app/models/dc_poll_result.rb +4 -2
  51. data/app/models/dc_temp.rb +6 -3
  52. data/app/models/dc_user_role.rb +2 -2
  53. data/app/models/drgcms_form_fields/date_picker.rb +6 -3
  54. data/app/models/drgcms_form_fields/datetime_picker.rb +4 -3
  55. data/app/models/drgcms_form_fields/drgcms_field.rb +20 -5
  56. data/app/models/drgcms_form_fields/embedded.rb +23 -16
  57. data/app/models/drgcms_form_fields/file_field.rb +2 -2
  58. data/app/models/drgcms_form_fields/file_select.rb +2 -2
  59. data/app/models/drgcms_form_fields/hash_field.rb +11 -7
  60. data/app/models/drgcms_form_fields/hidden_field.rb +1 -1
  61. data/app/models/drgcms_form_fields/link_to.rb +2 -2
  62. data/app/models/drgcms_form_fields/method.rb +66 -0
  63. data/app/models/drgcms_form_fields/multitext_autocomplete.rb +18 -12
  64. data/app/models/drgcms_form_fields/number_field.rb +4 -3
  65. data/app/models/drgcms_form_fields/radio.rb +10 -5
  66. data/app/models/drgcms_form_fields/readonly.rb +13 -17
  67. data/app/models/drgcms_form_fields/select.rb +58 -41
  68. data/app/models/drgcms_form_fields/text_autocomplete.rb +41 -33
  69. data/app/models/drgcms_form_fields.rb +12 -1
  70. data/app/renderers/dc_big_menu_renderer.rb +1 -0
  71. data/app/renderers/dc_gallery_renderer.rb +1 -0
  72. data/app/renderers/dc_menu_renderer.rb +1 -0
  73. data/app/renderers/dc_page_renderer.rb +8 -6
  74. data/app/renderers/dc_part_renderer.rb +1 -0
  75. data/app/renderers/dc_piece_renderer.rb +1 -1
  76. data/app/renderers/dc_poll_renderer.rb +56 -55
  77. data/app/renderers/dc_renderer.rb +1 -0
  78. data/app/renderers/dc_simple_menu_renderer.rb +1 -0
  79. data/app/views/cmsedit/_edit_stuff.html.erb +5 -2
  80. data/app/views/cmsedit/edit.html.erb +4 -1
  81. data/app/views/cmsedit/index.html.erb +3 -2
  82. data/app/views/cmsedit/new.html.erb +5 -2
  83. data/app/views/dc_common/_help.html.erb +17 -0
  84. data/app/views/layouts/models.html.erb +2 -1
  85. data/config/locales/drgcms_en.yml +17 -2
  86. data/config/locales/drgcms_sl.yml +22 -4
  87. data/config/locales/models_en.yml +16 -7
  88. data/config/locales/models_sl.yml +21 -12
  89. data/drg_cms.gemspec +16 -16
  90. data/lib/drg_cms/version.rb +1 -1
  91. data/lib/drg_cms.rb +98 -0
  92. data/lib/generators/new_drg_form/new_drg_form_generator.rb +5 -3
  93. data/lib/tasks/database.rake +6 -56
  94. metadata +39 -35
  95. data/app/helpers/application_helper.rb +0 -2
  96. data/app/models/__dc_dummy.rb +0 -102
@@ -27,17 +27,19 @@
27
27
  # data found in 3 major sections of DRG CMS form: index, result_set and form sections.
28
28
  #
29
29
  ###########################################################################
30
- module CmseditEditHelper
30
+ module CmsEditHelper
31
31
 
32
32
  ############################################################################
33
33
  # Will return value when internal or additional parameters are defined in action
34
34
  # Subroutine of dc_actions_for_form.
35
35
  ############################################################################
36
- def dc_value_for_parameter(param)#:nodoc:
36
+ def dc_value_for_parameter(param, current_document = nil)#:nodoc:
37
37
  if param.class == Hash
38
- dc_internal_var(param['object'] || 'record', param['method'])
38
+ dc_internal_var(param['object'] ||= 'record', param['method'], current_document)
39
+ elsif param.to_s.match(/record|document/)
40
+ current_document ? current_document : @record
39
41
  else
40
- param
42
+ param
41
43
  end
42
44
  end
43
45
 
@@ -51,9 +53,10 @@ end
51
53
  def dc_is_action_active?(options)
52
54
  if options['when_new']
53
55
  dc_deprecate("when_option will be deprecated and replaced by active: not_new_record! Form #{params[:form_name]}")
54
- return !(dc_dont?(options['when_new']) and @record.new_record?)
56
+ return !(dc_dont?(options['when_new']) && @record.new_record?)
55
57
  end
56
58
  return true unless options['active']
59
+
57
60
  # alias record and document so both can be used in eval
58
61
  record = document = @record
59
62
  option = options['active']
@@ -61,14 +64,20 @@ def dc_is_action_active?(options)
61
64
  # usually only for test
62
65
  when option.class == TrueClass || option['eval'].class == TrueClass then true
63
66
  when option.class == String then
64
- (@record.new_record? && option == 'new_record') || (!@record.new_record? && option == 'not_new_record')
67
+ if option.match(/new_record/i)
68
+ (@record.new_record? && option == 'new_record') || (!@record.new_record? && option == 'not_new_record')
69
+ elsif option.match(/\./)
70
+ # shortcut for method and eval option
71
+ dc_process_eval(option, self)
72
+ else
73
+ eval(option['eval'])
74
+ end
65
75
  # direct evaluate expression
66
76
  when option['eval'] then
67
77
  eval(option['eval'])
68
78
  when option['method'] then
69
- # if record present send record otherwise send params as parameter
70
- parms = @record ? @record : params
71
- dc_process_eval(option['method'],parms)
79
+ # if record present send record otherwise send self as parameter
80
+ dc_process_eval(option['method'], self)
72
81
  else
73
82
  false
74
83
  end
@@ -82,31 +91,40 @@ end
82
91
  # normal link.
83
92
  ############################################################################
84
93
  def dc_actions_for_form(position)
85
- # create standard actions
94
+ # create standard actions
86
95
  std_actions = {1 => 'back', 2 => {'type' => 'submit', 'caption' => 'drgcms.save'},
87
96
  3 => {'type' => 'submit', 'caption' => 'drgcms.save&back'} }
88
- # when edit only
97
+ # when edit only
89
98
  unless @record.try(:id).nil?
90
99
  std_actions.merge!({6 => 'new'} )
91
100
  std_actions.merge!(@record.active ? {5 => 'disable'} : {5 => 'enable'} ) if @record.respond_to?('active')
92
101
  std_actions.merge!({7 => 'refresh'} )
93
102
  end
103
+ # readonly
104
+ std_actions = { 1 => 'back' } if @form['readonly']
105
+
94
106
  actions = @form['form']['actions']
95
- # shortcut for actions: standard
107
+ # shortcut for actions: standard
96
108
  actions = nil if actions.class == String && actions == 'standard'
97
- # standard actions
98
109
  actions = std_actions if actions.nil?
99
- # readonly
100
- actions = {1 => 'back'} if @form['readonly']
101
- # Actions are strictly forbidden
102
- if @form['form']['actions'] and dc_dont?(@form['form']['actions'])
110
+
111
+ # Actions are strictly forbidden
112
+ if @form['form']['actions'] && dc_dont?(@form['form']['actions'])
103
113
  actions = []
104
114
  elsif actions['standard']
105
115
  actions.merge!(std_actions)
106
116
  actions['standard'] = nil
107
117
  end
108
- # Update save and save&back
109
- actions.each do |k,v|
118
+ # request for close window button present
119
+ if actions.class == Hash
120
+ case params[:window_close]
121
+ when '0' then actions[1] = 'close'; actions[3] = nil
122
+ when '1' then actions = { 1 => 'close' }
123
+ when '2' then actions = { 1 => 'close' }
124
+ end
125
+ end
126
+ # Update save and save&back
127
+ actions.each do |k, v|
110
128
  if v.class == String
111
129
  if v.match(/save\&back/i)
112
130
  actions[k] = {'type' => 'submit', 'caption' => 'drgcms.save&back'}
@@ -115,10 +133,10 @@ def dc_actions_for_form(position)
115
133
  end
116
134
  end
117
135
  end
118
- # remove standard option and sort so that standard actions come first
136
+ # remove standard option and sort so that standard actions come first
119
137
  actions.delete('standard')
120
- actions = actions.to_a.sort {|x,y| x[0] <=> y[0]}
121
- # Add spinner to the beginning
138
+ actions = actions.to_a.sort { |x, y| x[0] <=> y[0] }
139
+ # Add spinner to the beginning
122
140
  html = %Q[<span class="dc-spinner">#{fa_icon('spinner lg spin')}</span><ul class="dc-menu #{position}">]
123
141
 
124
142
  actions.each do |key, options|
@@ -126,12 +144,12 @@ def dc_actions_for_form(position)
126
144
  next if options.nil? # yes it happends
127
145
  parms = @parms.clone
128
146
  if options.class == String
129
- next if params[:readonly] and !(options == 'back')
147
+ next if @form['readonly'] and !options.match(/back|close/)
130
148
 
131
149
  html << '<li class="dc-link dc-animate">'
132
150
  html << case
133
151
  when (options == 'back' or options == 'cancle') then
134
- # If return_to is present link directly to URL
152
+ # If return_to is present link directly to URL
135
153
  if parms['xreturn_to'] # disabled for now
136
154
  dc_link_to( 'drgcms.back','arrow-left', parms['return_to'] )
137
155
  else
@@ -162,12 +180,23 @@ def dc_actions_for_form(position)
162
180
 
163
181
  when options == 'refresh' then
164
182
  "<div onclick='window.location.href=window.location.href;'>#{fa_icon('refresh')} #{t('drgcms.refresh')}</div></li>"
183
+
184
+ when options == 'close' then
185
+ close = params[:window_close].to_i
186
+ if close < 2
187
+ "<div onclick='window.close();'>#{fa_icon('close')} #{t('drgcms.close')}</div></li>"
188
+ else
189
+ "<div onclick='history.back();'>#{fa_icon('close')} #{t('drgcms.close')}</div></li>"
190
+ end
165
191
  else
166
192
  "err1 #{key}=>#{options}"
167
193
  end
168
194
  html << '</td>'
169
195
  # non standard actions
170
196
  else
197
+ # action will be displayed when show: always or readonly option is declared and form is readonly
198
+ next if @form['readonly'] && !%w[readonly always].include?(options['show'].to_s)
199
+
171
200
  options['title'] = t("#{options['title'].downcase}", options['title']) if options['title']
172
201
  html << case
173
202
  # submit button
@@ -216,7 +245,7 @@ def dc_background_for_result(start)
216
245
  if start == :start
217
246
  html = '<div class="dc-result-div" '
218
247
  html << (@form['result_set']['table_style'] ? 'style="overflow-x: scroll;" >' : '>')
219
- #
248
+
220
249
  html << "\n<div class=\"dc-result #{@form['result_set']['table_class']}\" "
221
250
  html << (@form['result_set']['table_style'] ? "style=\"#{@form['result_set']['table_style']}\" >" : '>')
222
251
  else
@@ -247,21 +276,13 @@ def dc_check_and_default(value, default, values=nil) #:nodoc:
247
276
  value
248
277
  end
249
278
 
250
- ############################################################################
251
- # Creates top or bottom horizontal line on form.
252
- ############################################################################
253
- def dc_top_bottom_line(options)
254
- '<div class="dc-separator"></div>'
255
- end
256
-
257
279
  ############################################################################
258
280
  # Creates input fields for one tab. Subroutine of dc_fields_for_form.
259
281
  ############################################################################
260
282
  def dc_fields_for_tab(fields_on_tab) #:nodoc:
261
- html = '<div class="dc-form">'
262
- labels_pos = dc_check_and_default(@form['form']['labels_pos'], 'right', ['top','left','right'])
263
- hidden_fields = ''
264
- odd_even = nil
283
+ html = '<div class="dc-form">'
284
+ labels_pos = dc_check_and_default(@form['form']['labels_pos'], 'right', ['top', 'left', 'right'])
285
+ hidden_fields, odd_even = '', nil
265
286
  group_option, group_count = 0, 0
266
287
  reset_cycle()
267
288
  # Select form fields and sort them by key
@@ -278,8 +299,8 @@ def dc_fields_for_tab(fields_on_tab) #:nodoc:
278
299
  # label
279
300
  field_html,label,help = dc_field_label_help(options)
280
301
  # Line separator
281
- html << dc_top_bottom_line(options['top-line']) if options['top-line']
282
- # Begining of new row
302
+ html << dc_top_bottom_line(:top, options)
303
+ # Beginning of new row
283
304
  if group_count == 0
284
305
  html << '<div class="row-div">'
285
306
  odd_even = cycle('odd','even')
@@ -320,49 +341,50 @@ def dc_fields_for_tab(fields_on_tab) #:nodoc:
320
341
  html << '<div></div>' if group_option == 2
321
342
  end
322
343
 
323
- html << dc_top_bottom_line(options['bottom-line']) if options['bottom-line']
344
+ html << dc_top_bottom_line(:bottom, options)
324
345
  end
325
346
  html << '</div>' << hidden_fields
326
347
  end
327
348
 
328
349
  ############################################################################
329
- # Creates edit form div.
350
+ # Creates edit form from fields or tabs options
330
351
  ############################################################################
331
- def dc_fields_for_form()
352
+ def dc_fields_for_form
332
353
  html, tabs, tab_data = '',[], ''
333
354
  @js ||= ''
334
355
  @css ||= ''
335
- # Only fields defined
356
+ # Only fields defined
336
357
  if (form_fields = @form['form']['fields'])
337
358
  html << "<div id='data_fields' " + (@form['form']['height'] ? "style=\"height: #{@form['form']['height']}px;\">" : '>')
338
359
  html << dc_fields_for_tab(form_fields) + '</div>'
339
360
  else
340
- # there are multiple tabs on form
361
+ # there are multiple tabs on form
341
362
  first = true # first tab
342
363
  @form['form']['tabs'].keys.sort.each do |tab_name|
343
364
  next if tab_name.match('actions')
344
- # Tricky. If field name is not on the tab skip to next tab
365
+ # Tricky when editing single field. If field is not present on the tab skip to next tab
345
366
  if params[:edit_only]
346
367
  is_on_tab = false
347
- @form['form']['tabs'][tab_name].each {|k,v| is_on_tab = true if params[:edit_only] == v['name'] }
368
+ @form['form']['tabs'][tab_name].each { |k, v| is_on_tab = true if params[:edit_only] == v['name'] }
348
369
  next unless is_on_tab
349
370
  end
350
- # first div is displayed, all others are hidden
371
+ # first div is displayed, all others are hidden
351
372
  tab_data << "<div id=\"data_#{tab_name.delete("\s\n")}\""
352
373
  tab_data << ' class="div-hidden"' unless first
353
374
  tab_data << " style=\"height: #{@form['form']['height']}px;\"" if @form['form']['height']
354
375
  tab_data << ">#{dc_fields_for_tab(@form['form']['tabs'][tab_name])}</div>"
355
- tab_label = @form['form']['tabs'][tab_name]['caption'] || tab_name
356
- tabs << [tab_name, tab_label]
376
+
377
+ tab_label, tab_title = dc_tab_label_help(tab_name)
378
+ tabs << [tab_name, tab_label, tab_title]
357
379
  first = false
358
380
  end
359
- # make it all work together
381
+ # make it all work together
360
382
  html << '<ul class="dc-form-ul" >'
361
383
  first = true # first tab must be selected
362
- tabs.each do |tab_name, tab_label|
363
- html << "<li id=\"li_#{tab_name}\" data-div=\"#{tab_name.delete("\s\n")}\" class=\"dc-form-li"
364
- html << ' dc-form-li-selected' if first
365
- html << "\">#{t(tab_label, t_name(tab_label,tab_label))}</li>"
384
+ tabs.each do |tab_name, tab_label, tab_title|
385
+ html << %(<li id="li_#{tab_name}" data-div="#{tab_name.delete("\s\n")}" title="#{tab_title}" class="dc-form-li)
386
+ html << ' dc-form-li-selected' if first
387
+ html << "\">#{tab_label}</li>"
366
388
  first = false
367
389
  end
368
390
  html << '</ul>'
@@ -378,16 +400,15 @@ def dc_fields_for_form()
378
400
  html.html_safe
379
401
  end
380
402
 
381
-
382
403
  ############################################################################
383
- # Creates head form div. Head form div is used to display header datausefull
404
+ # Creates head form div. Head form div is used to display header data usefull
384
405
  # to be seen even when tabs are switched.
385
406
  ############################################################################
386
- def dc_head_for_form()
407
+ def dc_head_for_form
387
408
  @css ||= ''
388
409
  head = @form['form']['head']
389
410
  return '' if head.nil?
390
- html = %Q[<div class="dc-head #{head['class']}">\n<div class="dc-row">]
411
+ html = %(<div class="dc-head #{head['class']}">\n<div class="dc-row">)
391
412
  split = head['split'] || 4
392
413
  percent = 100/split
393
414
  current = 0
@@ -413,7 +434,7 @@ def dc_head_for_form()
413
434
  @record.send(options['name'])
414
435
  end
415
436
  rescue Exception => e
416
- dc_log_exception(e)
437
+ dc_log_exception(e, 'dc_head_for_form')
417
438
  field = '!!!Error'
418
439
  end
419
440
  #
@@ -421,7 +442,7 @@ def dc_head_for_form()
421
442
  style = dc_style_or_class(nil, options['style'], field, @record)
422
443
  html << %Q[<div class="dc-column #{klass}" style="width:#{percent*span}%;#{style}">
423
444
  #{label.blank? ? '' : "<span class=\"label\">#{label}</span>"}
424
- <span class="field">#{field}</span>
445
+ <span id="head-#{options['name']}" class="field">#{field}</span>
425
446
  </div>]
426
447
  current += span
427
448
  if current == split
@@ -437,11 +458,10 @@ end
437
458
  # Returns username for id. Subroutine of dc_document_statistics
438
459
  ###########################################################################
439
460
  def dc_document_user_for(field_name) #:nodoc:
440
- if @record[field_name]
441
- u = DcUser.find(@record[field_name])
442
- return u ? u.name : @record[field_name]
443
- end
444
- # nil
461
+ return if @record[field_name].nil?
462
+
463
+ user = DcUser.find(@record[field_name])
464
+ user ? user.name : @record[field_name]
445
465
  end
446
466
 
447
467
  ############################################################################
@@ -463,9 +483,33 @@ def dc_document_statistics
463
483
  parms[:controller] = 'dc_common'
464
484
  parms[:action] = 'copy_clipboard'
465
485
  url = url_for(parms.permit!)
466
- html << fa_icon('copy 2x', class: 'dc-link-img dc-link-ajax dc-animate',
486
+ html << fa_icon('copy lg', class: 'dc-link-img dc-link-ajax dc-animate',
467
487
  'data-url' => url, 'data-request' => 'get', title: t('drgcms.doc_copy_clipboard') )
488
+
489
+ url = url_for(controller: :cmsedit, action: :index, table: 'dc_journal', filter: 'on',
490
+ filter_oper: 'eq', filter_field: 'doc_id', filter_value: @record.id)
491
+ html << fa_icon('history lg', class: 'dc-link-img dc-animate dc-window-open',
492
+ 'data-url' => url, title: t('helpers.label.dc_journal.tabletitle') )
493
+
468
494
  (html << '</div></div>').html_safe
469
495
  end
470
496
 
497
+ private
498
+
499
+ ############################################################################
500
+ # Creates top or bottom horizontal line on form.
501
+ #
502
+ # @param [String] location (top or bottom)
503
+ # @param [Object] options yaml field definition
504
+ #
505
+ # @return [String] html code for drawing a line
506
+ ############################################################################
507
+ def dc_top_bottom_line(location, options)
508
+ if options["#{location}-line"] || options['line'].to_s == location.to_s
509
+ '<div class="dc-separator"></div>'
510
+ else
511
+ ''
512
+ end
513
+ end
514
+
471
515
  end
@@ -26,7 +26,7 @@
26
26
  # CmseditHelper module defines common methods used for DRGCMS forms.
27
27
  #
28
28
  ###########################################################################
29
- module CmseditHelper
29
+ module CmsHelper
30
30
  # javascript part created by form helpers
31
31
  attr_reader :js
32
32
 
@@ -46,7 +46,7 @@ end
46
46
  # Field definition will be used for input field on the form.
47
47
  ############################################################################
48
48
  def dc_get_field_form_definition(name) #:nodoc:
49
- return nil if @form['form'].nil?
49
+ return if @form['form'].nil?
50
50
 
51
51
  @form['form']['tabs'].each do |tab|
52
52
  # Array with 2 elements. First is tabname, second is data
@@ -67,40 +67,79 @@ end
67
67
  # Parameters:
68
68
  # options : Hash : Field definition
69
69
  #
70
- # Returns:
70
+ # Returns: Array[3]
71
71
  # field_html : String : HTML code for field definition
72
72
  # label : String : Label text
73
73
  # help : String : Help text
74
74
  ############################################################################
75
75
  def dc_field_label_help(options)
76
- # no label or help in comments
77
- unless %w(comment action).include?(options['type'])
78
- caption = options['caption'] || options['text']
79
- label = if caption.blank?
80
- t_name(options['name'], options['name'].capitalize.gsub('_',' ') )
81
- elsif options['name']
82
- t(caption, caption)
83
- end
84
- # help text can be defined in form or in translations starting with helpers. or as helpers.help.collection.field
85
- help = if options['help']
86
- options['help'].match('helpers.') ? t(options['help']) : options['help']
76
+ label, help = dc_label_help(options)
77
+ # create field object from type and call its render method
78
+ if options['type'].present?
79
+ klass_string = options['type'].camelize
80
+ field_html = if DrgcmsFormFields.const_defined?(klass_string) # when field type defined
81
+ klass = DrgcmsFormFields.const_get(klass_string)
82
+ field = klass.new(self, @record, options).render
83
+ @js << field.js
84
+ @css << field.css
85
+ field.html
86
+ else
87
+ "Error: Field type #{options['type']} not defined!"
87
88
  end
88
- help ||= t('helpers.help.' + @form['table'] + '.' + options['name'],' ') if options['name']
89
- end
90
- # create field object from class and call its render method
91
- klass_string = options['type'].camelize
92
- field_html = if DrgcmsFormFields.const_defined?(klass_string) # when field type defined
93
- klass = DrgcmsFormFields.const_get(klass_string)
94
- field = klass.new(self, @record, options).render
95
- @js << field.js
96
- @css << field.css
97
- field.html
98
- else # litle error string
99
- "Error: Field type #{options['type']} not defined!"
89
+ else
90
+ "Error: Field type missing!"
100
91
  end
101
92
  [field_html, label, help]
102
93
  end
103
94
 
95
+ ############################################################################
96
+ # Return label and help text for a field defined on Form.
97
+ #
98
+ # Parameters:
99
+ # options : Hash : Field definition
100
+ #
101
+ # Returns:
102
+ # label : String : Label text
103
+ # help : String : Help text
104
+ ############################################################################
105
+ def dc_label_help(options)
106
+ # no label or help in comments
107
+ return [nil, nil] if %w(comment action).include?(options['type'])
108
+
109
+ label = options['caption'] || options['text'] || options['label']
110
+ label = if label.blank?
111
+ t_name(options['name'], options['name'].capitalize.gsub('_',' ') )
112
+ elsif options['name']
113
+ t(label, label)
114
+ end
115
+ # help text can be defined in form or in translations starting with helpers. or as helpers.help.collection.field
116
+ help = options['help']
117
+ help ||= "helpers.help.#{@form['table']}.#{options['name']}" if options['name']
118
+ help = t(help, ' ') if help.to_s.match(/helpers\./)
119
+ [label, help]
120
+ end
121
+
122
+ ############################################################################
123
+ # Return label and help for tab on Form.
124
+ #
125
+ # Parameters:
126
+ # options : String : Tab name on form
127
+ #
128
+ # Returns:
129
+ # label : String : Label text
130
+ # help : String : Help text
131
+ ############################################################################
132
+ def dc_tab_label_help(tab_name)
133
+ label = @form['form']['tabs'][tab_name]['caption'] || tab_name
134
+ label = t(label, t_name(label, label))
135
+
136
+ help = @form['form']['tabs'][tab_name]['help'] || "helpers.help.#{@form['table']}.#{tab_name}"
137
+ help = t(help, t_name(help, help))
138
+ help = nil if help.match('helpers.') # help not found in translation
139
+
140
+ [label, help]
141
+ end
142
+
104
143
  ############################################################################
105
144
  # Creates code for including data entry field in index actions.
106
145
  ############################################################################
@@ -110,25 +149,26 @@ def dc_field_action(yaml)
110
149
  value = params['record'][yaml['name']]
111
150
  params["p_#{yaml['name']}"] = value
112
151
  end
113
- #
152
+ # find field definition on form
114
153
  if ( field_definition = dc_get_field_form_definition(yaml['name']) )
115
- field, label, help = dc_field_label_help(field_definition)
154
+ # some options may be redefined
155
+ field_definition['size'] = yaml['size'] if yaml['size']
156
+ field, label, help = dc_field_label_help(field_definition)
116
157
  else
117
158
  yaml['type'] = yaml['field_type']
118
159
  field, label, help = dc_field_label_help(yaml)
119
160
  end
120
- # input field will have label as placeholder
121
- field = field.sub('input',"input placeholder=\"#{label}\"")
122
- %Q[<li class="no-background">#{field}</li>]
123
-
161
+ # input field will have label as placeholder
162
+ field = field.sub('input',"input placeholder=\"#{label}\"")
163
+ %Q[<li class="no-background">#{field}</li>]
124
164
  end
125
165
 
126
166
  ############################################################################
127
- #
167
+ # Create ex. class="my-class" html code from html options for action
128
168
  ############################################################################
129
169
  def dc_html_data(yaml)
130
170
  return '' if yaml.blank?
131
- yaml.inject(' ') {|result, e| result << "#{e.first}=\"#{e.last}\" "}
171
+ yaml.inject(' ') {|result, e| result = e.last.nil? ? result : result << "#{e.first}=\"#{e.last}\" "}
132
172
  end
133
173
 
134
174
  ############################################################################
@@ -144,7 +184,8 @@ end
144
184
  ############################################################################
145
185
  def dc_link_ajax_window_submit_action(yaml, record=nil, action_active=true)
146
186
  parms = {}
147
- caption = yaml['caption'] ? t("#{yaml['caption'].downcase}", yaml['caption']) : nil
187
+ caption = yaml['caption'] || yaml['text']
188
+ caption = caption ? t("#{caption.downcase}", caption) : nil
148
189
  icon = yaml['icon'] ? "#{fa_icon(yaml['icon'])}" : ''
149
190
  # action is not active
150
191
  unless dc_is_action_active?(yaml)
@@ -153,16 +194,19 @@ def dc_link_ajax_window_submit_action(yaml, record=nil, action_active=true)
153
194
  # set data-confirm when confirm
154
195
  yaml['html'] ||= {}
155
196
  confirm = yaml['html']['data-confirm'] || yaml['confirm']
156
- yaml['html']['data-confirm'] = t(confirm) unless confirm.blank?
197
+ yaml['html']['data-confirm'] = t(confirm) if confirm.present?
198
+ yaml['html']['title'] ||= yaml['title']
199
+ yaml['html']['title'] = t(yaml['title']) if yaml['title'].present?
200
+ yaml['html']['target'] ||= yaml['target']
157
201
  # direct url
158
202
  if yaml['url']
159
- parms['controller'] = yaml['url']
160
- parms['idr'] = dc_document_path(record) if record
203
+ parms['url'] = yaml['url']
204
+ parms['idr'] = dc_document_path(record) if record
161
205
  # make url from action controller
162
206
  else
163
207
  parms['controller'] = yaml['controller'] || 'cmsedit'
164
208
  parms['action'] = yaml['action']
165
- parms['table'] = yaml['table']
209
+ parms['table'] = yaml['table'] || @form['table']
166
210
  parms['form_name'] = yaml['form_name']
167
211
  parms['control'] = yaml['control'] if yaml['control']
168
212
  parms['id'] = record.id if record
@@ -170,21 +214,22 @@ def dc_link_ajax_window_submit_action(yaml, record=nil, action_active=true)
170
214
  # add current id to parameters
171
215
  parms['id'] = dc_document_path(record) if record
172
216
  # overwrite with or add additional parameters from environment or record
173
- yaml['params'].each { |k,v| parms[k] = dc_value_for_parameter(v) } if yaml['params']
217
+ yaml['params'].each { |k, v| parms[k] = dc_value_for_parameter(v, record) } if yaml['params']
218
+
174
219
  parms['table'] = parms['table'].underscore if parms['table'] # might be CamelCase
175
220
  # error if controller parameter is missing
176
221
  if parms['controller'].nil? && parms['url'].nil?
177
222
  "<li>#{'Controller not defined'}</li>"
178
223
  else
179
- yaml['caption'] ||= yaml['text']
180
-
224
+ #yaml['caption'] ||= yaml['text']
181
225
  html_data = dc_html_data(yaml['html'])
182
- #
183
226
  url = url_for(parms) rescue 'URL error'
227
+ url = nil if parms['url'] == '#'
228
+
184
229
  request = yaml['request'] || yaml['method'] || 'get'
185
230
  if yaml['type'] == 'ajax' # ajax button
186
231
  clas = "dc-link-ajax dc-animate"
187
- %Q[<li class="#{clas}" data-url="#{action_active ? url : ''}" #{html_data}
232
+ %Q[<li class="#{clas}" data-url="#{action_active ? url : ''}" #{html_data}
188
233
  data-request="#{request}" title="#{yaml['title']}">#{icon}#{caption}</li>]
189
234
 
190
235
  elsif yaml['type'] == 'submit' # submit button
@@ -197,7 +242,7 @@ def dc_link_ajax_window_submit_action(yaml, record=nil, action_active=true)
197
242
 
198
243
  elsif yaml['type'] == 'link' # link button
199
244
  clas = "dc-link dc-animate"
200
- link = dc_link_to(yaml['caption'],yaml['icon'], parms, {target: yaml['target'], html: yaml['html']} )
245
+ link = dc_link_to(caption, yaml['icon'], parms, yaml['html'] )
201
246
  %Q[<li class="#{clas}">#{action_active ? link : caption}</li>]
202
247
 
203
248
  elsif yaml['type'] == 'window'
@@ -211,10 +256,10 @@ def dc_link_ajax_window_submit_action(yaml, record=nil, action_active=true)
211
256
  end
212
257
 
213
258
  ############################################################################
214
- #
259
+ # Log exception to rails log. Usefull for debugging eval errors.
215
260
  ############################################################################
216
- def dc_log_exception(exception)
217
- log = exception ? "\n!!!Error: #{exception.message}\n#{exception.backtrace.first.inspect}\n" : ''
261
+ def dc_log_exception(exception, where = '')
262
+ log = exception ? "\n*** Error:#{where + ':'} #{exception.message}\n#{exception.backtrace.first.inspect}\n" : ''
218
263
  log << "DRG Form processing line: #{session[:form_processing]}\n"
219
264
 
220
265
  logger.error log