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
@@ -9,6 +9,6 @@
9
9
  * compiled file, but it's generally better to create a new file per style scope.
10
10
  *
11
11
  *= require drg_cms/drg_cms
12
- *= require font-awesome
12
+ *= require drg_material_icons
13
13
 
14
14
  */
@@ -14,9 +14,6 @@
14
14
  *= require drg_cms/jstree
15
15
 
16
16
  *= require jquery-ui/all
17
-
18
- *= require font-awesome
17
+ *= require drg_material_icons
19
18
  */
20
19
 
21
- /* Required for link buttons to look alike */
22
- .dc-link a, .dc-link-submit input {font-weight: 600; }
@@ -99,7 +99,7 @@ end
99
99
  ########################################################################
100
100
  # Filter action.
101
101
  ########################################################################
102
- def filter
102
+ def _filter
103
103
  index
104
104
  end
105
105
 
@@ -128,12 +128,10 @@ end
128
128
  # Login can be called directly with url http://site.com/cmsedit/login
129
129
  ########################################################################
130
130
  def login
131
- if params[:id] == 'test' then set_test_site
132
- elsif params[:ok] then render action: 'login', layout: 'cms'
133
- else
134
- session[:edit_mode] = 0
135
- render action: 'login', layout: 'cms'
136
- end
131
+ return set_test_site if params[:id] == 'test'
132
+
133
+ session[:edit_mode] = 0 if !params[:ok]
134
+ render action: 'login', layout: 'cms'
137
135
  end
138
136
 
139
137
  ########################################################################
@@ -198,7 +196,7 @@ def new
198
196
  end
199
197
  # new_record callback. Set default values for new record
200
198
  if (m = callback_method('new_record') ) then call_callback_method(m) end
201
- @parms['action'] = 'create'
199
+ @form_params['action'] = 'create'
202
200
  end
203
201
 
204
202
  ########################################################################
@@ -259,12 +257,9 @@ def duplicate_document(source)
259
257
  end
260
258
 
261
259
  ########################################################################
262
- # Create (or duplicate) action. Action is also used for turning filter on.
260
+ # Create (or duplicate) action.
263
261
  ########################################################################
264
262
  def create
265
- # abusing create for turning filter on
266
- return index if params[:filter].to_s == 'on'
267
-
268
263
  # not authorized
269
264
  unless dc_user_can(DcPermission::CAN_CREATE)
270
265
  flash[:error] = t('drgcms.not_authorized')
@@ -284,8 +279,8 @@ def create
284
279
  flash[:info] = t('drgcms.doc_saved')
285
280
  params[:return_to] = 'index' if params[:commit] == t('drgcms.save&back') # save & back
286
281
  return process_return_to(params[:return_to]) if params[:return_to]
287
-
288
- @parms['id'] = @record.id # must be set, for proper update link
282
+
283
+ @form_params['id'] = @record.id # must be set, for proper update link
289
284
  params[:id] = @record.id # must be set, for find_record
290
285
  edit
291
286
  else # error
@@ -314,7 +309,7 @@ def edit
314
309
  # don't do anything if return is false
315
310
  return index if ret.class == FalseClass
316
311
  end
317
- @parms['action'] = 'update'
312
+ @form_params['action'] = 'update'
318
313
  render action: :edit
319
314
  end
320
315
 
@@ -336,7 +331,7 @@ def update
336
331
 
337
332
  if save_data
338
333
  params[:return_to] = 'index' if params[:commit] == t('drgcms.save&back') # save & back
339
- @parms['action'] = 'update'
334
+ @form_params['action'] = 'update'
340
335
  # Process return_to
341
336
  return process_return_to(params[:return_to]) if params[:return_to]
342
337
  else
@@ -427,7 +422,7 @@ def destroy
427
422
 
428
423
  end
429
424
 
430
- @parms['action'] = 'update'
425
+ @form_params['action'] = 'update'
431
426
  render action: :edit
432
427
  end
433
428
 
@@ -439,7 +434,7 @@ def run
439
434
  control_name, method_name = params[:control].split('.')
440
435
  if method_name.nil?
