drg_cms 0.7.0.2 → 0.7.1.1

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 (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
@@ -53,32 +53,33 @@ end
53
53
  ######################################################################
54
54
  def self.get_filter(filter)
55
55
  yaml = YAML.load(filter) rescue nil
56
- return yaml if yaml.nil?
57
- return nil if yaml['table'].nil? # old data
58
- #
56
+ return if yaml.nil? || yaml['table'].nil? # old data
57
+
59
58
  model = yaml['table'].classify.constantize
60
59
  field = yaml['field'] == 'id' ? '_id' : yaml['field'] # must be
61
- # evaluate
62
- if yaml['operation'] == 'eval' and model.respond_to?(yaml['field'])
63
- return model.send( yaml['field'] )
60
+ # evaluate
61
+ if yaml['operation'] == 'eval'
62
+ return eval(yaml['value']) if yaml['value'] && yaml['value'] != '#NIL' # evaluated as string
63
+ return model.send( yaml['field'] ) if model.respond_to?(yaml['field']) # defined as scope or method in the model
64
+ return
64
65
  end
65
- # if empty
66
+ # if empty
66
67
  if yaml['operation'] == 'empty'
67
- return model.in(field => [nil,''])
68
+ return model.in(field => [nil, ''])
68
69
  end
69
- # if value == NIL no filter is necessary
70
- return nil if yaml['value'].class == String and yaml['value'] == '#NIL'
70
+ # if value == NIL no filter is necessary
71
+ return if yaml['value'].class == String && yaml['value'] == '#NIL'
71
72
 
72
- # do regex if operation is like
73
+ # do regex if operation is like
73
74
  value = yaml['operation'] == 'like' ? /#{yaml['value']}/i : yaml['value']
74
- # when field type is ObjectId transform value
75
- if model.fields[field] and model.fields[field].type == BSON::ObjectId
75
+ # when field type is ObjectId transform value
76
+ if model.fields[field] && model.fields[field].type == BSON::ObjectId
76
77
  value = BSON::ObjectId.from_string(value) rescue nil
77
78
  end
78
- #
79
- if ['eq','like'].include?(yaml['operation'])
79
+
80
+ if %w[eq like].include?(yaml['operation'])
80
81
  model.where(field => value)
81
- # TODO in operator
82
+ # TODO in operator
82
83
  else
83
84
  model.where(field.to_sym.send(yaml['operation']) => value)
84
85
  end
@@ -109,11 +110,11 @@ end
109
110
  def self.get_filter_field(parent)
110
111
  return '' if parent.session[ parent.form['table'] ].nil?
111
112
 
112
- filter = parent.session[ parent.form['table'] ][:filter]
113
+ filter = parent.session[parent.form['table']][:filter]
113
114
  return '' if filter.nil?
114
115
 
115
116
  filter = YAML.load(filter) rescue nil
116
- return '' if filter.nil?
117
+ return '' if filter.nil? || filter['operation'].to_s == 'eval'
117
118
 
118
119
  field = get_field_form_definition(filter['field'], parent)
119
120
  return '' if field.nil? && filter['input'].nil?
@@ -124,7 +125,7 @@ def self.get_filter_field(parent)
124
125
  # If field has choices available in labels, use them. This is most likely select input field.
125
126
  if field['name']
126
127
  choices = parent.t('helpers.label.' + parent.form['table'] + '.choices4_' + field['name'] )
127
- unless choices.match( 'translation missing' ) or choices.match('helpers.label')
128
+ unless choices.match(/translation missing/i) || choices.match('helpers.label')
128
129
  field['choices'] = choices
129
130
  end
130
131
  end
@@ -185,14 +186,10 @@ def self.menu_filter(parent)
185
186
  # only single defined. Convert to array.
186
187
  filters = [filters] if filters.class == Hash
187
188
  filters.each do |filter|
188
- url = parent.dc_link_to(filter['title'], nil, controller: 'cmsedit', action: :run, t: table,
189
- f: CmsHelper.form_param(parent.params),
190
- control: 'cmsedit.filter_on',
191
- filter_field: filter['field'],
192
- filter_oper: filter['operation'],
193
- filter_value: filter['value'])
194
-
195
- url = parent.url_for(controller: 'cmsedit', action: :run, t: table, f: CmsHelper.form_param(parent.params),
189
+ url = parent.url_for(controller: :cmsedit,
190
+ action: :run,
191
+ table: table,
192
+ form_name: CmsHelper.form_param(parent.params),
196
193
  control: 'cmsedit.filter_on',
197
194
  filter_field: filter['field'],
198
195
  filter_oper: filter['operation'],
@@ -0,0 +1,237 @@
1
+ #--
2
+ # Copyright (c) 2022+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ ##########################################################################
25
+ # == Schema information
26
+ #
27
+ # Collection name: dc_images : Images
28
+ #
29
+ # _id BSON::ObjectId _id
30
+ # created_at Time created_at
31
+ # updated_at Time updated_at
32
+ # dc_site_id BSON::ObjectId Site id
33
+ # dc_user_id BSON::ObjectId User's id
34
+ # name String ip
35
+ # short String short name
36
+ # text String text
37
+ # size_l String Large image size
38
+ # size_m String Medium image size
39
+ # size_s String Small image size
40
+ #
41
+ # DRG CMS module for saveing and manipulating images.
42
+ #
43
+ # If you want to use this module you must install image magick tools
44
+ # and mini_magick ruby gem.
45
+ ##########################################################################
46
+ class DcImage
47
+ include Mongoid::Document
48
+ include Mongoid::Timestamps
49
+
50
+ field :name, type: String
51
+ field :img_type, type: String
52
+ field :text, type: String
53
+ field :short, type: String
54
+ field :keep_original, type: Boolean, default: false
55
+ field :size_o, type: String
56
+ field :size_l, type: String
57
+ field :size_m, type: String
58
+ field :size_s, type: String
59
+ field :categories, type: Array, default: []
60
+ field :created_by, type: BSON::ObjectId
61
+
62
+ belongs_to :dc_site
63
+
64
+ index dc_site_id: 1
65
+ index created_by: 1
66
+ index categories: 1
67
+
68
+ before_validation :set_original
69
+
70
+ validate :validate_image_values
71
+
72
+ #########################################################################
73
+ # checks that image size values are in correct format. Must be hsize[x]vsize (ex. 300x200)
74
+ #########################################################################
75
+ def set_original
76
+ if keep_original
77
+ if size_o.blank?
78
+ image = MiniMagick::Image.open(name)
79
+ self.size_o = "#{image.width}x#{image.height}"
80
+ end
81
+ else
82
+ self.size_o = ''
83
+ end
84
+ end
85
+
86
+ #########################################################################
87
+ # checks that image size values are in correct format. Must be hsize[x]vsize (ex. 300x200)
88
+ #########################################################################
89
+ def validate_image_values
90
+ %w[l m s o].each do |size|
91
+ field = "size_#{size}"
92
+ value = send(field)
93
+ next if value.blank?
94
+
95
+ a = value.strip.split(/x|\+/)
96
+ a[0, 2].each { |e| errors.add(field, I18n.t('drgcms.not_valid')) unless e.to_i > 0 }
97
+ end
98
+ end
99
+
100
+ #########################################################################
101
+ # For mapping categories array to input text_area field
102
+ #########################################################################
103
+ def cats_input=(what)
104
+ self.categories = if what.blank?
105
+ []
106
+ else
107
+ what.chomp.split("\n").map(&:downcase).map(&:strip)
108
+ end
109
+ end
110
+
111
+ #########################################################################
112
+ # For mapping categories array to input text_area field
113
+ #########################################################################
114
+ def cats_input
115
+ self.categories.join("\n")
116
+ end
117
+
118
+ #########################################################################
119
+ # For mapping categories array to display field
120
+ #########################################################################
121
+ def categories_line
122
+ categories ? categories.join(", ") : ''
123
+ end
124
+
125
+ #########################################################################
126
+ # Will return first available image starting from small up
127
+ #########################################################################
128
+ def first_available_image
129
+ image = %w[o s m l].each do |size|
130
+ field = "size_#{size}"
131
+ value = send(field)
132
+ return "#{id}-#{size}.#{img_type}" if value.present?
133
+ end
134
+ end
135
+
136
+ #########################################################################
137
+ # Will return size for large image
138
+ #########################################################################
139
+ def size_ls
140
+ size_l.blank? ? '' : size_l.split(/x|\+/)[0, 2].join('x')
141
+ end
142
+
143
+ #########################################################################
144
+ # Will set new size for large image
145
+ #########################################################################
146
+ def size_ls=(value)
147
+ self.size_l = value.blank? ? '' : value
148
+ end
149
+
150
+ #########################################################################
151
+ # Will return x offset for cropping large image
152
+ #########################################################################
153
+ def offset_lx
154
+ size_l.blank? ? '' : size_l.split(/x|\+/)[2].to_i
155
+ end
156
+
157
+ #########################################################################
158
+ # Will set x offset for cropping large image
159
+ #########################################################################
160
+ def offset_lx=(value)
161
+ self.size_l << (size_l.blank? ? '' : "+#{value}")
162
+ end
163
+
164
+ #########################################################################
165
+ # Will return y offset for cropping large image
166
+ #########################################################################
167
+ def offset_ly
168
+ size_l.blank? ? '' : size_l.split(/x|\+/)[3].to_i
169
+ end
170
+
171
+ #########################################################################
172
+ # Will set y offset for cropping large image
173
+ #########################################################################
174
+ def offset_ly=(value)
175
+ self.size_l << (size_l.blank? ? '' : "+#{value}")
176
+ end
177
+
178
+ def size_ms
179
+ size_m.blank? ? '' : size_m.split(/x|\+/)[0, 2].join('x')
180
+ end
181
+
182
+ def size_ms=(value)
183
+ self.size_m = value.blank? ? '' : value
184
+ end
185
+
186
+ def offset_mx
187
+ size_m.blank? ? '' : size_m.split(/x|\+/)[2].to_i
188
+ end
189
+
190
+ def offset_mx=(value)
191
+ self.size_m << (size_m.blank? ? '' : "+#{value}")
192
+ end
193
+
194
+ def offset_my
195
+ size_m.blank? ? '' : size_m.split(/x|\+/)[3].to_i
196
+ end
197
+
198
+ def offset_my=(value)
199
+ self.size_m << (size_m.blank? ? '' : "+#{value}")
200
+ end
201
+
202
+ def size_ss
203
+ size_s.blank? ? '' : size_s.split(/x|\+/)[0, 2].join('x')
204
+ end
205
+
206
+ def size_ss=(value)
207
+ self.size_s = value.blank? ? '' : value
208
+ end
209
+
210
+ def offset_sx
211
+ size_s.blank? ? '' : size_s.split(/x|\+/)[2].to_i
212
+ end
213
+
214
+ def offset_sx=(value)
215
+ self.size_s << (size_s.blank? ? '' : "+#{value}")
216
+ end
217
+
218
+ def offset_sy
219
+ size_s.blank? ? '' : size_s.split(/x|\+/)[3].to_i
220
+ end
221
+
222
+ def offset_sy=(value)
223
+ self.size_s << (size_s.blank? ? '' : "+#{value}")
224
+ end
225
+
226
+ #########################################################################
227
+ # Return all users that have contributed images
228
+ #########################################################################
229
+ def self.all_users
230
+ DcUser.where(:id.in => distinct(:created_by)).order_by(name: 1).map { |doc| [doc.name, doc.id] }
231
+ end
232
+
233
+ def self.html_code
234
+ 'code'
235
+ end
236
+
237
+ end
@@ -28,11 +28,10 @@
28
28
  ##########################################################################
29
29
  module DcInternals
30
30
  INTERNALS = {
31
- 'current_user' => 'session[:user_id]',
31
+ 'current_user' => 'session[:user_id].to_s',
32
32
  'current_user_name' => 'session[:user_name]',
33
- 'current_site' => 'dc_get_site.id'
33
+ 'current_site' => 'dc_get_site.id.to_s'
34
34
  }
35
- #
36
35
  @additions = {}
37
36
 
38
37
  ##########################################################################
@@ -40,7 +39,7 @@ module DcInternals
40
39
  # to be added to structure and be used together with predefined values.
41
40
  ##########################################################################
42
41
  def self.add_internal(hash)
43
- hash.each {|key,value| additions[key] = value}
42
+ hash.each { |key, value| additions[key] = value }
44
43
  end
45
44
 
46
45
  ##########################################################################
@@ -48,11 +47,8 @@ end
48
47
  # to be added to structure and be used together with predefined values.
49
48
  ##########################################################################
50
49
  def self.get(key)
51
- key = key.sub('@','')
52
-
53
- value = INTERNALS[key]
54
- value = @additions[key] if value.nil?
55
- value
50
+ key.sub!('@', '')
51
+ INTERNALS[key] || @additions[key]
56
52
  end
57
53
 
58
54
  end
@@ -63,8 +63,8 @@
63
63
  # As result report.pdf file will be opened in new browser window.
64
64
  ########################################################################
65
65
  class DcMemory
66
- include Mongoid::Document
67
-
66
+ include Mongoid::Document
67
+
68
68
  ########################################################################
69
69
  # Initilize object
70
70
  ########################################################################
@@ -55,30 +55,30 @@ after_save :cache_clear
55
55
  after_destroy :cache_clear
56
56
 
57
57
  ####################################################################
58
- # Clear cache if cache is configured
58
+ # Clear cache when cache is configured
59
59
  ####################################################################
60
60
  def cache_clear
61
61
  DrgCms.cache_clear(:dc_permission)
62
62
  DrgCms.cache_clear(:dc_site)
63
+ DrgCms.cache_clear(:dc_policy_role)
63
64
  end
64
65
 
65
66
  ########################################################################
66
67
  # Return all defined roles as choices for use in select field.
67
68
  ########################################################################
68
69
  def self.choices4_roles
69
- where(active: true).order_by(name: 1).inject([]) { |r,role| r << [ role.name, role._id] }
70
+ where(active: true).order_by(name: 1).inject([]) { |r, role| r << [ role.name, role._id] }
70
71
  end
71
72
 
72
73
  ########################################################################
73
74
  # Search for role when role parameter is String.
74
75
  ########################################################################
75
76
  def self.get_role(role)
76
- if role.class == String
77
- rol = role
78
- role = find_by(name: rol) || find_by(system_name: rol)
79
- end
80
- role
81
- end
77
+ doc = DrgCms.cache_read(['dc_policy_role', role])
78
+ return doc if doc
82
79
 
80
+ doc = find_by(name: role) || find_by(system_name: role)
81
+ DrgCms.cache_write(['dc_policy_role', role], doc)
82
+ end
83
83
 
84
84
  end
@@ -0,0 +1,111 @@
1
+ #--
2
+ # Copyright (c) 2024+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ ##############################################################################
25
+ # DcSetup collection is used for settings, that are specific to the application,
26
+ # or part of application (gem). It consists of data dafinitions and form for editing data.
27
+ # Data is saved internaly in YAML format.
28
+ #
29
+ # When editing, admin can see and edit form definition (adding new data to application setup), while user
30
+ # sees only data entry form.
31
+ #
32
+ # Usage:
33
+ # my_app_settings = DcSetup.find_by(name: 'my_app')
34
+ # my_app_settings = DcSetup.get('my_app')
35
+ # company = my_app_settings.company_name
36
+ # company, ceo = my_app_settings[:company_name, 'ceo_name']
37
+ #
38
+ ##############################################################################
39
+ class DcSetup
40
+ include Mongoid::Document
41
+ include Mongoid::Timestamps
42
+
43
+ attr_reader :my_data
44
+ attr_reader :my_fields
45
+
46
+ field :name, type: String, default: ''
47
+ field :data, type: String, default: ''
48
+ field :form, type: String, default: ''
49
+ field :editors, type: Array, default: []
50
+
51
+ field :created_by, type: BSON::ObjectId
52
+ field :updated_by, type: BSON::ObjectId
53
+
54
+ index name: 1
55
+
56
+ validates_length_of :name, minimum: 3
57
+
58
+ before_save do
59
+ self.data = my_data.to_yaml
60
+ end
61
+
62
+ ##############################################################################
63
+ # Will return settings record for specified application.
64
+ #
65
+ # @param [String] app_name The name of the application
66
+ # @return [Object, nil] The settings record if found, nil otherwise
67
+ ##############################################################################
68
+ def self.get(app_name)
69
+ DcSetup.find_by(name: app_name.to_s)
70
+ end
71
+
72
+ ##############################################################################
73
+ # Will return value for single setting if called as method.
74
+ ##############################################################################
75
+ def method_missing(m, *args, &block)
76
+ m = m.to_s
77
+ if m.match('=')
78
+ m.chomp!('=')
79
+ my_data[m] = args.first
80
+ else
81
+ my_data[m]
82
+ end
83
+ end
84
+
85
+ ##############################################################################
86
+ # Will return value for single setting. Called as parameter in square brackets.
87
+ # If more then one parameter is passed it will return them as array.
88
+ ##############################################################################
89
+ def [](*keys)
90
+ return my_data[keys.first.to_s] if keys.size == 1
91
+
92
+ keys.inject([]) { |r, k| r << my_data[k.to_s] }
93
+ end
94
+
95
+ ##############################################################################
96
+ # Will return true if setting is defined on the form
97
+ ##############################################################################
98
+ def respond_to?(field_name)
99
+ return true #if my_fields[field_name.to_s]
100
+
101
+ super.respond_to?(field_name)
102
+ end
103
+
104
+ ##############################################################################
105
+ #
106
+ ##############################################################################
107
+ def my_data
108
+ @my_data ||= (YAML.unsafe_load(data)) || {}
109
+ end
110
+
111
+ end
@@ -81,7 +81,7 @@ end
81
81
  ###########################################################################
82
82
  def self.get_data(params, name)
83
83
  t = params['record'][name] ? params['record'][name].to_datetime : nil
84
- t ? Time.zone.local(t.year, t.month, t.day, t.hour, t.min) : nil
84
+ t ? Time.new(t.year, t.month, t.day, t.hour, t.min) : nil
85
85
  end
86
86
 
87
87
  end
@@ -114,11 +114,11 @@ end
114
114
  # Returns:
115
115
  # String. Translated text.
116
116
  ####################################################################
117
- def t(key, default='')
117
+ def t(key, default = '')
118
118
  c = I18n.t(key)
119
- if c.match( 'translation missing' )
119
+ if c.match(/translation missing/i)
120
120
  c = I18n.t(key, locale: 'en')
121
- # Still not found. Return default if set
121
+ # Still not found. Return default if set
122
122
  c = default unless default.blank?
123
123
  end
124
124
  c
@@ -127,15 +127,8 @@ end
127
127
  ####################################################################
128
128
  # Standard code for returning readonly field.
129
129
  ####################################################################
130
- def ro_standard(value=nil)
131
- if value.nil?
132
- value = if @yaml['html']['value']
133
- @yaml['html']['value']
134
- else
135
- @record.respond_to?(@yaml['name']) ? @record.send(@yaml['name']) : nil
136
- end
137
- end
138
- #@html << (value.blank? ? '' : "<div class='dc-readonly'>#{value}</div>")
130
+ def ro_standard(value = nil)
131
+ value ||= @yaml['html']['value'] || (@record.respond_to?(@yaml['name']) ? @record.send(@yaml['name']) : nil)
139
132
  @html << %(<div id="#{@yaml['name']}" class="dc-readonly">#{value}</div>)
140
133
  self
141
134
  end
@@ -157,8 +150,9 @@ def set_initial_value(opt1 = 'html', opt2 = 'value')
157
150
  value_send_as = 'p_' + @yaml['name']
158
151
  if @parent.params[value_send_as]
159
152
  @yaml[opt1][opt2] = @parent.params[value_send_as]
160
- elsif @parent.flash[:record] and @parent.flash[:record][@yaml['name']]
161
- @yaml[opt1][opt2] = @parent.flash[:record][@yaml['name']]
153
+ elsif @parent.flash[:record]
154
+ value = @parent.flash[:record][@yaml['name']] || @parent.flash[:record][@yaml['name'].to_sym]
155
+ @yaml[opt1][opt2] = value if value
162
156
  end
163
157
  set_default_value(opt1, opt2) if @yaml['default']
164
158
  end
@@ -217,24 +211,13 @@ def set_style()
217
211
  end
218
212
  end
219
213
 
220
- ####################################################################
221
- # DEPRECATED!
222
- #
223
- # Returns css code for the field if specified. It replaces all occurences of '# '
224
- # with field name id, as defined on form.
225
- ####################################################################
226
- def __css_code
227
- return '' if @css.blank?
228
- @css.gsub!('# ',"#td_record_#{@yaml['name']} ")
229
- "\n<style type=\"text/css\">#{@css}</style>"
230
- end
231
-
232
214
  ####################################################################
233
215
  # Sets css code for the field if specified. It replaces all occurences of '# '
234
216
  # with field name id, as defined on form.
235
217
  ####################################################################
236
218
  def set_css_code(css)
237
219
  return '' if css.blank?
220
+
238
221
  css.gsub!('# ',"#td_record_#{@yaml['name']} ") if css.match('# ')
239
222
  css
240
223
  end
@@ -53,19 +53,26 @@ def render
53
53
  # HTML defaults. Some must be set
54
54
  @yaml['html'] ||= {}
55
55
  @yaml['html']['width'] ||= '99%'
56
+ # message when new record
57
+ if @record.new_record?
58
+ @yaml['html']['srcdoc'] = %(
59
+ <div style='font-family: helvetica; font-size: 1.7rem; font-weight: bold; color: #ddd; padding: 1rem'>
60
+ #{I18n.t('drgcms.iframe_save_to_view')}
61
+ </div>)
62
+ end
56
63
  html = @yaml['html'].inject('') { |r, val| r << "#{val.first}=\"#{val.last}\" " }
57
64
 
58
65
  @yaml['action'] ||= 'index'
59
66
  # defaults both way
60
- @yaml['table'] ||= @yaml['form_name'] if @yaml['form_name']
61
- @yaml['form_name'] ||= @yaml['table'] if @yaml['table']
67
+ @yaml['table'] ||= @yaml['form_name']
68
+ @yaml['form_name'] ||= @yaml['table']
62
69
 
63
- if @yaml['name'] == @yaml['table'] or @yaml['table'] == 'dc_memory'
70
+ if @yaml['name'] == @yaml['table'] || @yaml['table'] == 'dc_memory'
64
71
  tables = @yaml['table']
65
72
  ids = @record.id
66
73
  else
67
- tables = @parent.tables.inject('') { |r,v| r << "#{v[1]};" } + @yaml['table']
68
- ids = @parent.ids.inject('') { |r,v| r << "#{v};" } + @record.id
74
+ tables = (@parent.tables.map(&:first) + [@yaml['table']]).join(';')
75
+ ids = (@parent.ids + [@record.id]).join(';')
69
76
  end
70
77
  # edit enabled embedded form on a readonly form
71
78
  readonly = @yaml['readonly'].class == FalseClass ? nil : @readonly
@@ -73,20 +80,24 @@ def render
73
80
  ids: ids, table: tables, form_name: @yaml['form_name'],
74
81
  field_name: @yaml['name'], iframe: "if_#{@yaml['name']}", readonly: readonly }
75
82
  # additional parameters if specified
76
- @yaml['params'].each { |k,v| opts[k] = @parent.dc_value_for_parameter(v) } if @yaml['params']
77
-
83
+ @yaml['params'].each { |k, v| opts[k] = @parent.dc_value_for_parameter(v) } if @yaml['params']
84
+
78
85
  @html << "<iframe class='iframe_embedded' id='if_#{@yaml['name']}' name='if_#{@yaml['name']}' #{html}></iframe>"
79
- unless @record.new_record?
80
- url = @parent.url_for(opts)
81
- data = if @yaml['load'].nil? || @yaml['load'].match('default')
82
- "src"
83
- else
84
- "data-src-#{@yaml['load']}"
85
- end
86
- @js << %Q[
86
+ if @record.new_record?
87
+ else
88
+ url = @parent.url_for(opts)
89
+ attributes = case
90
+ when @yaml['load'].nil? || @yaml['load'].match('default')
91
+ "'src', '#{url}'"
92
+ when @yaml['load'].match('delay')
93
+ "'data-src-#{@yaml['load']}', '#{url}'"
94
+ when @yaml['load'].match('always')
95
+ "{'data-src-#{@yaml['load']}': '#{url}', src: '#{url}'}"
96
+ end
97
+ @js << %(
87
98
  $(document).ready( function() {
88
- $('#if_#{@yaml['name']}').attr('#{data}', '#{url}');
89
- });]
99
+ $('#if_#{@yaml['name']}').attr(#{attributes});
100
+ });)
90
101
  end
91
102
  self
92
103
  end