drg_cms 0.6.1.6 → 0.6.1.9

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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +203 -24
  3. data/app/assets/javascripts/drg_cms/drg_cms.js +183 -95
  4. data/app/assets/stylesheets/drg_cms/drg_cms.css +542 -509
  5. data/app/assets/stylesheets/drg_cms_application.css +1 -1
  6. data/app/assets/stylesheets/drg_cms_cms.css +1 -4
  7. data/app/controllers/cmsedit_controller.rb +25 -103
  8. data/app/controllers/dc_common_controller.rb +6 -5
  9. data/app/controls/browse_models_control.rb +15 -26
  10. data/app/controls/cmsedit_control.rb +125 -0
  11. data/app/controls/dc_help_control.rb +1 -1
  12. data/app/controls/dc_page_control.rb +0 -1
  13. data/app/controls/dc_poll_result_control.rb +1 -1
  14. data/app/controls/dc_report.rb +1 -1
  15. data/app/forms/all_options.yml +1 -1
  16. data/app/forms/cms_menu.yml +24 -24
  17. data/app/forms/dc_browse_fields.yml +13 -9
  18. data/app/forms/dc_poll_result_export.yml +1 -1
  19. data/app/helpers/cms_common_helper.rb +7 -5
  20. data/app/helpers/cms_edit_helper.rb +52 -45
  21. data/app/helpers/cms_helper.rb +76 -40
  22. data/app/helpers/cms_index_helper.rb +180 -139
  23. data/app/helpers/dc_application_helper.rb +37 -43
  24. data/app/models/concerns/dc_page_concern.rb +1 -1
  25. data/app/models/dc_filter.rb +30 -22
  26. data/app/models/dc_json_ld.rb +1 -1
  27. data/app/models/dc_part.rb +19 -9
  28. data/app/models/drgcms_form_fields/drgcms_field.rb +10 -4
  29. data/app/models/drgcms_form_fields/link_to.rb +1 -1
  30. data/app/models/drgcms_form_fields/multitext_autocomplete.rb +5 -5
  31. data/app/models/drgcms_form_fields/readonly.rb +3 -0
  32. data/app/models/drgcms_form_fields/select.rb +8 -7
  33. data/app/models/drgcms_form_fields/text_autocomplete.rb +2 -2
  34. data/app/renderers/dc_part_renderer.rb +1 -1
  35. data/app/renderers/dc_poll_renderer.rb +1 -1
  36. data/app/views/cmsedit/_edit_stuff.html.erb +12 -12
  37. data/app/views/cmsedit/login.html.erb +1 -1
  38. data/app/views/dc_common/paste_clipboard.html.erb +1 -1
  39. data/config/locales/drgcms_en.yml +2 -1
  40. data/config/locales/drgcms_sl.yml +2 -1
  41. data/config/locales/kaminari.yml +1 -1
  42. data/drg_cms.gemspec +1 -1
  43. data/lib/drg_cms/version.rb +1 -1
  44. data/lib/drg_cms.rb +4 -4
  45. metadata +4 -5
  46. data/app/views/cmsedit/__remove_edit_stuff.js.erb +0 -6
  47. data/app/views/cmsedit/__show.html.erb +0 -21
@@ -24,124 +24,124 @@
24
24
  menu:
25
25
  10_system_menu:
26
26
  caption: drgcms.cms_main
27
- icon: support lg
27
+ icon: support
28
28
 
29
29
  items:
30
30
  10:
31
31
  caption: helpers.label.dc_site.tabletitle
32
32
  controller: cmsedit
33
- icon: globe lg
33
+ icon: public
34
34
  table: dc_site
35
35
  20:
36
36
  caption: helpers.label.dc_design.tabletitle
37
37
  controller: cmsedit
38
- icon: credit-card lg
38
+ icon: web
39
39
  table: dc_design
40
40
  30:
41
41
  caption: helpers.label.dc_page.tabletitle
42
42
  controller: cmsedit
43
- icon: file-text-o lg
43
+ icon: description-o
44
44
  table: dc_page
45
45
  50:
46
46
  caption: helpers.label.dc_piece.tabletitle
47
47
  controller: cmsedit