441
436
  method_name = control_name
442
- control_name = params[:table]
437
+ control_name = CmsHelper.table_param(params)
443
438
  end
444
439
  # extend with control methods
445
440
  extend_with_control_module(control_name)
@@ -476,7 +471,7 @@ def can_process_run
476
471
  response = send(:dc_can_process)
477
472
  return response unless response.class == Array
478
473
  else
479
- response = [DcPermission::CAN_VIEW, params[:table] || 'dc_memory']
474
+ response = [DcPermission::CAN_VIEW, CmsHelper.table_param(params) || 'dc_memory']
480
475
  end
481
476
  dc_user_can *response
482
477
  end
@@ -501,108 +496,6 @@ def user_has_permission?(permission, collection_name)
501
496
  true
502
497
  end
503
498
 
504
- ########################################################################
505
- # Merges two forms when current form extends other form. Subroutine of read_drg_form.
506
- # With a little help of https://www.ruby-forum.com/topic/142809
507
- ########################################################################
508
- def forms_merge(hash1, hash2)
509
- target = hash1.dup
510
- hash2.keys.each do |key|
511
- if hash2[key].is_a? Hash and hash1[key].is_a? Hash
512
- target[key] = forms_merge(hash1[key], hash2[key])
513
- next
514
- end
515
- target[key] = hash2[key] == '/' ? nil : hash2[key]
516
- end
517
- # delete keys with nil value
518
- target.delete_if { |k, v| v.nil? }
519
- end
520
-
521
- ########################################################################
522
- # Extends DRGCMS form file. Extended file is processed first and then merged
523
- # with code in this form file. Form can extend only single form file.
524
- #
525
- # [Parameters:]
526
- # [extend_option] : Value of @form['extend'] option
527
- ########################################################################
528
- def extend_drg_form(extend_option)
529
- form_file_name = dc_find_form_file(extend_option)
530
- @form_js << read_js_drg_form(form_file_name)
531
- form = YAML.load_file( form_file_name )
532
- @form = forms_merge(form, @form)
533
- # If combined form contains tabs and fields options, merge fields into tabs
534
- if @form['form']['tabs'] && @form['form']['fields']
535
- @form['form']['tabs']['fields'] = @form['form']['fields']
536
- @form['form']['fields'] = nil
537
- end
538
- end
539
-
540
- ########################################################################
541
- # Include code from another DRGCMS form file. Included code is merged
542
- # with current form file code. Form can include more than one other DRGCMS forms.
543
- #
544
- # [Parameters:]
545
- # [include_option] : Value of @form['include'] option
546
- ########################################################################
547
- def include_drg_form(include_option)
548
- includes = include_option.class == Array ? include_option : include_option.split(/\,|\;/)
549
- includes.each do |include_file|
550
- form_file_name = dc_find_form_file(include_file)
551
- @form_js << read_js_drg_form(form_file_name)
552
- form = YAML.load_file(form_file_name)
553
- @form = forms_merge(@form, form)
554
- end
555
- end
556
-
557
- ########################################################################
558
- # Will read data from form_file_name.js if exists.
559
- #
560
- # [Parameters:]
561
- # [form_file_name] : Physical form filename
562
- ########################################################################
563
- def read_js_drg_form(form_file_name)
564
- js_form_file_name = form_file_name.sub('.yml','.js')
565
- File.read(js_form_file_name) rescue ''
566
- end
567
-
568
- ########################################################################
569
- # Read DRG form into @form object. Subroutine of check_authorization.
570
- ########################################################################
571
- def read_drg_form
572
- table_name = decamelize_type(params[:table].strip)
573
- @tables = table_name.split(';').inject([]) { |r,v| r << [(v.classify.constantize rescue nil), v] }
574
-
575
- # split ids passed when embedded document
576
- ids = params[:ids].to_s.strip.downcase
577
- @ids = ids.split(';').inject([]) { |r,v| r << v }
578
-
579
- # form_name defaults to last table specified
580
- form_name = params[:form_name] || @tables.last[1]
581
- @form_js = ''
582
-
583
- # dynamically generated form
584
- @form = if params[:form_name] == 'method'
585
- dc_eval_class_method(params[:form_method], params)
586
- else
587
- form_file_name = dc_find_form_file(form_name)
588
- @form_js = read_js_drg_form(form_file_name)
589
- YAML.load_file(form_file_name)
590
- end
591
-
592
- # form includes or extends another form file
593
- include_drg_form(@form['include']) if @form['include']
594
- extend_drg_form(@form['extend']) if @form['extend']
595
- @form['script'] = (@form['script'].blank? ? @form_js : @form['script'] + @form_js)
596
- # add readonly key to form if readonly parameter is passed in url
597
- @form['readonly'] = 1 if params['readonly'] #and %w(1 yes true).include?(params['readonly'].to_s.downcase.strip)
598
-
599
- # !!!!!! Always use strings for key names since @parms['table'] != @parms[:table]
600
- @parms = { 'table' => table_name, 'ids' => params[:ids], 'form_name' => form_name,
601
- 'return_to' => params['return_to'], 'edit_only' => params['edit_only'],
602
- 'readonly' => params['readonly']
603
- }
604
- end
605
-
606
499
  ############################################################################
