drg_cms 0.6.1.9 → 0.6.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/drg_cms/drg_cms.js +35 -14
  3. data/app/assets/stylesheets/drg_cms/drg_cms.css +89 -26
  4. data/app/controllers/cmsedit_controller.rb +9 -111
  5. data/app/controllers/dc_application_controller.rb +97 -21
  6. data/app/controllers/dc_common_controller.rb +3 -17
  7. data/app/controls/browse_models_control.rb +3 -1
  8. data/app/controls/cmsedit_control.rb +5 -1
  9. data/app/controls/dc_report.rb +1 -1
  10. data/app/forms/all_options.yml +2 -0
  11. data/app/forms/dc_browse_models.yml +24 -2
  12. data/app/forms/dc_steps_template.yml +51 -0
  13. data/app/helpers/cms_common_helper.rb +66 -1
  14. data/app/helpers/cms_edit_helper.rb +228 -119
  15. data/app/helpers/cms_helper.rb +74 -17
  16. data/app/helpers/cms_index_helper.rb +40 -37
  17. data/app/helpers/dc_application_helper.rb +6 -27
  18. data/app/models/dc_journal.rb +2 -2
  19. data/app/models/dc_json_ld.rb +18 -41
  20. data/app/models/drgcms_form_fields/readonly.rb +1 -1
  21. data/app/models/drgcms_form_fields/select.rb +2 -2
  22. data/app/models/drgcms_form_fields/text_autocomplete.rb +2 -2
  23. data/app/models/drgcms_form_fields/text_with_select.rb +1 -0
  24. data/app/renderers/dc_common_renderer.rb +20 -3
  25. data/app/views/cmsedit/_form.html.erb +19 -12
  26. data/app/views/cmsedit/edit.html.erb +10 -6
  27. data/app/views/cmsedit/index.html.erb +5 -3
  28. data/app/views/cmsedit/new.html.erb +9 -5
  29. data/app/views/dc_common/_help.html.erb +1 -0
  30. data/config/locales/drgcms_en.yml +5 -0
  31. data/config/locales/drgcms_sl.yml +5 -0
  32. data/drg_cms.gemspec +1 -1
  33. data/lib/drg_cms/version.rb +1 -1
  34. metadata +8 -7
@@ -268,7 +268,7 @@ end
268
268
  ########################################################################
269
269
  def add_json_ld_schema
270
270
  edited_document = DcJsonLd.find_document_by_ids(CmsHelper.table_param(params), params[:ids])
271
- yaml = YAML.load_file( dc_find_form_file('json_ld_schema') )
271
+ yaml = YAML.load_file( CmsHelper.form_file_find('json_ld_schema') )
272
272
  schema_data = yaml[params[:schema]]
273
273
  # Existing document
274
274
  if edited_document.dc_json_lds.find_by(type: "@#{params[:schema]}")
@@ -283,12 +283,10 @@ end
283
283
  # Will provide help data
284
284
  ########################################################################
285
285
  def help
286
+ dc_form_read
286
287
  form_name = CmsHelper.form_param(params) || CmsHelper.table_param(params)
287
- @form = form_name ? YAML.load_file(dc_find_form_file(form_name)) : {}
288
- return render json: {} if @form.nil?
289
-
290
288
  help_file_name = @form['help'] || @form['extend'] || form_name
291
- help_file_name = find_help_file(help_file_name)
289
+ help_file_name = DcApplicationController.find_help_file(help_file_name)
292
290
  @help = YAML.load_file(help_file_name) if help_file_name
293
291
  # no auto generated help on index action
294
292
  return render json: {} if params[:type] == 'index' && @help.nil?
@@ -298,18 +296,6 @@ end
298
296
 
299
297
  protected
300
298
 
301
- ########################################################################
302
- # Will search for help file and return it's path if found
303
- ########################################################################
304
- def find_help_file(help_file_name)
305
- file_name = nil
306
- DrgCms.paths(:forms).reverse.each do |path|
307
- f = "#{path}/help/#{help_file_name}.#{I18n.locale}"
308
- file_name = f and break if File.exist?(f)
309
- end
310
- file_name
311
- end
312
-
313
299
  ########################################################################
314
300
  # Subroutine of add_json_ld_schema for adding one element
315
301
  ########################################################################
@@ -49,6 +49,8 @@ end
49
49
  def collections
50
50
  @records = []
51
51
  all_collections.each do |collection|
