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
@@ -44,20 +44,20 @@ module CmsCommonHelper
44
44
  # Returns:
45
45
  # String. Translated text.
46
46
  ####################################################################
47
- def self.t(key, default=nil)
47
+ def self.t(key, default = nil)
48
48
  c = I18n.t(key)
49
- if c.class == Hash or c.match( 'translation missing' )
49
+ if c.class == Hash || c.match( /translation missing/i )
50
50
  c = I18n.t(key, locale: 'en')
51
- # Still not found. Return default if set
52
- if c.class == Hash or c.match( 'translation missing' )
53
- c = default.nil? ? key : default
51
+ # Still not found, return default
52
+ if c.class == Hash || c.match( /translation missing/i )
53
+ c = default || key
54
54
  end
55
55
  end
56
56
  c
57
57
  end
58
58
 
59
59
  ####################################################################
60
- def t(key, default=nil) #:nodoc
60
+ def t(key, default = nil) #:nodoc
61
61
  CmsCommonHelper.t(key, default)
62
62
  end
63
63
 
@@ -72,7 +72,7 @@ end
72
72
  # Returns:
73
73
  # String. Translated text.
74
74
  ####################################################################
75
- def t_tablename(tablename, default=nil)
75
+ def t_tablename(tablename, default = nil)
76
76
  t('helpers.label.' + tablename + '.tabletitle', default || tablename)
77
77
  end
78
78
 
@@ -81,21 +81,31 @@ 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_label_for_field(field_name, default='')
85
- c = t("helpers.label.#{@form['table']}.#{field_name}", default)
86
- c = field_name.capitalize.gsub('_',' ') if c.match( 'translation missing' )
87
- c
84
+ def t_label_for_field(field_name, default = '')
85
+ c = (@form['i18n_prefix'] || "helpers.label.#{@form['table']}") + ".#{field_name}"
86
+ c = field_name if field_name.match(/helpers\./)
87
+
88
+ label = t(c, default)
89
+ label = field_name.capitalize.gsub('_', ' ') if c.match( /translation missing/i )
90
+ label
88
91
  end
89
92
 
90
93
  ############################################################################
91
- # Returns label for field translated to current locale for usage browser header.
94
+ # Returns label for field translated to current locale for usage in browser header.
92
95
  # Translation is provided by lang.helpers.label.table_name.field_name locale. If
93
96
  # not found method will look in standard drgcms translations.
94
- #
95
97
  ############################################################################
96
98
  def t_label_for_column(options)
97
99
  label = options['caption'] || options['label']
98
- label = (options['name'] ? "helpers.label.#{@form['table']}.#{options['name']}" : '') if label.nil?
100
+ return ' ' if label == false
101
+
102
+ if label.blank?
103
+ label = if options['name']
104
+ prefix = @form['i18n_prefix'] || "helpers.label.#{@form['table']}"
105
+ "#{prefix}.#{options['name']}"
106
+ end
107
+ label = label.to_s
108
+ end
99
109
  label = t(label) if label.match(/\./)
100
110
  label = t("drgcms.#{options['name']}") if label.match('helpers.') # standard field names like created_by, updated_at
101
111
  label
@@ -127,9 +137,10 @@ end
127
137
  ############################################################################
128
138
  def self.dc_name_for_value(model, field, value)
129
139
  return '' if value.nil?
130
- c = t('helpers.label.' + model + '.choices4_' + field )
131
- a = c.chomp.split(',').inject([]) {|r,v| r << v.split(':') }
132
- a.each {|e| return e.first if e.last.to_s == value.to_s }
140
+
141
+ choices = t("helpers.label.#{model}.choices4_#{field}")
142
+ values = choices.chomp.split(',').map{ _1.split(':') }
143
+ values.each{ |e| return e.first if e.last.to_s == value.to_s }
133
144
  '???'
134
145
  end
135
146
 
@@ -160,9 +171,10 @@ end
160
171
  # Array. Choices for select input field
161
172
  ############################################################################
162
173
  def self.dc_choices_for_field(model, field)
163
- c = CmsCommonHelper.t('helpers.label.' + model + '.choices4_' + field )
164
- return ['error'] if c.match( 'translation missing' )
165
- c.chomp.split(',').inject([]) {|r,v| r << v.split(':') }
174
+ choices = CmsCommonHelper.t("helpers.label.#{model}.choices4_#{field}" )
175
+ return ['error'] if choices.match( /translation missing/i )
176
+
177
+ choices.chomp.split(',').map{ _1.split(':') }
166
178
  end
167
179
 
168
180
  ############################################################################
@@ -206,13 +218,13 @@ end
206
218
  # Returns:
207
219
  # String. Name (descriptive value) for specified key in table.