607
500
  # Load module if available. Try not to mask errors in control module
608
501
  ############################################################################
@@ -621,7 +514,7 @@ end
621
514
  ############################################################################
622
515
  def extend_with_control_module(control_name = @form['controls'] || @form['control'])
623
516
  # May include embedded forms so ; => _
624
- control_name ||= params[:table].gsub(';','_')
517
+ control_name ||= CmsHelper.table_param(params).gsub(';','_')
625
518
  control_name += '_control' unless control_name.match(/control$|report$/i)
626
519
  # p '************', control_name
627
520
  controls = load_controls_module(control_name)
@@ -642,9 +535,10 @@ end
642
535
  # load DRG form.
643
536
  ############################################################################
644
537
  def check_authorization
645
- params[:table] ||= params[:form_name]
538
+ params[:table] ||= params[:t] || CmsHelper.form_param(params)
646
539
  # Only show menu
647
540
  return login if params[:id].in?(%w(login logout test))
541
+
648
542
  table = params[:table].to_s.strip.downcase
649
543
  set_default_guest_user_role if session[:user_roles].nil?
650
544
  # request shouldn't pass
@@ -652,8 +546,7 @@ def check_authorization
652
546
  (table.size < 3 or !dc_user_can(DcPermission::CAN_VIEW))
653
547
  return render(action: 'error', locals: { error: t('drgcms.not_authorized')} )
654
548
  end
655
- read_drg_form
656
- return render( plain: t('drgcms.form_error') ) if @form.nil?
549
+ dc_form_read
657
550
 
658
551
  # Permissions can be also defined on form
659
552
  #TODO So far only can_view is used. Think about if using other permissions has sense
@@ -702,6 +595,7 @@ def update_standards(record = @record)
702
595
  # and will be directly visible only to admins
703
596
  record.dc_site_id = dc_get_site.id if record.respond_to?('dc_site_id') && record.dc_site_id.nil?
704
597
  end
598
+ record.send(:set_history, self) if record.respond_to?(:set_history)
705
599
  end
706
600
 
707
601
  ########################################################################
@@ -743,7 +637,7 @@ def callback_method(key) #:nodoc:
743
637
  callback = case
744
638
  when params['data'] && params['data'][data_key] then params['data'][data_key]
745
639
  # dc_ + key method is present then call it automatically
746
- when @form['form'][key] then @form['form'][key]
640
+ when @form.dig('form', key) then @form['form'][key]
747
641
  when respond_to?('dc_' + key) then 'dc_' + key
748
642
  when params[data_key] then params[data_key]
749
643
  else nil
@@ -783,9 +677,10 @@ end
783
677
  def process_return_to(return_to)
784
678
  script = case
785
679
  when return_to == 'index' then return index
680
+ when return_to.match(/eval=/i) then return_to.sub('eval=', '')
786
681
  when return_to.match(/parent\.reload/i) then 'parent.location.href=parent.location.href;'