52
+ next if params[:filter] && !collection.match(/#{params[:filter]}/i)
53
+
52
54
  @records << DcMemory.new({'id' => collection, 'description' => t("helpers.label.#{collection}.tabletitle") })
53
55
  end
54
56
  @records
@@ -75,7 +77,7 @@ def all_fields
75
77
  '_default' => options[:default]
76
78
  })
77
79
  end
78
- # embedded documents
80
+ # embedded documents
79
81
  document.embedded_relations.each do |a_embedded|
80
82
  embedded = a_embedded.last
81
83
  description = I18n.t("helpers.help.#{params[:id]}.#{embedded.key}")
@@ -43,11 +43,15 @@ end
43
43
  ######################################################################
44
44
  def filter_on
45
45
  table_name = CmsHelper.table_param(params).strip.split(';').first.underscore
46
+ session[table_name] ||= {}
46
47
  session[table_name][:page] = 1
47
48
  set_session_filter(table_name)
48
49
  url = url_for( controller: 'cmsedit', t: table_name, f: CmsHelper.form_param(params))
49
50
 
50
- render json: { url: url }
51
+ respond_to do |format|
52
+ format.json { render json: { url: url } }
53
+ format.html { redirect_to url }
54
+ end
51
55
  end
52
56
 
53
57
  ########################################################################
@@ -132,7 +132,7 @@ end
132
132
  # Export data to Excel
133
133
  ######################################################################
134
134
  def export_to_excel(report_id)
135
- read_drg_form if @form.blank?
135
+ dc_form_read if @form.blank?
136
136
  # use report options if present
137
137
  columns = (@form['report'] ? @form['report'] : @form)['result_set']['columns'].sort
138
138
 
@@ -156,6 +156,8 @@ form:
156
156
  or
157
157
  active:
158
158
  method: SomeClass.is_active_method
159
+ html:
160
+ data-validate: no
159
161
 
160
162
  5:
161
163
  type: window
@@ -6,6 +6,16 @@ controls: browse_models
6
6
  permissions:
7
7
  can_view: admin
8
8
 
9
+ index:
10
+ actions:
11
+ 10:
12
+ type: field
13
+ name: filter
14
+ field_type: text_field
15
+ caption: Filter
16
+ size: 10
17
+
18
+
9
19
  result_set:
10
20
  filter: collections
11
21
 
@@ -19,8 +29,20 @@ result_set:
19
29
  10:
20
30
  name: id
21
31
  caption: Collection
22
- td_style: 'font-weight: bold;width: 150px;'
23
-
32
+ td_style: 'font-weight: bold;'
33
+
24
34
  20:
25
35
  name: description
26
36
  caption: Decription
37
+
38
+ script: '
39
+ $(document).ready( function() {
40
+ $("#record_filter").keydown( function(e) {
41
+ if (e.which == "13" || e.which == "9") {
42
+ let url = "/cmsedit?form_name=dc_browse_models&table=dc_memory&filter=" + this.value;
43
+ window.location.href = url;
44
+ e.preventDefault();
45
+ };
46
+ });
47
+ });
48
+ '
@@ -0,0 +1,51 @@
1
+ ## Template for standard options on wizard form
2
+ form:
3
+ css: '#dc-form-left {display: block;width: 20%}'
4
+ actions:
5
+ 1:
6
+ type: ajax
7
+ caption: drgcms.cancel
8
+ icon: cancel
9
+ method: post
10
+ form_name: x
11
+ action: run
12
+ control: x.steps_cancel
13
+ params:
14
+ step: x
15
+ next_step: x
16
+
17
+ 10:
18
+ type: ajax
19
+ caption: drgcms.back
20
+ icon: arrow-back
21
+ method: post
22
+ form_name: x
23
+ action: run
24
+ control: x.steps
25
+ params:
26
+ step: x
27
+ next_step: x
28
+
29
+ 20:
30
+ type: ajax
31
+ caption: drgcms.next
32
+ icon: arrow-forward
33
+ method: post
34
+ form_name: x
35
+ action: run
36
+ control: x.steps
37
+ params:
38
+ step: x
39
+ next_step: x
40
+
41
+ 100:
42
+ type: ajax
43
+ caption: drgcms.finish
44
+ icon: done
45
+ method: post
46
+ form_name: x
47
+ action: run
48
+ control: x.steps_finish
49
+ params:
50
+ step: x
51
+ next_step: x
@@ -81,12 +81,26 @@ end
81
81
  # Translation is provided by lang.helpers.label.table_name.field_name locale. If