208
220
  ############################################################################
209
- def dc_name_for_id(model, field, field_name, id=nil)
221
+ def dc_name_for_id(model, field, field_name, id = nil)
210
222
  return '' if id.nil?
211
223
 
212
224
  field_name = (field_name || 'id').strip.to_sym
213
225
  field = field.strip.to_sym
214
226
  model = model.strip.classify.constantize if model.class == String
215
- doc = Mongoid::QueryCache.cache { model.find_by(field_name => id) }
227
+ doc = Mongo::QueryCache.cache { model.find_by(field_name => id) }
216
228
 
217
229
  doc.nil? ? '' : (doc.send(field) rescue 'not defined')
218
230
  end
@@ -220,7 +232,7 @@ end
220
232
  ############################################################################
221
233
  #
222
234
  ############################################################################
223
- def dc_name4_id(model, field, field_name, id=nil) #nodoc
235
+ def dc_name4_id(model, field, field_name, id = nil) #nodoc
224
236
  #dc_deprecate('dc_name4_id will be deprecated. Use dc_name_for_id instead.')
225
237
  dc_name_for_id(model, field, field_name, id)
226
238
  end
@@ -250,7 +262,7 @@ end
250
262
  ############################################################################
251
263
  #
252
264
  ############################################################################
253
- def dc_icon4_boolean(document = false, field_name = false) #nodoc
265
+ def dc_icon4_boolean(document = false, field_name = nil) #nodoc
254
266
  #dc_deprecate('dc_icon4_boolean will be deprecated. Use dc_icon_for_boolean instead.')
255
267
  dc_icon_for_boolean(document, field_name)
256
268
  end
@@ -44,17 +44,11 @@ def dc_value_for_parameter(param, current_document = nil)#:nodoc:
44
44
  end
45
45
 
46
46
  ############################################################################
47
- # Creates actions div for edit form.
48
- #
49
- # Displaying readonly form turned out to be challenge. For now when readonly parameter
50
- # has value 2, back link will force readonly form. Value 1 or not set will result in
51
- # normal link.
47
+ # Determine if action button on the form is active. Action will be greyed out otherwise.
48
+ #
49
+ # @return : Boolean : defined by 'active' option'. Default is True.
52
50
  ############################################################################
53
51
  def dc_is_action_active?(options)
54
- if options['when_new']
55
- dc_deprecate("when_option will be deprecated and replaced by active: not_new_record! Form #{CmsHelper.form_param(params)}")
56
- return !(dc_dont?(options['when_new']) && @record.new_record?)
57
- end
58
52
  return true unless options['active']
59
53
 
60
54
  # alias record and document so both can be used in eval
@@ -322,25 +316,25 @@ def dc_head_for_form
322
316
  caption = options['caption']
323
317
  span = options['span'] || 1
324
318
  @css << "\n#{options['css']}" unless options['css'].blank?
325
- label = if caption.blank?
326
- ''
327
- elsif options['name'] == caption
328
- t_label_for_field(options['name'], options['name'].capitalize.gsub('_',' ') )
329
- else
330
- t(caption, caption)
331
- end
319
+ label = if caption.blank?
320
+ ''
321
+ elsif options['name'] == caption
322
+ t_label_for_field(options['name'], options['name'].capitalize.gsub('_', ' ') )
323
+ else
324
+ t(caption, caption)
325
+ end
332
326
  # Field value
333
327
  begin
334
328
  field = if options['eval']
335
- dc_process_column_eval(options, @record)
336
- else
337
- @record.send(options['name'])
338
- end
329
+ dc_process_column_eval(options, @record)
330
+ else
331
+ dc_format_value(@record.send(options['name']), options['format'])
332
+ end
339
333
  rescue Exception => e
340
334
  dc_log_exception(e, 'dc_head_for_form')
341
335
  field = '!!!Error'
342
336
  end
343
- #
337
+
344
338
  klass = dc_style_or_class(nil, options['class'], field, @record)
345
339
  style = dc_style_or_class(nil, options['style'], field, @record)
346
340
  html << %(<div class="dc-column #{klass}" style="width:#{percent*span}%;#{style}">
@@ -487,18 +481,17 @@ def dc_input_form_create(fields_on_tab) #:nodoc:
487
481
  </div> )
488
482
  else
489
483
  # 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?