787
682
  when return_to.match(/reload/i) then 'location.href=location.href;'
788
- when return_to.match(/close/i) then 'window.close();'
683
+ when return_to.match(/window.close/i) then 'window.close();'
789
684
  when return_to.match(/none/i) then return
790
685
  else "location.href='#{return_to}'"
791
686
  end
@@ -829,6 +724,7 @@ def save_data
829
724
  value = DrgcmsFormFields.const_get(v['type'].camelize).get_data(params, v['name'])
830
725
  @record.send("#{v['name']}=", value)
831
726
  end
727
+
832
728
  # before_save callback
833
729
  if (m = callback_method('before_save') )
834
730
  ret = call_callback_method(m)
@@ -870,23 +766,12 @@ end
870
766
  ########################################################################
871
767
  # Will check and set sorting options for current result set. Subroutine of index method.
872
768
  ########################################################################
873
- def check_sort_options() #:nodoc:
769
+ def check_sort_options #:nodoc:
874
770
  table_name = @tables.first[1]
875
- old_sort = session[table_name][:sort].to_s
876
- sort, direction = old_sort.split(' ')
771
+ return if session[table_name][:sort].nil? || @records.class != Mongoid::Criteria
877
772
 
878
- if params['sort']
879
- # reverse sort if same selected
880
- if params['sort'] == sort
881
- direction = (direction == '1') ? '-1' : '1'
882
- end
883
- direction ||= '1'
884
- sort = params[:sort]
885
- session[table_name][:sort] = "#{params['sort']} #{direction}"
886
- session[table_name][:page] = 1
887
- end
888
- @records.sort( sort => direction.to_i ) if session[table_name][:sort] && @records.class == Mongoid::Criteria
889
- params['sort'] = nil # otherwise there is problem with other links
773
+ sort, direction = session[table_name][:sort].split(' ')
774
+ @records = @records.order_by( sort => direction.to_i )
890
775
  end
891
776
 
892
777
  ########################################################################
@@ -912,82 +797,20 @@ def user_sort_options(model) #:nodoc:
912
797
  { field.to_sym => direction.to_i }
913
798
  end
914
799
 
915
- ########################################################################
916
- # Will set session[table_name][:filter] and save last filter settings to session.
917
- # subroutine of check_filter_options.
918
- ########################################################################
919
- def set_session_filter(table_name)
920
- # models that can not be filtered (for now)
921
- return if %w(dc_temp dc_memory).include?(params[:table])
922
- # clear filter
923
- if params[:filter] == 'off'
924
- session[table_name][:filter] = nil
925
- return
926
- end
927
- # field_name should exist on set filter condition
928
- return if params[:filter_oper] && params[:filter_field].blank?
929
-
930
- filter_value = if params[:filter_value].nil?
931
- #NIL indicates that no filtering is needed
932
- '#NIL'
933
- else
934
- if params[:filter_value].class == String and params[:filter_value][0] == '@'
935
- # Internal value. Remove leading @ and evaluate expression
936
- expression = DcInternals.get(params[:filter_value])
937
- eval(expression) rescue nil
938
- else
939
- # No filter when empty
940
- params[:filter_value] == '' ? '#NIL' : params[:filter_value]
941
- end
942
- end
943
- # if filter field parameter is omitted then just set filter value
944
- session[table_name][:filter] =
945
- if params[:filter_field].nil?
946
- saved = YAML.load(session[table_name][:filter])
947
- saved['value'] = filter_value
948
- saved.to_yaml
949
- else
950
- # as field defined. Split name and alternative input field
951
- field = if params[:filter_field].match(' as ')
952
- params[:filter_input] = params[:filter_field].split(' as ').last.strip
953
- params[:filter_field].split(' as ').first.strip
954
- else
955
- params[:filter_field]
956
- end
957
-
958
- {'field' => field,
959
- 'operation' => params[:filter_oper],
960
- 'value' => filter_value,
961
- 'input' => params[:filter_input],
962
- 'table' => table_name }.to_yaml
963
- end
964
- # must be. Otherwise kaminari includes parames on paging links
965
- params[:filter] = nil
966
- params[:filter_id] = nil
967
- params[:filter_oper] = nil
968
- params[:filter_input] = nil
969
- params[:filter_field] = nil
970
- end
971
-
972
800
  ########################################################################
