drg_cms 0.7.0.2 → 0.7.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/drg_cms/drg_cms.js +110 -35
  3. data/app/assets/javascripts/drg_cms/jquery.bpopup.js +372 -0
  4. data/app/assets/javascripts/drg_cms_application.js +1 -1
  5. data/app/assets/javascripts/drg_cms_cms.js +1 -1
  6. data/app/assets/stylesheets/drg_cms/drg_cms.css +126 -36
  7. data/app/assets/stylesheets/drg_cms/select-multiple.css +6 -7
  8. data/app/controllers/cmsedit_controller.rb +78 -47
  9. data/app/controllers/dc_application_controller.rb +22 -25
  10. data/app/controllers/dc_common_controller.rb +9 -6
  11. data/app/controllers/dc_main_controller.rb +0 -1
  12. data/app/controls/{dc_category_control.rb → dc_gallery_control.rb} +15 -30
  13. data/app/controls/dc_image_control.rb +180 -0
  14. data/app/controls/dc_page_control.rb +3 -3
  15. data/app/controls/dc_poll_result_control.rb +38 -39
  16. data/app/controls/dc_report.rb +9 -4
  17. data/app/controls/dc_setup_control.rb +53 -0
  18. data/app/controls/design_element_settings_control.rb +88 -37
  19. data/app/forms/all_options.yml +20 -9
  20. data/app/forms/cms_menu.yml +14 -2
  21. data/app/forms/dc_gallery.yml +1 -1
  22. data/app/forms/dc_image.yml +122 -0
  23. data/app/forms/dc_image_search.yml +72 -0
  24. data/app/forms/dc_page.yml +11 -8
  25. data/app/forms/dc_poll.yml +2 -1
  26. data/app/forms/dc_poll_result.yml +10 -7
  27. data/app/forms/dc_setup.yml +45 -0
  28. data/app/forms/dc_steps_template.yml +6 -2
  29. data/app/helpers/cms_common_helper.rb +36 -24
  30. data/app/helpers/cms_edit_helper.rb +26 -33
  31. data/app/helpers/cms_helper.rb +29 -12
  32. data/app/helpers/cms_index_helper.rb +109 -80
  33. data/app/helpers/dc_application_helper.rb +108 -86
  34. data/app/helpers/dc_image_helper.rb +127 -0
  35. data/app/models/concerns/dc_policy_rule_concern.rb +1 -1
  36. data/app/models/concerns/dc_user_concern.rb +13 -5
  37. data/app/models/dc_big_table.rb +1 -1
  38. data/app/models/dc_category.rb +12 -0
  39. data/app/models/dc_design.rb +5 -4
  40. data/app/models/dc_filter.rb +24 -27
  41. data/app/models/dc_image.rb +237 -0
  42. data/app/models/dc_internals.rb +5 -9
  43. data/app/models/dc_memory.rb +2 -2
  44. data/app/models/dc_policy_role.rb +8 -8
  45. data/app/models/dc_setup.rb +111 -0
  46. data/app/models/drgcms_form_fields/datetime_picker.rb +1 -1
  47. data/app/models/drgcms_form_fields/drgcms_field.rb +9 -26
  48. data/app/models/drgcms_form_fields/embedded.rb +28 -17
  49. data/app/models/drgcms_form_fields/journal_diff.rb +2 -2
  50. data/app/models/drgcms_form_fields/multitext_autocomplete.rb +88 -76
  51. data/app/models/drgcms_form_fields/select.rb +41 -19
  52. data/app/models/drgcms_form_fields/text_with_select.rb +5 -9
  53. data/app/renderers/dc_big_menu_renderer.rb +18 -20
  54. data/app/renderers/dc_gallery_renderer.rb +10 -4
  55. data/app/renderers/dc_menu_renderer.rb +21 -58
  56. data/app/renderers/dc_page_renderer.rb +7 -7
  57. data/app/renderers/dc_poll_renderer.rb +13 -12
  58. data/app/renderers/dc_simple_menu_renderer.rb +1 -1
  59. data/app/views/cmsedit/_edit_stuff.html.erb +4 -1
  60. data/app/views/cmsedit/edit.html.erb +1 -1
  61. data/app/views/cmsedit/index.html.erb +1 -1
  62. data/app/views/cmsedit/new.html.erb +1 -0
  63. data/config/locales/drgcms_en.yml +22 -2
  64. data/config/locales/drgcms_sl.yml +25 -6
  65. data/config/locales/models_en.yml +50 -1
  66. data/config/locales/models_sl.yml +60 -1
  67. data/drg_cms.gemspec +1 -1
  68. data/lib/drg_cms/version.rb +1 -1
  69. data/lib/drg_cms.rb +40 -27
  70. data/lib/generators/convert_to_ar/USAGE +8 -0
  71. data/lib/generators/convert_to_ar/convert_to_ar_generator.rb +158 -0
  72. data/lib/generators/new_drg_form/new_drg_form_generator.rb +32 -14
  73. metadata +19 -10
  74. data/app/assets/javascripts/drg_cms/jquery.bpopup.min.js +0 -7
  75. data/app/views/layouts/__cmsedit.html.erb +0 -16