48
- icon: puzzle-piece lg
48
+ icon: extension-o
49
49
  table: dc_piece
50
50
  60:
51
51
  caption: helpers.label.dc_link.tabletitle
52
52
  controller: cmsedit
53
- icon: link lg
53
+ icon: link
54
54
  table: dc_link
55
55
  70:
56
56
  caption: helpers.label.dc_menu.tabletitle
57
57
  controller: cmsedit
58
- icon: th-list lg
58
+ icon: menu
59
59
  table: dc_menu
60
60
  80:
61
61
  caption: helpers.label.dc_simple_menu.tabletitle
62
62
  controller: cmsedit
63
- icon: ellipsis-h lg
63
+ icon: more_horiz-o
64
64
  table: dc_simple_menu
65
65
  90:
66
66
  caption: helpers.label.dc_category.tabletitle
67
67
  controller: cmsedit
68
- icon: list lg
68
+ icon: list
69
69
  table: dc_category
70
70
  100:
71
71
  caption: helpers.label.dc_poll.tabletitle
72
72
  controller: cmsedit
73
- icon: list-alt lg
73
+ icon: poll-o
74
74
  table: dc_poll
75
75
  110:
76
76
  caption: helpers.label.dc_poll_result.tabletitle
77
77
  controller: cmsedit
78
- icon: database lg
78
+ icon: leaderboard
79
79
  table: dc_poll_result
80
80
  120:
81
81
  caption: helpers.label.dc_ad.tabletitle
82
82
  controller: cmsedit
83
- icon: money lg
83
+ icon: ads_click
84
84
  table: dc_ad
85
85
 
86
86
  11_system_menu:
87
87
  caption: drgcms.cms_advanced
88
- icon: star lg
88
+ icon: star
89
89
  items:
90
90
  10:
91
91
  caption: helpers.label.dc_user.tabletitle
92
92
  controller: cmsedit
93
- icon: users lg
93
+ icon: account_circle-o
94
94
  table: dc_user
95
95
  20:
96
96
  caption: helpers.label.dc_policy_role.tabletitle
97
97
  controller: cmsedit
98
- icon: user-secret lg
98
+ icon: manage_accounts
99
99
  table: dc_policy_role
100
100
  30:
101
101
  caption: helpers.label.dc_permission.tabletitle
102
102
  controller: cmsedit
103
- icon: shield lg
103
+ icon: security
104
104
  table: dc_permission
105
105
  40:
106
106
  caption: helpers.label.dc_folder_permission.tabletitle
107
107
  controller: cmsedit
108
- icon: shield lg
108
+ icon: shield-o
109
109
  table: dc_folder_permission
110
110
  60:
111
111
  caption: helpers.label.dc_big_table.tabletitle
112
112
  controller: cmsedit
113
- icon: table lg
113
+ icon: topic-o
114
114
  table: dc_big_table
115
115
  70:
116
116
  caption: helpers.label.dc_key_value_store.tabletitle
117
117
  controller: cmsedit
118
- icon: list lg
118
+ icon: view_list
119
119
  table: dc_key_value_store
120
120
  80:
121
121
  caption: helpers.label.dc_filter.tabletitle
122
122
  controller: cmsedit
123
- icon: filter lg
123
+ icon: topic-o
124
124
  table: dc_filter
125
125
  90:
126
126
  caption: helpers.label.dc_removed_url.tabletitle
127
127
  controller: cmsedit
128
- icon: trash-o lg
128
+ icon: link_off
129
129
  table: dc_removed_url
130
130
  400:
131
131
  caption: drgcms.dc_help.title
132
132
  controller: cmsedit
133
- icon: question-circle lg
133
+ icon: help-o
134
134
  table: dc_temp
135
135
  form_name: dc_help_1
136
136
  500:
137
137
  caption: helpers.label.dc_journal.tabletitle
138
138
  controller: cmsedit
139
- icon: history lg
139
+ icon: history
140
140
  table: dc_journal
141
141
 
142
142
  600:
143
143
  caption: drgcms.browse_collections
144
144
  controller: cmsedit
145
- icon: table lg
145
+ icon: list_alt
146
146
  table: dc_memory
