drg_cms 0.7.0.8 → 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.
- checksums.yaml +4 -4
- data/app/assets/javascripts/drg_cms/drg_cms.js +50 -20
- data/app/assets/stylesheets/drg_cms/drg_cms.css +89 -31
- data/app/assets/stylesheets/drg_cms/select-multiple.css +5 -6
- data/app/controllers/cmsedit_controller.rb +57 -24
- data/app/controllers/dc_application_controller.rb +18 -21
- data/app/controls/dc_poll_result_control.rb +36 -36
- data/app/controls/dc_setup_control.rb +53 -0
- data/app/forms/all_options.yml +3 -3
- data/app/forms/cms_menu.yml +7 -0
- data/app/forms/dc_image_search.yml +2 -2
- 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 +4 -1
- data/app/helpers/cms_common_helper.rb +14 -10
- data/app/helpers/cms_helper.rb +8 -7
- data/app/helpers/cms_index_helper.rb +56 -42
- data/app/helpers/dc_application_helper.rb +46 -16
- data/app/helpers/dc_image_helper.rb +2 -2
- data/app/models/concerns/dc_user_concern.rb +1 -1
- data/app/models/dc_big_table.rb +1 -1
- data/app/models/dc_filter.rb +5 -9
- data/app/models/dc_image.rb +1 -1
- data/app/models/dc_memory.rb +2 -2
- 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/embedded.rb +17 -9
- data/app/models/drgcms_form_fields/multitext_autocomplete.rb +44 -36
- data/app/models/drgcms_form_fields/select.rb +21 -5
- data/app/renderers/dc_big_menu_renderer.rb +18 -20
- data/app/renderers/dc_menu_renderer.rb +21 -58
- data/app/renderers/dc_simple_menu_renderer.rb +1 -1
- data/app/views/cmsedit/_edit_stuff.html.erb +3 -0
- data/config/locales/drgcms_en.yml +8 -0
- data/config/locales/drgcms_sl.yml +12 -4
- data/config/locales/models_en.yml +17 -1
- data/config/locales/models_sl.yml +17 -1
- data/lib/drg_cms/version.rb +1 -1
- data/lib/drg_cms.rb +22 -23
- data/lib/generators/new_drg_form/new_drg_form_generator.rb +32 -14
- metadata +5 -2
@@ -27,61 +27,61 @@
|
|
27
27
|
module DcPollResultControl
|
28
28
|
|
29
29
|
######################################################################
|
30
|
-
#
|
30
|
+
# Set filter action called from form.
|
31
31
|
######################################################################
|
32
|
-
def
|
33
|
-
|
34
|
-
|
32
|
+
def filter_set
|
33
|
+
record = params[:record]
|
34
|
+
filter = "DcPollResult.where(dc_poll_id: '#{record[:dc_poll_id]}')"
|
35
|
+
filter << ".and(:created_at.gte => '#{Time.parse(record[:start_date]).beginning_of_day}')" if record[:start_date].present?
|
36
|
+
filter << ".and(:created_at.lte => '#{Time.parse(record[:end_date]).end_of_day}')" if record[:end_date].present?
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
)
|
45
|
-
dc_render_ajax(operation: :url, value: url)
|
38
|
+
session['dc_poll_result'][:filter] = {'field' => I18n.t('drgcms.filter_off'),
|
39
|
+
'operation' => 'eval',
|
40
|
+
'value' => filter,
|
41
|
+
'input' => '',
|
42
|
+
'table' => 'dc_poll_result' }.to_yaml
|
43
|
+
session['dc_poll_result'][:page] = 1 # must also be set
|
44
|
+
|
45
|
+
render json: { url: '/cmsedit?t=dc_poll_result'}
|
46
46
|
end
|
47
47
|
|
48
48
|
######################################################################
|
49
49
|
# Export data to file
|
50
50
|
######################################################################
|
51
|
-
def
|
51
|
+
def data_export
|
52
52
|
c, keys = '', []
|
53
|
-
|
54
|
-
# ensure, that fields are always in same order
|
53
|
+
data_get.each do |doc|
|
55
54
|
data = YAML.load(doc.data)
|
55
|
+
# header and ensure fields are always in same order
|
56
56
|
if c.blank?
|
57
|
-
|
58
|
-
c << I18n.t('helpers.label.dc_poll_result.created_at') + "
|
59
|
-
c << keys.join("
|
57
|
+
keys = data.map(&:first)
|
58
|
+
c << I18n.t('helpers.label.dc_poll_result.created_at') + ";"
|
59
|
+
c << keys.join(";") + "\n"
|
60
60
|
end
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
|
62
|
+
c << doc.created_at.strftime(I18n.t('time.formats.default')) + ";"
|
63
|
+
keys.each do |k|
|
64
|
+
c << if data[k].class == String
|
65
|
+
%("#{data[k].gsub(/\"/, "'").gsub(';', ',')}";)
|
66
|
+
else
|
67
|
+
%("#{data[k]}";)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
c << "\r\n"
|
64
71
|
end
|
65
72
|
File.write(Rails.root.join('public', 'export.csv'), c)
|
66
|
-
|
73
|
+
render json: { 'window_' => 'export.csv' }
|
67
74
|
end
|
68
75
|
|
69
76
|
private
|
70
77
|
######################################################################
|
71
78
|
# Creates query for Poll results
|
72
79
|
######################################################################
|
73
|
-
def
|
74
|
-
if
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
unless params[:record][:start_date].blank?
|
79
|
-
start_date = DrgcmsFormFields::DatePicker.get_data(params,'start_date').beginning_of_day
|
80
|
-
end_date = DrgcmsFormFields::DatePicker.get_data(params,'end_date').end_of_day
|
81
|
-
qry = qry.and(:created_at.gt => start_date).and(:created_at.lt => end_date)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
qry
|
80
|
+
def data_get
|
81
|
+
return [] if session.dig('dc_poll_result', :filter).blank?
|
82
|
+
|
83
|
+
filter = YAML.load(session['dc_poll_result'][:filter])
|
84
|
+
eval filter['value'] rescue []
|
85
85
|
end
|
86
86
|
|
87
87
|
end
|
@@ -0,0 +1,53 @@
|
|
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
|
+
# Controls for DcSetup edit form.
|
26
|
+
################################################################################
|
27
|
+
module DcSetupControl
|
28
|
+
|
29
|
+
################################################################################
|
30
|
+
# Update edit form. Admin sees everything while user sees only setup fields.
|
31
|
+
################################################################################
|
32
|
+
def dc_update_form
|
33
|
+
return unless params[:id]
|
34
|
+
|
35
|
+
record = if BSON::ObjectId.legal?(params[:id])
|
36
|
+
DcSetup.find(params[:id])
|
37
|
+
else
|
38
|
+
DcSetup.find_by(name: params[:id])
|
39
|
+
end
|
40
|
+
|
41
|
+
unless dc_user_has_role('admin')
|
42
|
+
@form['form'].delete('tabs')
|
43
|
+
@form['readonly'] = true unless record.editors.include?(session[:user_id])
|
44
|
+
end
|
45
|
+
|
46
|
+
form = YAML.load(record.form) rescue nil
|
47
|
+
if form.present?
|
48
|
+
@form['form']['tabs'] ||= {}
|
49
|
+
@form['form']['tabs'].merge!(form)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/app/forms/all_options.yml
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
## DRGCMS Form
|
2
2
|
---
|
3
|
-
extend: form_name
|
3
|
+
extend: form_name,another_form_name
|
4
4
|
table: table_name
|
5
5
|
title: Some title
|
6
6
|
title:
|
7
|
-
text:
|
7
|
+
text: Same as above
|
8
8
|
eval: SomeClass.title_method
|
9
9
|
controls: controls_file
|
10
10
|
readonly: 1
|
11
11
|
permissions:
|
12
12
|
can_view: role_name
|
13
|
-
class:
|
13
|
+
class: report
|
14
14
|
|
15
15
|
script: "
|
16
16
|
javascript code
|
data/app/forms/cms_menu.yml
CHANGED
@@ -145,6 +145,13 @@ menu:
|
|
145
145
|
icon: history
|
146
146
|
table: dc_journal
|
147
147
|
|
148
|
+
510:
|
149
|
+
caption: helpers.label.dc_setup.tabletitle
|
150
|
+
controller: cmsedit
|
151
|
+
icon: cog-o
|
152
|
+
table: dc_setup
|
153
|
+
form_name: dc_setup
|
154
|
+
|
148
155
|
600:
|
149
156
|
caption: drgcms.browse_collections
|
150
157
|
controller: cmsedit
|
@@ -55,14 +55,14 @@ result_set:
|
|
55
55
|
columns:
|
56
56
|
10:
|
57
57
|
name: preview
|
58
|
-
eval:
|
58
|
+
eval: first_dc_image
|
59
59
|
caption: drgcms.dc_image.image
|
60
60
|
width: 20%
|
61
61
|
20:
|
62
62
|
name: short
|
63
63
|
30:
|
64
64
|
name: links
|
65
|
-
eval:
|
65
|
+
eval: select_links_for_dc_image
|
66
66
|
caption: drgcms.dc_image.available
|
67
67
|
|
68
68
|
css: "
|
data/app/forms/dc_poll.yml
CHANGED
@@ -9,27 +9,30 @@ index:
|
|
9
9
|
10:
|
10
10
|
type: field
|
11
11
|
name: dc_poll_id
|
12
|
+
position: left
|
12
13
|
|
13
14
|
30:
|
14
15
|
type: field
|
15
16
|
name: start_date
|
16
17
|
field_type: date_picker
|
17
|
-
|
18
|
+
position: left
|
19
|
+
|
18
20
|
40:
|
19
21
|
type: field
|
20
22
|
name: end_date
|
21
23
|
field_type: date_picker
|
22
24
|
options:
|
23
25
|
openOnFocus: false
|
24
|
-
|
26
|
+
position: left
|
27
|
+
|
25
28
|
50:
|
26
29
|
type: ajax
|
27
30
|
caption: drgcms.filter_poll
|
28
31
|
title: drgcms.filter_poll_title
|
29
|
-
icon: filter
|
32
|
+
icon: filter-alt-o
|
30
33
|
controller: cmsedit
|
31
34
|
action: run
|
32
|
-
control: dc_poll_result.
|
35
|
+
control: dc_poll_result.filter_set
|
33
36
|
method: post
|
34
37
|
|
35
38
|
60:
|
@@ -37,9 +40,9 @@ index:
|
|
37
40
|
caption: drgcms.export_poll
|
38
41
|
title: drgcms.export_poll_title
|
39
42
|
controller: cmsedit
|
40
|
-
icon:
|
43
|
+
icon: download-o
|
41
44
|
action: run
|
42
|
-
control: dc_poll_result.
|
45
|
+
control: dc_poll_result.data_export
|
43
46
|
method: post
|
44
47
|
|
45
48
|
result_set:
|
@@ -50,7 +53,7 @@ result_set:
|
|
50
53
|
10:
|
51
54
|
name: dc_poll_id
|
52
55
|
eval: dc_name4_id,dc_poll,name
|
53
|
-
width:
|
56
|
+
width: 40%
|
54
57
|
20:
|
55
58
|
name: created_at
|
56
59
|
format: '%d.%m.%Y %H:%M'
|
@@ -0,0 +1,45 @@
|
|
1
|
+
table: dc_setup
|
2
|
+
|
3
|
+
index:
|
4
|
+
filter: data as text_field
|
5
|
+
actions: standard
|
6
|
+
|
7
|
+
result_set:
|
8
|
+
actions: standard
|
9
|
+
|
10
|
+
columns:
|
11
|
+
10:
|
12
|
+
name: name
|
13
|
+
width: 20%
|
14
|
+
20:
|
15
|
+
name: updated_at
|
16
|
+
format: '%d.%m.%Y'
|
17
|
+
width: 10%
|
18
|
+
|
19
|
+
form:
|
20
|
+
title:
|
21
|
+
field: name
|
22
|
+
actions: standard
|
23
|
+
|
24
|
+
tabs:
|
25
|
+
tab0:
|
26
|
+
10:
|
27
|
+
name: name
|
28
|
+
type: text_field
|
29
|
+
size: 20
|
30
|
+
|
31
|
+
20:
|
32
|
+
name: editors
|
33
|
+
type: multitext_autocomplete
|
34
|
+
search: dc_user.name
|
35
|
+
size: 30
|
36
|
+
|
37
|
+
tab00:
|
38
|
+
10:
|
39
|
+
name: form
|
40
|
+
type: text_area
|
41
|
+
size: 80x50
|
42
|
+
|
43
|
+
css: '
|
44
|
+
#record_form {font-family: monospace; font-size: 12px;}
|
45
|
+
'
|
@@ -97,6 +97,8 @@ end
|
|
97
97
|
############################################################################
|
98
98
|
def t_label_for_column(options)
|
99
99
|
label = options['caption'] || options['label']
|
100
|
+
return ' ' if label == false
|
101
|
+
|
100
102
|
if label.blank?
|
101
103
|
label = if options['name']
|
102
104
|
prefix = @form['i18n_prefix'] || "helpers.label.#{@form['table']}"
|
@@ -135,9 +137,10 @@ end
|
|
135
137
|
############################################################################
|
136
138
|
def self.dc_name_for_value(model, field, value)
|
137
139
|
return '' if value.nil?
|
138
|
-
|
139
|
-
|
140
|
-
|
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 }
|
141
144
|
'???'
|
142
145
|
end
|
143
146
|
|
@@ -168,9 +171,10 @@ end
|
|
168
171
|
# Array. Choices for select input field
|
169
172
|
############################################################################
|
170
173
|
def self.dc_choices_for_field(model, field)
|
171
|
-
|
172
|
-
return ['error'] if
|
173
|
-
|
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(':') }
|
174
178
|
end
|
175
179
|
|
176
180
|
############################################################################
|
@@ -214,13 +218,13 @@ end
|
|
214
218
|
# Returns:
|
215
219
|
# String. Name (descriptive value) for specified key in table.
|
216
220
|
############################################################################
|
217
|
-
def dc_name_for_id(model, field, field_name, id=nil)
|
221
|
+
def dc_name_for_id(model, field, field_name, id = nil)
|
218
222
|
return '' if id.nil?
|
219
223
|
|
220
224
|
field_name = (field_name || 'id').strip.to_sym
|
221
225
|
field = field.strip.to_sym
|
222
226
|
model = model.strip.classify.constantize if model.class == String
|
223
|
-
doc =
|
227
|
+
doc = Mongo::QueryCache.cache { model.find_by(field_name => id) }
|
224
228
|
|
225
229
|
doc.nil? ? '' : (doc.send(field) rescue 'not defined')
|
226
230
|
end
|
@@ -228,7 +232,7 @@ end
|
|
228
232
|
############################################################################
|
229
233
|
#
|
230
234
|
############################################################################
|
231
|
-
def dc_name4_id(model, field, field_name, id=nil) #nodoc
|
235
|
+
def dc_name4_id(model, field, field_name, id = nil) #nodoc
|
232
236
|
#dc_deprecate('dc_name4_id will be deprecated. Use dc_name_for_id instead.')
|
233
237
|
dc_name_for_id(model, field, field_name, id)
|
234
238
|
end
|
@@ -258,7 +262,7 @@ end
|
|
258
262
|
############################################################################
|
259
263
|
#
|
260
264
|
############################################################################
|
261
|
-
def dc_icon4_boolean(document = false, field_name =
|
265
|
+
def dc_icon4_boolean(document = false, field_name = nil) #nodoc
|
262
266
|
#dc_deprecate('dc_icon4_boolean will be deprecated. Use dc_icon_for_boolean instead.')
|
263
267
|
dc_icon_for_boolean(document, field_name)
|
264
268
|
end
|
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
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('_',' ') )
|
@@ -175,7 +176,7 @@ def dc_field_action(yaml)
|
|
175
176
|
field, label, help = dc_field_label_help(yaml)
|
176
177
|
end
|
177
178
|
# input field will have label as placeholder
|
178
|
-
field = field.sub('input',"input placeholder=\"#{label}\"")
|
179
|
+
field = field.sub('input', "input placeholder=\"#{label}\"")
|
179
180
|
%(<li class="no-background">#{field}</li>)
|
180
181
|
end
|
181
182
|
|
@@ -185,7 +186,7 @@ end
|
|
185
186
|
def dc_html_data(yaml)
|
186
187
|
return '' if yaml.blank?
|
187
188
|
|
188
|
-
yaml.inject(' ') { |result, e| result
|
189
|
+
yaml.inject(' ') { |result, e| result << (e.last ? %(#{e.first}="#{e.last}" ) : '') }
|
189
190
|
end
|
190
191
|
|
191
192
|
############################################################################
|
@@ -129,12 +129,17 @@ def dc_actions_for_index
|
|
129
129
|
parms['id'] = params[:ids]
|
130
130
|
parms['table'] = @form['table']
|
131
131
|
dc_link_to( caption, 'reorder', parms, method: :delete )
|
132
|
-
=end
|
132
|
+
=end
|
133
|
+
|
133
134
|
when action == 'script'
|
134
135
|
html_left << dc_script_action(options)
|
135
136
|
|
136
137
|
when action == 'field'
|
137
|
-
|
138
|
+
if options['position'] && options['position'] == 'left'
|
139
|
+
html_left << dc_field_action(yaml)
|
140
|
+
else
|
141
|
+
html_right << dc_field_action(yaml)
|
142
|
+
end
|
138
143
|
|
139
144
|
when %w(ajax link window popup submit).include?(action)
|
140
145
|
html_left << dc_link_ajax_window_submit_action(options, nil)
|
@@ -304,34 +309,37 @@ def dc_actions_for_result(document)
|
|
304
309
|
caption = has_sub_menu ? t(caption, '') : nil
|
305
310
|
html = '<li>'
|
306
311
|
html << case yaml['type']
|
307
|
-
when 'check'
|
312
|
+
when 'check'
|
308
313
|
main_menu << '<li>' + check_box_tag("check-#{document.id}", false, false, { class: 'dc-check' }) + '</li>'
|
309
314
|
next
|
310
315
|
|
311
|
-
when 'edit'
|
316
|
+
when 'edit'
|
312
317
|
parms['action'] = 'edit'
|
313
318
|
parms['id'] = document.id
|
314
319
|
parms['readonly'] = yaml['readonly']
|
315
|
-
|
320
|
+
icon = yaml['icon'] || 'edit-o'
|
321
|
+
dc_link_to( caption, icon, parms, title: title )
|
316
322
|
|
317
|
-
when 'show'
|
323
|
+
when 'show'
|
318
324
|
parms['action'] = 'show'
|
319
325
|
parms['id'] = document.id
|
320
326
|
parms['readonly'] = true
|
321
327
|
icon = yaml['icon'] || 'eye-o'
|
322
328
|
dc_link_to( caption, icon, parms, title: title )
|
323
329
|
|
324
|
-
when 'duplicate'
|
330
|
+
when 'duplicate'
|
325
331
|
parms['id'] = document.id
|
326
332
|
# duplicate string will be added to these fields.
|
327
333
|
parms['dup_fields'] = yaml['dup_fields']
|
328
334
|
parms['action'] = 'create'
|
329
|
-
|
335
|
+
icon = yaml['icon'] || 'content_copy-o'
|
336
|
+
dc_link_to( caption, icon, parms, data: { confirm: t('drgcms.confirm_dup') }, method: :post, title: title )
|
330
337
|
|
331
|
-
when 'delete'
|
338
|
+
when 'delete'
|
332
339
|
parms['action'] = 'destroy'
|
333
340
|
parms['id'] = document.id
|
334
|
-
|
341
|
+
icon = yaml['icon'] || 'delete-o'
|
342
|
+
dc_link_to( caption, icon, parms, data: { confirm: t('drgcms.confirm_delete') }, method: :delete, title: title )
|
335
343
|
|
336
344
|
else # error.
|
337
345
|
yaml['type'].to_s
|
@@ -480,7 +488,7 @@ def dc_columns_for_result(document)
|
|
480
488
|
|
481
489
|
# convert shortcut to hash
|
482
490
|
v = {'name' => v} if v.class == String
|
483
|
-
begin
|
491
|
+
#begin
|
484
492
|
# as Array (footer)
|
485
493
|
value = if document.class == Array
|
486
494
|
dc_format_value(document[index], v['format']) if document[index]
|
@@ -498,10 +506,10 @@ def dc_columns_for_result(document)
|
|
498
506
|
else
|
499
507
|
"??? #{v['name']}"
|
500
508
|
end
|
501
|
-
rescue Exception => e
|
502
|
-
|
503
|
-
|
504
|
-
end
|
509
|
+
#rescue Exception => e
|
510
|
+
# dc_log_exception(e, 'dc_columns_for_result')
|
511
|
+
# value = '!!!Error'
|
512
|
+
#end
|
505
513
|
html << '<div class="spacer"></div>'
|
506
514
|
# set class
|
507
515
|
clas = dc_style_or_class(nil, v['td_class'] || v['class'], value, document)
|
@@ -522,7 +530,7 @@ end
|
|
522
530
|
# Ex. Will split dc_name4_value(one ,"two") => ['dc_name4_value', 'one', 'two']
|
523
531
|
############################################################################
|
524
532
|
def dc_eval_to_array(expression)
|
525
|
-
expression.split(/\ |\,|\(|\)/).
|
533
|
+
expression.split(/\ |\,|\(|\)/).select(&:present?).map{ _1.gsub(/\'|\"/, '').strip }
|
526
534
|
end
|
527
535
|
|
528
536
|
############################################################################
|
@@ -532,7 +540,7 @@ end
|
|
532
540
|
# parameters : Array : array of parameters which will be send to method
|
533
541
|
############################################################################
|
534
542
|
def dc_process_eval(evaluate, parameters = nil)
|
535
|
-
# evaluate by calling send method
|
543
|
+
# evaluate by calling send method
|
536
544
|
clas, method = evaluate.split('.')
|
537
545
|
if method.nil?
|
538
546
|
send(clas, *parameters)
|
@@ -545,40 +553,46 @@ end
|
|
545
553
|
private
|
546
554
|
|
547
555
|
############################################################################
|
548
|
-
# Process eval option for field value.
|
556
|
+
# Process eval option for field value.
|
557
|
+
#
|
549
558
|
# Used for processing single field column on result_set or form head.
|
550
559
|
############################################################################
|
560
|
+
#TODO make it universal without parameters complications
|
551
561
|
def dc_process_column_eval(yaml, document)
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
562
|
+
if yaml['params'].blank?
|
563
|
+
parms = dc_eval_to_array(yaml['eval'])
|
564
|
+
method = parms.shift
|
565
|
+
|
566
|
+
# prepare parameters for dc_name_for_* methods
|
567
|
+
method.sub!('dc_name4_', 'dc_name_for_') if method.match(/^dc_name4_/)
|
568
|
+
if method == 'dc_name_for_id' && parms.size == 2
|
569
|
+
parms << 'id'
|
559
570
|
end
|
560
|
-
|
561
|
-
|
562
|
-
elsif yaml['eval'].match(/dc_name4_value|dc_name_for_value/)
|
563
|
-
parms = dc_eval_to_array(yaml['eval'])
|
564
|
-
if parms.size == 1
|
565
|
-
dc_name_for_value( @form['table'], yaml['name'], document[ yaml['name'] ] )
|
566
|
-
else
|
567
|
-
dc_name_for_value( parms[1], parms[2], document[ yaml['name'] ] )
|
571
|
+
if method == 'dc_name_for_value' && parms.size < 2
|
572
|
+
parms = [@form['table'], yaml['name']]
|
568
573
|
end
|
569
574
|
|
570
|
-
|
571
|
-
|
572
|
-
|
575
|
+
parms << document[yaml['name']]
|
576
|
+
parms.map!{ %w[record document].include?(_1.to_s) ? document : _1 }
|
577
|
+
case
|
578
|
+
when method.match(/^dc_/)
|
579
|
+
send(method, *parms)
|
573
580
|
|
574
|
-
|
575
|
-
|
576
|
-
|
581
|
+
when respond_to?(method)
|
582
|
+
parms = [document] + parms
|
583
|
+
send(method, *parms)
|
577
584
|
|
578
|
-
|
579
|
-
|
580
|
-
|
585
|
+
# model method
|
586
|
+
when document.respond_to?(method)
|
587
|
+
document.send(method)
|
581
588
|
|
589
|
+
# some class method
|
590
|
+
when method.match('.')
|
591
|
+
klass, method = method.split('.')
|
592
|
+
klass.classify.constantize.send(method, *parms)
|
593
|
+
else
|
594
|
+
'?????'
|
595
|
+
end
|
582
596
|
# eval with params
|
583
597
|
else
|
584
598
|
parms = {}
|