@@ -45,7 +45,7 @@
45
45
  font-family: DrgSans;
46
46
  font-style: normal;
47
47
  font-weight: 600;
48
- src: url('ibm-plex-sans-600.woff2') format('woff2')
48
+ src: url('ibm-plex-sans-600.woff2') format('woff2');
49
49
  }
50
50
  @font-face {
51
51
  font-family: DrgSans;
@@ -83,7 +83,6 @@ time, mark, audio, video {
83
83
  margin: 0;
84
84
  padding: 0;
85
85
  border: 0;
86
- font-size: 100%;
87
86
  font: inherit;
88
87
  vertical-align: baseline;
89
88
  }
@@ -138,6 +137,10 @@ textarea, input, select {
138
137
  max-width: 200px;
139
138
  }
140
139
 
140
+ .dc-action-menu .ui-autocomplete-input {
141
+ padding: 8px 4px 8px 12px;
142
+ }
143
+
141
144
  textarea:focus, input:focus, select:focus {
142
145
  border: 1px solid rgba(44, 142, 255, 1);
143
146
  outline: 1px solid rgba(44, 142, 255, 1);
@@ -212,6 +215,13 @@ img { vertical-align:bottom; }
212
215
  .dc-image-preview img { max-height: 2rem; padding-left: 0.5rem;}
213
216
  .dc-image-preview img:hover { cursor: zoom-in;}
214
217
 
218
+ #dc-image-preview {
219
+ padding: 2px;
220
+ background-color: #fff;
221
+ filter: drop-shadow(0 0 1rem #000);
222
+ display: none;
223
+ }
224
+
215
225
  .text-with-select { width: 20px; }
216
226
 
217
227
  .no-borders {
@@ -396,7 +406,7 @@ border-radius: 1px;
396
406
  .dc-result-data.footer {
397
407
  border-top: 2px solid #222;
398
408
  color: #000;
399
- font-weight: bold;
409
+ font-weight: 600;
400
410
  background-color: #eee;
401
411
  }
402
412
 
@@ -548,6 +558,12 @@ display: inline-table;
548
558
  background-color: #444;
549
559
  }
550
560
 
561
+ .dc-inline-link.dc-link-ajax {
562
+ padding: initial;
563
+ border: none;
564
+ background: initial;
565
+ }
566
+
551
567
  .skip-next {
552
568
  text-align: center;
553
569
  border:1px solid #888;
@@ -630,8 +646,7 @@ display: inline-table;
630
646
  /***** FORM *****/
631
647
 
632
648
  #dc-form-container {
633
- display: flex;
634
- padding-left: 4px;
649
+ /*display: flex;*/
635
650
  }
636
651
 
637
652
  #dc-form-left {
@@ -646,7 +661,7 @@ display: inline-table;
646
661
  }
647
662
 
648
663
  .dc-form-frame {
649
- margin: 0px;
664
+ margin: 0;
650
665
  padding: 4px;
651
666
  }
652
667
 
@@ -670,7 +685,6 @@ display: inline-table;
670
685
  border-radius: 2px;
671
686
  margin: 2px 0;
672
687
  }
673
-
674
688
  .dc-form-warning {
675
689
  padding: 8px;
676
690
  background-image: linear-gradient(to bottom, rgba(213, 143, 218, 0.1) 0, rgba(213, 143, 218, 0.5) 100%);
@@ -702,7 +716,7 @@ display: inline-table;
702
716
  color: #555;
703
717
  text-align: right;
704
718
  vertical-align: middle;
705
- font-weight: 600;
719
+ font-weight: 500;
706
720
  padding: 10px 2px;
707
721
  width: 150px;
708
722
  }