484
+ label_width, data_width = if dc_dont?(options['caption'])
485
+ label = ''
486
+ [0, 100]
487
+ elsif group_option == 1
488
+ [14, 85]
489
+ elsif group_option == 2
490
+ group_count == 2 ? [14, 21] : [10, 45]
491
+ elsif group_option == 3
492
+ group_count == 3 ? [14, 21] : [10, 21]
493
+ end
494
+ help.gsub!('<br>', "\n") if help.present?
502
495
  %(
503
496
  <div class="dc-form-label dc-color-#{odd_even} dc-align-#{labels_pos} dc-width-#{label_width}" title="#{help}">
504
497
  <label for="record_#{options['name']}">#{label} </label>
@@ -53,12 +53,12 @@ end
53
53
  ############################################################################
54
54
  def dc_get_field_form_definition(name) #:nodoc:
55
55
  return if @form['form'].nil?
56
-
56
+
57
57
  @form['form']['tabs'].each do |tab|
58
58
  # Array with 2 elements. First is tab name, second is data
59
59
  my_fields = tab.last
60
60
  my_fields.each { |k, v| return v if (k.class == Integer && v['name'] == name) }
61
- end if @form['form']['tabs'] # I know. But nice.
61
+ end if @form['form']['tabs'] # I know. But nice.
62
62
 
63
63
  @form['form']['fields'].each do |field|
64
64
  next unless field.first.class == Integer # options
@@ -102,17 +102,18 @@ end
102
102
  # Return label and help text for a field defined on Form.
103
103
  #
104
104
  # Parameters:
105
- # options : Hash : Field definition
105
+ # @options : Hash : Field definition
106
106
  #
107
107
  # Returns:
108
- # label : String : Label text
109
- # help : String : Help text
108
+ # @label : String : Label text
109
+ # @help : String : Help text
110
110
  ############################################################################
111
111
  def dc_label_help(options)
112
112
  # no label or help in comments
113
- return [nil, nil] if %w(comment action).include?(options['type'])
113
+ return [nil, nil] if %w[comment action].include?(options['type'])
114
114
 
115
115
  label = options['caption'] || options['text'] || options['label']
116
+ label = '' if options['type'] == 'check_box'
116
117
  if options['name']
117
118
  label = if label.blank?
118
119
  t_label_for_field(options['name'], options['name'].capitalize.gsub('_',' ') )
@@ -122,8 +123,16 @@ def dc_label_help(options)
122
123
  end
123
124
  # help text can be defined in form or in translations starting with helpers. or as helpers.help.collection.field
124
125
  help = options['help']
125
- help ||= "helpers.help.#{@form['table']}.#{options['name']}" if options['name']
126
- help = t(help, ' ') if help.to_s.match(/helpers\./)
126
+ if help.blank?
127
+ help = if options['name']
128
+ # if defined as i18n_prefix replace "label" with "help"
129
+ prefix = @form['i18n_prefix'] ? @form['i18n_prefix'].sub('label', 'help') : "helpers.help.#{@form['table']}"
130
+ "#{prefix}.#{options['name']}"
131
+ end
132
+ help = help.to_s
133
+ end
134
+ help = t(help, ' ') if help.to_s.match(/help\./)
135
+
127
136
  [label, help]
128
137
  end
129
138
 
@@ -167,7 +176,7 @@ def dc_field_action(yaml)
167
176
  field, label, help = dc_field_label_help(yaml)
168
177
  end
169
178
  # input field will have label as placeholder
170
- field = field.sub('input',"input placeholder=\"#{label}\"")
179
+ field = field.sub('input', "input placeholder=\"#{label}\"")
171
180
  %(<li class="no-background">#{field}</li>)
172
181
  end
173
182
 
@@ -177,7 +186,7 @@ end
177
186
  def dc_html_data(yaml)
178
187
  return '' if yaml.blank?
179
188
 
180
- yaml.inject(' ') { |result, e| result = e.last.nil? ? result : result << "#{e.first}=\"#{e.last}\" " }
189
+ yaml.inject(' ') { |result, e| result << (e.last ? %(#{e.first}="#{e.last}" ) : '') }
181
190
  end
182
191
 
183
192
  ############################################################################
@@ -300,10 +309,18 @@ def dc_log_exception(exception, where = '')
300
309
  end
301
310
 
302
311
  ############################################################################
303
- # Will return form id, to be used on each form for simpler css selecting.
312
+ # Will return form id. id can be used for css selecting of fields on form.
313
+ # Form id is by default form_name || table parameter.
304
314
  ############################################################################
305
315
  def dc_form_id
306
- %( id=#{CmsHelper.form_param(params) || CmsHelper.table_param(params)} )
316
+ %(id="#{CmsHelper.form_param(params) || CmsHelper.table_param(params)}" ).html_safe
317
+ end
318
+
319
+ ############################################################################
320
+ # Will return class for form. Class can be used for different styling of forms.
321
+ ############################################################################
322
+ def dc_form_class(additional_class = nil)
323
+ %(class="#{additional_class} #{@form['class']}" ).html_safe
307
324
  end
308
325
 
309
326
  ############################################################################