973
801
  # Will check and set current filter options for result set. Subroutine of index method.
974
802
  ########################################################################
975
- def check_filter_options() #:nodoc:
976
- table_name = @tables.first[1]
977
- model = @tables.first[0]
803
+ def check_filter_options #:nodoc:
804
+ table_name = CmsHelper.table_param(params).strip.split(';').first.underscore
805
+ model = table_name.classify.constantize
978
806
  session[table_name] ||= {}
979
807
  # page is set
980
808
  session[table_name][:page] = params[:page] if params[:page]
981
- # new filter is applied
982
- if params[:filter]
983
- set_session_filter(table_name)
984
- session[table_name][:page] = 1
985
- end
986
809
  # if data model has field dc_site_id ensure that only documents which belong to the site are selected.
987
810
  site_id = dc_get_site._id if dc_get_site
988
811
 
989
812
  # don't filter site if no dc_site_id field or user is ADMIN
990
- site_id = nil if !model.method_defined?('dc_site_id') or dc_user_can(DcPermission::CAN_ADMIN)
813
+ site_id = nil if !model.method_defined?('dc_site_id') || dc_user_can(DcPermission::CAN_ADMIN)
991
814
  site_id = nil if session[table_name][:filter].to_s.match('dc_site_id')
992
815
 
993
816
  if @records = DcFilter.get_filter(session[table_name][:filter])
@@ -997,7 +820,7 @@ def check_filter_options() #:nodoc:
997
820
  end
998
821
  process_select_and_deny_fields
999
822
  # pagination if required
1000
- per_page = (@form['result_set']['per_page'] || 30).to_i
823
+ per_page = (@form['result_set']['per_page'] || 25).to_i
1001
824
  @records = @records.page(session[table_name][:page]).per(per_page) if per_page > 0
1002
825
  end
1003
826
 
@@ -1033,7 +856,7 @@ def process_collections #:nodoc
1033
856
  process_select_and_deny_fields
1034
857
  # pagination but only if not already set
1035
858
  unless (@form['table'] == 'dc_memory' || @records.options[:limit])
1036
- per_page = (@form['result_set']['per_page'] || 30).to_i
859
+ per_page = (@form['result_set']['per_page'] || 25).to_i
1037
860
  @records = @records.page(params[:page]).per(per_page) if per_page > 0
1038
861
  end
1039
862
  elsif form_filter != 'dc_filter'
@@ -1077,5 +900,4 @@ def process_in_memory #:nodoc
1077
900
  false
1078
901
  end
1079
902
 
1080
-
1081
903
  end
@@ -114,27 +114,6 @@ def set_page_title
114
114
  dc_add_meta_tag(:name, 'description', @page.meta_description)
115
115
  end
116
116
 
