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.
- checksums.yaml +4 -4
- data/app/assets/javascripts/drg_cms/drg_cms.js +110 -35
- data/app/assets/javascripts/drg_cms/jquery.bpopup.js +372 -0
- data/app/assets/javascripts/drg_cms_application.js +1 -1
- data/app/assets/javascripts/drg_cms_cms.js +1 -1
- data/app/assets/stylesheets/drg_cms/drg_cms.css +126 -36
- data/app/assets/stylesheets/drg_cms/select-multiple.css +6 -7
- data/app/controllers/cmsedit_controller.rb +78 -47
- data/app/controllers/dc_application_controller.rb +22 -25
- data/app/controllers/dc_common_controller.rb +9 -6
- data/app/controllers/dc_main_controller.rb +0 -1
- data/app/controls/{dc_category_control.rb → dc_gallery_control.rb} +15 -30
- data/app/controls/dc_image_control.rb +180 -0
- data/app/controls/dc_page_control.rb +3 -3
- data/app/controls/dc_poll_result_control.rb +38 -39
- data/app/controls/dc_report.rb +9 -4
- data/app/controls/dc_setup_control.rb +53 -0
- data/app/controls/design_element_settings_control.rb +88 -37
- data/app/forms/all_options.yml +20 -9
- data/app/forms/cms_menu.yml +14 -2
- data/app/forms/dc_gallery.yml +1 -1
- data/app/forms/dc_image.yml +122 -0
- data/app/forms/dc_image_search.yml +72 -0
- data/app/forms/dc_page.yml +11 -8
- data/app/forms/dc_poll.yml +2 -1
- data/app/forms/dc_poll_result.yml +10 -7
- data/app/forms/dc_setup.yml +45 -0
- data/app/forms/dc_steps_template.yml +6 -2
- data/app/helpers/cms_common_helper.rb +36 -24
- data/app/helpers/cms_edit_helper.rb +26 -33
- data/app/helpers/cms_helper.rb +29 -12
- data/app/helpers/cms_index_helper.rb +109 -80
- data/app/helpers/dc_application_helper.rb +108 -86
- data/app/helpers/dc_image_helper.rb +127 -0
- data/app/models/concerns/dc_policy_rule_concern.rb +1 -1
- data/app/models/concerns/dc_user_concern.rb +13 -5
- data/app/models/dc_big_table.rb +1 -1
- data/app/models/dc_category.rb +12 -0
- data/app/models/dc_design.rb +5 -4
- data/app/models/dc_filter.rb +24 -27
- data/app/models/dc_image.rb +237 -0
- data/app/models/dc_internals.rb +5 -9
- data/app/models/dc_memory.rb +2 -2
- data/app/models/dc_policy_role.rb +8 -8
- data/app/models/dc_setup.rb +111 -0
- data/app/models/drgcms_form_fields/datetime_picker.rb +1 -1
- data/app/models/drgcms_form_fields/drgcms_field.rb +9 -26
- data/app/models/drgcms_form_fields/embedded.rb +28 -17
- data/app/models/drgcms_form_fields/journal_diff.rb +2 -2
- data/app/models/drgcms_form_fields/multitext_autocomplete.rb +88 -76
- data/app/models/drgcms_form_fields/select.rb +41 -19
- data/app/models/drgcms_form_fields/text_with_select.rb +5 -9
- data/app/renderers/dc_big_menu_renderer.rb +18 -20
- data/app/renderers/dc_gallery_renderer.rb +10 -4
- data/app/renderers/dc_menu_renderer.rb +21 -58
- data/app/renderers/dc_page_renderer.rb +7 -7
- data/app/renderers/dc_poll_renderer.rb +13 -12
- data/app/renderers/dc_simple_menu_renderer.rb +1 -1
- data/app/views/cmsedit/_edit_stuff.html.erb +4 -1
- data/app/views/cmsedit/edit.html.erb +1 -1
- data/app/views/cmsedit/index.html.erb +1 -1
- data/app/views/cmsedit/new.html.erb +1 -0
- data/config/locales/drgcms_en.yml +22 -2
- data/config/locales/drgcms_sl.yml +25 -6
- data/config/locales/models_en.yml +50 -1
- data/config/locales/models_sl.yml +60 -1
- data/drg_cms.gemspec +1 -1
- data/lib/drg_cms/version.rb +1 -1
- data/lib/drg_cms.rb +40 -27
- data/lib/generators/convert_to_ar/USAGE +8 -0
- data/lib/generators/convert_to_ar/convert_to_ar_generator.rb +158 -0
- data/lib/generators/new_drg_form/new_drg_form_generator.rb +32 -14
- metadata +19 -10
- data/app/assets/javascripts/drg_cms/jquery.bpopup.min.js +0 -7
- 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
|
49
|
+
if c.class == Hash || c.match( /translation missing/i )
|
50
50
|
c = I18n.t(key, locale: 'en')
|
51
|
-
# Still not found
|
52
|
-
if c.class == Hash
|
53
|
-
c = 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 =
|
86
|
-
c = field_name
|
87
|
-
|
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
|
-
|
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
|
-
|
131
|
-
|
132
|
-
|
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
|
-
|
164
|
-
return ['error'] if
|
165
|
-
|
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 =
|
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 =
|
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
|
-
#
|
48
|
-
#
|
49
|
-
#
|
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
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
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
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
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
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
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>
|
data/app/helpers/cms_helper.rb
CHANGED
@@ -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
|
-
#
|
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
|
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
|
126
|
-
|
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
|
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
|
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
|
-
%(
|
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
|
############################################################################
|