147
147
  form_name: dc_browse_models
@@ -6,27 +6,31 @@ controls: browse_models
6
6
  permissions:
7
7
  can_view: admin
8
8
 
9
+ index:
10
+ actions:
11
+ 1: back
12
+
9
13
  result_set:
10
- filter: fields
11
- tr_style:
12
- eval: "document['field'] == document['description'] ? 'color: #669;' : 'color: #000;'"
14
+ filter: all_fields
13
15
 
14
16
  columns:
15
17
  10:
16
18
  name: collection
17
19
  caption: Collection
18
- td_style: 'width: 150px;'
19
- 20:
20
+ width: 10%
21
+ 20:
20
22
  name: field
21
23
  caption: Field name
22
- td_style: 'width: 150px;'
23
- 30:
24
+ 30:
24
25
  name: type
25
26
  caption: Field type
26
- 40:
27
+ 40:
27
28
  name: description
28
29
  caption: description
29
- 50:
30
+ width: 25%
31
+ style:
32
+ eval: "document['field'] == document['description'] ? 'color: #f43;' : 'color: #000;'"
33
+ 50:
30
34
  name: _default
31
35
  caption: Default
32
36
 
@@ -8,7 +8,7 @@ form:
8
8
  type: script
9
9
  caption: drgcms.back
10
10
  js: 'history.back();'
11
- icon: arrow-left
11
+ icon: arrow_back
12
12
 
13
13
  3:
14
14
  type: ajax
@@ -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(some_value)
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(value=false)
231
- dc_dont?(value, true) ? fa_icon('square-o lg') : fa_icon('check-square-o lg')
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(value=false) #nodoc
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(value)
241
+ dc_icon_for_boolean(document, field_name)
240
242
  end
241
243
 
242
244
  ############################################################################
