drg_cms 0.6.1.5 → 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/README.md +203 -24
- data/app/assets/fonts/ibm-plex-sans-300.woff2 +0 -0
- data/app/assets/fonts/ibm-plex-sans-400.woff2 +0 -0
- data/app/assets/fonts/ibm-plex-sans-500.woff2 +0 -0
- data/app/assets/fonts/ibm-plex-sans-600.woff2 +0 -0
- data/app/assets/fonts/ibm-plex-sans-700.woff2 +0 -0
- data/app/assets/fonts/ibm-plex-sans-italic.woff2 +0 -0
- data/app/assets/javascripts/drg_cms/drg_cms.js +253 -106
- data/app/assets/stylesheets/drg_cms/drg_cms.css +670 -521
- data/app/assets/stylesheets/drg_cms_application.css +1 -1
- data/app/assets/stylesheets/drg_cms_cms.css +1 -4
- data/app/controllers/cmsedit_controller.rb +33 -211
- data/app/controllers/dc_application_controller.rb +98 -22
- data/app/controllers/dc_common_controller.rb +9 -22
- data/app/controls/browse_models_control.rb +18 -27
- data/app/controls/cmsedit_control.rb +129 -0
- data/app/controls/dc_help_control.rb +1 -1
- data/app/controls/dc_page_control.rb +0 -1
- data/app/controls/dc_poll_result_control.rb +1 -1
- data/app/controls/dc_report.rb +2 -2
- data/app/controls/design_element_settings_control.rb +1 -1
- data/app/forms/all_options.yml +25 -7
- data/app/forms/cms_menu.yml +24 -24
- data/app/forms/dc_browse_fields.yml +13 -9
- data/app/forms/dc_browse_models.yml +24 -2
- data/app/forms/dc_poll_result_export.yml +1 -1
- data/app/forms/dc_site.yml +2 -5
- data/app/forms/dc_steps_template.yml +51 -0
- data/app/helpers/cms_common_helper.rb +73 -6
- data/app/helpers/cms_edit_helper.rb +275 -159
- data/app/helpers/cms_helper.rb +152 -59
- data/app/helpers/cms_index_helper.rb +220 -172
- data/app/helpers/dc_application_helper.rb +40 -67
- data/app/models/concerns/dc_page_concern.rb +1 -1
- data/app/models/concerns/dc_site_concern.rb +9 -3
- data/app/models/dc_filter.rb +30 -22
- data/app/models/dc_journal.rb +2 -2
- data/app/models/dc_json_ld.rb +19 -42
- data/app/models/dc_part.rb +19 -9
- data/app/models/dc_site.rb +0 -1
- data/app/models/drgcms_form_fields/drgcms_field.rb +10 -4
- data/app/models/drgcms_form_fields/link_to.rb +1 -1
- data/app/models/drgcms_form_fields/multitext_autocomplete.rb +5 -5
- data/app/models/drgcms_form_fields/readonly.rb +4 -1
- data/app/models/drgcms_form_fields/select.rb +10 -9
- data/app/models/drgcms_form_fields/text_autocomplete.rb +20 -12
- data/app/models/drgcms_form_fields/text_with_select.rb +1 -0
- data/app/renderers/dc_common_renderer.rb +20 -3
- data/app/renderers/dc_part_renderer.rb +1 -1
- data/app/renderers/dc_poll_renderer.rb +1 -1
- data/app/views/cmsedit/_edit_stuff.html.erb +12 -12
- 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/login.html.erb +1 -1
- data/app/views/cmsedit/new.html.erb +9 -5
- data/app/views/dc_common/_help.html.erb +1 -0
- data/app/views/dc_common/paste_clipboard.html.erb +1 -1
- data/app/views/layouts/cms.html.erb +3 -5
- data/config/locales/drgcms_en.yml +7 -1
- data/config/locales/drgcms_sl.yml +7 -1
- data/config/locales/kaminari.yml +1 -1
- data/drg_cms.gemspec +2 -2
- data/lib/drg_cms/version.rb +1 -1
- data/lib/drg_cms.rb +4 -4
- metadata +16 -10
- data/app/views/cmsedit/__remove_edit_stuff.js.erb +0 -6
- data/app/views/cmsedit/__show.html.erb +0 -21
data/app/helpers/cms_helper.rb
CHANGED
@@ -34,11 +34,17 @@ module CmsHelper
|
|
34
34
|
# Creates code for script action type.
|
35
35
|
############################################################################
|
36
36
|
def dc_script_action(yaml)
|
37
|
-
# data = {'request' => 'script', 'script' => yaml['js'] || yaml['script'] }
|
38
|
-
# %Q[<li class="dc-link-ajax with-link dc-animate">#{ dc_link_to(yaml['caption'], yaml['icon'], '#', data: data ) }</li>]
|
39
37
|
icon = dc_icon_for_link yaml['icon']
|
40
|
-
|
41
|
-
|
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>)
|
42
48
|
end
|
43
49
|
|
44
50
|
############################################################################
|
@@ -49,11 +55,11 @@ def dc_get_field_form_definition(name) #:nodoc:
|
|
49
55
|
return if @form['form'].nil?
|
50
56
|
|
51
57
|
@form['form']['tabs'].each do |tab|
|
52
|
-
# Array with 2 elements. First is
|
58
|
+
# Array with 2 elements. First is tab name, second is data
|
53
59
|
my_fields = tab.last
|
54
|
-
my_fields.each {|k,v| return v if (k.class == Integer
|
60
|
+
my_fields.each { |k, v| return v if (k.class == Integer && v['name'] == name) }
|
55
61
|
end if @form['form']['tabs'] # I know. But nice.
|
56
|
-
|
62
|
+
|
57
63
|
@form['form']['fields'].each do |field|
|
58
64
|
next unless field.first.class == Integer # options
|
59
65
|
return field.last if field.last['name'] == name
|
@@ -107,11 +113,13 @@ def dc_label_help(options)
|
|
107
113
|
return [nil, nil] if %w(comment action).include?(options['type'])
|
108
114
|
|
109
115
|
label = options['caption'] || options['text'] || options['label']
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
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
|
115
123
|
# help text can be defined in form or in translations starting with helpers. or as helpers.help.collection.field
|
116
124
|
help = options['help']
|
117
125
|
help ||= "helpers.help.#{@form['table']}.#{options['name']}" if options['name']
|
@@ -130,11 +138,11 @@ end
|
|
130
138
|
# help : String : Help text
|
131
139
|
############################################################################
|
132
140
|
def dc_tab_label_help(tab_name)
|
133
|
-
label = @form
|
134
|
-
label = t(label,
|
141
|
+
label = @form.dig('form', 'tabs', tab_name, 'caption') || tab_name
|
142
|
+
label = t(label, t_label_for_field(label, label))
|
135
143
|
|
136
|
-
help = @form
|
137
|
-
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))
|
138
146
|
help = nil if help.match('helpers.') # help not found in translation
|
139
147
|
|
140
148
|
[label, help]
|
@@ -160,7 +168,7 @@ def dc_field_action(yaml)
|
|
160
168
|
end
|
161
169
|
# input field will have label as placeholder
|
162
170
|
field = field.sub('input',"input placeholder=\"#{label}\"")
|
163
|
-
%
|
171
|
+
%(<li class="no-background">#{field}</li>)
|
164
172
|
end
|
165
173
|
|
166
174
|
############################################################################
|
@@ -168,9 +176,17 @@ end
|
|
168
176
|
############################################################################
|
169
177
|
def dc_html_data(yaml)
|
170
178
|
return '' if yaml.blank?
|
171
|
-
|
179
|
+
|
180
|
+
yaml.inject(' ') { |result, e| result = e.last.nil? ? result : result << "#{e.first}=\"#{e.last}\" " }
|
172
181
|
end
|
173
182
|
|
183
|
+
############################################################################
|
184
|
+
# There are several options for defining caption (caption,label, text). This method
|
185
|
+
# will ensure that caption is returned anyhow provided.
|
186
|
+
############################################################################
|
187
|
+
def dc_get_caption(yaml)
|
188
|
+
yaml['caption'] || yaml['text'] || yaml['label']
|
189
|
+
end
|
174
190
|
############################################################################
|
175
191
|
# Creates code for link, ajax or windows action for index or form actions.
|
176
192
|
#
|
@@ -184,19 +200,21 @@ end
|
|
184
200
|
############################################################################
|
185
201
|
def dc_link_ajax_window_submit_action(yaml, record = nil, action_active = true)
|
186
202
|
parms = {}
|
187
|
-
caption = yaml
|
203
|
+
caption = dc_get_caption(yaml)
|
188
204
|
caption = caption ? t("#{caption.downcase}", caption) : nil
|
189
205
|
icon = yaml['icon'] ? "#{fa_icon(yaml['icon'])}" : ''
|
190
206
|
# action is not active
|
191
207
|
unless dc_is_action_active?(yaml)
|
192
|
-
return
|
208
|
+
return %(<li><div class="dc-link-no">#{icon} #{caption}</div></li>)
|
193
209
|
end
|
194
|
-
# set data-confirm when confirm
|
210
|
+
# set data-confirm when confirm shortcut present
|
195
211
|
yaml['html'] ||= {}
|
196
|
-
|
197
|
-
yaml['html']['data-confirm'] = t(
|
198
|
-
|
199
|
-
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
|
+
|
200
218
|
yaml['html']['target'] ||= yaml['target']
|
201
219
|
# direct url
|
202
220
|
if yaml['url']
|
@@ -218,41 +236,57 @@ def dc_link_ajax_window_submit_action(yaml, record = nil, action_active = true)
|
|
218
236
|
|
219
237
|
parms['table'] = parms['table'].underscore if parms['table'] # might be CamelCase
|
220
238
|
# error if controller parameter is missing
|
221
|
-
if parms['controller'].nil? && parms['url'].nil?
|
222
|
-
|
239
|
+
return "<li>#{'Controller not defined'}</li>" if parms['controller'].nil? && parms['url'].nil?
|
240
|
+
|
241
|
+
html_data = dc_html_data(yaml['html'])
|
242
|
+
url = url_for(parms) rescue 'URL error'
|
243
|
+
url = nil if parms['url'] == '#'
|
244
|
+
request = yaml['request'] || yaml['method'] || 'get'
|
245
|
+
|
246
|
+
code = case yaml['type']
|
247
|
+
when 'ajax' # ajax button
|
248
|
+
clas = 'dc-link-ajax'
|
249
|
+
%(<div class="#{clas}" data-url="#{action_active ? url : ''}" #{html_data}
|
250
|
+
data-request="#{request}" title="#{yaml['title']}">#{icon}#{caption}</div>)
|
251
|
+
|
252
|
+
when 'submit' # submit button
|
253
|
+
# It's dirty hack, but will prevent not authorized message and render index action correctly
|
254
|
+
parms[:filter] = 'on'
|
255
|
+
url = url_for(parms) rescue 'URL error'
|
256
|
+
clas = 'dc-action-submit'
|
257
|
+
%(<div class="#{clas}" data-url="#{action_active ? url : ''}" #{html_data}
|
258
|
+
data-request="#{request}" title="#{yaml['title']}">#{icon}#{caption}</div>)
|
259
|
+
|
260
|
+
when 'link' # link button
|
261
|
+
yaml['html'] = dc_yaml_add_option(yaml['html'], class: 'dc-link')
|
262
|
+
link = dc_link_to(caption, yaml['icon'], parms, yaml['html'] )
|
263
|
+
%(#{action_active ? link : caption})
|
264
|
+
|
265
|
+
when 'window' # open window
|
266
|
+
clas = 'dc-link dc-window-open'
|
267
|
+
%(<div class="#{clas}" data-url="#{action_active ? url : ''}" #{html_data}>#{icon}#{caption}</div>)
|
268
|
+
|
269
|
+
when 'popup' # popup dialog
|
270
|
+
clas = 'dc-link dc-popup-open'
|
271
|
+
%(<div class="#{clas}" data-url="#{action_active ? url : ''}" #{html_data}>#{icon}#{caption}</div>)
|
272
|
+
|
223
273
|
else
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
request = yaml['request'] || yaml['method'] || 'get'
|
230
|
-
if yaml['type'] == 'ajax' # ajax button
|
231
|
-
clas = "dc-link-ajax dc-animate"
|
232
|
-
%Q[<li class="#{clas}" data-url="#{action_active ? url : ''}" #{html_data}
|
233
|
-
data-request="#{request}" title="#{yaml['title']}">#{icon}#{caption}</li>]
|
234
|
-
|
235
|
-
elsif yaml['type'] == 'submit' # submit button
|
236
|
-
# It's dirty hack, but will prevent not authorized message and render index action correctly
|
237
|
-
parms[:filter] = 'on'
|
238
|
-
url = url_for(parms) rescue 'URL error'
|
239
|
-
clas = "dc-action-submit"
|
240
|
-
%Q[<li class="#{clas}" data-url="#{action_active ? url : ''}" #{html_data}
|
241
|
-
data-request="#{request}" title="#{yaml['title']}">#{icon}#{caption}</li>]
|
242
|
-
|
243
|
-
elsif yaml['type'] == 'link' # link button
|
244
|
-
clas = "dc-link plus-link dc-animate"
|
245
|
-
link = dc_link_to(caption, yaml['icon'], parms, yaml['html'] )
|
246
|
-
%Q[<li class="#{clas}">#{action_active ? link : caption}</li>]
|
247
|
-
|
248
|
-
elsif yaml['type'] == 'window'
|
249
|
-
clas = "dc-link dc-animate dc-window-open"
|
250
|
-
%Q[<li class="#{clas}" data-url="#{action_active ? url : ''}" #{html_data}>#{icon}#{caption}</li>]
|
274
|
+
'Type error!'
|
275
|
+
end
|
276
|
+
"<li>#{code}</li>"
|
277
|
+
end
|
251
278
|
|
252
|
-
|
253
|
-
|
254
|
-
|
279
|
+
############################################################################
|
280
|
+
# Add new option to yaml. Subroutine of dc_link_ajax_window_submit_action.
|
281
|
+
############################################################################
|
282
|
+
def dc_yaml_add_option(source, options) #nodoc
|
283
|
+
options.each do |k, v|
|
284
|
+
key = k.to_s
|
285
|
+
source[key] ||= ''
|
286
|
+
# only if not already present
|
287
|
+
source[key] << " #{v}" unless source[key].match(v.to_s)
|
255
288
|
end
|
289
|
+
source
|
256
290
|
end
|
257
291
|
|
258
292
|
############################################################################
|
@@ -260,9 +294,68 @@ end
|
|
260
294
|
############################################################################
|
261
295
|
def dc_log_exception(exception, where = '')
|
262
296
|
log = exception ? "\n*** Error:#{where + ':'} #{exception.message}\n#{exception.backtrace.first.inspect}\n" : ''
|
263
|
-
log << "DRG Form
|
297
|
+
log << "DRG Form: #{CmsHelper.form_param(params)}, line: #{session[:form_processing]}\n"
|
264
298
|
|
265
299
|
logger.error log
|
266
300
|
end
|
267
|
-
|
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
|
+
|
309
|
+
############################################################################
|
310
|
+
# Will return form_name from parameter regardless if set as form_name or just f.
|
311
|
+
############################################################################
|
312
|
+
def self.form_param(params)
|
313
|
+
params[:form_name] || params[:f]
|
314
|
+
end
|
315
|
+
|
316
|
+
############################################################################
|
317
|
+
# Will return table name from parameter regardless if set as table or just t.
|
318
|
+
############################################################################
|
319
|
+
def self.table_param(params)
|
320
|
+
params[:table] || params[:t]
|
321
|
+
end
|
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
|
+
|
268
361
|
end
|