@@ -721,7 +735,8 @@ display: inline-table;
721
735
  }
722
736
 
723
737
  .dc-form-label.dc-color-odd, .dc-form-label.dc-color-even {background-color: transparent;}
724
- .dc-form-field.dc-color-odd, .dc-form-field.dc-color-even {background-color: transparent;}
738
+
739
+ .dc-form-label.dc-width-0 { padding: 0;}
725
740
 
726
741
  .dc-align-left {
727
742
  text-align: left;
@@ -733,7 +748,9 @@ display: inline-table;
733
748
  .dc-form-field {
734
749
  text-align: left;
735
750
  padding: 4px 2px;
736
- z-index: 10;
751
+ /*z-index: 10;*/
752
+ white-space: nowrap;
753
+ text-overflow: fade;
737
754
  }
738
755
 
739
756
  .dc-form-field .action li {
@@ -878,6 +895,10 @@ display: flex;
878
895
  color: rgba(44, 142, 255, 1);
879
896
  }
880
897
 
898
+ .dc-popup-open:hover {
899
+ color: rgba(44, 142, 255, 1);
900
+ }
901
+
881
902
  /*** CMS toggle button */
882
903
  .cms-toggle {
883
904
  z-index: 1000000;
@@ -1058,6 +1079,7 @@ font-size: 1.2em;
1058
1079
  font-size: 1.1em;
1059
1080
  line-height: 1.4em;
1060
1081
  }
1082
+
1061
1083
  /****** jquery ui-autocomplete widget ***************/
1062
1084
  .ui-autocomplete-input {
1063
1085
  padding: 8px 4px 8px 12px;
@@ -1119,16 +1141,7 @@ color: #000;
1119
1141
  margin-left: 4px;
1120
1142
  }
1121
1143
 
1122
-
1123
- .dc-red { color: #f76;}
1124
- .dc-red:hover { color: #c43;}
1125
- .dc-green { color: #9c9;}
1126
- .dc-green:hover { color: #6a6;}
1127
-
1128
- .aui-corner-all {
1129
- background-color: lightyellow;
1130
- }
1131
-
1144
+ /************* login *************/
1132
1145
  #dc-login {
1133
1146
  position: fixed;
1134
1147
  top: 50%;
@@ -1166,16 +1179,18 @@ color: #000;
1166
1179
  border-radius: 2px;
1167
1180
  z-index: 100;
1168
1181
  list-style-type: none;
1169
- filter: drop-shadow(1px 1px 4px #eee);
1182
+ filter: drop-shadow(1px 1px 6px #ccc);
1170
1183
  }
1171
1184
 
1172
1185
  .drgcms_popmenu_class i {
1173
1186
  vertical-align: sub;
1174
1187
  color: rgba(44, 142, 255, 1);
1188
+ font-size: 22px;
1175
1189
  }
1176
1190
 
1177
1191
  .drgcms_popmenu_item {
1178
1192
  padding: 4px;
1193
+ font-size: 1.1em;
1179
1194
  }
1180
1195
 
1181
1196
  .drgcms_popmenu_item:hover {
@@ -1186,14 +1201,14 @@ color: #000;
1186
1201
  color: white;
1187
1202
  }
1188
1203
  .iframe_embedded {
1189
- padding: 4px;
1204
+ padding: 2px;
1190
1205
  background-color: #fff;
1191
1206
  border-radius: 2px;
1192
- border: 2px solid #666;
1207
+ border: 2px solid #888;
1193
1208
  }
1194
1209
 
1195
1210
  #iframe_edit, #iframe_cms {
1196
- height: 1px;
1211
+ /* height: 1px;*/
1197
1212
  width: 100%;
1198
1213
  border: 0;
1199
1214
  margin-bottom: 0;
@@ -1367,6 +1382,7 @@ color: #000;
1367
1382
  max-height: 700px;
1368
1383
  overflow-y: auto;
1369
1384
  max-width: 800px;
1385
+ line-height: 1.5em;
1370
1386
  }
1371
1387
 
1372
1388
  #popup .dc-help h1 {
@@ -1460,6 +1476,35 @@ color: #000;
1460
1476
  display: inline-flex;
1461
1477
  }
1462
1478
 
1479
+ #popup:has(.popup-info) {
1480
+ padding: 1rem;
1481
+ background-image: linear-gradient(to bottom, #dff0d8 0, #c8e5bc 100%);
1482
+ color: darkgreen;
1483
+ font-weight: 600;
1484
+ font-size: 1.1em;
1485
+ min-width: 30%;
1486
+ border: 2px solid darkgreen;
1487
+ }
1488
+
1489
+ #popup:has(.popup-error) {
1490
+ padding: 1rem;
1491
+ background-image: linear-gradient(to bottom, #f2dede 0, #e7c3c3 100%);
1492
+ color: #a94442;
1493
+ font-weight: 600;
1494
+ font-size: 1.1em;
1495
+ min-width: 30%;
1496
+ border: 2px solid #a94442;
1497
+ }
1498
+
1499
+ #popup .popup-info button, #popup .popup-error button {
1500
+ margin-top: 1rem;
1501
+ padding: 4px 2rem;
1502
+ line-height: initial;
1503
+ filter: none;
1504
+ border: 2px solid #222;
1505
+ border-radius: 5px;
1506
+ }
1507
+
1463
1508
  .filter-popup {
1464
1509
  background-color: #fff;
1465
1510
  filter: drop-shadow(2px 2px 8px #888);
@@ -1529,7 +1574,7 @@ cursor: pointer;
1529
1574
 
1530
1575
  #drgcms_filter h1 {
1531
1576
  font-size: 1.8em;
1532
- font-width: 600;
1577
+ font-weight: 600;
1533
1578
  color: rgba(44, 142, 255, 1);
1534
1579
  }
1535
1580
 
@@ -1552,6 +1597,36 @@ cursor: pointer;
1552
1597
  margin-left: 1px;
1553
1598
  }
1554
1599
 
1600
+ /**** reports ****/
1601
+ .report .dc-title { color: #003A68; }
1602
+ .report .dc-result-header {
1603
+ border-bottom: 2px solid #003A68;
1604
+ }
1605
+ .report .dc-result-header .th {
1606
+ color: #003A68;
1607
+ padding: 3px;
1608
+ }
1609
+
1610
+ .report .dc-result-data {
1611
+ padding: 0;
1612
+ }
1613
+
1614
+ .report.dc-form-frame {
1615
+ padding: 0;
1616
+ }
1617
+
1618
+
1619
+ .report .dc-result-data .td {
1620
+ padding: 3px;
1621
+ }
1622
+
1623
+ .iframe_embedded#if_dc_temp {
1624
+ border: none;
1625
+ padding: 0;
1626
+ }
1627
+
1628
+ .report .dc-odd {background-color: #e0eeff;}
1629
+
1555
1630
  /** Radio button input field **/
1556
1631
 
1557
1632
  .dc-radio {
@@ -1576,23 +1651,30 @@ cursor: pointer;
1576
1651
  margin: 6px 4px 0 0;
1577
1652
  }
1578
1653
 
1654
+ .dc-image-preview-1 {
1655
+ right: 1rem;
1656
+ position: absolute;
1657
+ top: 5rem;
1658
+ max-height: 150px;
1659
+ max-width: 200px;
1660
+ }
1661
+
1662
+ #dc_image .dc-image-preview img {
1663
+ max-height: 150px;
1664
+ max-width: 200px;
1665
+ }
1666
+
1579
1667
  /****** MOBILE DEVICE *****/
1580
1668
  @media only screen and (max-device-width: 600px) {
1581
1669
  #body-cms {font-size: 11px;}
1582
1670
  #site-top div:nth-of-type(2) {padding-top: 0 !important;}
1583
- .dc-title { font-size: 1.5em;}
1584
-
1585
-
1586
- .dc-form {
1587
- border: none;
1588
- border-top: 2px solid #888;
1589
- border-bottom: 2px solid #888;
1590
- margin-top: 4px;
1671
+ .dc-title {
1672
+ font-size: 1.5em;
1673
+ padding-bottom: 4px;
1591
1674
  }
1675
+ .dc-form-field { padding-bottom: 4px; }
1592
1676
 
1593
- .dc-form .row-div {
1594
- display: block;
1595
- }
1677
+ .dc-form .row-div { display: block; }
1596
1678
  .dc-form-li {margin-top: 3px;}
1597
1679
 
1598
1680
  .dc-form-label {
@@ -1603,6 +1685,7 @@ cursor: pointer;
1603
1685
  }
1604
1686
  .dc-form-label label {
1605
1687
  font-size: 15px;
1688
+ padding: 0;
1606
1689
  }
1607
1690
 
1608
1691
  .dc-menu { padding: 0;}
@@ -1638,6 +1721,13 @@ cursor: pointer;
1638
1721
  font-size: 2em;
1639
1722
  }
1640
1723
 
1724
+ #menu-hamburger .mi:before{
1725
+ background-color: #222;
1726
+ color: #fff;
1727
+ padding: 1px;
1728
+ border-radius: 2px;
1729
+ }
1730
+
1641
1731
  .cmsedit-container {display: block;}
1642
1732
  .cmsedit-container #cms-menu {display: none;}
1643
1733
  .cmsedit-container #cms-menu.visible {
@@ -34,7 +34,7 @@
34
34
  -moz-border-radius: 1px;
35
35
  border-radius: 1px;
36
36
  position: relative;
37
- height: 200px;
37
+ max-height: 200px;
38
38
  padding: 0;
39
39
  overflow-y: auto;
40
40
  }
@@ -63,20 +63,19 @@
63
63
  }
64
64
 
65
65
  .ms-container .ms-selectable li.ms-elem-selectable{
66
- padding: 3px 10px;
66
+ padding: 5px 10px;
67
67
  color: #444;
68
- font-size: 14px;
69
68
  }
70
69
 
71
- .ms-container .ms-selectable li:nth-child(odd) {
72
- background-color: #f4f4f4;
70
+ .ms-container .ms-selectable li:nth-child(even) {
71
+ background-color: #f8f8f8;
73
72
  }
74
73
 
75
74
  .ms-container .ms-selectable li.ms-hover{
76
75
  cursor: pointer;
77
76
  color: #fff;
78
77
  text-decoration: none;
79
- background-color: #08c;
78
+ background-color: rgba(76,154,255, 0.6);
80
79
  }
81
80
 
82
81
  .ms-container .ms-selectable li.disabled{
@@ -92,10 +91,10 @@
92
91
 
93
92
  .ms-container .ms-selected {
94
93
  font-weight: 600;
94
+ color: darkblue !important;
95
95
  }
96
96
 
97
97
  .pull-right.ms-elem-selected{
98
98
  float: right;
99
- font-size: smaller;
100
99
  padding-left: 4px;
101
100
  }
@@ -77,7 +77,7 @@
77
77
  ########################################################################
78
78
  class CmseditController < DcApplicationController
79
79
  before_action :check_authorization, :except => [:login, :logout, :test, :run]
80
- protect_from_forgery with: :null_session, only: Proc.new { |c| c.request.format.json? }
80
+ protect_from_forgery with: :null_session, only: Proc.new { _1.request.format.json? }
81
81
 
82
82
  layout 'cms'
83
83
 
@@ -108,12 +108,17 @@ end
108
108
  ########################################################################
109
109
  def show
110
110
  find_record
111
+ if @record.nil?
112
+ flash[:error] ||= t('drgcms.doc_no_edit')
113
+ return index
114
+ end
111
115
  # before_show callback
112
116
  if (m = callback_method('before_show') )
113
117
  ret = call_callback_method(m)
114
118
  if ret.class == FalseClass
115
119
  @form['readonly'] = nil # must be
116
- return index
120
+ flash[:error] ||= t('drgcms.not_authorized')
121
+ return index
117
122
  end
118
123
  end
119
124
 
@@ -269,11 +274,8 @@ def create
269
274
  # create document
270
275
  if params['id'].nil?
271
276
  # Prevent double form submit
272
- params[:form_time_stamp] = params[:form_time_stamp].to_i
273
- session[:form_time_stamp] ||= 0
274
- return index if params[:form_time_stamp] <= session[:form_time_stamp]
277
+ return index if double_form_submit?
275
278
 
276
- session[:form_time_stamp] = params[:form_time_stamp]
277
279
  create_new_empty_record
278
280
  if save_data
279
281
  flash[:info] = t('drgcms.doc_saved')
@@ -385,7 +387,7 @@ def destroy
385
387
  save_journal(:delete)
386
388
  flash[:info] = t('drgcms.record_deleted')
387
389
  # after_delete callback
388
- if (m = callback_method('after_delete') )
390
+ if (m = callback_method('after_delete') )
389
391
  call_callback_method(m)
390
392
  elsif params['after-delete'].to_s.match('return_to')
391
393
  params[:return_to] = params['after-delete']
@@ -548,14 +550,14 @@ def check_authorization
548
550
  end
549
551
  dc_form_read
550
552
 
551
- # Permissions can be also defined on form
553
+ # Permissions can be also defined in form
552
554
  #TODO So far only can_view is used. Think about if using other permissions has sense
553
555
  can_view = @form.dig('permissions','can_view')
554
- if can_view.nil? or dc_user_has_role(can_view)
556
+ if can_view.nil? || can_view.split(',').any? { |role| dc_user_has_role(role) }
555
557
  extend_with_control_module
556
558
  else
557
559
  render(action: 'error', locals: { error: t('drgcms.not_authorized')} )
558
- end
560
+ end
559
561
  end
560
562
 
561
563
  ########################################################################
@@ -613,7 +615,7 @@ def save_journal(operation, changes = {})
613
615
 
614
616
  if (operation != :update) || changes.size > 0
615
617
  # determine site_id
616
- site_id = @record.site_id if @record.respond_to?('site_id')
618
+ site_id = @record.site_id if @record && @record.respond_to?('site_id')
617
619
  site_id = dc_get_site._id if site_id.nil? && dc_get_site
618
620
 
619
621
  DcJournal.create(site_id: site_id,
@@ -637,8 +639,9 @@ def callback_method(key) #:nodoc:
637
639
  callback = case
638
640
  when params['data'] && params['data'][data_key] then params['data'][data_key]
639
641
  # dc_ + key method is present then call it automatically
640
- when @form.dig('form', key) then @form['form'][key]
642
+ when @form.dig('permissions', key) then @form['permissions'][key]
641
643
  when respond_to?('dc_' + key) then 'dc_' + key
644
+ when respond_to?(key) then key
642
645
  when params[data_key] then params[data_key]
643
646
  else nil
644
647
  end
@@ -714,10 +717,10 @@ def save_data
714
717
 
715
718
  form_fields.each do |v|
716
719
  session[:form_processing] = v['name'] # for debuging
717
- next if v['type'].nil? or v['name'].nil? or
718
- v['type'].match('embedded') or # don't wipe embedded types
719
- (params[:edit_only] and params[:edit_only] != v['name']) or # otherwise other fields would be wiped
720
- v['readonly'] or # fields with readonly option don't return value and would be wiped
720
+ next if v['type'].nil? || v['name'].nil? ||
721
+ v['type'].match('embedded') || # don't wipe embedded types
722
+ (params[:edit_only] && params[:edit_only] != v['name']) || # otherwise other fields would be wiped
723
+ v['readonly'] || # fields with readonly option don't return value and would be wiped
721
724
  !@record.respond_to?(v['name']) # there are temporary fields on the form
722
725
  # good to know! How to get type of field @record.fields[v['name']].type
723
726
  # return value from form field definition
@@ -734,7 +737,7 @@ def save_data
734
737
 
735
738
  # save data
736
739
  changes = @record.changes
737
- update_standards() if changes.size > 0 # update only if there has been some changes
740
+ update_standards if changes.size > 0 # update only if there has been some changes
738
741
  if (saved = @record.save)
739
742
  operation = @record.new_record? ? :new : :update
740
743
  save_journal(operation, @record.previous_changes)
@@ -749,9 +752,9 @@ end
749
752
  # in select_fields and deny_fields
750
753
  ########################################################################
751
754
  def separated_to_symbols(data)
752
- data.chomp.split(',').map { |e| e.strip.downcase.to_sym }
755
+ data.chomp.split(',').map { _1.strip.downcase.to_sym }
753
756
  end
754
-
757
+
755
758
  ########################################################################
756
759
  # Will process only (select_fields) and without (deny_fields) option
757
760
  ########################################################################
@@ -843,24 +846,20 @@ def process_collections #:nodoc
843
846
  check_sort_options()
844
847
  end
845
848
  # result set is defined by filter method in control object
846
- form_filter = @form['result_set']['filter']
847
- if form_filter
848
- if respond_to?(form_filter)
849
- @records = send(form_filter)
850
- # something went wrong. flash[] should have explanation.
851
- if @records.class == FalseClass
852
- @records = []
853
- render(action: :index)
854
- return true
855
- end
856
- process_select_and_deny_fields
857
- # pagination but only if not already set
858
- unless (@form['table'] == 'dc_memory' || @records.options[:limit])
859
- per_page = (@form['result_set']['per_page'] || 25).to_i
860
- @records = @records.page(params[:page]).per(per_page) if per_page > 0
861
- end
862
- elsif form_filter != 'dc_filter'
863
- Rails.logger.error "Error: result_set:filter: #{@form['result_set']['filter']} not found in controls!"
849
+ form_filter = @form['result_set']['filter'] || 'default_filter'
850
+ if respond_to?(form_filter)
851
+ @records = send(form_filter)
852
+ # something went wrong. flash[] should have explanation.
853
+ if @records.class == FalseClass
854
+ @records = []
855
+ render(action: :index)
856
+ return true
857
+ end
858
+ process_select_and_deny_fields
859
+ # pagination but only if not already set
860
+ unless (@form['table'] == 'dc_memory' || (@records.respond_to?(:options) && @records.options[:limit]))
861
+ per_page = (@form['result_set']['per_page'] || 25).to_i
862
+ @records = @records.page(params[:page]).per(per_page) if per_page > 0
864
863
  end
865
864
  else
866
865
  if @tables.size > 1
@@ -871,7 +870,7 @@ def process_collections #:nodoc
871
870
  @records = rec.send(embedded_field_name) # current embedded set
872
871
  # sort by order if order field is present in model
873
872
  if @tables.last[1].classify.constantize.respond_to?(:order)
874
- @records = @records.order_by('order asc')
873
+ @records = @records.order_by(order: 1)
875
874
  end
876
875
  end
877
876
  end
@@ -879,19 +878,14 @@ def process_collections #:nodoc
879
878
  end
880
879
 
881
880
  ########################################################################
882
- # Process index action for in memory data.
881
+ # Process index action for in memory data. default_filter method must fill @records array
882
+ # with data, that will be shown in browser.
883
883
  ########################################################################
884
884
  def process_in_memory #:nodoc
885
885
  @records = []
886
886
  # result set is defined by filter method in control object
887
- if (method = @form['result_set']['filter'])
888
- send(method) if respond_to?(method)
889
- end
890
- # result set is defined by class method
891
- if (klass_method = @form['result_set']['filter_method'])
892
- _klass, method = klass_method.split('.')
893
- klass = _klass.classify.constantize
894
- @records = klass.send(method) if klass.respond_to?(method)
887
+ if (method = @form['result_set']['filter'] || 'default_filter')
888
+ send(method) if respond_to?(method)
895
889
  end
896
890
  # ensure that record has id field
897
891
  if @records.size > 0
@@ -900,4 +894,41 @@ def process_in_memory #:nodoc
900
894
  false
901
895
  end
902
896
 
897
+ ########################################################################
898
+ # Prevent double form submit
899
+ #
900
+ # There was a problem with old solution when user opened another browser session while
901
+ # entering data into new document. If in new session user added document to some other
902
+ # collection, save to document in primary session was silently ignored. Now creation time for last three forms
903
+ # is remembered. This will work unless user tries to add new document to the same collection in another session.
904
+ # But that is highly unlikely.
905
+ ########################################################################
906
+ def double_form_submit?
907
+ session[:dfs] ||= {}
908
+ form_name = CmsHelper.form_param(params) || CmsHelper.table_param(params)
909
+ params[:form_time_stamp] = params[:form_time_stamp].to_i
910
+ if params[:form_time_stamp] <= update_dfs_time(form_name) && !Rails.env.test? # test must be excluded
911
+ flash[:error] = I18n.t('drgcms.dfs')
912
+ return true
913
+ end
914
+ update_dfs_time(form_name, params[:form_time_stamp])
915
+
916
+ false
917
+ end
918
+
919
+ ########################################################################
920
+ # Updates double_form_submit timings.
921
+ ########################################################################
922
+ def update_dfs_time(form_name, time = nil)
923
+ if time.nil?
924
+ session[:dfs][form_name] ||= 0
925
+ else
926
+ session[:dfs][form_name] = time
927
+ if session[:dfs].size > 3
928
+ oldest = session[:dfs].invert.min
929
+ session[:dfs].delete(oldest.last)
930
+ end
931
+ end
932
+ end
933
+
903
934
  end