drg_cms 0.6.1.5 → 0.6.1.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +203 -24
  3. data/app/assets/fonts/ibm-plex-sans-300.woff2 +0 -0
  4. data/app/assets/fonts/ibm-plex-sans-400.woff2 +0 -0
  5. data/app/assets/fonts/ibm-plex-sans-500.woff2 +0 -0
  6. data/app/assets/fonts/ibm-plex-sans-600.woff2 +0 -0
  7. data/app/assets/fonts/ibm-plex-sans-700.woff2 +0 -0
  8. data/app/assets/fonts/ibm-plex-sans-italic.woff2 +0 -0
  9. data/app/assets/javascripts/drg_cms/drg_cms.js +253 -106
  10. data/app/assets/stylesheets/drg_cms/drg_cms.css +670 -521
  11. data/app/assets/stylesheets/drg_cms_application.css +1 -1
  12. data/app/assets/stylesheets/drg_cms_cms.css +1 -4
  13. data/app/controllers/cmsedit_controller.rb +33 -211
  14. data/app/controllers/dc_application_controller.rb +98 -22
  15. data/app/controllers/dc_common_controller.rb +9 -22
  16. data/app/controls/browse_models_control.rb +18 -27
  17. data/app/controls/cmsedit_control.rb +129 -0
  18. data/app/controls/dc_help_control.rb +1 -1
  19. data/app/controls/dc_page_control.rb +0 -1
  20. data/app/controls/dc_poll_result_control.rb +1 -1
  21. data/app/controls/dc_report.rb +2 -2
  22. data/app/controls/design_element_settings_control.rb +1 -1
  23. data/app/forms/all_options.yml +25 -7
  24. data/app/forms/cms_menu.yml +24 -24
  25. data/app/forms/dc_browse_fields.yml +13 -9
  26. data/app/forms/dc_browse_models.yml +24 -2
  27. data/app/forms/dc_poll_result_export.yml +1 -1
  28. data/app/forms/dc_site.yml +2 -5
  29. data/app/forms/dc_steps_template.yml +51 -0
  30. data/app/helpers/cms_common_helper.rb +73 -6
  31. data/app/helpers/cms_edit_helper.rb +275 -159
  32. data/app/helpers/cms_helper.rb +152 -59
  33. data/app/helpers/cms_index_helper.rb +220 -172
  34. data/app/helpers/dc_application_helper.rb +40 -67
  35. data/app/models/concerns/dc_page_concern.rb +1 -1
  36. data/app/models/concerns/dc_site_concern.rb +9 -3
  37. data/app/models/dc_filter.rb +30 -22
  38. data/app/models/dc_journal.rb +2 -2
  39. data/app/models/dc_json_ld.rb +19 -42
  40. data/app/models/dc_part.rb +19 -9
  41. data/app/models/dc_site.rb +0 -1
  42. data/app/models/drgcms_form_fields/drgcms_field.rb +10 -4
  43. data/app/models/drgcms_form_fields/link_to.rb +1 -1
  44. data/app/models/drgcms_form_fields/multitext_autocomplete.rb +5 -5
  45. data/app/models/drgcms_form_fields/readonly.rb +4 -1
  46. data/app/models/drgcms_form_fields/select.rb +10 -9
  47. data/app/models/drgcms_form_fields/text_autocomplete.rb +20 -12
  48. data/app/models/drgcms_form_fields/text_with_select.rb +1 -0
  49. data/app/renderers/dc_common_renderer.rb +20 -3
  50. data/app/renderers/dc_part_renderer.rb +1 -1
  51. data/app/renderers/dc_poll_renderer.rb +1 -1
  52. data/app/views/cmsedit/_edit_stuff.html.erb +12 -12
  53. data/app/views/cmsedit/_form.html.erb +19 -12
  54. data/app/views/cmsedit/edit.html.erb +10 -6
  55. data/app/views/cmsedit/index.html.erb +5 -3
  56. data/app/views/cmsedit/login.html.erb +1 -1
  57. data/app/views/cmsedit/new.html.erb +9 -5
  58. data/app/views/dc_common/_help.html.erb +1 -0
  59. data/app/views/dc_common/paste_clipboard.html.erb +1 -1
  60. data/app/views/layouts/cms.html.erb +3 -5
  61. data/config/locales/drgcms_en.yml +7 -1
  62. data/config/locales/drgcms_sl.yml +7 -1
  63. data/config/locales/kaminari.yml +1 -1
  64. data/drg_cms.gemspec +2 -2
  65. data/lib/drg_cms/version.rb +1 -1
  66. data/lib/drg_cms.rb +4 -4
  67. metadata +16 -10
  68. data/app/views/cmsedit/__remove_edit_stuff.js.erb +0 -6
  69. data/app/views/cmsedit/__show.html.erb +0 -21