82
82
  # translation is not found method will capitalize field_name and replace '_' with ' '.
83
83
  ############################################################################
84
- def t_name(field_name, default='')
84
+ def t_label_for_field(field_name, default='')
85
85
  c = t("helpers.label.#{@form['table']}.#{field_name}", default)
86
86
  c = field_name.capitalize.gsub('_',' ') if c.match( 'translation missing' )
87
87
  c
88
88
  end
89
89
 
90
+ ############################################################################
91
+ # Returns label for field translated to current locale for usage browser header.
92
+ # Translation is provided by lang.helpers.label.table_name.field_name locale. If
93
+ # not found method will look in standard drgcms translations.
94
+ #
95
+ ############################################################################
96
+ def t_label_for_column(options)
97
+ label = options['caption'] || options['label']
98
+ label = (options['name'] ? "helpers.label.#{@form['table']}.#{options['name']}" : '') if label.nil?
99
+ label = t(label) if label.match(/\./)
100
+ label = t("drgcms.#{options['name']}") if label.match('helpers.') # standard field names like created_by, updated_at
101
+ label
102
+ end
103
+
90
104
  ###########################################################################
91
105
  # When select field is used on form options for select can be provided by
92
106
  # helpers.label.table_name.choices4_name locale. This is how select
@@ -374,4 +388,55 @@ def dc_help_body
374
388
  (params[:type] == 'index' ? @help['index'] : @help['form']).html_safe
375
389
  end
376
390
 
