drg_cms 0.6.0.8 → 0.6.1.5
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.
- checksums.yaml +4 -4
- data/README.md +25 -10
- data/app/assets/javascripts/drg_cms/drg_cms.js +208 -81
- data/app/assets/stylesheets/drg_cms/drg_cms.css +298 -93
- data/app/assets/stylesheets/drg_cms/select-multiple.css +1 -1
- data/app/controllers/cmsedit_controller.rb +174 -167
- data/app/controllers/dc_application_controller.rb +230 -196
- data/app/controllers/dc_common_controller.rb +88 -50
- data/app/controls/dc_help_control.rb +138 -0
- data/app/controls/dc_report.rb +12 -16
- data/app/forms/all_options.yml +14 -5
- data/app/forms/cms_menu.yml +7 -1
- data/app/forms/dc_big_table.yml +0 -2
- data/app/forms/dc_big_table_value.yml +0 -2
- data/app/forms/dc_category.yml +2 -1
- data/app/forms/dc_design.yml +2 -2
- data/app/forms/dc_folder_permission.yml +0 -2
- data/app/forms/dc_help_1.yml +110 -0
- data/app/forms/dc_journal.yml +3 -1
- data/app/forms/dc_json_ld.yml +0 -3
- data/app/forms/dc_link.yml +1 -1
- data/app/forms/dc_menu.yml +8 -12
- data/app/forms/dc_menu_item.yml +2 -3
- data/app/forms/dc_page.yml +7 -2
- data/app/forms/dc_part.yml +1 -0
- data/app/forms/dc_piece.yml +1 -0
- data/app/forms/dc_policy.yml +2 -5
- data/app/forms/dc_poll.yml +13 -16
- data/app/forms/dc_seo.yml +1 -2
- data/app/forms/dc_simple_menu.yml +3 -2
- data/app/forms/dc_site.yml +5 -8
- data/app/forms/dc_user.yml +27 -11
- data/app/forms/dc_user_role.yml +3 -0
- data/app/helpers/cms_common_helper.rb +68 -4
- data/app/helpers/cms_edit_helper.rb +73 -55
- data/app/helpers/cms_helper.rb +70 -32
- data/app/helpers/cms_index_helper.rb +155 -102
- data/app/helpers/dc_application_helper.rb +132 -109
- data/app/models/concerns/dc_page_concern.rb +14 -4
- data/app/models/concerns/dc_piece_concern.rb +1 -1
- data/app/models/concerns/dc_policy_rule_concern.rb +20 -8
- data/app/models/concerns/dc_site_concern.rb +56 -44
- data/app/models/concerns/dc_user_concern.rb +58 -19
- data/app/models/dc_big_table.rb +2 -2
- data/app/models/dc_design.rb +29 -19
- data/app/models/dc_filter.rb +28 -22
- data/app/models/dc_key_value_store.rb +1 -0
- data/app/models/dc_permission.rb +19 -9
- data/app/models/dc_policy.rb +25 -14
- data/app/models/dc_policy_role.rb +22 -11
- data/app/models/dc_temp.rb +8 -1
- data/app/models/dc_user_role.rb +2 -2
- data/app/models/drgcms_form_fields/comment.rb +11 -2
- data/app/models/drgcms_form_fields/date_picker.rb +2 -0
- data/app/models/drgcms_form_fields/drgcms_field.rb +2 -1
- data/app/models/drgcms_form_fields/embedded.rb +9 -10
- data/app/models/drgcms_form_fields/file_field.rb +1 -1
- data/app/models/drgcms_form_fields/file_select.rb +2 -2
- data/app/models/drgcms_form_fields/hash_field.rb +11 -7
- data/app/models/drgcms_form_fields/link_to.rb +2 -2
- data/app/models/drgcms_form_fields/method.rb +5 -4
- data/app/models/drgcms_form_fields/multitext_autocomplete.rb +1 -1
- data/app/models/drgcms_form_fields/number_field.rb +4 -3
- data/app/models/drgcms_form_fields/readonly.rb +13 -17
- data/app/models/drgcms_form_fields/select.rb +24 -25
- data/app/models/drgcms_form_fields/text_autocomplete.rb +22 -14
- data/app/renderers/dc_page_renderer.rb +7 -6
- data/app/renderers/dc_poll_renderer.rb +16 -20
- data/app/views/cmsedit/_edit_stuff.html.erb +5 -2
- data/app/views/cmsedit/_form.html.erb +3 -2
- data/app/views/cmsedit/_result.html.erb +21 -18
- data/app/views/cmsedit/edit.html.erb +4 -1
- data/app/views/cmsedit/index.html.erb +3 -2
- data/app/views/cmsedit/new.html.erb +5 -2
- data/app/views/dc_common/_help.html.erb +17 -0
- data/app/views/layouts/models.html.erb +2 -1
- data/config/locales/drgcms_en.yml +17 -2
- data/config/locales/drgcms_sl.yml +20 -2
- data/config/locales/models_en.yml +7 -5
- data/config/locales/models_sl.yml +12 -9
- data/drg_cms.gemspec +16 -16
- data/lib/drg_cms/version.rb +1 -1
- data/lib/drg_cms.rb +94 -2
- metadata +32 -30
- data/app/models/__dc_dummy.rb +0 -102
@@ -32,14 +32,17 @@ module CmsIndexHelper
|
|
32
32
|
############################################################################
|
33
33
|
# Creates action div for cmsedit index action.
|
34
34
|
############################################################################
|
35
|
-
def dc_actions_for_index
|
35
|
+
def dc_actions_for_index
|
36
36
|
@js = @form['script'] || @form['js'] || ''
|
37
37
|
@css = @form['css'] || ''
|
38
|
-
return '' if @form['index'].nil?
|
38
|
+
return '' if @form['index'].nil?
|
39
|
+
|
39
40
|
actions = @form['index']['actions']
|
40
41
|
return '' if actions.blank?
|
41
42
|
|
42
43
|
std_actions = {2 => 'new', 3 => 'sort', 4 => 'filter' }
|
44
|
+
std_actions.delete(2) if @form['readonly']
|
45
|
+
|
43
46
|
if actions.class == String
|
44
47
|
actions = dc_define_standard_actions(actions, std_actions)
|
45
48
|
elsif actions['standard']
|
@@ -47,19 +50,20 @@ def dc_actions_for_index()
|
|
47
50
|
actions['standard'] = nil
|
48
51
|
end
|
49
52
|
|
50
|
-
# start div with hidden spinner image
|
51
|
-
html =
|
53
|
+
# start div with hidden spinner image
|
54
|
+
html = %(
|
52
55
|
<form id="dc-action-menu">
|
53
56
|
<span class="dc-spinner">#{fa_icon('spinner lg spin')}</span>
|
54
|
-
<ul class="dc-action-menu">
|
55
|
-
|
56
|
-
# Remove actions settings and sort
|
57
|
+
<ul class="dc-action-menu">)
|
58
|
+
|
59
|
+
# Remove actions settings and sort
|
57
60
|
only_actions = []
|
58
61
|
actions.each { |key, value| only_actions << [key, value] if key.class == Integer }
|
59
62
|
only_actions.sort_by!(&:first)
|
60
63
|
only_actions.each do |key, options|
|
61
64
|
session[:form_processing] = "index:actions: #{key}=#{options}"
|
62
65
|
next if options.nil? # must be
|
66
|
+
|
63
67
|
url = @parms.clone
|
64
68
|
yaml = options.class == String ? {'type' => options} : options # if single definition simulate type parameter
|
65
69
|
action = yaml['type'].to_s.downcase
|
@@ -67,7 +71,7 @@ EOT
|
|
67
71
|
dc_deprecate "action: url will be deprecated. Use action: link in index: actions! Form #{params['form_name']}"
|
68
72
|
action = 'link'
|
69
73
|
end
|
70
|
-
# if return_to is present link directly to URL
|
74
|
+
# if return_to is present link directly to URL
|
71
75
|
if action == 'link' and yaml['url']
|
72
76
|
url = yaml['url']
|
73
77
|
else
|
@@ -77,11 +81,11 @@ EOT
|
|
77
81
|
url['form_name'] = yaml['form_name'] if yaml['form_name']
|
78
82
|
url['control'] = yaml['control'] if yaml['control']
|
79
83
|
end
|
80
|
-
# html link options
|
84
|
+
# html link options
|
81
85
|
yhtml = yaml['html'] || {}
|
82
86
|
yhtml['title'] = yaml['title'] if yaml['title']
|
83
|
-
code = case
|
84
|
-
# sort
|
87
|
+
code = case
|
88
|
+
# sort
|
85
89
|
when action == 'sort' then
|
86
90
|
choices = [['id','id']]
|
87
91
|
if @form['index']['sort']
|
@@ -93,11 +97,12 @@ EOT
|
|
93
97
|
fa_icon('sort-alpha-asc') + ' ' + t('drgcms.sort') + ' ' +
|
94
98
|
select('sort', 'sort', choices, { include_blank: true },
|
95
99
|
{ class: 'drgcms_sort', 'data-table' => @form['table'], 'data-form' => params['form_name']} )
|
96
|
-
|
100
|
+
|
101
|
+
# filter
|
97
102
|
when action == 'filter' then
|
98
103
|
caption = t('drgcms.filter')
|
99
104
|
caption << ' ' + fa_icon('caret-down lg') + DcFilter.menu_filter(self)
|
100
|
-
# add filter OFF link
|
105
|
+
# add filter OFF link
|
101
106
|
sess = session[@form['table']]
|
102
107
|
if sess and sess[:filter]
|
103
108
|
caption << ' ' + dc_link_to(nil,'remove lg',
|
@@ -105,14 +110,25 @@ EOT
|
|
105
110
|
{ title: DcFilter.title4_filter_off(sess[:filter]) })
|
106
111
|
end
|
107
112
|
caption
|
108
|
-
|
109
|
-
|
113
|
+
|
114
|
+
# new
|
115
|
+
when action == 'new' then
|
110
116
|
caption = yaml['caption'] || 'drgcms.new'
|
111
|
-
dc_link_to(caption,'plus', url, yhtml )
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
117
|
+
html << "<li class=\"dc-link plus-link dc-animate\">#{dc_link_to(caption, 'plus', url, yhtml )}</li>"
|
118
|
+
next
|
119
|
+
|
120
|
+
when action == 'close' then
|
121
|
+
html << %(<li class="dc-link dc-animate" onclick="window.close();"'>#{fa_icon('close')} #{t('drgcms.close')}</li>)
|
122
|
+
next
|
123
|
+
|
124
|
+
# menu
|
125
|
+
when action == 'menu' then
|
126
|
+
if options['caption']
|
127
|
+
caption = t(options['caption'], options['caption']) + ' ' + fa_icon('caret-down lg')
|
128
|
+
caption + eval(options['eval'])
|
129
|
+
else # when caption is false, provide own actions
|
130
|
+
eval(options['eval'])
|
131
|
+
end
|
116
132
|
=begin
|
117
133
|
# reorder
|
118
134
|
when action == 'reorder' then
|
@@ -126,13 +142,16 @@ EOT
|
|
126
142
|
when action == 'script'
|
127
143
|
html << dc_script_action(options)
|
128
144
|
next
|
145
|
+
|
129
146
|
when action == 'field'
|
130
147
|
html << dc_field_action(yaml)
|
131
148
|
next
|
149
|
+
|
132
150
|
when %w(ajax link window submit).include?(action)
|
133
151
|
html << dc_link_ajax_window_submit_action(options, nil)
|
134
152
|
next
|
135
|
-
|
153
|
+
|
154
|
+
else
|
136
155
|
caption = yaml['caption'] || yaml['text']
|
137
156
|
icon = yaml['icon'] ? yaml['icon'] : action
|
138
157
|
dc_link_to(caption, icon, url, yhtml)
|
@@ -140,22 +159,21 @@ EOT
|
|
140
159
|
html << "<li class=\"dc-link dc-animate\">#{code}</li>"
|
141
160
|
html << DcFilter.get_filter_field(self) if action == 'filter'
|
142
161
|
end
|
143
|
-
html << '</ul>'
|
144
|
-
html << '</form>'
|
162
|
+
html << '</ul></form>'
|
145
163
|
html.html_safe
|
146
164
|
end
|
147
165
|
|
148
166
|
############################################################################
|
149
167
|
# Creates filter div for cmsedit index/filter action.
|
150
168
|
############################################################################
|
151
|
-
def dc_div_filter
|
169
|
+
def dc_div_filter
|
152
170
|
choices = []
|
153
171
|
filter = (@form['index'] and @form['index']['filter']) ? @form['index']['filter'] + ',' : ''
|
154
172
|
filter << 'id as text_field' # filter id is added by default
|
155
173
|
filter.split(',').each do |f|
|
156
174
|
f.strip!
|
157
175
|
name = f.match(' as ') ? f.split(' ').first : f
|
158
|
-
# like another field on the form
|
176
|
+
# like another field on the form
|
159
177
|
if f.match(' like ')
|
160
178
|
a = f.split(' ')
|
161
179
|
name = a.first
|
@@ -164,7 +182,7 @@ def dc_div_filter()
|
|
164
182
|
choices << [ t("helpers.label.#{@form['table']}.#{name}", name), f ]
|
165
183
|
end
|
166
184
|
choices4_operators = t('drgcms.choices4_filter_operators').chomp.split(',').inject([]) {|r,v| r << (v.match(':') ? v.split(':') : v )}
|
167
|
-
# currently selected options
|
185
|
+
# currently selected options
|
168
186
|
if session[@form['table']] and session[@form['table']][:filter]
|
169
187
|
field_name, operators_value, dummy = session[@form['table']][:filter].split("\t")
|
170
188
|
else
|
@@ -190,7 +208,7 @@ end
|
|
190
208
|
############################################################################
|
191
209
|
# Creates popup div for setting filter on result set header.
|
192
210
|
############################################################################
|
193
|
-
def dc_filter_popup
|
211
|
+
def dc_filter_popup
|
194
212
|
html = %Q[<div class="filter-popup" style="display: none;">
|
195
213
|
<div>#{t('drgcms.filter_set')}</div>
|
196
214
|
<ul>]
|
@@ -204,20 +222,22 @@ def dc_filter_popup()
|
|
204
222
|
end
|
205
223
|
|
206
224
|
############################################################################
|
207
|
-
#
|
208
|
-
# options.
|
225
|
+
# Will return title based on @form['title']
|
209
226
|
############################################################################
|
210
|
-
def
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
227
|
+
def dc_form_title
|
228
|
+
return t("helpers.label.#{@form['table']}.tabletitle", @form['table']) if @form['title'].nil?
|
229
|
+
return t(@form['title'], @form['title']) if @form['title'].class == String
|
230
|
+
|
231
|
+
# Hash
|
232
|
+
dc_process_eval(@form['title']['eval'], [@form['title']['caption'] || @form['title']['text'], params])
|
233
|
+
end
|
234
|
+
|
235
|
+
############################################################################
|
236
|
+
# Creates title div for index action. Title div also includes paging options
|
237
|
+
# and help link
|
238
|
+
############################################################################
|
239
|
+
def dc_title_for_index(result = nil)
|
240
|
+
dc_table_title(dc_form_title(), result)
|
221
241
|
end
|
222
242
|
|
223
243
|
############################################################################
|
@@ -225,15 +245,16 @@ end
|
|
225
245
|
############################################################################
|
226
246
|
def dc_actions_column
|
227
247
|
actions = @form['result_set']['actions']
|
228
|
-
return [{}, 0] if actions.nil?
|
229
|
-
|
248
|
+
return [{}, 0] if actions.nil? || dc_dont?(actions)
|
249
|
+
|
250
|
+
# standard actions
|
230
251
|
actions = {'standard' => true} if actions.class == String && actions == 'standard'
|
231
252
|
std_actions = { 2 => 'edit', 5 => 'delete' }
|
232
253
|
if actions['standard']
|
233
254
|
actions.merge!(std_actions)
|
234
255
|
actions.delete('standard')
|
235
256
|
end
|
236
|
-
|
257
|
+
|
237
258
|
width = @form['result_set']['actions_width'] || 18*actions.size
|
238
259
|
[actions, width]
|
239
260
|
end
|
@@ -253,7 +274,7 @@ end
|
|
253
274
|
############################################################################
|
254
275
|
def dc_actions_for_result(document)
|
255
276
|
actions = @form['result_set']['actions']
|
256
|
-
return '' if actions.nil?
|
277
|
+
return '' if actions.nil? || @form['readonly']
|
257
278
|
|
258
279
|
actions, width = dc_actions_column()
|
259
280
|
html = %Q[<ul class="actions" style="width: #{width}px;">]
|
@@ -263,27 +284,33 @@ def dc_actions_for_result(document)
|
|
263
284
|
# if single definition simulate type parameter
|
264
285
|
yaml = v.class == String ? { 'type' => v } : v
|
265
286
|
# code already includes li tag
|
266
|
-
if %w(ajax link window submit).include?(yaml['type'])
|
287
|
+
if %w(ajax link window submit).include?(yaml['type'])
|
267
288
|
@record = document # otherwise document fields can't be used as parameters
|
268
289
|
html << dc_link_ajax_window_submit_action(yaml, document)
|
269
290
|
else
|
270
291
|
html << '<li class="dc-link">'
|
271
292
|
html << case
|
293
|
+
when yaml['type'] == 'check' then
|
294
|
+
check_box_tag("check-#{document.id}", false,false,{ class: 'dc-check' })
|
295
|
+
|
272
296
|
when yaml['type'] == 'edit' then
|
273
297
|
parms['action'] = 'edit'
|
274
298
|
parms['id'] = document.id
|
275
299
|
dc_link_to( nil, 'pencil lg', parms )
|
300
|
+
|
276
301
|
when yaml['type'] == 'duplicate' then
|
277
302
|
parms['id'] = document.id
|
278
303
|
# duplicate string will be added to these fields.
|
279
304
|
parms['dup_fields'] = yaml['dup_fields']
|
280
305
|
parms['action'] = 'create'
|
281
306
|
dc_link_to( nil, 'copy lg', parms, data: { confirm: t('drgcms.confirm_dup') }, method: :post )
|
307
|
+
|
282
308
|
when yaml['type'] == 'delete' then
|
283
309
|
parms['action'] = 'destroy'
|
284
310
|
parms['id'] = document.id
|
285
|
-
parms['return_to'] = request.url
|
311
|
+
#parms['return_to'] = request.url
|
286
312
|
dc_link_to( nil, 'remove lg', parms, data: { confirm: t('drgcms.confirm_delete') }, method: :delete )
|
313
|
+
|
287
314
|
# undocumented so far
|
288
315
|
when yaml['type'] == 'edit_embedded'
|
289
316
|
parms['controller'] = 'cmsedit'
|
@@ -305,11 +332,14 @@ end
|
|
305
332
|
############################################################################
|
306
333
|
# Creates header div for result set.
|
307
334
|
############################################################################
|
308
|
-
def dc_header_for_result
|
335
|
+
def dc_header_for_result
|
309
336
|
html = '<div class="dc-result-header">'
|
310
337
|
if @form['result_set']['actions'] and !@form['readonly']
|
311
338
|
ignore, width = dc_actions_column()
|
312
|
-
|
339
|
+
if width > 0 && @form['result_set']['actions'][0].to_s == 'check'
|
340
|
+
check_all = fa_icon('check-square-o', class: 'dc-check-all')
|
341
|
+
end
|
342
|
+
html << %Q[<div class="actions" style="width:#{width}px;">#{check_all}</div>]
|
313
343
|
end
|
314
344
|
# preparation for sort icon
|
315
345
|
sort_field, sort_direction = nil, nil
|
@@ -325,9 +355,10 @@ def dc_header_for_result()
|
|
325
355
|
th = %Q[<div class="th" style="width:#{v['width'] || '15%'};text-align:#{v['align'] || 'left'};" data-name="#{v['name']}"]
|
326
356
|
label = v['caption'] || v['label']
|
327
357
|
label = (v['name'] ? "helpers.label.#{@form['table']}.#{v['name']}" : '') if label.nil?
|
328
|
-
label = t(label) if label.match(
|
358
|
+
label = t(label) if label.match(/\./)
|
329
359
|
# no sorting when embedded documents or custom filter is active
|
330
|
-
sort_ok = @form['result_set'].nil? || (@form['result_set'] && @form['result_set']['filter'].nil?)
|
360
|
+
#sort_ok = @form['result_set'].nil? || (@form['result_set'] && @form['result_set']['filter'].nil?)
|
361
|
+
sort_ok = true
|
331
362
|
sort_ok = sort_ok || (@form['index'] && @form['index']['sort'])
|
332
363
|
sort_ok = sort_ok && !dc_dont?(v['sort'], false)
|
333
364
|
if @tables.size == 1 and sort_ok
|
@@ -364,9 +395,9 @@ def dc_clicks_for_result(document)
|
|
364
395
|
html << ' data-dblclick=' + url_for(opts)
|
365
396
|
else
|
366
397
|
html << (' data-dblclick=' +
|
367
|
-
|
368
|
-
|
369
|
-
|
398
|
+
url_for(action: 'show', controller: 'cmsedit', id: document.id, ids: params[:ids],
|
399
|
+
readonly: (params[:readonly] ? 2 : 1), table: params[:table],
|
400
|
+
form_name: params[:form_name]) ) if @form['form']
|
370
401
|
end
|
371
402
|
html
|
372
403
|
end
|
@@ -378,11 +409,13 @@ def dc_format_value(value, format=nil)
|
|
378
409
|
return '' if value.nil?
|
379
410
|
|
380
411
|
klass = value.class.to_s
|
381
|
-
if klass.match(/time|date/i)
|
382
|
-
|
383
|
-
|
384
|
-
|
412
|
+
return CmsCommonHelper.dc_format_date_time(value, format) if klass.match(/time|date/i)
|
413
|
+
|
414
|
+
format = format.to_s.upcase
|
415
|
+
if format[0] == 'N'
|
416
|
+
return '' if value == 0 && format.match('Z')
|
385
417
|
|
418
|
+
format.gsub!('Z', '')
|
386
419
|
dec = format[1].blank? ? nil : format[1].to_i
|
387
420
|
sep = format[2].blank? ? nil : format[2]
|
388
421
|
del = format[3].blank? ? nil : format[3]
|
@@ -407,6 +440,7 @@ end
|
|
407
440
|
############################################################################
|
408
441
|
def dc_columns_for_result(document)
|
409
442
|
return '' unless @form['result_set']['columns']
|
443
|
+
|
410
444
|
html = ''
|
411
445
|
@form['result_set']['columns'].sort.each do |k,v|
|
412
446
|
session[:form_processing] = "result_set:columns: #{k}=#{v}"
|
@@ -429,7 +463,7 @@ def dc_columns_for_result(document)
|
|
429
463
|
"??? #{v['name']}"
|
430
464
|
end
|
431
465
|
rescue Exception => e
|
432
|
-
dc_log_exception(e)
|
466
|
+
dc_log_exception(e, 'dc_columns_for_result')
|
433
467
|
value = '!!!Error'
|
434
468
|
end
|
435
469
|
html << '<div class="spacer"></div>'
|
@@ -446,6 +480,14 @@ def dc_columns_for_result(document)
|
|
446
480
|
html.html_safe
|
447
481
|
end
|
448
482
|
|
483
|
+
############################################################################
|
484
|
+
# Split eval expression to array by parameters.
|
485
|
+
# Ex. Will split dc_name4_value(one ,"two") => ['dc_name4_value', 'one', 'two']
|
486
|
+
############################################################################
|
487
|
+
def dc_eval_to_array(expression)
|
488
|
+
expression.split(/\ |\,|\(|\)/).delete_if {|e| e.blank? }.map {|e| e.gsub(/\'|\"/,'').strip }
|
489
|
+
end
|
490
|
+
|
449
491
|
private
|
450
492
|
|
451
493
|
############################################################################
|
@@ -465,58 +507,52 @@ def dc_process_eval(evaluate, parameters)
|
|
465
507
|
end
|
466
508
|
end
|
467
509
|
|
468
|
-
############################################################################
|
469
|
-
# Break eval expression to array by parameters.
|
470
|
-
# Will break dc_name4_value(one ,"two") => ['dc_name4_value', 'one', 'two']
|
471
|
-
############################################################################
|
472
|
-
def dc_eval_to_array(expression)
|
473
|
-
expression.split(/\ |\,|\(|\)/).delete_if {|e| e.blank? }.map {|e| e.gsub(/\'|\"/,'').strip }
|
474
|
-
end
|
475
|
-
|
476
510
|
############################################################################
|
477
511
|
# Process eval option for field value.
|
478
512
|
# Used for processing single field column on result_set or form head.
|
479
513
|
############################################################################
|
480
514
|
def dc_process_column_eval(yaml, document)
|
481
515
|
# dc_name_for_id
|
482
|
-
if yaml['eval'].match(
|
483
|
-
|
484
|
-
if
|
485
|
-
dc_name_for_id(
|
516
|
+
if yaml['eval'].match(/dc_name4_id|dc_name_for_id/)
|
517
|
+
parms = dc_eval_to_array(yaml['eval'])
|
518
|
+
if parms.size == 3
|
519
|
+
dc_name_for_id(parms[1], parms[2], nil, document[ yaml['name'] ])
|
486
520
|
else
|
487
|
-
dc_name_for_id(
|
521
|
+
dc_name_for_id(parms[1], parms[2], parms[3], document[ yaml['name'] ])
|
488
522
|
end
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
523
|
+
|
524
|
+
# dc_name_for_value from locale definition
|
525
|
+
elsif yaml['eval'].match(/dc_name4_value|dc_name_for_value/)
|
526
|
+
parms = dc_eval_to_array(yaml['eval'])
|
527
|
+
if parms.size == 1
|
528
|
+
dc_name_for_value( @form['table'], yaml['name'], document[ yaml['name'] ] )
|
529
|
+
else
|
530
|
+
dc_name_for_value( parms[1], parms[2], document[ yaml['name'] ] )
|
531
|
+
end
|
532
|
+
|
533
|
+
# defined in helpers. For example dc_icon_for_boolean
|
497
534
|
elsif respond_to?(yaml['eval'])
|
498
|
-
send(yaml['eval'], document[
|
499
|
-
|
535
|
+
send(yaml['eval'], document[yaml['name']])
|
536
|
+
|
537
|
+
# defined in model
|
500
538
|
elsif document.respond_to?(yaml['eval'])
|
501
539
|
document.send(yaml['eval'])
|
540
|
+
|
502
541
|
# special eval
|
503
542
|
elsif yaml['eval'].match('eval ')
|
504
543
|
# TO DO evaluate with specified parameters
|
544
|
+
|
545
|
+
# eval with params
|
505
546
|
else
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
yaml['params'].chomp.split(',').inject([]) do |result,e|
|
512
|
-
result << document[e.strip]
|
513
|
-
end
|
514
|
-
end
|
547
|
+
parms = {}
|
548
|
+
if yaml['params'].class == String
|
549
|
+
parms = dc_value_for_parameter(yaml['params'], document)
|
550
|
+
elsif yaml['params'].class == Hash
|
551
|
+
yaml['params'].each { |k, v| parms[k] = dc_value_for_parameter(v) }
|
515
552
|
else
|
516
|
-
document[ yaml['name'] ]
|
553
|
+
parms = document[ yaml['name'] ]
|
517
554
|
end
|
518
|
-
|
519
|
-
dc_process_eval(yaml['eval'], parameters)
|
555
|
+
dc_process_eval(yaml['eval'], parms)
|
520
556
|
end
|
521
557
|
end
|
522
558
|
|
@@ -525,18 +561,23 @@ end
|
|
525
561
|
############################################################################
|
526
562
|
def dc_style_or_class(selector, yaml, value, record)
|
527
563
|
return '' if yaml.nil?
|
528
|
-
|
564
|
+
|
565
|
+
# alias record and value so both names can be used in eval
|
529
566
|
field, document = value, record
|
530
567
|
html = selector ? "#{selector}=\"" : ''
|
531
|
-
|
532
|
-
yaml
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
568
|
+
begin
|
569
|
+
html << if yaml.class == String
|
570
|
+
yaml
|
571
|
+
# direct evaluate expression
|
572
|
+
elsif yaml['eval']
|
573
|
+
eval(yaml['eval'])
|
574
|
+
elsif yaml['method']
|
575
|
+
dc_process_eval(yaml['method'], record)
|
576
|
+
end
|
577
|
+
rescue Exception => e
|
578
|
+
dc_log_exception(e, 'dc_style_or_class')
|
538
579
|
end
|
539
|
-
html << '"' if selector
|
580
|
+
html << '"' if selector
|
540
581
|
html
|
541
582
|
end
|
542
583
|
|
@@ -561,4 +602,16 @@ def dc_define_standard_actions(actions_params, standard)
|
|
561
602
|
actions
|
562
603
|
end
|
563
604
|
|
605
|
+
############################################################################
|
606
|
+
# When result set is to be drawn by Rails helper method.
|
607
|
+
############################################################################
|
608
|
+
def dc_process_result_set_method
|
609
|
+
method = @form['result_set']['eval']
|
610
|
+
if respond_to?(method)
|
611
|
+
send method
|
612
|
+
else
|
613
|
+
I18n.t('drgcms.no_method', method: method)
|
614
|
+
end
|
615
|
+
end
|
616
|
+
|
564
617
|
end
|