117
- ########################################################################
118
- # Searches forms path for file_name and returns full file name or nil if not found.
119
- #
120
- # @param [String] Form file name. File name can be passed as gem_name.filename. This can
121
- # be useful when you are extending form but want to retain same name as original form
122
- # For example. You are extending dc_user form from drg_cms gem and want to
123
- # retain same dc_user name. This can be done by setting drg_cms.dc_user as extend option.
124
- #
125
- # @return [String] Form file name including path or nil if not found.
126
- ########################################################################
127
- def dc_find_form_file(form_file)
128
- form_path = nil
129
- form_path, form_file = form_file.split(/\.|\//) if form_file.match(/\.|\//)
130
-
131
- DrgCms.paths(:forms).reverse.each do |path|
132
- f = "#{path}/#{form_file}.yml"
133
- return f if File.exist?(f) && (form_path.nil? || path.to_s.match(/\/#{form_path}(-|\/)/i))
134
- end
135
- raise "Exception: Form file '#{form_file}' not found!"
136
- end
137
-
138
117
  #######################################################################
139
118
  # Will render public/404.html file with some debug code includded.
140
119
  #
@@ -257,7 +236,7 @@ def dc_set_options(parameters)
257
236
  return if parameters.to_s.size < 3
258
237
  # parameters are set as YAML. This should be default in future.
259
238
  parms = YAML.load(parameters) rescue {}
260
- @options.merge!(parms)
239
+ @options = @options.deep_merge(parms)
261
240
  end
262
241
 
263
242
  ##########################################################################
@@ -833,4 +812,101 @@ def redis
833
812
  Rails.cache.redis
834
813
  end
835
814
 
815
+ ########################################################################
816
+ # Extends DRGCMS form file. Extended file is processed first and then merged
817
+ # with code in this form file. Form can extend only single form file.
818
+ #
819
+ # [Parameters:]
820
+ # [extend_option] : Value of @form['extend'] option
821
+ ########################################################################
822
+ def dc_form_extend(extend_option)
823
+ form_file_name = CmsHelper.form_file_find(extend_option)
824
+ @form_js << read_js_drg_form(form_file_name)
825
+ form = YAML.load_file( form_file_name )
826
+ @form = CmsHelper.forms_merge(form, @form)
827
+ # If combined form contains tabs and fields options, merge fields into tabs
828
+ if @form['form']['tabs'] && @form['form']['fields']
829
+ @form['form']['tabs']['fields'] = @form['form']['fields']
830
+ @form['form']['fields'] = nil
831
+ end
832
+ end
833
+
834
+ ########################################################################
835
+ # Include code from another DRGCMS form file. Included code is merged
836
+ # with current form file code. Form can include more than one other DRGCMS forms.
837
+ #
838
+ # [Parameters:]
839
+ # [include_option] : Value of @form['include'] option
840
+ ########################################################################
841
+ def dc_form_include(include_option)
842
+ includes = include_option.class == Array ? include_option : include_option.split(/\,|\;/)
843
+ includes.each do |include_file|
844
+ form_file_name = CmsHelper.form_file_find(include_file)
845
+ @form_js << read_js_drg_form(form_file_name)
846
+ form = YAML.load_file(form_file_name)
847
+ @form = CmsHelper.forms_merge(@form, form)
848
+ end
849
+ end
850
+
851
+ ########################################################################
852
+ # Will read data from form_file_name.js if exists.
853
+ #
854
+ # [Parameters:]
855
+ # [form_file_name] : Physical form filename
856
+ ########################################################################
857
+ def read_js_drg_form(form_file_name)
858
+ js_form_file_name = form_file_name.sub('.yml','.js')
859
+ File.read(js_form_file_name) rescue ''
860
+ end
861
+
862
+ ########################################################################
863
+ # Read DRG form into @form object. Subroutine of check_authorization.
864
+ ########################################################################
865
+ def dc_form_read
866
+ params[:table] ||= params[:t] || CmsHelper.form_param(params)
867
+ table_name = decamelize_type(CmsHelper.table_param(params).strip)
868
+ @tables = table_name.split(';').inject([]) { |r, v| r << [(v.classify.constantize rescue nil), v] }
869
+
870
+ # split ids passed when embedded document
871
+ ids = params[:ids].to_s.strip.downcase
872
+ @ids = ids.split(';').inject([]) { |r,v| r << v }
873
+
874
+ # form_name defaults to last table specified
875
+ form_name = CmsHelper.form_param(params) || @tables.last[1]
876
+ @form_js = ''
877
+
878
+ # dynamically generated form
879
+ @form = if CmsHelper.form_param(params) == 'method'
880
+ dc_eval_class_method(params[:form_method], params)
881
+ else
882
+ form_file_name = CmsHelper.form_file_find(form_name)
883
+ @form_js = read_js_drg_form(form_file_name)
884
+ YAML.load_file(form_file_name)
885
+ end
886
+
887
+ # form includes or extends another form file
888
+ dc_form_include(@form['include']) if @form['include']
889
+ dc_form_extend(@form['extend']) if @form['extend']
890
+ @form['script'] = (@form['script'].blank? ? @form_js : @form['script'] + @form_js)
891
+ # add readonly key to form if readonly parameter is passed in url
892
+ @form['readonly'] = 1 if params['readonly'] #and %w(1 yes true).include?(params['readonly'].to_s.downcase.strip)
893
+
894
+ # !!!!!! Always use strings for key names since @form_params['table'] != @form_params[:table]
895
+ @form_params = { 'table' => table_name, 'ids' => params[:ids], 'form_name' => form_name,
896
+ 'return_to' => params['return_to'], 'edit_only' => params['edit_only'],
897
+ 'readonly' => params['readonly'], 'window_close' => params['window_close']}
898
+ end
899
+
900
+ ########################################################################
901
+ # Will search for help file and return it's full path name if found.
902
+ ########################################################################
903
+ def self.find_help_file(help_file_name)
904
+ file_name = nil
905
+ DrgCms.paths(:forms).reverse.each do |path|
906
+ f = "#{path}/help/#{help_file_name}.#{I18n.locale}"
907
+ file_name = f and break if File.exist?(f)
908
+ end
909
+ file_name
910
+ end
911
+
836
912
  end
@@ -217,8 +217,9 @@ def copy_clipboard
217
217
  format.json { dc_render_ajax(operation: 'window', url: request.url ) }
218
218
 
219
219
  format.html do
220
- doc = dc_find_document(params[:table], params[:id], params[:ids])
221
- text = "<br><br>[#{params[:table]},#{params[:id]},#{params[:ids]}]<br>"
220
+ table = CmsHelper.table_param(params)
221
+ doc = dc_find_document(table, params[:id], params[:ids])
222
+ text = "<br><br>[#{table},#{params[:id]},#{params[:ids]}]<br>"
222
223
  render plain: text + doc.as_document.to_json
223
224
  end
224
225
  end
@@ -266,8 +267,8 @@ end
266
267
  # document.
267
268
  ########################################################################
268
269
  def add_json_ld_schema
269
- edited_document = DcJsonLd.find_document_by_ids(params[:table], params[:ids])
270
- yaml = YAML.load_file( dc_find_form_file('json_ld_schema') )
270
+ edited_document = DcJsonLd.find_document_by_ids(CmsHelper.table_param(params), params[:ids])
271
+ yaml = YAML.load_file( CmsHelper.form_file_find('json_ld_schema') )
271
272
  schema_data = yaml[params[:schema]]
272
273
  # Existing document
273
274
  if edited_document.dc_json_lds.find_by(type: "@#{params[:schema]}")
@@ -282,12 +283,10 @@ end
282
283
  # Will provide help data
283
284
  ########################################################################
284
285
  def help
285
- form_name = params[:form_name] || params[:table]
286
- @form = form_name ? YAML.load_file(dc_find_form_file(form_name)) : {}
287
- return render json: {} if @form.nil?
288
-
289
- help_file_name = @form['help'] || @form['extend'] || params[:form_name] || params[:table]
290
- help_file_name = find_help_file(help_file_name)
286
+ dc_form_read
287
+ form_name = CmsHelper.form_param(params) || CmsHelper.table_param(params)
288
+ help_file_name = @form['help'] || @form['extend'] || form_name
289
+ help_file_name = DcApplicationController.find_help_file(help_file_name)
291
290
  @help = YAML.load_file(help_file_name) if help_file_name
292
291
  # no auto generated help on index action
293
292
  return render json: {} if params[:type] == 'index' && @help.nil?
@@ -297,18 +296,6 @@ end
297
296
 
298
297
  protected
299
298
 
300
- ########################################################################
301
- # Will search for help file and return it's path if found
302
- ########################################################################
303
- def find_help_file(help_file_name)
304
- file_name = nil
305
- DrgCms.paths(:forms).reverse.each do |path|
306
- f = "#{path}/help/#{help_file_name}.#{I18n.locale}"
307
- file_name = f and break if File.exist?(f)
308
- end
309
- file_name
310
- end
311
-
312
299
  ########################################################################
313
300
  # Subroutine of add_json_ld_schema for adding one element
314
301
  ########################################################################