391
+ ############################################################################
392
+ # Will return code for help button if there is any help text available for the form.
393
+ ############################################################################
394
+ def dc_help_button(result_set)
395
+ type = result_set.nil? ? 'form' : 'index'
396
+ form_name = CmsHelper.form_param(params) || CmsHelper.table_param(params)
397
+ url = url_for(controller: :dc_common, action: :help, type: type, f: form_name)
398
+ html = %(<div class="dc-help-icon dc-link-ajax" data-url=#{url}>#{fa_icon('question-circle')}</div>)
399
+ return html if type == 'form'
400
+
401
+ # check if index has any help available
402
+ help_file_name = @form['help'] || @form['extend'] || form_name
403
+ help_file_name = DcApplicationController.find_help_file(help_file_name)
404
+ if help_file_name
405
+ help = YAML.load_file(help_file_name)
406
+ return html if help['index']
407
+ end
408
+ ''
409
+ end
410
+
411
+ ############################################################################
412
+ # Will return html code for steps menu when form with steps is processed.
413
+ ############################################################################
414
+ def dc_steps_menu_get(parent)
415
+ yaml = @form['form']['steps']
416
+ return '' unless yaml
417
+
418
+ html = %(<ul id="dc-steps-menu"><h2>#{t('drgcms.steps')}</h2>)
419
+ control = @form['control'] ? @form['control'] : @form['table']
420
+ parms = { controller: 'cmsedit', action: 'run', control: "#{control}.steps",
421
+ table: CmsHelper.table_param(params),
422
+ form_name: CmsHelper.form_param(params),
423
+ id: @record.id }
424
+
425
+ yaml.sort.each_with_index do |data, i|
426
+ n = i + 1
427
+ step = data.last # it's an array
428
+ url = case params[:step].to_i
429
+ when n + 1 then url_for(parms.merge({ step: n + 1, next_step: n}))
430
+ when n then url_for(parms.merge({ step: n, next_step: n}))
431
+ when n - 1 then url_for(parms.merge({ step: n - 1, next_step: n}))
432
+ else
433
+ ''
434
+ end
435
+ _class = url.present? ? 'dc-link-ajax' : ''
436
+ _class << (params[:step].to_i == n ? ' active' : '')
437
+ html << %(<li class="#{_class}" data-url="#{url}">#{step['title']}</li>)
438
+ end
439
+ html << '</ul>'
440
+ end
441
+
377
442
  end
@@ -143,7 +143,7 @@ def dc_actions_for_form(position)
143
143
  session[:form_processing] = "form:actions: #{key} #{options}"
144
144
  next if options.nil? # yes it happens
145
145
 
146
- parms = @parms.clone
146
+ parms = @form_params.clone
147
147
  if options.class == String
148
148
  next if @form['readonly'] and !options.match(/back|close/)
149
149
 
@@ -279,127 +279,26 @@ def dc_check_and_default(value, default, values=nil) #:nodoc:
279
279
  end
280
280
 
281
281
  ############################################################################
282
- # Creates input fields for one tab. Subroutine of dc_fields_for_form.
283
- ############################################################################
284
- def dc_fields_for_tab(fields_on_tab) #:nodoc:
285
- html = '<div class="dc-form">'
286
- labels_pos = dc_check_and_default(@form['form']['labels_pos'], 'right', ['top', 'left', 'right'])
287
- hidden_fields, odd_even = '', nil
288
- group_option, group_count = 0, 0
289
- reset_cycle()
290
- # Select form fields and sort them by key
291
- form_fields = fields_on_tab.select {|field| field.class == Integer }
292
- form_fields.to_a.sort.each do |number, options|
293
- session[:form_processing] = "form:fields: #{number}=#{options}"
294
- # ignore if edit_only singe field is required
295
- next if params[:edit_only] and params[:edit_only] != options['name']
296
- # hidden_fields. Add them at the end
297
- if options['type'] == 'hidden_field'
298
- hidden_fields << DrgcmsFormFields::HiddenField.new(self, @record, options).render
299
- next
300
- end
301
- # label
302
- field_html,label,help = dc_field_label_help(options)
303
- # Line separator
304
- html << dc_top_bottom_line(:top, options)
305
- # Beginning of new row
306
- if group_count == 0
307
- html << '<div class="row-div">'
308
- odd_even = cycle('odd','even')
309
- group_count = options['group'] || 1
310
- group_option = options['group'] || 1
311
- end
312
-
313
- html << if labels_pos == 'top'
314
- %(
315
- <div class="dc-form-label-top dc-color-#{odd_even} dc-align-left" title="#{help}">
316
- <label for="record_#{options['name']}">#{label} </label>
317
- <div id="td_record_#{options['name']}">#{field_html}</div>
318
- </div> )
319
- else
320
- # no label
321
- if dc_dont?(options['caption'])
322
- label = ''
323
- label_width = 0
324
- data_width = 100
325
- elsif group_option > 1
326
- label_width = group_option != group_count ? 10 : 14
327
- data_width = 21
328
- else
329
- label_width = 14
330
- data_width = 85
331
- end
332
- help.gsub!('<br>',"\n") if help.present?
333
- %(
334
- <div class="dc-form-label dc-color-#{odd_even} dc-align-#{labels_pos} dc-width-#{label_width}" title="#{help}">
335
- <label for="record_#{options['name']}">#{label} </label>
336
- </div>
337
- <div id="td_record_#{options['name']}" class="dc-form-field dc-color-#{odd_even} dc-width-#{data_width}">#{field_html}</div>
338
- )
339
- end
340
- # check if group end
341
- if (group_count -= 1) == 0
342
- html << '</div>'
343
- # insert dummy div when only two fields in group
344
- html << '<div></div>' if group_option == 2
345
- end
346
-
347
- html << dc_top_bottom_line(:bottom, options)
348
- end
349
- html << '</div>' << hidden_fields
350
- end
351
-
352
- ############################################################################
353
- # Creates edit form from fields or tabs options
282
+ # Creates input fields defined in form options
354
283
  ############################################################################
355
284
  def dc_fields_for_form
356
- html, tabs, tab_data = '',[], ''
285
+ html = "<div id='data_fields' " + (@form['form']['height'] ? "style=\"height: #{@form['form']['height']}px;\">" : '>')
357
286
  @js ||= ''
358
287
  @css ||= ''
359
- # Only fields defined
288
+ # fields
360
289
  if (form_fields = @form['form']['fields'])
361
- html << "<div id='data_fields' " + (@form['form']['height'] ? "style=\"height: #{@form['form']['height']}px;\">" : '>')
362
- html << dc_fields_for_tab(form_fields) + '</div>'
363
- else
364
- # there are multiple tabs on form
365
- first = true # first tab
366
- @form['form']['tabs'].keys.sort.each do |tab_name|
367
- next if tab_name.match('actions')
368
- # Tricky when editing single field. If field is not present on the tab skip to next tab
369
- if params[:edit_only]
370
- is_on_tab = false
371
- @form['form']['tabs'][tab_name].each { |k, v| is_on_tab = true if params[:edit_only] == v['name'] }
372
- next unless is_on_tab
373
- end
374
- # first div is displayed, all others are hidden
375
- tab_data << "<div id=\"data_#{tab_name.delete("\s\n")}\""
376
- tab_data << ' class="div-hidden"' unless first
377
- tab_data << " style=\"height: #{@form['form']['height']}px;\"" if @form['form']['height']
378
- tab_data << ">#{dc_fields_for_tab(@form['form']['tabs'][tab_name])}</div>"
379
-
380
- tab_label, tab_title = dc_tab_label_help(tab_name)
381
- tabs << [tab_name, tab_label, tab_title]
382
- first = false
383
- end
384
- # make it all work together
385
- html << '<ul class="dc-form-ul" >'
386
- first = true # first tab must be selected
387
- tabs.each do |tab_name, tab_label, tab_title|
388
- html << %(<li id="li_#{tab_name}" data-div="#{tab_name.delete("\s\n")}" title="#{tab_title}" class="dc-form-li)
389
- html << ' dc-form-li-selected' if first
390
- html << "\">#{tab_label}</li>"
391
- first = false
392
- end
393
- html << '</ul>'
394
- 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()
395
294
  end
396
295
  # add last_updated_at hidden field so controller can check if record was updated in db during editing
397
296
  html << hidden_field(nil, :last_updated_at, value: @record.updated_at.to_i) if @record.respond_to?(:updated_at)
398
297
  # add form time stamp to prevent double form submit
399
298
  html << hidden_field(nil, :form_time_stamp, value: Time.now.to_i)
400
299
  # add javascript code if defined by form
401
- @js << "\n#{@form['script']}"
402
- @css << "\n#{@form['css']}"
300
+ @js << "\n#{@form['script']} #{@form['js']}"
301
+ @css << "\n#{@form['css']}\n#{@form['form']['css']}"
403
302
  html.html_safe
404
303
  end
405
304
 
@@ -426,7 +325,7 @@ def dc_head_for_form
426
325
  label = if caption.blank?
427
326
  ''
428
327
  elsif options['name'] == caption
429
- t_name(options['name'], options['name'].capitalize.gsub('_',' ') )
328
+ t_label_for_field(options['name'], options['name'].capitalize.gsub('_',' ') )
430
329
  else
431
330
  t(caption, caption)
432
331
  end
@@ -444,13 +343,13 @@ def dc_head_for_form
444
343
  #
445
344
  klass = dc_style_or_class(nil, options['class'], field, @record)
446
345
  style = dc_style_or_class(nil, options['style'], field, @record)
447
- html << %Q[<div class="dc-column #{klass}" style="width:#{percent*span}%;#{style}">
346
+ html << %(<div class="dc-column #{klass}" style="width:#{percent*span}%;#{style}">
448
347
  #{label.blank? ? '' : "<span class=\"label\">#{label}</span>"}
449
348
  <span id="head-#{options['name']}" class="field">#{field}</span>
450
- </div>]
349
+ </div>)
451
350
  current += span
452
351
  if current == split
453
- html << %Q[</div>\n<div class="dc-row">]
352
+ html << %(</div>\n<div class="dc-row">)
454
353
  current = 0
455
354
  end
456
355
  end
@@ -488,18 +387,44 @@ def dc_document_statistics
488
387
  parms[:controller] = 'dc_common'
489
388
  parms[:action] = 'copy_clipboard'
490
389
  url = url_for(parms.permit!)
390
+ html << '<div>'
491
391
  html << fa_icon('content_copy-o md-18', class: 'dc-link-img dc-link-ajax',
492
392
  'data-url' => url, 'data-request' => 'get', title: t('drgcms.doc_copy_clipboard') )
493
393
 
494
- 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',
495
395
  filter_oper: 'eq', filter_field: 'doc_id', filter_value: @record.id)
396
+
496
397
  html << fa_icon('history md-18', class: 'dc-link-img dc-window-open',
497
398
  'data-url' => url, title: t('helpers.label.dc_journal.tabletitle') )
498
- html << %(<span>ID: </span><span id="record-id" class="hover" onclick="dc_copy_to_clipboard('record-id');" title="Copy document ID to clipboard">#{@record.id}</span>)
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>)
402
+
403
+ (html << '</div></div>').html_safe
404
+ end
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
499
423
 
500
- #dc_copy_to_clipboard
424
+ html = ''
425
+ html << dc_process_eval(yaml['eval'], self) if yaml['eval']
501
426
 
502
- (html << '</div>').html_safe
427
+ html.html_safe
503
428
  end
504
429
 
505
430
  private
@@ -520,4 +445,188 @@ def dc_top_bottom_line(location, options)
520
445
  end
521
446
  end
522
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
+
523
632
  end