@@ -52,7 +52,7 @@ end
52
52
  ############################################################################
53
53
  def dc_is_action_active?(options)
54
54
  if options['when_new']
55
- dc_deprecate("when_option will be deprecated and replaced by active: not_new_record! Form #{params[:form_name]}")
55
+ dc_deprecate("when_option will be deprecated and replaced by active: not_new_record! Form #{CmsHelper.form_param(params)}")
56
56
  return !(dc_dont?(options['when_new']) && @record.new_record?)
57
57
  end
58
58
  return true unless options['active']
@@ -137,56 +137,57 @@ def dc_actions_for_form(position)
137
137
  actions.delete('standard')
138
138
  actions = actions.to_a.sort { |x, y| x[0] <=> y[0] }
139
139
  # Add spinner to the beginning
140
- html = %Q[<span class="dc-spinner">#{fa_icon('spinner lg spin')}</span><ul class="dc-menu #{position}">]
140
+ html = %Q[<span class="dc-spinner">#{fa_icon('settings-o spin')}</span><ul class="dc-menu #{position}">]
141
141
 
142
142
  actions.each do |key, options|
143
143
  session[:form_processing] = "form:actions: #{key} #{options}"
144
144
  next if options.nil? # yes it happens
145
- parms = @parms.clone
145
+
146
+ parms = @form_params.clone
146
147
  if options.class == String
147
148
  next if @form['readonly'] and !options.match(/back|close/)
148
-
149
- html << '<li class="dc-link dc-animate">'
150
- html << case
151
- when (options == 'back' or options == 'cancle') then
149
+
150
+ html << '<li>'
151
+ html << case
152
+ when (options == 'back' || options == 'cancle')
152
153
  # If return_to is present link directly to URL
153
154
  if parms['xreturn_to'] # disabled for now
154
- dc_link_to( 'drgcms.back','arrow-left', parms['return_to'] )
155
+ dc_link_to( 'drgcms.back', 'arrow_back', parms['return_to'], class: 'dc-link' )
155
156
  else
156
157
  parms['action'] = 'index'
157
158
  parms['readonly'] = parms['readonly'].to_s.to_i < 2 ? nil : 1
158
- dc_link_to( 'drgcms.back','arrow-left', parms )
159
+ dc_link_to( 'drgcms.back', 'arrow_back', parms, class: 'dc-link' )
159
160
  end
160
161
 
161
- when options == 'delete' then
162
+ when options == 'delete'
162
163
  parms['operation'] = options
163
164
  parms['id'] = @record.id
164
- dc_link_to( 'drgcms.delete','remove', parms, data: { confirm: t('drgcms.confirm_delete') }, method: :delete )
165
+ dc_link_to( 'drgcms.delete','remove', parms, data: { confirm: t('drgcms.confirm_delete') }, method: :delete, class: 'dc-link' )
165
166
 
166
- when options == 'new' then
167
+ when options == 'new'
167
168
  parms['action'] = options
168
- dc_link_to( 'drgcms.new', 'plus', parms)
169
+ dc_link_to( 'drgcms.new', 'add', parms, class: 'dc-link')
169
170
 
170
- when (options == 'enable' or options == 'disable') then
171
+ when (options == 'enable' || options == 'disable')
171
172
  parms['operation'] = options
172
173
  parms['id'] = @record.id
173
- icon = (options == 'enable' ? 'thumbs-o-up' : 'thumbs-o-down')
174
- dc_link_to( "drgcms.#{options}",icon, parms, method: :delete )
174
+ icon = (options == 'enable' ? 'check_box-o' : 'check_box_outline_blank')
175
+ dc_link_to( "drgcms.#{options}",icon, parms, method: :delete, class: 'dc-link' )
175
176
 
176
- when options == 'edit' then
177
+ when options == 'edit'
177
178
  parms['operation'] = options
178
179
  parms['id'] = @record.id
179
- dc_link_to( "drgcms.#{options}",options, parms )
180
+ dc_link_to( "drgcms.#{options}", options, parms, class: 'dc-link' )
180
181
 
181
- when options == 'refresh' then
182
- "<div onclick='window.location.href=window.location.href;'>#{fa_icon('refresh')} #{t('drgcms.refresh')}</div></li>"
182
+ when options == 'refresh'
183
+ %(<div class="dc-link" onclick='window.location.href=window.location.href;'>#{fa_icon('refresh')} #{t('drgcms.refresh')}</div></li>)
183
184
 
184
- when options == 'close' then
185
+ when options == 'close'
185
186
  close = params[:window_close].to_i
186
187
  if close < 2
187
- "<div onclick='window.close();'>#{fa_icon('close')} #{t('drgcms.close')}</div></li>"
188
+ %(<div class="dc-link" onclick='window.close();'>#{fa_icon('close')} #{t('drgcms.close')}</div></li>)
188
189
  else
189
- "<div onclick='history.back();'>#{fa_icon('close')} #{t('drgcms.close')}</div></li>"
190
+ %(<div class="dc-link" onclick='history.back();'>#{fa_icon('close')} #{t('drgcms.close')}</div></li>)
190
191
  end
191
192
  else
192
193
  "err1 #{key}=>#{options}"
@@ -203,14 +204,14 @@ def dc_actions_for_form(position)
203
204
  when options['type'] == 'submit'
204
205
  caption = options['caption'] || 'drgcms.save'
205
206
  icon = options['icon'] || 'save'
206
- prms = {}
207
- options['params'].each { |k,v| prms[k] = dc_value_for_parameter(v) } if options['params']
207
+ parameters = {}
208
+ options['params'].each { |k, v| parameters[k] = dc_value_for_parameter(v) } if options['params']
208
209
  if dc_is_action_active?(options)
209
- '<li class="dc-link-submit dc-animate">' +
210
- dc_submit_tag(caption, icon, {:data => prms, :title => options['title'] }) +
210
+ '<li>' +
211
+ dc_submit_tag(caption, icon, { data: parameters, title: options['title'] }) +
211
212
  '</li>'
212
213
  else
213
- "<li class=\"dc-link-no\">#{fa_icon(icon)} #{caption}</li>"
214
+ %(<li><div class="dc-link-no">#{fa_icon(icon)} #{caption}</div></li>)
214
215
  end
215
216
 
216
217
  # delete with some sugar added
@@ -219,21 +220,22 @@ def dc_actions_for_form(position)
219
220
  parms.merge!(options['params'])
220
221
  caption = options['caption'] || 'drgcms.delete'
221
222
  icon = options['icon'] || 'remove'
222
- '<li class="dc-link dc-animate">' +
223
- dc_link_to( caption, icon, parms, data: t('drgcms.confirm_delete'), method: :delete ) +
223
+ '<li class="">' +
224
+ dc_link_to( caption, icon, parms, data: t('drgcms.confirm_delete'), method: :delete, class: 'dc-link' ) +
224
225
  '</li>'
225
-
226
+
226
227
  # ajax or link button
227
- when %w(ajax link window).include?(options['type'])
228
+ when %w(ajax link window popup).include?(options['type'])
228
229
  dc_link_ajax_window_submit_action(options, @record)
229
-
230
- # Javascript action
230
+
231
+ # Javascript action
231
232
  when options['type'] == 'script'
232
233
  dc_script_action(options)
233
234
  else
234
235
  '<li>err2</li>'
235
236
  end
236
237
  end
238
+
237
239
  end
238
240
  (html << '</ul>').html_safe
239
241
  end
@@ -277,127 +279,26 @@ def dc_check_and_default(value, default, values=nil) #:nodoc:
277
279
  end
278
280
 
279
281
  ############################################################################
280
- # Creates input fields for one tab. Subroutine of dc_fields_for_form.
281
- ############################################################################
282
- def dc_fields_for_tab(fields_on_tab) #:nodoc:
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
286
- group_option, group_count = 0, 0
287
- reset_cycle()
288
- # Select form fields and sort them by key
289
- form_fields = fields_on_tab.select {|field| field.class == Integer }
290
- form_fields.to_a.sort.each do |number, options|
291
- session[:form_processing] = "form:fields: #{number}=#{options}"
292
- # ignore if edit_only singe field is required
293
- next if params[:edit_only] and params[:edit_only] != options['name']
294
- # hidden_fields. Add them at the end
295
- if options['type'] == 'hidden_field'
296
- hidden_fields << DrgcmsFormFields::HiddenField.new(self, @record, options).render
297
- next
298
- end
299
- # label
300
- field_html,label,help = dc_field_label_help(options)
301
- # Line separator
302
- html << dc_top_bottom_line(:top, options)
303
- # Beginning of new row
304
- if group_count == 0
305
- html << '<div class="row-div">'
306
- odd_even = cycle('odd','even')
307
- group_count = options['group'] || 1
308
- group_option = options['group'] || 1
309
- end
310
-
311
- html << if labels_pos == 'top'
312
- %(
313
- <div class="dc-form-label-top dc-color-#{odd_even} dc-align-left" title="#{help}">
314
- <label for="record_#{options['name']}">#{label} </label>
315
- <div id="td_record_#{options['name']}">#{field_html}</div>
316
- </div> )
317
- else
318
- # no label
319
- if dc_dont?(options['caption'])
320
- label = ''
321
- label_width = 0
322
- data_width = 100
323
- elsif group_option > 1
324
- label_width = group_option != group_count ? 10 : 14
325
- data_width = 21
326
- else
327
- label_width = 14
328
- data_width = 85
329
- end
330
- help.gsub!('<br>',"\n") if help.present?
331
- %(
332
- <div class="dc-form-label dc-color-#{odd_even} dc-align-#{labels_pos} dc-width-#{label_width}" title="#{help}">
333
- <label for="record_#{options['name']}">#{label} </label>
334
- </div>
335
- <div id="td_record_#{options['name']}" class="dc-form-field dc-color-#{odd_even} dc-width-#{data_width}">#{field_html}</div>
336
- )
337
- end
338
- # check if group end
339
- if (group_count -= 1) == 0
340
- html << '</div>'
341
- # insert dummy div when only two fields in group
342
- html << '<div></div>' if group_option == 2
343
- end
344
-
345
- html << dc_top_bottom_line(:bottom, options)
346
- end
347
- html << '</div>' << hidden_fields
348
- end
349
-
350
- ############################################################################
351
- # Creates edit form from fields or tabs options
282
+ # Creates input fields defined in form options
352
283
  ############################################################################
353
284
  def dc_fields_for_form
354
- html, tabs, tab_data = '',[], ''
285
+ html = "<div id='data_fields' " + (@form['form']['height'] ? "style=\"height: #{@form['form']['height']}px;\">" : '>')
355
286
  @js ||= ''
356
287
  @css ||= ''
357
- # Only fields defined
288
+ # fields
358
289
  if (form_fields = @form['form']['fields'])
359
- html << "<div id='data_fields' " + (@form['form']['height'] ? "style=\"height: #{@form['form']['height']}px;\">" : '>')
360
- html << dc_fields_for_tab(form_fields) + '</div>'
361
- else
362
- # there are multiple tabs on form
363
- first = true # first tab
364
- @form['form']['tabs'].keys.sort.each do |tab_name|
365
- next if tab_name.match('actions')
366
- # Tricky when editing single field. If field is not present on the tab skip to next tab
367
- if params[:edit_only]
368
- is_on_tab = false
369
- @form['form']['tabs'][tab_name].each { |k, v| is_on_tab = true if params[:edit_only] == v['name'] }
370
- next unless is_on_tab
371
- end
372
- # first div is displayed, all others are hidden
373
- tab_data << "<div id=\"data_#{tab_name.delete("\s\n")}\""
374
- tab_data << ' class="div-hidden"' unless first
375
- tab_data << " style=\"height: #{@form['form']['height']}px;\"" if @form['form']['height']
376
- tab_data << ">#{dc_fields_for_tab(@form['form']['tabs'][tab_name])}</div>"
377
-
378
- tab_label, tab_title = dc_tab_label_help(tab_name)
379
- tabs << [tab_name, tab_label, tab_title]
380
- first = false
381
- end
382
- # make it all work together
383
- html << '<ul class="dc-form-ul" >'
384
- first = true # first tab must be selected
385
- tabs.each do |tab_name, tab_label, tab_title|
386
- html << %(<li id="li_#{tab_name}" data-div="#{tab_name.delete("\s\n")}" title="#{tab_title}" class="dc-form-li)
387
- html << ' dc-form-li-selected' if first
388
- html << "\">#{tab_label}</li>"
389
- first = false
390
- end
391
- html << '</ul>'
392
- html << tab_data
290
+ html << dc_input_form_create(form_fields) + '</div>'
291
+ # tabs
292
+ elsif @form['form']['tabs']
293
+ html = dc_tabs_form_create()
393
294
  end
394
295
  # add last_updated_at hidden field so controller can check if record was updated in db during editing
395
296
  html << hidden_field(nil, :last_updated_at, value: @record.updated_at.to_i) if @record.respond_to?(:updated_at)
396
297
  # add form time stamp to prevent double form submit
397
298
  html << hidden_field(nil, :form_time_stamp, value: Time.now.to_i)
398
299
  # add javascript code if defined by form
399
- @js << "\n#{@form['script']}"
400
- @css << "\n#{@form['css']}"
300
+ @js << "\n#{@form['script']} #{@form['js']}"
301
+ @css << "\n#{@form['css']}\n#{@form['form']['css']}"
401
302
  html.html_safe
402
303
  end
403
304
 
@@ -409,6 +310,7 @@ def dc_head_for_form
409
310
  @css ||= ''
410
311
  head = @form['form']['head']
411
312
  return '' if head.nil?
313
+
412
314
  html = %(<div class="dc-head #{head['class']}">\n<div class="dc-row">)
413
315
  split = head['split'] || 4
414
316
  percent = 100/split
@@ -423,7 +325,7 @@ def dc_head_for_form
423
325
  label = if caption.blank?
424
326
  ''
425
327
  elsif options['name'] == caption
426
- t_name(options['name'], options['name'].capitalize.gsub('_',' ') )
328
+ t_label_for_field(options['name'], options['name'].capitalize.gsub('_',' ') )
427
329
  else
428
330
  t(caption, caption)
429
331
  end
@@ -441,13 +343,13 @@ def dc_head_for_form
441
343
  #
442
344
  klass = dc_style_or_class(nil, options['class'], field, @record)
443
345
  style = dc_style_or_class(nil, options['style'], field, @record)
444
- html << %Q[<div class="dc-column #{klass}" style="width:#{percent*span}%;#{style}">
346
+ html << %(<div class="dc-column #{klass}" style="width:#{percent*span}%;#{style}">
445
347
  #{label.blank? ? '' : "<span class=\"label\">#{label}</span>"}
446
348
  <span id="head-#{options['name']}" class="field">#{field}</span>
447
- </div>]
349
+ </div>)
448
350
  current += span
449
351
  if current == split
450
- html << %Q[</div>\n<div class="dc-row">]
352
+ html << %(</div>\n<div class="dc-row">)
451
353
  current = 0
452
354
  end
453
355
  end
@@ -470,31 +372,61 @@ end
470
372
  # + lots of more. At the moment also adds icon for dumping current document as json text.
471
373
  ############################################################################
472
374
  def dc_document_statistics
473
- return '' if @record.new_record? or dc_dont?(@form['form']['info'])
474
- html = %Q[<div id="dc-document-info">#{fa_icon('info-circle lg')}</div> <div id="dc-document-info-popup" class="div-hidden"> ]
475
- #
375
+ return '' if @record.id.nil? || dc_dont?(@form['form']['info'])
376
+
377
+ html = %(<div id="dc-document-info">#{fa_icon('info md-18')}</div> <div id="dc-document-info-popup" class="div-hidden">)
476
378
  u = dc_document_user_for('created_by')
477
- html << %Q[<div><span>#{t('drgcms.created_by', 'Created by')}: </span><span>#{u}</span></div>] if u
379
+ html << %(<div><span>#{t('drgcms.created_by', 'Created by')}: </span><span>#{u}</span></div>) if u
478
380
  u = dc_document_user_for('updated_by')
479
- html << %Q[<div><span>#{t('drgcms.updated_by', 'Updated by')}: </span><span>#{u}</span></div>] if u
480
- html << %Q[<div><span>#{t('drgcms.created_at', 'Created at')}: </span><span>#{dc_format_value(@record.created_at)}</span></div>] if @record['created_at']
481
- html << %Q[<div><span>#{t('drgcms.updated_at', 'Updated at')}: </span><span>#{dc_format_value(@record.updated_at)}</span></div>] if @record['updated_at']
482
- # copy to clipboard icon
381
+ html << %(<div><span>#{t('drgcms.updated_by', 'Updated by')}: </span><span>#{u}</span></div>) if u
382
+
383
+ html << %(<div><span>#{t('drgcms.created_at', 'Created at')}: </span><span>#{dc_format_value(@record.created_at)}</span></div>) if @record['created_at']
384
+ html << %(<div><span>#{t('drgcms.updated_at', 'Updated at')}: </span><span>#{dc_format_value(@record.updated_at)}</span></div>) if @record['updated_at']
385
+ # copy to clipboard icon
483
386
  parms = params.clone
484
387
  parms[:controller] = 'dc_common'
485
388
  parms[:action] = 'copy_clipboard'
486
389
  url = url_for(parms.permit!)
487
- html << fa_icon('copy lg', class: 'dc-link-img dc-link-ajax dc-animate',
390
+ html << '<div>'
391
+ html << fa_icon('content_copy-o md-18', class: 'dc-link-img dc-link-ajax',
488
392
  'data-url' => url, 'data-request' => 'get', title: t('drgcms.doc_copy_clipboard') )
489
393
 
490
- url = url_for(controller: :cmsedit, action: :index, table: 'dc_journal', filter: 'on',
394
+ url = url_for(controller: :cmsedit, action: :run, table: 'dc_journal', control: 'cmsedit.filter_on',
491
395
  filter_oper: 'eq', filter_field: 'doc_id', filter_value: @record.id)
492
- html << fa_icon('history lg', class: 'dc-link-img dc-animate dc-window-open',
396
+
397
+ html << fa_icon('history md-18', class: 'dc-link-img dc-window-open',
493
398
  'data-url' => url, title: t('helpers.label.dc_journal.tabletitle') )
399
+ html << %(<span>ID: </span>
400
+ <span id="record-id" class="hover" onclick="dc_copy_to_clipboard('record-id');" title="Copy document ID to clipboard">#{@record.id}
401
+ </span>)
494
402
 
495
403
  (html << '</div></div>').html_safe
496
404
  end
497
405
 
406
+ ############################################################################
407
+ # Updates form prior to processing form
408
+ ############################################################################
409
+ def dc_form_update
410
+ # update form for steps options
411
+ if @form.dig('form', 'steps')
412
+ dc_form_update_steps
413
+ end
414
+ end
415
+
416
+ ############################################################################
417
+ # If form is divided into two parts, this method gathers html to be painted
418
+ # on right side of the form pane.
419
+ ############################################################################
420
+ def dc_form_left
421
+ yaml = @form.dig('form', 'form_left')
422
+ return '' unless yaml
423
+
424
+ html = ''
425
+ html << dc_process_eval(yaml['eval'], self) if yaml['eval']
426
+
427
+ html.html_safe
428
+ end
429
+
498
430
  private
499
431
 
500
432
  ############################################################################
@@ -513,4 +445,188 @@ def dc_top_bottom_line(location, options)
513
445
  end
514
446
  end
515
447
 
448
+ ############################################################################
449
+ # Creates input fields for one tab. Subroutine of dc_fields_for_form.
450
+ ############################################################################
451
+ def dc_input_form_create(fields_on_tab) #:nodoc:
452
+ html = '<div class="dc-form">'
453
+ labels_pos = dc_check_and_default(@form['form']['labels_pos'], 'right', %w[top left right])
454
+ hidden_fields, odd_even = '', nil
455
+ group_option, group_count = 0, 0
456
+ reset_cycle()
457
+ # Select form fields and sort them by key
458
+ form_fields = fields_on_tab.select {|field| field.class == Integer }
459
+ form_fields.to_a.sort.each do |number, options|
460
+ session[:form_processing] = "form:fields: #{number}=#{options}"
461
+ # ignore if edit_only singe field is required
462
+ next if params[:edit_only] and params[:edit_only] != options['name']
463
+ next if options.nil?
464
+
465
+ # hidden_fields. Add them at the end
466
+ if options['type'] == 'hidden_field'
467
+ hidden_fields << DrgcmsFormFields::HiddenField.new(self, @record, options).render
468
+ next
469
+ end
470
+ # label
471
+ field_html,label,help = dc_field_label_help(options)
472
+ # Line separator
473
+ html << dc_top_bottom_line(:top, options)
474
+ # Beginning of new row
475
+ if group_count == 0
476
+ html << '<div class="row-div">'
477
+ odd_even = cycle('odd','even')
478
+ group_count = options['group'] || 1
479
+ group_option = options['group'] || 1
480
+ end
481
+
482
+ html << if labels_pos == 'top'
483
+ %(
484
+ <div class="dc-form-label-top dc-color-#{odd_even} dc-align-left" title="#{help}">
485
+ <label for="record_#{options['name']}">#{label} </label>
486
+ <div id="td_record_#{options['name']}">#{field_html}</div>
487
+ </div> )
488
+ else
489
+ # no label
490
+ if dc_dont?(options['caption'])
491
+ label = ''
492
+ label_width = 0
493
+ data_width = 100
494
+ elsif group_option > 1
495
+ label_width = group_option != group_count ? 10 : 14
496
+ data_width = 21
497
+ else
498
+ label_width = 14
499
+ data_width = 85
500
+ end
501
+ help.gsub!('<br>',"\n") if help.present?
502
+ %(
503
+ <div class="dc-form-label dc-color-#{odd_even} dc-align-#{labels_pos} dc-width-#{label_width}" title="#{help}">
504
+ <label for="record_#{options['name']}">#{label} </label>
505
+ </div>
506
+ <div id="td_record_#{options['name']}" class="dc-form-field dc-color-#{odd_even} dc-width-#{data_width}">#{field_html}</div>
507
+ )
508
+ end
509
+ # check if group end
510
+ if (group_count -= 1) == 0
511
+ html << '</div>'
512
+ # insert dummy div when only two fields in group
513
+ html << '<div></div>' if group_option == 2
514
+ end
515
+
516
+ html << dc_top_bottom_line(:bottom, options)
517
+ end
518
+ html << '</div>' << hidden_fields
519
+ end
520
+
521
+ ############################################################################
522
+ # Will create html code required for input form with steps defined
523
+ ############################################################################
524
+ def dc_steps_one_element(element, tab_name = nil)
525
+ def add_one_step(key, tab_name, key_number)
526
+ fields = tab_name ? @form['form']['tabs'][tab_name] : @form['form']['fields']
527
+ { key_number => fields[key] }
528
+ end
529
+
530
+ key_number, fields = 0, {}
531
+ element.to_s.split(',').each do |particle|
532
+ if particle.match('-')
533
+ tabs_fields = tab_name ? @form['form']['tabs'][tab_name] : @form['form']['fields']
534
+ next if tabs_fields.nil?
535
+
536
+ start, to_end = particle.split('-').map(&:to_i)
537
+ tabs_fields.each { |key, data| fields.merge!(add_one_step(key, tab_name, key_number += 10)) if (start..to_end).include?(key) }
538
+ else
539
+ fields.merge!(add_one_step(particle.to_i, tab_name, key_number += 10))
540
+ end
541
+ end
542
+ fields
543
+ end
544
+
545
+ ############################################################################
546
+ # Will create html code required for input form with steps defined and update
547
+ # actions.
548
+ ############################################################################
549
+ def dc_form_update_steps
550
+ def add_step_to_form(index, step, next_step)
551
+ @form['form']['actions'][index]['params']['step'] = step
552
+ @form['form']['actions'][index]['params']['next_step'] = next_step
553
+ end
554
+
555
+ form = {}
556
+ step = params[:step].to_i
557
+ step_data = @form['form']['steps'].to_a[step - 1]
558
+
559
+ step_data.last.each do |element|
560
+ if element.first == 'fields'
561
+ form.merge!(dc_steps_one_element(element.second))
562
+ elsif element.first == 'tabs'
563
+ element.last.each do |tab_name, data|
564
+ form.merge!(dc_steps_one_element(data, tab_name))
565
+ end
566
+ end
567
+ end
568
+ # fraction updates of newly created form
569
+ form.deep_merge!(step_data.last['update']) if step_data.last['update']
570
+ # update steps data on form
571
+ add_step_to_form(10, step, step - 1)
572
+ add_step_to_form(20, step, step + 1)
573
+ add_step_to_form(100, step, step + 1)
574
+ # remove not needed steps
575
+ if step < 2
576
+ @form['form']['actions'].delete(10)
577
+ elsif step == @form['form']['steps'].size
578
+ @form['form']['actions'].delete(20)
579
+ end
580
+ @form['form']['actions'].delete(100) unless step == @form['form']['steps'].size
581
+ # update form_name and control name if defined
582
+ %w[1 10 20 100].each do |i|
583
+ next unless @form['form']['actions'][i.to_i]
584
+
585
+ @form['form']['actions'][i.to_i]['form_name'] = CmsHelper.form_param(params)
586
+ control = @form['control'] ? @form['control'] : @form['table']
587
+ @form['form']['actions'][i.to_i]['control'].sub!('x.', "#{control}.")
588
+ end
589
+
590
+ @form['form']['form_left'] ||= { 'eval' => 'dc_steps_menu_get'}
591
+ @form['form']['fields'] = form
592
+ end
593
+
594
+ ############################################################################
595
+ # Will create html code required for input form with tabs
596
+ ############################################################################
597
+ def dc_tabs_form_create
598
+ html, tabs, tab_data = '', [], ''
599
+ # there are multiple tabs on form
600
+ first = true # first tab
601
+ @form['form']['tabs'].keys.sort.each do |tab_name|
602
+ next if tab_name.match('actions')
603
+ # Tricky when editing single field. If field is not present on the tab skip to next tab
604
+ if params[:edit_only]
605
+ is_on_tab = false
606
+ @form['form']['tabs'][tab_name].each { |k, v| is_on_tab = true if params[:edit_only] == v['name'] }
607
+ next unless is_on_tab
608
+ end
609
+ # first div is displayed, all others are hidden
610
+ tab_data << "<div id=\"data_#{tab_name.delete("\s\n")}\""
611
+ tab_data << ' class="div-hidden"' unless first
612
+ tab_data << " style=\"height: #{@form['form']['height']}px;\"" if @form['form']['height']
613
+ tab_data << ">#{dc_input_form_create(@form['form']['tabs'][tab_name])}</div>"
614
+
615
+ tab_label, tab_title = dc_tab_label_help(tab_name)
616
+ tabs << [tab_name, tab_label, tab_title]
617
+ first = false
618
+ end
619
+ # make it all work together
620
+ html << '<ul class="dc-form-ul" >'
621
+ first = true # first tab must be selected
622
+ tabs.each do |tab_name, tab_label, tab_title|
623
+ html << %(<li id="li_#{tab_name}" data-div="#{tab_name.delete("\s\n")}" title="#{tab_title}" class="dc-form-li)
624
+ html << ' dc-form-li-selected' if first
625
+ html << "\">#{tab_label}</li>"
626
+ first = false
627
+ end
628
+ html << '</ul>'
629
+ html << tab_data
630
+ end
631
+
516
632
  end