@@ -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[:form_name]}")
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('spinner lg spin')}</span><ul class="dc-menu #{position}">]
140
+ html = %Q[<span class="dc-spinner">#{fa_icon('settings-o spin')}</span><ul class="dc-menu #{position}">]
141
141
 
142
142
  actions.each do |key, options|
143
143
  session[:form_processing] = "form:actions: #{key} #{options}"
144
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 class="dc-link dc-animate">'
150
- html << case
151
- when (options == 'back' or options == 'cancle') then
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','arrow-left', parms['return_to'] )
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','arrow-left', parms )
159
+ dc_link_to( 'drgcms.back', 'arrow_back', parms, class: 'dc-link' )
159
160
  end
160
161
 
161
- when options == 'delete' then
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' then
167
+ when options == 'new'
167
168
  parms['action'] = options
168
- dc_link_to( 'drgcms.new', 'plus', parms)
169
+ dc_link_to( 'drgcms.new', 'add', parms, class: 'dc-link')
169
170
 
170
- when (options == 'enable' or options == 'disable') then
171
+ when (options == 'enable' || options == 'disable')
171
172
  parms['operation'] = options
172
173
  parms['id'] = @record.id
173
- icon = (options == 'enable' ? 'thumbs-o-up' : 'thumbs-o-down')
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' then
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' then
182
- "<div onclick='window.location.href=window.location.href;'>#{fa_icon('refresh')} #{t('drgcms.refresh')}</div></li>"
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' then
185
+ when options == 'close'
185
186
  close = params[:window_close].to_i
186
187
  if close < 2
187
- "<div onclick='window.close();'>#{fa_icon('close')} #{t('drgcms.close')}</div></li>"
188
+ %(<div class="dc-link" onclick='window.close();'>#{fa_icon('close')} #{t('drgcms.close')}</div></li>)
188
189
  else
189
- "<div onclick='history.back();'>#{fa_icon('close')} #{t('drgcms.close')}</div></li>"
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
- prms = {}
207
- options['params'].each { |k,v| prms[k] = dc_value_for_parameter(v) } if options['params']
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 class="dc-link-submit dc-animate">' +
210
- dc_submit_tag(caption, icon, {:data => prms, :title => options['title'] }) +
210
+ '<li>' +
211
+ dc_submit_tag(caption, icon, { data: parameters, title: options['title'] }) +
211
212
  '</li>'
212
213
  else
213
- "<li class=\"dc-link-no\">#{fa_icon(icon)} #{caption}</li>"
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="dc-link dc-animate">' +
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
@@ -409,6 +411,7 @@ def dc_head_for_form
409
411
  @css ||= ''
410
412
  head = @form['form']['head']
411
413
  return '' if head.nil?
414
+
412
415
  html = %(<div class="dc-head #{head['class']}">\n<div class="dc-row">)
413
416
  split = head['split'] || 4
414
417
  percent = 100/split
@@ -470,29 +473,33 @@ end
470
473
  # + lots of more. At the moment also adds icon for dumping current document as json text.
471
474
  ############################################################################
472
475
  def dc_document_statistics
473
- return '' if @record.new_record? or dc_dont?(@form['form']['info'])
474
- html = %Q[<div id="dc-document-info">#{fa_icon('info-circle lg')}</div> <div id="dc-document-info-popup" class="div-hidden"> ]
475
- #
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">)
476
479
  u = dc_document_user_for('created_by')
477
- html << %Q[<div><span>#{t('drgcms.created_by', 'Created by')}: </span><span>#{u}</span></div>] if u
480
+ html << %(<div><span>#{t('drgcms.created_by', 'Created by')}: </span><span>#{u}</span></div>) if u
478
481
  u = dc_document_user_for('updated_by')
479
- html << %Q[<div><span>#{t('drgcms.updated_by', 'Updated by')}: </span><span>#{u}</span></div>] if u
480
- html << %Q[<div><span>#{t('drgcms.created_at', 'Created at')}: </span><span>#{dc_format_value(@record.created_at)}</span></div>] if @record['created_at']
481
- html << %Q[<div><span>#{t('drgcms.updated_at', 'Updated at')}: </span><span>#{dc_format_value(@record.updated_at)}</span></div>] if @record['updated_at']
482
- # copy to clipboard icon
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
483
487
  parms = params.clone
484
488
  parms[:controller] = 'dc_common'
485
489
  parms[:action] = 'copy_clipboard'
486
490
  url = url_for(parms.permit!)
487
- html << fa_icon('copy lg', class: 'dc-link-img dc-link-ajax dc-animate',
491
+ html << fa_icon('content_copy-o md-18', class: 'dc-link-img dc-link-ajax',
488
492
  'data-url' => url, 'data-request' => 'get', title: t('drgcms.doc_copy_clipboard') )
489
493
 
490
- url = url_for(controller: :cmsedit, action: :index, table: 'dc_journal', filter: 'on',
494
+ url = url_for(controller: 'cmsedit', action: :index, table: 'dc_journal', filter: 'on',
491
495
  filter_oper: 'eq', filter_field: 'doc_id', filter_value: @record.id)
492
- html << fa_icon('history lg', class: 'dc-link-img dc-animate dc-window-open',
496
+ html << fa_icon('history md-18', class: 'dc-link-img dc-window-open',
493
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
494
501
 
495
- (html << '</div></div>').html_safe
502
+ (html << '</div>').html_safe
496
503
  end
497
504
 
498
505
  private
@@ -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
38
  data = %(data-request="script" data-script="#{yaml['js'] || yaml['script']}" data-url="script")
41
- %Q[<li class="dc-link-ajax dc-animate" #{data}>#{icon} #{ t(yaml['caption'],yaml['caption']) }</li>]
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 tabname, second is data
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 and v['name'] == name) }
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
- %Q[<li class="no-background">#{field}</li>]
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
- yaml.inject(' ') {|result, e| result = e.last.nil? ? result : result << "#{e.first}=\"#{e.last}\" "}
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
  #
@@ -184,12 +190,12 @@ end
184
190
  ############################################################################
185
191
  def dc_link_ajax_window_submit_action(yaml, record = nil, action_active = true)
186
192
  parms = {}
187
- caption = yaml['caption'] || yaml['text']
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 "<li class=\"dc-link-no\">#{icon} #{caption}</li>"
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
- 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>]
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
- 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>]
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
- 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>]
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
- 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>]
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
- else
253
- '<li>Action Type error</li>'
254
- end
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