drg_cms 0.6.1.9 → 0.6.1.11
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 +35 -14
- data/app/assets/stylesheets/drg_cms/drg_cms.css +89 -26
- data/app/controllers/cmsedit_controller.rb +9 -111
- data/app/controllers/dc_application_controller.rb +97 -21
- data/app/controllers/dc_common_controller.rb +3 -17
- data/app/controls/browse_models_control.rb +3 -1
- data/app/controls/cmsedit_control.rb +5 -1
- data/app/controls/dc_report.rb +1 -1
- data/app/forms/all_options.yml +2 -0
- data/app/forms/dc_browse_models.yml +24 -2
- data/app/forms/dc_steps_template.yml +51 -0
- data/app/helpers/cms_common_helper.rb +66 -1
- data/app/helpers/cms_edit_helper.rb +228 -119
- data/app/helpers/cms_helper.rb +74 -17
- data/app/helpers/cms_index_helper.rb +40 -37
- data/app/helpers/dc_application_helper.rb +6 -27
- data/app/models/dc_journal.rb +2 -2
- data/app/models/dc_json_ld.rb +18 -41
- data/app/models/drgcms_form_fields/readonly.rb +1 -1
- data/app/models/drgcms_form_fields/select.rb +2 -2
- data/app/models/drgcms_form_fields/text_autocomplete.rb +2 -2
- data/app/models/drgcms_form_fields/text_with_select.rb +1 -0
- data/app/renderers/dc_common_renderer.rb +20 -3
- data/app/views/cmsedit/_form.html.erb +19 -12
- data/app/views/cmsedit/edit.html.erb +10 -6
- data/app/views/cmsedit/index.html.erb +5 -3
- data/app/views/cmsedit/new.html.erb +9 -5
- data/app/views/dc_common/_help.html.erb +1 -0
- data/config/locales/drgcms_en.yml +5 -0
- data/config/locales/drgcms_sl.yml +5 -0
- data/drg_cms.gemspec +1 -1
- data/lib/drg_cms/version.rb +1 -1
- metadata +8 -7
data/app/helpers/cms_helper.rb
CHANGED
@@ -35,8 +35,16 @@ module CmsHelper
|
|
35
35
|
############################################################################
|
36
36
|
def dc_script_action(yaml)
|
37
37
|
icon = dc_icon_for_link yaml['icon']
|
38
|
-
|
39
|
-
|
38
|
+
yaml['html'] ||= {}
|
39
|
+
yaml['html']['data-url'] = 'script'
|
40
|
+
yaml['html']['data-request'] = 'script'
|
41
|
+
yaml['html']['data-script'] = "#{yaml['js'] || yaml['script']}"
|
42
|
+
yaml['html']['class'] ||= 'dc-link-ajax'
|
43
|
+
attributes = yaml['html'].inject('') { |r, e| r << "#{e.first}=\"#{e.last}\"" }
|
44
|
+
|
45
|
+
# data = %(data-request="script" data-script="#{yaml['js'] || yaml['script']}" data-url="script")
|
46
|
+
#%(<li><div class="dc-link-ajax" #{data}>#{icon} #{ t(yaml['caption'], yaml['caption']) }</div></li>)
|
47
|
+
%(<li><div #{attributes}>#{icon} #{ t(yaml['caption'], yaml['caption']) }</div></li>)
|
40
48
|
end
|
41
49
|
|
42
50
|
############################################################################
|
@@ -105,11 +113,13 @@ def dc_label_help(options)
|
|
105
113
|
return [nil, nil] if %w(comment action).include?(options['type'])
|
106
114
|
|
107
115
|
label = options['caption'] || options['text'] || options['label']
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
116
|
+
if options['name']
|
117
|
+
label = if label.blank?
|
118
|
+
t_label_for_field(options['name'], options['name'].capitalize.gsub('_',' ') )
|
119
|
+
elsif options['name']
|
120
|
+
t(label, label)
|
121
|
+
end
|
122
|
+
end
|
113
123
|
# help text can be defined in form or in translations starting with helpers. or as helpers.help.collection.field
|
114
124
|
help = options['help']
|
115
125
|
help ||= "helpers.help.#{@form['table']}.#{options['name']}" if options['name']
|
@@ -128,11 +138,11 @@ end
|
|
128
138
|
# help : String : Help text
|
129
139
|
############################################################################
|
130
140
|
def dc_tab_label_help(tab_name)
|
131
|
-
label = @form
|
132
|
-
label = t(label,
|
141
|
+
label = @form.dig('form', 'tabs', tab_name, 'caption') || tab_name
|
142
|
+
label = t(label, t_label_for_field(label, label))
|
133
143
|
|
134
|
-
help = @form
|
135
|
-
help = t(help,
|
144
|
+
help = @form.dig('form', 'tabs', tab_name, 'help') || "helpers.help.#{@form['table']}.#{tab_name}"
|
145
|
+
help = t(help, t_label_for_field(help, help))
|
136
146
|
help = nil if help.match('helpers.') # help not found in translation
|
137
147
|
|
138
148
|
[label, help]
|
@@ -197,12 +207,14 @@ def dc_link_ajax_window_submit_action(yaml, record = nil, action_active = true)
|
|
197
207
|
unless dc_is_action_active?(yaml)
|
198
208
|
return %(<li><div class="dc-link-no">#{icon} #{caption}</div></li>)
|
199
209
|
end
|
200
|
-
# set data-confirm when confirm
|
210
|
+
# set data-confirm when confirm shortcut present
|
201
211
|
yaml['html'] ||= {}
|
202
|
-
|
203
|
-
yaml['html']['data-confirm'] = t(
|
204
|
-
|
205
|
-
yaml['html']['title']
|
212
|
+
text = yaml['html']['data-confirm'] || yaml['confirm']
|
213
|
+
yaml['html']['data-confirm'] = t(text) if text.present?
|
214
|
+
|
215
|
+
text = yaml['html']['title'] || yaml['title']
|
216
|
+
yaml['html']['title'] = t(text) if text.present?
|
217
|
+
|
206
218
|
yaml['html']['target'] ||= yaml['target']
|
207
219
|
# direct url
|
208
220
|
if yaml['url']
|
@@ -282,11 +294,18 @@ end
|
|
282
294
|
############################################################################
|
283
295
|
def dc_log_exception(exception, where = '')
|
284
296
|
log = exception ? "\n*** Error:#{where + ':'} #{exception.message}\n#{exception.backtrace.first.inspect}\n" : ''
|
285
|
-
log << "DRG Form
|
297
|
+
log << "DRG Form: #{CmsHelper.form_param(params)}, line: #{session[:form_processing]}\n"
|
286
298
|
|
287
299
|
logger.error log
|
288
300
|
end
|
289
301
|
|
302
|
+
############################################################################
|
303
|
+
# Will return form id, to be used on each form for simpler css selecting.
|
304
|
+
############################################################################
|
305
|
+
def dc_form_id
|
306
|
+
%( id=#{CmsHelper.form_param(params) || CmsHelper.table_param(params)} )
|
307
|
+
end
|
308
|
+
|
290
309
|
############################################################################
|
291
310
|
# Will return form_name from parameter regardless if set as form_name or just f.
|
292
311
|
############################################################################
|
@@ -301,4 +320,42 @@ def self.table_param(params)
|
|
301
320
|
params[:table] || params[:t]
|
302
321
|
end
|
303
322
|
|
323
|
+
########################################################################
|
324
|
+
# Searches forms path for file_name and returns full file name or nil if not found.
|
325
|
+
#
|
326
|
+
# @param [String] Form file name. File name can be passed as gem_name.filename. This can
|
327
|
+
# be useful when you are extending form but want to retain same name as original form
|
328
|
+
# For example. You are extending dc_user form from drg_cms gem and want to
|
329
|
+
# retain same dc_user name. This can be done by setting drg_cms.dc_user as extend option.
|
330
|
+
#
|
331
|
+
# @return [String] Form file name including path or nil if not found.
|
332
|
+
########################################################################
|
333
|
+
def self.form_file_find(form_file)
|
334
|
+
form_path = nil
|
335
|
+
form_path, form_file = form_file.split(/\.|\//) if form_file.match(/\.|\//)
|
336
|
+
|
337
|
+
DrgCms.paths(:forms).reverse.each do |path|
|
338
|
+
f = "#{path}/#{form_file}.yml"
|
339
|
+
return f if File.exist?(f) && (form_path.nil? || path.to_s.match(/\/#{form_path}(-|\/)/i))
|
340
|
+
end
|
341
|
+
raise "Exception: Form file '#{form_file}' not found!"
|
342
|
+
end
|
343
|
+
|
344
|
+
########################################################################
|
345
|
+
# Merges two forms when current form extends other form. Subroutine of dc_form_read.
|
346
|
+
# With a little help of https://www.ruby-forum.com/topic/142809
|
347
|
+
########################################################################
|
348
|
+
def self.forms_merge(hash1, hash2)
|
349
|
+
target = hash1.dup
|
350
|
+
hash2.keys.each do |key|
|
351
|
+
if hash2[key].is_a?(Hash) && hash1[key].is_a?(Hash)
|
352
|
+
target[key] = CmsHelper.forms_merge(hash1[key], hash2[key])
|
353
|
+
next
|
354
|
+
end
|
355
|
+
target[key] = hash2[key] == '/' ? nil : hash2[key]
|
356
|
+
end
|
357
|
+
# delete keys with nil value
|
358
|
+
target.delete_if { |k, v| v.nil? }
|
359
|
+
end
|
360
|
+
|
304
361
|
end
|
@@ -59,7 +59,7 @@ def dc_actions_for_index
|
|
59
59
|
session[:form_processing] = "index:actions: #{key}=#{options}"
|
60
60
|
next if options.nil? # must be
|
61
61
|
|
62
|
-
url = @
|
62
|
+
url = @form_params.clone
|
63
63
|
yaml = options.class == String ? {'type' => options} : options # if single definition simulate type parameter
|
64
64
|
action = yaml['type'].to_s.downcase
|
65
65
|
if action == 'url'
|
@@ -90,8 +90,10 @@ def dc_actions_for_index
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
data = t('drgcms.sort') + select('sort', 'sort', choices, { include_blank: true }, { class: 'dc-sort-select',
|
93
|
-
|
94
|
-
|
93
|
+
'data-table' => @form['table'], 'data-form' => CmsHelper.form_param(params)} )
|
94
|
+
data = mi_icon('sort') + select('sort', 'sort', choices, { include_blank: true }, { class: 'dc-sort-select',
|
95
|
+
'data-table' => @form['table'], 'data-form' => CmsHelper.form_param(params)} )
|
96
|
+
html_right << %(<li title="#{t('drgcms.sort')}"><div class="dc-sort">#{data}</li>)
|
95
97
|
|
96
98
|
# filter
|
97
99
|
when action == 'filter'
|
@@ -102,7 +104,7 @@ def dc_actions_for_index
|
|
102
104
|
html_right << %(
|
103
105
|
<li>
|
104
106
|
<div class="dc-filter" title="#{DcFilter.title4_filter_off(table)}" data-url="#{url.html_safe}">
|
105
|
-
#{mi_icon(url.blank? ? 'search' : '
|
107
|
+
#{mi_icon(url.blank? ? 'search' : 'filter_alt_off') }#{DcFilter.menu_filter(self).html_safe}
|
106
108
|
</div>
|
107
109
|
</li>#{DcFilter.get_filter_field(self)}).html_safe
|
108
110
|
|
@@ -132,7 +134,7 @@ def dc_actions_for_index
|
|
132
134
|
# reorder
|
133
135
|
when action == 'reorder' then
|
134
136
|
caption = t('drgcms.reorder')
|
135
|
-
parms = @
|
137
|
+
parms = @form_params.clone
|
136
138
|
parms['operation'] = v
|
137
139
|
parms['id'] = params[:ids]
|
138
140
|
parms['table'] = @form['table']
|
@@ -257,13 +259,13 @@ def dc_actions_column
|
|
257
259
|
actions = { 'standard' => true } if actions.class == String && actions == 'standard'
|
258
260
|
std_actions = { 2 => 'edit', 5 => 'delete' }
|
259
261
|
if actions['standard']
|
260
|
-
actions.merge!(std_actions)
|
262
|
+
actions.merge!(std_actions)
|
261
263
|
actions.delete('standard')
|
262
264
|
end
|
263
265
|
# check must be first action
|
264
|
-
has_check = actions
|
266
|
+
has_check = actions[0] && actions[0]['type'] == 'check'
|
265
267
|
width = actions.size == 1 ? 22 : 44
|
266
|
-
width = 22 if actions.size > 2
|
268
|
+
width = 22 if actions.size > 2 && !has_check
|
267
269
|
[actions, width, has_check]
|
268
270
|
end
|
269
271
|
|
@@ -290,7 +292,7 @@ def dc_actions_for_result(document)
|
|
290
292
|
main_menu, sub_menu = '', ''
|
291
293
|
actions.sort_by(&:first).each do |num, action|
|
292
294
|
session[:form_processing] = "result_set:actions: #{num}=#{action}"
|
293
|
-
parms = @
|
295
|
+
parms = @form_params.clone
|
294
296
|
# if single definition simulate type parameter
|
295
297
|
yaml = action.class == String ? { 'type' => action } : action
|
296
298
|
|
@@ -362,7 +364,7 @@ def dc_header_for_result
|
|
362
364
|
html = '<div class="dc-result-header">'
|
363
365
|
if @form['result_set']['actions'] && !@form['readonly']
|
364
366
|
ignore, width, has_check = dc_actions_column()
|
365
|
-
check_all = fa_icon('check-
|
367
|
+
check_all = fa_icon('check-box-o', class: 'dc-check-all') if has_check
|
366
368
|
html << %(<div class="dc-result-actions" style="width:#{width}px;">#{check_all}</div>)
|
367
369
|
end
|
368
370
|
# preparation for sort icon
|
@@ -372,22 +374,20 @@ def dc_header_for_result
|
|
372
374
|
end
|
373
375
|
|
374
376
|
if (columns = @form['result_set']['columns'])
|
375
|
-
columns.sort.each do |
|
376
|
-
session[:form_processing] = "result_set:columns: #{
|
377
|
-
next if
|
378
|
-
|
379
|
-
th = %(<div class="th" style="width:#{
|
380
|
-
label =
|
381
|
-
label = (v['name'] ? "helpers.label.#{@form['table']}.#{v['name']}" : '') if label.nil?
|
382
|
-
label = t(label) if label.match(/\./)
|
377
|
+
columns.sort.each do |key, options|
|
378
|
+
session[:form_processing] = "result_set:columns: #{key}=#{options}"
|
379
|
+
next if options['width'].to_s.match(/hidden|none/i)
|
380
|
+
|
381
|
+
th = %(<div class="th" style="width:#{options['width'] || '15%'};text-align:#{options['align'] || 'left'};" data-name="#{options['name']}")
|
382
|
+
label = t_label_for_column(options)
|
383
383
|
# no sorting when embedded documents or custom filter is active
|
384
384
|
sort_ok = !dc_dont?(@form['result_set']['sort'], false)
|
385
385
|
sort_ok = sort_ok || (@form['index'] && @form['index']['sort'])
|
386
|
-
sort_ok = sort_ok && !dc_dont?(
|
386
|
+
sort_ok = sort_ok && !dc_dont?(options['sort'], false)
|
387
387
|
if @tables.size == 1 && sort_ok
|
388
388
|
icon = 'sort_unset md-18'
|
389
|
-
filter_class = form_has_input_field?(
|
390
|
-
if
|
389
|
+
filter_class = form_has_input_field?(options['name']) ? nil : 'no-filter'
|
390
|
+
if options['name'] == sort_field
|
391
391
|
icon = sort_direction == '1' ? 'sort_down md-18' : 'sort_up md-18'
|
392
392
|
else
|
393
393
|
# no icon if filter can not be set
|
@@ -395,7 +395,7 @@ def dc_header_for_result
|
|
395
395
|
end
|
396
396
|
# sort and filter icon
|
397
397
|
icon = mi_icon(icon, class: filter_class) if icon
|
398
|
-
url = url_for(controller: 'cmsedit', action: 'run', control: 'cmsedit.sort', sort:
|
398
|
+
url = url_for(controller: 'cmsedit', action: 'run', control: 'cmsedit.sort', sort: options['name'],
|
399
399
|
t: CmsHelper.table_param(params), f: CmsHelper.form_param(params))
|
400
400
|
th << %(><span data-url="#{url}">#{label}</span>#{icon}</div>)
|
401
401
|
else
|
@@ -472,27 +472,29 @@ end
|
|
472
472
|
def dc_columns_for_result(document)
|
473
473
|
return '' unless @form['result_set']['columns']
|
474
474
|
|
475
|
-
html = ''
|
476
|
-
@form['result_set']['columns'].sort.each do |k,v|
|
475
|
+
html, index = '', 0
|
476
|
+
@form['result_set']['columns'].sort.each do |k, v|
|
477
477
|
session[:form_processing] = "result_set:columns: #{k}=#{v}"
|
478
478
|
next if v['width'].to_s.match(/hidden|none/i)
|
479
479
|
|
480
480
|
# convert shortcut to hash
|
481
481
|
v = {'name' => v} if v.class == String
|
482
482
|
begin
|
483
|
-
|
484
|
-
value = if
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
483
|
+
# as Array (footer)
|
484
|
+
value = if document.class == Array
|
485
|
+
dc_format_value(document[index], v['format']) if document[index]
|
486
|
+
# as Hash (dc_memory)
|
487
|
+
elsif document.class == Hash
|
488
|
+
dc_format_value(document[ v['name'] ], v['format'])
|
489
|
+
# eval
|
490
|
+
elsif v['eval']
|
491
|
+
dc_process_column_eval(v, document)
|
492
|
+
# as field
|
493
|
+
elsif document.respond_to?(v['name'])
|
494
|
+
dc_format_value(document.send( v['name'] ), v['format'])
|
495
|
+
else
|
496
|
+
"??? #{v['name']}"
|
497
|
+
end
|
496
498
|
rescue Exception => e
|
497
499
|
dc_log_exception(e, 'dc_columns_for_result')
|
498
500
|
value = '!!!Error'
|
@@ -507,6 +509,7 @@ def dc_columns_for_result(document)
|
|
507
509
|
style = "style=\"#{width_align}#{style}\" "
|
508
510
|
|
509
511
|
html << "<div class=\"td #{clas}\" #{style}>#{value}</div>"
|
512
|
+
index += 1
|
510
513
|
end
|
511
514
|
html.html_safe
|
512
515
|
end
|
@@ -242,7 +242,7 @@ end
|
|
242
242
|
# and renderers during page rendering.
|
243
243
|
########################################################################
|
244
244
|
def dc_page_bottom
|
245
|
-
%(<style
|
245
|
+
%(<style>#{@css}</style>#{javascript_tag @js}).html_safe
|
246
246
|
end
|
247
247
|
|
248
248
|
############################################################################
|
@@ -258,13 +258,9 @@ end
|
|
258
258
|
############################################################################
|
259
259
|
def dc_table_title(text, result_set = nil)
|
260
260
|
c = %(<div class="dc-title">#{text})
|
261
|
-
|
262
|
-
type = result_set.nil? ? 'form' : 'index'
|
263
|
-
form_name = CmsHelper.form_param(params) || CmsHelper.table_param(params)
|
264
|
-
url = url_for(controller: :dc_common, action: :help, type: type, f: form_name)
|
265
|
-
c << %(<div class="dc-help-icon dc-link-ajax" data-url=#{url}>#{fa_icon('question-circle')}</div>)
|
261
|
+
c << dc_help_button(result_set)
|
266
262
|
|
267
|
-
if result_set
|
263
|
+
if result_set && result_set.respond_to?(:current_page)
|
268
264
|
c << %(<div class="dc-paginate">#{paginate(result_set, :params => {action: 'index', clear: 'no', filter: nil})}</div>)
|
269
265
|
end
|
270
266
|
c << '<div style="clear: both;"></div></div>'
|
@@ -302,11 +298,11 @@ end
|
|
302
298
|
# Returns:
|
303
299
|
# String. HTML code for title.
|
304
300
|
############################################################################
|
305
|
-
def dc_new_title
|
301
|
+
def dc_new_title
|
306
302
|
session[:form_processing] = "form:title:"
|
307
303
|
title = @form['form']['title']
|
308
304
|
# defined as form:title:new
|
309
|
-
if title
|
305
|
+
if title && title['new']
|
310
306
|
t( title['new'], title['new'] )
|
311
307
|
else
|
312
308
|
# in memory structures
|
@@ -745,23 +741,6 @@ def dc_choices4_all_collections
|
|
745
741
|
choices.invert.to_a.sort # hash has to be inverted for values to be returned right
|
746
742
|
end
|
747
743
|
|
748
|
-
########################################################################
|
749
|
-
# Merges two forms when current form extends other form. Subroutine of dc_choices4_cmsmenu.
|
750
|
-
# With a little help of https://www.ruby-forum.com/topic/142809
|
751
|
-
########################################################################
|
752
|
-
def forms_merge(hash1, hash2) #:nodoc:
|
753
|
-
target = hash1.dup
|
754
|
-
hash2.keys.each do |key|
|
755
|
-
if hash2[key].is_a? Hash and hash1[key].is_a? Hash
|
756
|
-
target[key] = forms_merge(hash1[key], hash2[key])
|
757
|
-
next
|
758
|
-
end
|
759
|
-
target[key] = hash2[key] == '/' ? nil : hash2[key]
|
760
|
-
end
|
761
|
-
# delete keys with nil value
|
762
|
-
target.delete_if{ |k, v| v.nil? }
|
763
|
-
end
|
764
|
-
|
765
744
|
##########################################################################
|
766
745
|
# Returns choices for creating collection edit select field on CMS top menu.
|
767
746
|
##########################################################################
|
@@ -772,7 +751,7 @@ def dc_choices4_cmsmenu
|
|
772
751
|
next unless File.exist?(filename)
|
773
752
|
menu = YAML.load_file(filename) rescue nil # load menu
|
774
753
|
next if menu.nil? or !menu['menu'] # not menu or error
|
775
|
-
menus = forms_merge(menu['menu'], menus)
|
754
|
+
menus = CmsHelper.forms_merge(menu['menu'], menus) # ignore top level part
|
776
755
|
end
|
777
756
|
|
778
757
|
html = '<ul>'
|
data/app/models/dc_journal.rb
CHANGED
data/app/models/dc_json_ld.rb
CHANGED
@@ -37,21 +37,21 @@
|
|
37
37
|
#
|
38
38
|
########################################################################
|
39
39
|
class DcJsonLd
|
40
|
-
|
41
|
-
|
40
|
+
include Mongoid::Document
|
41
|
+
include Mongoid::Timestamps
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
field :name, type: String
|
44
|
+
field :type, type: String
|
45
|
+
field :data, type: String
|
46
|
+
field :active, type: Boolean, default: true
|
47
47
|
|
48
|
-
|
48
|
+
embeds_many :dc_json_lds, :cyclic => true
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
field :created_by, type: BSON::ObjectId
|
51
|
+
field :updated_by, type: BSON::ObjectId
|
52
|
+
|
53
|
+
validates :name, presence: true
|
54
|
+
validates :type, presence: true
|
55
55
|
|
56
56
|
##########################################################################
|
57
57
|
# Returns JSON LD data as YAML
|
@@ -71,29 +71,6 @@ def get_json_ld(parent_data)
|
|
71
71
|
yaml
|
72
72
|
end
|
73
73
|
|
74
|
-
########################################################################
|
75
|
-
# Searches forms path for file_name and returns full file name or nil if not found.
|
76
|
-
#
|
77
|
-
# @param [String] Form file name. File name can be passed as gem_name.filename. This can
|
78
|
-
# be useful when you are extending form but want to retain same name as original form
|
79
|
-
# For example. You are extending dc_user form from drg_cms gem and want to
|
80
|
-
# retain same dc_user name. This can be done by setting drg_cms.dc_user to extend option.
|
81
|
-
#
|
82
|
-
# @return [String] Form file name including path or nil if not found.
|
83
|
-
########################################################################
|
84
|
-
def self.dc_find_form_file(form_file)
|
85
|
-
form_path=nil
|
86
|
-
if form_file.match(/\.|\//)
|
87
|
-
form_path,form_file=form_file.split(/\.|\//)
|
88
|
-
end
|
89
|
-
DrgCms.paths(:forms).reverse.each do |path|
|
90
|
-
f = "#{path}/#{form_file}.yml"
|
91
|
-
return f if File.exist?(f) and (form_path.nil? or path.to_s.match(/\/#{form_path}\//i))
|
92
|
-
end
|
93
|
-
p "Form file #{form_file} not found!"
|
94
|
-
nil
|
95
|
-
end
|
96
|
-
|
97
74
|
########################################################################
|
98
75
|
# Find document by ids when document are embedded into main d even if embedded
|
99
76
|
#
|
@@ -105,9 +82,9 @@ end
|
|
105
82
|
def self.find_document_by_ids(tables, ids)
|
106
83
|
collection = tables.split(';').first.classify.constantize
|
107
84
|
ar_ids = ids.split(';')
|
108
|
-
# Find top document
|
85
|
+
# Find top document
|
109
86
|
document = collection.find(ar_ids.shift)
|
110
|
-
# Search for embedded document
|
87
|
+
# Search for embedded document
|
111
88
|
ar_ids.each {|id| document = document.dc_json_lds.find(id) }
|
112
89
|
document
|
113
90
|
end
|
@@ -116,7 +93,7 @@ end
|
|
116
93
|
# Returns possible options for type select field on form.
|
117
94
|
#########################################################################
|
118
95
|
def self.choices4_type()
|
119
|
-
yaml = YAML.load_file(
|
96
|
+
yaml = YAML.load_file( CmsHelper.form_file_find('json_ld_schema') )
|
120
97
|
|
121
98
|
yaml.inject([]) {|result, schema_name| result << schema_name.first }
|
122
99
|
end
|
@@ -125,7 +102,7 @@ end
|
|
125
102
|
# Create menu to add schema element. Called from DRGCMS Form action.
|
126
103
|
#########################################################################
|
127
104
|
def self.add_schema_menu(parent)
|
128
|
-
yaml = YAML.load_file(
|
105
|
+
yaml = YAML.load_file( CmsHelper.form_file_find('json_ld_schema') )
|
129
106
|
if (level = parent.params['ids'].split(';').size) == 1
|
130
107
|
# select only top level elements
|
131
108
|
yaml.delete_if { |schema_name, schema_data| schema_data['level'].nil? }
|
@@ -139,7 +116,7 @@ def self.add_schema_menu(parent)
|
|
139
116
|
end
|
140
117
|
yaml = _yaml
|
141
118
|
end
|
142
|
-
# create menu code
|
119
|
+
# create menu code
|
143
120
|
html = '<ul>'
|
144
121
|
yaml.each do |schema_name, schema_data|
|
145
122
|
next if level == 1 and schema_data['level'].nil?
|
@@ -149,4 +126,4 @@ def self.add_schema_menu(parent)
|
|
149
126
|
html << '</ul>'
|
150
127
|
end
|
151
128
|
|
152
|
-
end
|
129
|
+
end
|
@@ -56,7 +56,7 @@ def render
|
|
56
56
|
@record[@yaml['name']] = @yaml['html']['value'] if @yaml['html']['value']
|
57
57
|
|
58
58
|
@html << @parent.hidden_field('record', @yaml['name']) # retain field as hidden field
|
59
|
-
@html <<
|
59
|
+
@html << %(<div class="dc-readonly" id="record_#{@yaml['name']}_">)
|
60
60
|
|
61
61
|
@html << if @yaml['eval']
|
62
62
|
if @yaml['eval'].match(/dc_name4_id|dc_name_for_id/)
|
@@ -146,8 +146,8 @@ def add_view_code
|
|
146
146
|
|
147
147
|
table, form_name = @yaml['view'].split(/\ |\,/).delete_if { |e| e.blank? }
|
148
148
|
url = @parent.url_for(controller: 'cmsedit', id: data, action: :edit, table: table, form_name: form_name, readonly: true, window_close: 1 )
|
149
|
-
icon = @parent.
|
150
|
-
%(<span class="dc-window-open" data-url="#{url}"
|
149
|
+
icon = @parent.mi_icon('eye-o md-18')
|
150
|
+
%(<span class="dc-window-open" data-url="#{url}"> #{icon}</span>)
|
151
151
|
end
|
152
152
|
|
153
153
|
###########################################################################
|
@@ -114,7 +114,7 @@ def render
|
|
114
114
|
style: "vertical-align: top;", 'data-table' => @yaml['with_new'] )
|
115
115
|
end
|
116
116
|
# with edit icon
|
117
|
-
if @yaml['with_edit'] && @record[@yaml['name']].present?
|
117
|
+
if @yaml['with_edit'] && @record && @record[@yaml['name']].present?
|
118
118
|
@html << ' ' + @parent.fa_icon('edit-o', class: 'in-edit-add', title: t('drgcms.edit'),
|
119
119
|
style: "vertical-align: top;", 'data-table' => @yaml['with_edit'], 'data-id' => @record[@yaml['name']] )
|
120
120
|
end
|
@@ -148,7 +148,7 @@ $(document).ready(function() {
|
|
148
148
|
change: function (event, ui) {
|
149
149
|
#{not_id_code}
|
150
150
|
if (ui.item == null) return;
|
151
|
-
$("##{record}_#{@yaml['name']}").val(ui.item.id);
|
151
|
+
$("##{record}_#{@yaml['name']}").val(ui.item.id).trigger('change');
|
152
152
|
},
|
153
153
|
|
154
154
|
minLength: 2
|
@@ -83,6 +83,7 @@ $(document).ready(function() {
|
|
83
83
|
$('##{@yaml['name']}_').change( function() {
|
84
84
|
if ($(this).val().toString().length > 0) {
|
85
85
|
$('##{record}_#{@yaml['name']}').val( $(this).val() );
|
86
|
+
$('##{record}_#{@yaml['name']}').trigger("change");
|
86
87
|
}
|
87
88
|
$('##{record}_#{@yaml['name']}').focus();
|
88
89
|
});
|
@@ -68,9 +68,10 @@ end
|
|
68
68
|
# dc_render(:dc_common_renderer, method: 'google_analytics', code: 'UA-12345678-9')
|
69
69
|
########################################################################
|
70
70
|
def google_analytics
|
71
|
+
html = ''
|
71
72
|
ga_acc = @opts[:code] || @opts[:ga_acc]
|
72
|
-
|
73
|
-
|
73
|
+
if ga_acc && ga_acc != '/'
|
74
|
+
html << %(
|
74
75
|
<!-- Google analytics. -->
|
75
76
|
<script type="text/javascript">
|
76
77
|
(function(i,s,o,g,r,a,m){
|
@@ -86,7 +87,23 @@ def google_analytics
|
|
86
87
|
ga('send', 'pageview')
|
87
88
|
}
|
88
89
|
</script>
|
89
|
-
|
90
|
+
)
|
91
|
+
end
|
92
|
+
|
93
|
+
ga4_acc = @opts[:code4] || @opts[:ga4_acc]
|
94
|
+
if ga4_acc && ga4_acc != '/'
|
95
|
+
html << %(
|
96
|
+
<!-- Global site tag (gtag.js) - Google Analytics -->
|
97
|
+
<script async src="https://www.googletagmanager.com/gtag/js?id=#{ga4_acc}"></script>
|
98
|
+
<script>
|
99
|
+
window.dataLayer = window.dataLayer || [];
|
100
|
+
function gtag(){dataLayer.push(arguments);}
|
101
|
+
gtag('js', new Date());
|
102
|
+
|
103
|
+
gtag('config', '#{ga4_acc}');
|
104
|
+
</script>)
|
105
|
+
end
|
106
|
+
|
90
107
|
html.html_safe
|
91
108
|
end
|
92
109
|
|
@@ -1,17 +1,24 @@
|
|
1
|
+
<div id="dc-form-container">
|
2
|
+
<div id="dc-form-left">
|
3
|
+
<%= dc_form_left %>
|
4
|
+
</div>
|
1
5
|
|
2
|
-
|
3
|
-
<%=
|
4
|
-
<%=
|
6
|
+
<div id="dc-form-right">
|
7
|
+
<%= dc_flash_messages %>
|
8
|
+
<%= dc_error_messages_for @record %>
|
9
|
+
<%= dc_warning_messages_for @record %>
|
5
10
|
|
6
|
-
<div class="dc-form-frame">
|
11
|
+
<div class="dc-form-frame">
|
12
|
+
<% fields = dc_fields_for_form %>
|
13
|
+
<%= dc_actions_for_form 'top' %>
|
7
14
|
|
8
|
-
|
9
|
-
|
10
|
-
<%= dc_fields_for_form %>
|
11
|
-
<%= dc_document_statistics %>
|
15
|
+
<%= fields %>
|
16
|
+
<%= dc_document_statistics %>
|
12
17
|
|
13
|
-
|
14
|
-
</div>
|
18
|
+
<%= dc_actions_for_form 'bottom' %>
|
19
|
+
</div>
|
15
20
|
|
16
|
-
<%= javascript_tag(@js) unless @js.blank? %>
|
17
|
-
<% unless @css.blank? %><style
|
21
|
+
<%= javascript_tag(@js) unless @js.blank? %>
|
22
|
+
<% unless @css.blank? %><style><%= @css %></style><% end %>
|
23
|
+
</div>
|
24
|
+
</div>
|
@@ -1,9 +1,13 @@
|
|
1
|
-
|
2
|
-
<%= dc_table_title dc_edit_title() %>
|
1
|
+
<% dc_form_update %>
|
3
2
|
|
4
|
-
<%=
|
5
|
-
|
6
|
-
<%=
|
7
|
-
|
3
|
+
<div <%= dc_form_id %>>
|
4
|
+
<%= dc_head_for_form %>
|
5
|
+
<%= dc_table_title dc_edit_title() %>
|
6
|
+
|
7
|
+
<%= form_tag( @form_params, method: :put, id: CmsHelper.form_param(params) || CmsHelper.table_param(params),
|
8
|
+
class: 'cmsform', multipart: @form['form']['multipart'], window_close: params[:window_close] ) do %>
|
9
|
+
<%= render partial: 'form' %>
|
10
|
+
<% end %>
|
11
|
+
</div>
|
8
12
|
|
9
13
|
<div id="popup" style="display: none;"></div>
|