drg_cms 0.6.1.4 → 0.6.1.9
Sign up to get free protection for your applications and to get access to all the features.
- 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 +229 -95
- data/app/assets/stylesheets/drg_cms/drg_cms.css +608 -542
- 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 +54 -127
- data/app/controllers/dc_application_controller.rb +17 -2
- data/app/controllers/dc_common_controller.rb +13 -7
- data/app/controls/browse_models_control.rb +15 -26
- data/app/controls/cmsedit_control.rb +125 -0
- data/app/controls/dc_help_control.rb +13 -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 +1 -1
- data/app/controls/design_element_settings_control.rb +1 -1
- data/app/forms/all_options.yml +23 -7
- data/app/forms/cms_menu.yml +24 -24
- data/app/forms/dc_big_table.yml +0 -2
- data/app/forms/dc_big_table_value.yml +0 -2
- data/app/forms/dc_browse_fields.yml +13 -9
- data/app/forms/dc_design.yml +1 -2
- data/app/forms/dc_folder_permission.yml +0 -2
- data/app/forms/dc_help_1.yml +2 -1
- data/app/forms/dc_json_ld.yml +0 -3
- data/app/forms/dc_menu.yml +6 -12
- data/app/forms/dc_menu_item.yml +1 -3
- data/app/forms/dc_page.yml +1 -2
- data/app/forms/dc_policy.yml +2 -5
- data/app/forms/dc_poll.yml +10 -16
- data/app/forms/dc_poll_result_export.yml +1 -1
- data/app/forms/dc_seo.yml +1 -2
- data/app/forms/dc_simple_menu.yml +1 -2
- data/app/forms/dc_site.yml +5 -7
- data/app/helpers/cms_common_helper.rb +8 -6
- data/app/helpers/cms_edit_helper.rb +61 -53
- data/app/helpers/cms_helper.rb +78 -42
- data/app/helpers/cms_index_helper.rb +198 -137
- data/app/helpers/dc_application_helper.rb +65 -43
- data/app/models/concerns/dc_page_concern.rb +1 -1
- data/app/models/concerns/dc_site_concern.rb +9 -3
- data/app/models/dc_big_table.rb +2 -2
- data/app/models/dc_filter.rb +45 -37
- data/app/models/dc_json_ld.rb +1 -1
- data/app/models/dc_part.rb +19 -9
- data/app/models/dc_site.rb +0 -1
- data/app/models/dc_temp.rb +7 -0
- data/app/models/drgcms_form_fields/comment.rb +11 -2
- 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 +3 -0
- data/app/models/drgcms_form_fields/select.rb +14 -14
- data/app/models/drgcms_form_fields/text_autocomplete.rb +19 -11
- 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 +3 -2
- data/app/views/cmsedit/_result.html.erb +21 -18
- data/app/views/cmsedit/login.html.erb +1 -1
- 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 +5 -3
- data/config/locales/drgcms_sl.yml +5 -3
- data/config/locales/kaminari.yml +1 -1
- data/config/locales/models_sl.yml +1 -0
- data/drg_cms.gemspec +1 -1
- data/lib/drg_cms/version.rb +1 -1
- data/lib/drg_cms.rb +6 -12
- metadata +10 -5
- data/app/views/cmsedit/__remove_edit_stuff.js.erb +0 -6
- data/app/views/cmsedit/__show.html.erb +0 -21
data/app/forms/dc_site.yml
CHANGED
@@ -84,12 +84,8 @@ form:
|
|
84
84
|
name: document_extension
|
85
85
|
type: text_field
|
86
86
|
size: 10
|
87
|
-
25:
|
88
|
-
name: site_layout
|
89
|
-
type: text_field
|
90
|
-
size: 20
|
91
87
|
30:
|
92
|
-
name:
|
88
|
+
name: site_layout
|
93
89
|
type: text_field
|
94
90
|
size: 20
|
95
91
|
40:
|
@@ -132,8 +128,7 @@ form:
|
|
132
128
|
type: text_area
|
133
129
|
size: 130x40
|
134
130
|
|
135
|
-
5permissions:
|
136
|
-
|
131
|
+
5permissions:
|
137
132
|
10:
|
138
133
|
name: inherit_policy
|
139
134
|
type: select
|
@@ -145,9 +140,12 @@ form:
|
|
145
140
|
type: embedded
|
146
141
|
caption: false
|
147
142
|
form_name: dc_policy
|
143
|
+
load: delay
|
144
|
+
|
148
145
|
6parts:
|
149
146
|
10:
|
150
147
|
name: dc_parts
|
151
148
|
caption: false
|
152
149
|
type: embedded
|
153
150
|
form_name: dc_part
|
151
|
+
load: delay
|
@@ -213,13 +213,14 @@ end
|
|
213
213
|
|
214
214
|
############################################################################
|
215
215
|
# Return html code for icon presenting boolean value. Icon is a picture of checked or unchecked box.
|
216
|
+
# If second parameter (fiel_name) is ommited value is supplied as first parameter.
|
216
217
|
#
|
217
218
|
# Parameters:
|
218
219
|
# [value] Boolean.
|
219
220
|
#
|
220
221
|
# Example:
|
221
222
|
# # usage from program
|
222
|
-
# dc_icon4_boolean(
|
223
|
+
# dc_icon4_boolean(document, field_name)
|
223
224
|
#
|
224
225
|
# # usage from form description
|
225
226
|
# columns:
|
@@ -227,16 +228,17 @@ end
|
|
227
228
|
# name: active
|
228
229
|
# eval: dc_icon4_boolean
|
229
230
|
############################################################################
|
230
|
-
def dc_icon_for_boolean(
|
231
|
-
|
231
|
+
def dc_icon_for_boolean(document = false, field_name = nil)
|
232
|
+
value = field_name.nil? ? document : document[field_name]
|
233
|
+
dc_dont?(value, true) ? fa_icon('check_box_outline_blank md-18') : fa_icon('check_box-o md-18')
|
232
234
|
end
|
233
235
|
|
234
236
|
############################################################################
|
235
237
|
#
|
236
238
|
############################################################################
|
237
|
-
def dc_icon4_boolean(
|
239
|
+
def dc_icon4_boolean(document = false, field_name = false) #nodoc
|
238
240
|
#dc_deprecate('dc_icon4_boolean will be deprecated. Use dc_icon_for_boolean instead.')
|
239
|
-
dc_icon_for_boolean(
|
241
|
+
dc_icon_for_boolean(document, field_name)
|
240
242
|
end
|
241
243
|
|
242
244
|
############################################################################
|
@@ -345,7 +347,7 @@ def dc_help_for_tab(tab)
|
|
345
347
|
label, help = dc_label_help(field.last)
|
346
348
|
next if help.blank?
|
347
349
|
|
348
|
-
html << %(<div class="help-field"><div class="help-label">#{label}</div><div class="help-text">#{help}</div></div>)
|
350
|
+
html << %(<div class="help-field"><div class="help-label">#{label}</div><div class="help-text">#{help.gsub("\n",'<br>')}</div></div>)
|
349
351
|
end
|
350
352
|
html
|
351
353
|
end
|
@@ -52,7 +52,7 @@ end
|
|
52
52
|
############################################################################
|
53
53
|
def dc_is_action_active?(options)
|
54
54
|
if options['when_new']
|
55
|
-
dc_deprecate("when_option will be deprecated and replaced by active: not_new_record! Form #{params
|
55
|
+
dc_deprecate("when_option will be deprecated and replaced by active: not_new_record! Form #{CmsHelper.form_param(params)}")
|
56
56
|
return !(dc_dont?(options['when_new']) && @record.new_record?)
|
57
57
|
end
|
58
58
|
return true unless options['active']
|
@@ -137,56 +137,57 @@ def dc_actions_for_form(position)
|
|
137
137
|
actions.delete('standard')
|
138
138
|
actions = actions.to_a.sort { |x, y| x[0] <=> y[0] }
|
139
139
|
# Add spinner to the beginning
|
140
|
-
html = %Q[<span class="dc-spinner">#{fa_icon('
|
141
|
-
|
140
|
+
html = %Q[<span class="dc-spinner">#{fa_icon('settings-o spin')}</span><ul class="dc-menu #{position}">]
|
141
|
+
|
142
142
|
actions.each do |key, options|
|
143
143
|
session[:form_processing] = "form:actions: #{key} #{options}"
|
144
|
-
next if options.nil? # yes it
|
144
|
+
next if options.nil? # yes it happens
|
145
|
+
|
145
146
|
parms = @parms.clone
|
146
147
|
if options.class == String
|
147
148
|
next if @form['readonly'] and !options.match(/back|close/)
|
148
|
-
|
149
|
-
html << '<li
|
150
|
-
html << case
|
151
|
-
when (options == 'back'
|
149
|
+
|
150
|
+
html << '<li>'
|
151
|
+
html << case
|
152
|
+
when (options == 'back' || options == 'cancle')
|
152
153
|
# If return_to is present link directly to URL
|
153
154
|
if parms['xreturn_to'] # disabled for now
|
154
|
-
dc_link_to( 'drgcms.back','
|
155
|
+
dc_link_to( 'drgcms.back', 'arrow_back', parms['return_to'], class: 'dc-link' )
|
155
156
|
else
|
156
157
|
parms['action'] = 'index'
|
157
158
|
parms['readonly'] = parms['readonly'].to_s.to_i < 2 ? nil : 1
|
158
|
-
dc_link_to( 'drgcms.back','
|
159
|
+
dc_link_to( 'drgcms.back', 'arrow_back', parms, class: 'dc-link' )
|
159
160
|
end
|
160
161
|
|
161
|
-
when options == 'delete'
|
162
|
+
when options == 'delete'
|
162
163
|
parms['operation'] = options
|
163
164
|
parms['id'] = @record.id
|
164
|
-
dc_link_to( 'drgcms.delete','remove', parms, data: { confirm: t('drgcms.confirm_delete') }, method: :delete )
|
165
|
+
dc_link_to( 'drgcms.delete','remove', parms, data: { confirm: t('drgcms.confirm_delete') }, method: :delete, class: 'dc-link' )
|
165
166
|
|
166
|
-
when options == 'new'
|
167
|
+
when options == 'new'
|
167
168
|
parms['action'] = options
|
168
|
-
dc_link_to( 'drgcms.new', '
|
169
|
+
dc_link_to( 'drgcms.new', 'add', parms, class: 'dc-link')
|
169
170
|
|
170
|
-
when (options == 'enable'
|
171
|
+
when (options == 'enable' || options == 'disable')
|
171
172
|
parms['operation'] = options
|
172
173
|
parms['id'] = @record.id
|
173
|
-
icon = (options == 'enable' ? '
|
174
|
-
dc_link_to( "drgcms.#{options}",icon, parms, method: :delete )
|
174
|
+
icon = (options == 'enable' ? 'check_box-o' : 'check_box_outline_blank')
|
175
|
+
dc_link_to( "drgcms.#{options}",icon, parms, method: :delete, class: 'dc-link' )
|
175
176
|
|
176
|
-
when options == 'edit'
|
177
|
+
when options == 'edit'
|
177
178
|
parms['operation'] = options
|
178
179
|
parms['id'] = @record.id
|
179
|
-
dc_link_to( "drgcms.#{options}",options, parms )
|
180
|
+
dc_link_to( "drgcms.#{options}", options, parms, class: 'dc-link' )
|
180
181
|
|
181
|
-
when options == 'refresh'
|
182
|
-
|
182
|
+
when options == 'refresh'
|
183
|
+
%(<div class="dc-link" onclick='window.location.href=window.location.href;'>#{fa_icon('refresh')} #{t('drgcms.refresh')}</div></li>)
|
183
184
|
|
184
|
-
when options == 'close'
|
185
|
+
when options == 'close'
|
185
186
|
close = params[:window_close].to_i
|
186
187
|
if close < 2
|
187
|
-
|
188
|
+
%(<div class="dc-link" onclick='window.close();'>#{fa_icon('close')} #{t('drgcms.close')}</div></li>)
|
188
189
|
else
|
189
|
-
|
190
|
+
%(<div class="dc-link" onclick='history.back();'>#{fa_icon('close')} #{t('drgcms.close')}</div></li>)
|
190
191
|
end
|
191
192
|
else
|
192
193
|
"err1 #{key}=>#{options}"
|
@@ -203,14 +204,14 @@ def dc_actions_for_form(position)
|
|
203
204
|
when options['type'] == 'submit'
|
204
205
|
caption = options['caption'] || 'drgcms.save'
|
205
206
|
icon = options['icon'] || 'save'
|
206
|
-
|
207
|
-
options['params'].each { |k,v|
|
207
|
+
parameters = {}
|
208
|
+
options['params'].each { |k, v| parameters[k] = dc_value_for_parameter(v) } if options['params']
|
208
209
|
if dc_is_action_active?(options)
|
209
|
-
'<li
|
210
|
-
dc_submit_tag(caption, icon, {:
|
210
|
+
'<li>' +
|
211
|
+
dc_submit_tag(caption, icon, { data: parameters, title: options['title'] }) +
|
211
212
|
'</li>'
|
212
213
|
else
|
213
|
-
|
214
|
+
%(<li><div class="dc-link-no">#{fa_icon(icon)} #{caption}</div></li>)
|
214
215
|
end
|
215
216
|
|
216
217
|
# delete with some sugar added
|
@@ -219,21 +220,22 @@ def dc_actions_for_form(position)
|
|
219
220
|
parms.merge!(options['params'])
|
220
221
|
caption = options['caption'] || 'drgcms.delete'
|
221
222
|
icon = options['icon'] || 'remove'
|
222
|
-
'<li class="
|
223
|
-
dc_link_to( caption, icon, parms, data: t('drgcms.confirm_delete'), method: :delete ) +
|
223
|
+
'<li class="">' +
|
224
|
+
dc_link_to( caption, icon, parms, data: t('drgcms.confirm_delete'), method: :delete, class: 'dc-link' ) +
|
224
225
|
'</li>'
|
225
|
-
|
226
|
+
|
226
227
|
# ajax or link button
|
227
|
-
when %w(ajax link window).include?(options['type'])
|
228
|
+
when %w(ajax link window popup).include?(options['type'])
|
228
229
|
dc_link_ajax_window_submit_action(options, @record)
|
229
|
-
|
230
|
-
# Javascript action
|
230
|
+
|
231
|
+
# Javascript action
|
231
232
|
when options['type'] == 'script'
|
232
233
|
dc_script_action(options)
|
233
234
|
else
|
234
235
|
'<li>err2</li>'
|
235
236
|
end
|
236
237
|
end
|
238
|
+
|
237
239
|
end
|
238
240
|
(html << '</ul>').html_safe
|
239
241
|
end
|
@@ -307,13 +309,13 @@ def dc_fields_for_tab(fields_on_tab) #:nodoc:
|
|
307
309
|
group_count = options['group'] || 1
|
308
310
|
group_option = options['group'] || 1
|
309
311
|
end
|
310
|
-
|
312
|
+
|
311
313
|
html << if labels_pos == 'top'
|
312
|
-
%
|
314
|
+
%(
|
313
315
|
<div class="dc-form-label-top dc-color-#{odd_even} dc-align-left" title="#{help}">
|
314
316
|
<label for="record_#{options['name']}">#{label} </label>
|
315
317
|
<div id="td_record_#{options['name']}">#{field_html}</div>
|
316
|
-
</div>
|
318
|
+
</div> )
|
317
319
|
else
|
318
320
|
# no label
|
319
321
|
if dc_dont?(options['caption'])
|
@@ -326,13 +328,14 @@ def dc_fields_for_tab(fields_on_tab) #:nodoc:
|
|
326
328
|
else
|
327
329
|
label_width = 14
|
328
330
|
data_width = 85
|
329
|
-
end
|
330
|
-
|
331
|
+
end
|
332
|
+
help.gsub!('<br>',"\n") if help.present?
|
333
|
+
%(
|
331
334
|
<div class="dc-form-label dc-color-#{odd_even} dc-align-#{labels_pos} dc-width-#{label_width}" title="#{help}">
|
332
335
|
<label for="record_#{options['name']}">#{label} </label>
|
333
336
|
</div>
|
334
337
|
<div id="td_record_#{options['name']}" class="dc-form-field dc-color-#{odd_even} dc-width-#{data_width}">#{field_html}</div>
|
335
|
-
|
338
|
+
)
|
336
339
|
end
|
337
340
|
# check if group end
|
338
341
|
if (group_count -= 1) == 0
|
@@ -408,6 +411,7 @@ def dc_head_for_form
|
|
408
411
|
@css ||= ''
|
409
412
|
head = @form['form']['head']
|
410
413
|
return '' if head.nil?
|
414
|
+
|
411
415
|
html = %(<div class="dc-head #{head['class']}">\n<div class="dc-row">)
|
412
416
|
split = head['split'] || 4
|
413
417
|
percent = 100/split
|
@@ -469,29 +473,33 @@ end
|
|
469
473
|
# + lots of more. At the moment also adds icon for dumping current document as json text.
|
470
474
|
############################################################################
|
471
475
|
def dc_document_statistics
|
472
|
-
return '' if @record.
|
473
|
-
|
474
|
-
|
476
|
+
return '' if @record.id.nil? || dc_dont?(@form['form']['info'])
|
477
|
+
|
478
|
+
html = %(<div id="dc-document-info">#{fa_icon('info md-18')}</div> <div id="dc-document-info-popup" class="div-hidden">)
|
475
479
|
u = dc_document_user_for('created_by')
|
476
|
-
html << %
|
480
|
+
html << %(<div><span>#{t('drgcms.created_by', 'Created by')}: </span><span>#{u}</span></div>) if u
|
477
481
|
u = dc_document_user_for('updated_by')
|
478
|
-
html << %
|
479
|
-
|
480
|
-
html << %
|
481
|
-
|
482
|
+
html << %(<div><span>#{t('drgcms.updated_by', 'Updated by')}: </span><span>#{u}</span></div>) if u
|
483
|
+
|
484
|
+
html << %(<div><span>#{t('drgcms.created_at', 'Created at')}: </span><span>#{dc_format_value(@record.created_at)}</span></div>) if @record['created_at']
|
485
|
+
html << %(<div><span>#{t('drgcms.updated_at', 'Updated at')}: </span><span>#{dc_format_value(@record.updated_at)}</span></div>) if @record['updated_at']
|
486
|
+
# copy to clipboard icon
|
482
487
|
parms = params.clone
|
483
488
|
parms[:controller] = 'dc_common'
|
484
489
|
parms[:action] = 'copy_clipboard'
|
485
490
|
url = url_for(parms.permit!)
|
486
|
-
html << fa_icon('
|
491
|
+
html << fa_icon('content_copy-o md-18', class: 'dc-link-img dc-link-ajax',
|
487
492
|
'data-url' => url, 'data-request' => 'get', title: t('drgcms.doc_copy_clipboard') )
|
488
493
|
|
489
|
-
url = url_for(controller:
|
494
|
+
url = url_for(controller: 'cmsedit', action: :index, table: 'dc_journal', filter: 'on',
|
490
495
|
filter_oper: 'eq', filter_field: 'doc_id', filter_value: @record.id)
|
491
|
-
html << fa_icon('history
|
496
|
+
html << fa_icon('history md-18', class: 'dc-link-img dc-window-open',
|
492
497
|
'data-url' => url, title: t('helpers.label.dc_journal.tabletitle') )
|
498
|
+
html << %(<span>ID: </span><span id="record-id" class="hover" onclick="dc_copy_to_clipboard('record-id');" title="Copy document ID to clipboard">#{@record.id}</span>)
|
499
|
+
|
500
|
+
#dc_copy_to_clipboard
|
493
501
|
|
494
|
-
(html << '</div
|
502
|
+
(html << '</div>').html_safe
|
495
503
|
end
|
496
504
|
|
497
505
|
private
|
data/app/helpers/cms_helper.rb
CHANGED
@@ -34,11 +34,9 @@ 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
|
-
data = %
|
41
|
-
%
|
38
|
+
data = %(data-request="script" data-script="#{yaml['js'] || yaml['script']}" data-url="script")
|
39
|
+
%(<li><div class="dc-link-ajax" #{data}>#{icon} #{ t(yaml['caption'],yaml['caption']) }</div></li>)
|
42
40
|
end
|
43
41
|
|
44
42
|
############################################################################
|
@@ -49,11 +47,11 @@ def dc_get_field_form_definition(name) #:nodoc:
|
|
49
47
|
return if @form['form'].nil?
|
50
48
|
|
51
49
|
@form['form']['tabs'].each do |tab|
|
52
|
-
# Array with 2 elements. First is
|
50
|
+
# Array with 2 elements. First is tab name, second is data
|
53
51
|
my_fields = tab.last
|
54
|
-
my_fields.each {|k,v| return v if (k.class == Integer
|
52
|
+
my_fields.each { |k, v| return v if (k.class == Integer && v['name'] == name) }
|
55
53
|
end if @form['form']['tabs'] # I know. But nice.
|
56
|
-
|
54
|
+
|
57
55
|
@form['form']['fields'].each do |field|
|
58
56
|
next unless field.first.class == Integer # options
|
59
57
|
return field.last if field.last['name'] == name
|
@@ -160,7 +158,7 @@ def dc_field_action(yaml)
|
|
160
158
|
end
|
161
159
|
# input field will have label as placeholder
|
162
160
|
field = field.sub('input',"input placeholder=\"#{label}\"")
|
163
|
-
%
|
161
|
+
%(<li class="no-background">#{field}</li>)
|
164
162
|
end
|
165
163
|
|
166
164
|
############################################################################
|
@@ -168,9 +166,17 @@ end
|
|
168
166
|
############################################################################
|
169
167
|
def dc_html_data(yaml)
|
170
168
|
return '' if yaml.blank?
|
171
|
-
|
169
|
+
|
170
|
+
yaml.inject(' ') { |result, e| result = e.last.nil? ? result : result << "#{e.first}=\"#{e.last}\" " }
|
172
171
|
end
|
173
172
|
|
173
|
+
############################################################################
|
174
|
+
# There are several options for defining caption (caption,label, text). This method
|
175
|
+
# will ensure that caption is returned anyhow provided.
|
176
|
+
############################################################################
|
177
|
+
def dc_get_caption(yaml)
|
178
|
+
yaml['caption'] || yaml['text'] || yaml['label']
|
179
|
+
end
|
174
180
|
############################################################################
|
175
181
|
# Creates code for link, ajax or windows action for index or form actions.
|
176
182
|
#
|
@@ -182,14 +188,14 @@ end
|
|
182
188
|
# Returns:
|
183
189
|
# String : HTML code for action
|
184
190
|
############################################################################
|
185
|
-
def dc_link_ajax_window_submit_action(yaml, record=nil, action_active=true)
|
191
|
+
def dc_link_ajax_window_submit_action(yaml, record = nil, action_active = true)
|
186
192
|
parms = {}
|
187
|
-
caption = yaml
|
193
|
+
caption = dc_get_caption(yaml)
|
188
194
|
caption = caption ? t("#{caption.downcase}", caption) : nil
|
189
195
|
icon = yaml['icon'] ? "#{fa_icon(yaml['icon'])}" : ''
|
190
196
|
# action is not active
|
191
197
|
unless dc_is_action_active?(yaml)
|
192
|
-
return
|
198
|
+
return %(<li><div class="dc-link-no">#{icon} #{caption}</div></li>)
|
193
199
|
end
|
194
200
|
# set data-confirm when confirm
|
195
201
|
yaml['html'] ||= {}
|
@@ -218,41 +224,57 @@ def dc_link_ajax_window_submit_action(yaml, record=nil, action_active=true)
|
|
218
224
|
|
219
225
|
parms['table'] = parms['table'].underscore if parms['table'] # might be CamelCase
|
220
226
|
# error if controller parameter is missing
|
221
|
-
if parms['controller'].nil? && parms['url'].nil?
|
222
|
-
"<li>#{'Controller not defined'}</li>"
|
223
|
-
else
|
224
|
-
#yaml['caption'] ||= yaml['text']
|
225
|
-
html_data = dc_html_data(yaml['html'])
|
226
|
-
url = url_for(parms) rescue 'URL error'
|
227
|
-
url = nil if parms['url'] == '#'
|
227
|
+
return "<li>#{'Controller not defined'}</li>" if parms['controller'].nil? && parms['url'].nil?
|
228
228
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
data-request="#{request}" title="#{yaml['title']}">#{icon}#{caption}</li>]
|
229
|
+
html_data = dc_html_data(yaml['html'])
|
230
|
+
url = url_for(parms) rescue 'URL error'
|
231
|
+
url = nil if parms['url'] == '#'
|
232
|
+
request = yaml['request'] || yaml['method'] || 'get'
|
234
233
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
%Q[<li class="#{clas}" data-url="#{action_active ? url : ''}" #{html_data}
|
241
|
-
data-request="#{request}" title="#{yaml['title']}">#{icon}#{caption}</li>]
|
234
|
+
code = case yaml['type']
|
235
|
+
when 'ajax' # ajax button
|
236
|
+
clas = 'dc-link-ajax'
|
237
|
+
%(<div class="#{clas}" data-url="#{action_active ? url : ''}" #{html_data}
|
238
|
+
data-request="#{request}" title="#{yaml['title']}">#{icon}#{caption}</div>)
|
242
239
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
240
|
+
when 'submit' # submit button
|
241
|
+
# It's dirty hack, but will prevent not authorized message and render index action correctly
|
242
|
+
parms[:filter] = 'on'
|
243
|
+
url = url_for(parms) rescue 'URL error'
|
244
|
+
clas = 'dc-action-submit'
|
245
|
+
%(<div class="#{clas}" data-url="#{action_active ? url : ''}" #{html_data}
|
246
|
+
data-request="#{request}" title="#{yaml['title']}">#{icon}#{caption}</div>)
|
247
247
|
|
248
|
-
|
249
|
-
|
250
|
-
|
248
|
+
when 'link' # link button
|
249
|
+
yaml['html'] = dc_yaml_add_option(yaml['html'], class: 'dc-link')
|
250
|
+
link = dc_link_to(caption, yaml['icon'], parms, yaml['html'] )
|
251
|
+
%(#{action_active ? link : caption})
|
251
252
|
|
252
|
-
|
253
|
-
|
254
|
-
|
253
|
+
when 'window' # open window
|
254
|
+
clas = 'dc-link dc-window-open'
|
255
|
+
%(<div class="#{clas}" data-url="#{action_active ? url : ''}" #{html_data}>#{icon}#{caption}</div>)
|
256
|
+
|
257
|
+
when 'popup' # popup dialog
|
258
|
+
clas = 'dc-link dc-popup-open'
|
259
|
+
%(<div class="#{clas}" data-url="#{action_active ? url : ''}" #{html_data}>#{icon}#{caption}</div>)
|
260
|
+
|
261
|
+
else
|
262
|
+
'Type error!'
|
255
263
|
end
|
264
|
+
"<li>#{code}</li>"
|
265
|
+
end
|
266
|
+
|
267
|
+
############################################################################
|
268
|
+
# Add new option to yaml. Subroutine of dc_link_ajax_window_submit_action.
|
269
|
+
############################################################################
|
270
|
+
def dc_yaml_add_option(source, options) #nodoc
|
271
|
+
options.each do |k, v|
|
272
|
+
key = k.to_s
|
273
|
+
source[key] ||= ''
|
274
|
+
# only if not already present
|
275
|
+
source[key] << " #{v}" unless source[key].match(v.to_s)
|
276
|
+
end
|
277
|
+
source
|
256
278
|
end
|
257
279
|
|
258
280
|
############################################################################
|
@@ -264,5 +286,19 @@ def dc_log_exception(exception, where = '')
|
|
264
286
|
|
265
287
|
logger.error log
|
266
288
|
end
|
267
|
-
|
289
|
+
|
290
|
+
############################################################################
|
291
|
+
# Will return form_name from parameter regardless if set as form_name or just f.
|
292
|
+
############################################################################
|
293
|
+
def self.form_param(params)
|
294
|
+
params[:form_name] || params[:f]
|
295
|
+
end
|
296
|
+
|
297
|
+
############################################################################
|
298
|
+
# Will return table name from parameter regardless if set as table or just t.
|
299
|
+
############################################################################
|
300
|
+
def self.table_param(params)
|
301
|
+
params[:table] || params[:t]
|
302
|
+
end
|
303
|
+
|
268
304
|
end
|