drg_cms 0.6.0.3 → 0.6.0.6

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 (68) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/drg_cms/drg_cms.js +259 -102
  3. data/app/assets/javascripts/drg_cms_cms.js +1 -1
  4. data/app/assets/stylesheets/drg_cms/drg_cms.css +314 -142
  5. data/app/assets/stylesheets/drg_cms/select-multiple.css +11 -2
  6. data/app/controllers/cmsedit_controller.rb +313 -236
  7. data/app/controllers/dc_application_controller.rb +29 -4
  8. data/app/controllers/dc_common_controller.rb +19 -16
  9. data/app/{controllers → controls}/browse_models_control.rb +0 -0
  10. data/app/{controllers → controls}/dc_page_control.rb +24 -8
  11. data/app/controls/dc_poll_result_control.rb +88 -0
  12. data/app/{controllers → controls}/design_element_settings_control.rb +0 -0
  13. data/app/forms/all_options.yml +11 -3
  14. data/app/forms/cms_menu.yml +22 -18
  15. data/app/forms/dc_design.yml +6 -3
  16. data/app/forms/dc_filter.yml +3 -6
  17. data/app/forms/dc_poll_result.yml +74 -0
  18. data/app/forms/dc_poll_result_export.yml +35 -0
  19. data/app/helpers/cmsedit_edit_helper.rb +471 -0
  20. data/app/helpers/cmsedit_helper.rb +151 -821
  21. data/app/helpers/cmsedit_index_helper.rb +567 -0
  22. data/app/helpers/dc_application_helper.rb +48 -31
  23. data/app/models/{dc_dummy.rb → __dc_dummy.rb} +0 -0
  24. data/app/models/dc_filter.rb +12 -5
  25. data/app/models/dc_memory.rb +8 -1
  26. data/app/models/dc_poll.rb +38 -19
  27. data/app/models/dc_poll_result.rb +44 -0
  28. data/app/models/dc_temp.rb +137 -0
  29. data/app/models/drgcms_form_fields/action.rb +61 -0
  30. data/app/models/drgcms_form_fields/comment.rb +8 -4
  31. data/app/models/drgcms_form_fields/date_picker.rb +7 -6
  32. data/app/models/drgcms_form_fields/date_select.rb +1 -1
  33. data/app/models/drgcms_form_fields/datetime_picker.rb +8 -7
  34. data/app/models/drgcms_form_fields/datetime_select.rb +1 -1
  35. data/app/models/drgcms_form_fields/drgcms_field.rb +39 -7
  36. data/app/models/drgcms_form_fields/embedded.rb +7 -2
  37. data/app/models/drgcms_form_fields/file_field.rb +52 -0
  38. data/app/models/drgcms_form_fields/html_field.rb +1 -1
  39. data/app/models/drgcms_form_fields/multitext_autocomplete.rb +7 -4
  40. data/app/models/drgcms_form_fields/number_field.rb +15 -6
  41. data/app/models/drgcms_form_fields/radio.rb +91 -0
  42. data/app/models/drgcms_form_fields/readonly.rb +1 -1
  43. data/app/models/drgcms_form_fields/select.rb +14 -2
  44. data/app/models/drgcms_form_fields/text_area.rb +1 -1
  45. data/app/models/drgcms_form_fields/text_autocomplete.rb +1 -1
  46. data/app/models/drgcms_form_fields/text_field.rb +1 -1
  47. data/app/models/drgcms_form_fields/text_with_select.rb +6 -3
  48. data/app/models/drgcms_form_fields/tree_select.rb +11 -3
  49. data/app/renderers/dc_poll_renderer.rb +29 -11
  50. data/app/views/cmsedit/{remove_edit_stuff.js.erb → __remove_edit_stuff.js.erb} +0 -0
  51. data/app/views/cmsedit/{show.html.erb → __show.html.erb} +0 -0
  52. data/app/views/cmsedit/_edit_stuff.html.erb +2 -4
  53. data/app/views/cmsedit/_form.html.erb +4 -3
  54. data/app/views/cmsedit/_result.html.erb +2 -3
  55. data/app/views/cmsedit/edit.html.erb +2 -1
  56. data/app/views/cmsedit/index.html.erb +6 -1
  57. data/app/views/cmsedit/new.html.erb +1 -1
  58. data/config/locales/drgcms_en.yml +7 -0
  59. data/config/locales/drgcms_sl.yml +8 -1
  60. data/config/locales/models_en.yml +13 -4
  61. data/config/locales/models_sl.yml +13 -2
  62. data/drg_cms.gemspec +1 -1
  63. data/lib/drg_cms.rb +1 -0
  64. data/lib/drg_cms/version.rb +1 -1
  65. data/lib/generators/new_drg_form/new_drg_form_generator.rb +7 -2
  66. metadata +20 -13
  67. data/app/assets/stylesheets/drg_cms/__jquery-ui.css +0 -339
  68. data/test/fixtures/drg_cms_test_data.rb +0 -87
@@ -0,0 +1,74 @@
1
+ ## Form for retrieveng poll results
2
+ ---
3
+ table: dc_poll_result
4
+
5
+ index:
6
+ actions:
7
+ 10:
8
+ type: field
9
+ name: dc_poll_id
10
+
11
+ 30:
12
+ type: field
13
+ name: start_date
14
+ field_type: date_picker
15
+
16
+ 40:
17
+ type: field
18
+ name: end_date
19
+ field_type: date_picker
20
+ options:
21
+ openOnFocus: false
22
+
23
+ 50:
24
+ type: ajax
25
+ caption: drgcms.filter_poll
26
+ title: drgcms.filter_poll_title
27
+ icon: filter
28
+ controller: cmsedit
29
+ action: run
30
+ control: dc_poll_result.do_filter
31
+ method: post
32
+
33
+ 60:
34
+ type: ajax
35
+ caption: drgcms.export_poll
36
+ title: drgcms.export_poll_title
37
+ controller: cmsedit
38
+ icon: table
39
+ action: run
40
+ control: dc_poll_result.do_export
41
+ method: post
42
+
43
+ result_set:
44
+ actions: standard
45
+ filter: poll_filter
46
+
47
+ columns:
48
+ 10:
49
+ name: dc_poll_id
50
+ eval: dc_name4_id,dc_poll,name
51
+ width: 25%
52
+ 20:
53
+ name: created_at
54
+ format: '%d.%m.%Y %H:%M'
55
+ width: 10%
56
+
57
+ form:
58
+ actions:
59
+ 1: back
60
+ 2: save&back
61
+
62
+ fields:
63
+ 10:
64
+ name: dc_poll_id
65
+ type: select
66
+ eval: "dc_choices4('dc_poll','name','_id')"
67
+ 20:
68
+ name: data
69
+ type: text_area
70
+ size: 100x25
71
+ 30:
72
+ name: created_at
73
+ type: readonly
74
+ format: '%d.%m.%Y %H:%M'
@@ -0,0 +1,35 @@
1
+ ## Form for retrieveng poll results
2
+ ---
3
+ table: dc_memory
4
+
5
+ form:
6
+ actions:
7
+ 1:
8
+ type: script
9
+ caption: drgcms.back
10
+ js: 'history.back();'
11
+ icon: arrow-left
12
+
13
+ 3:
14
+ type: ajax
15
+ caption: drgcms.export_poll
16
+ title: drgcms.export_poll_title
17
+ icon: cog
18
+ controller: cmsedit
19
+ action: run
20
+ method: post
21
+ control: poll.export
22
+
23
+ fields:
24
+ 10:
25
+ name: dc_poll_id
26
+ type: select
27
+ eval: "dc_choices4('dc_poll','name','_id')"
28
+ 20:
29
+ name: date_start
30
+ type: date_picker
31
+ size: 8
32
+ 30:
33
+ name: date_end
34
+ type: date_picker
35
+ size: 8
@@ -0,0 +1,471 @@
1
+ #--
2
+ # Copyright (c) 2012+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ ###########################################################################
25
+ #
26
+ # CmseditHelper module defines helper methods used by cmsedit actions. Output is controlled by
27
+ # data found in 3 major sections of DRG CMS form: index, result_set and form sections.
28
+ #
29
+ ###########################################################################
30
+ module CmseditEditHelper
31
+
32
+ ############################################################################
33
+ # Will return value when internal or additional parameters are defined in action
34
+ # Subroutine of dc_actions_for_form.
35
+ ############################################################################
36
+ def dc_value_for_parameter(param)#:nodoc:
37
+ if param.class == Hash
38
+ dc_internal_var(param['object'] || 'record', param['method'])
39
+ else
40
+ param
41
+ end
42
+ end
43
+
44
+ ############################################################################
45
+ # Creates actions div for edit form.
46
+ #
47
+ # Displaying readonly form turned out to be challenge. For now when readonly parameter
48
+ # has value 2, back link will force readonly form. Value 1 or not set will result in
49
+ # normal link.
50
+ ############################################################################
51
+ def dc_is_action_active?(options)
52
+ if options['when_new']
53
+ dc_deprecate("when_option will be deprecated and replaced by active: not_new_record! Form #{params[:form_name]}")
54
+ return !(dc_dont?(options['when_new']) and @record.new_record?)
55
+ end
56
+ return true unless options['active']
57
+ # alias record and document so both can be used in eval
58
+ record = document = @record
59
+ option = options['active']
60
+ case
61
+ # usually only for test
62
+ when option.class == TrueClass || option['eval'].class == TrueClass then true
63
+ when option.class == String then
64
+ (@record.new_record? && option == 'new_record') || (!@record.new_record? && option == 'not_new_record')
65
+ # direct evaluate expression
66
+ when option['eval'] then
67
+ eval(option['eval'])
68
+ when option['method'] then
69
+ # if record present send record otherwise send params as parameter
70
+ parms = @record ? @record : params
71
+ dc_process_eval(option['method'],parms)
72
+ else
73
+ false
74
+ end
75
+ end
76
+
77
+ ############################################################################
78
+ # Creates actions div for edit form.
79
+ #
80
+ # Displaying readonly form turned out to be challenge. For now when readonly parameter
81
+ # has value 2, back link will force readonly form. Value 1 or not set will result in
82
+ # normal link.
83
+ ############################################################################
84
+ def dc_actions_for_form(position)
85
+ # create standard actions
86
+ std_actions = {1 => 'back', 2 => {'type' => 'submit', 'caption' => 'drgcms.save'},
87
+ 3 => {'type' => 'submit', 'caption' => 'drgcms.save&back'} }
88
+ # when edit only
89
+ unless @record.try(:id).nil?
90
+ std_actions.merge!({6 => 'new'} )
91
+ std_actions.merge!(@record.active ? {5 => 'disable'} : {5 => 'enable'} ) if @record.respond_to?('active')
92
+ std_actions.merge!({7 => 'refresh'} )
93
+ end
94
+ actions = @form['form']['actions']
95
+ # shortcut for actions: standard
96
+ actions = nil if actions.class == String && actions == 'standard'
97
+ # standard actions
98
+ actions = std_actions if actions.nil?
99
+ # readonly
100
+ actions = {1 => 'back'} if @form['readonly']
101
+ # Actions are strictly forbidden
102
+ if @form['form']['actions'] and dc_dont?(@form['form']['actions'])
103
+ actions = []
104
+ elsif actions['standard']
105
+ actions.merge!(std_actions)
106
+ actions['standard'] = nil
107
+ end
108
+ # Update save and save&back
109
+ actions.each do |k,v|
110
+ if v.class == String
111
+ if v.match(/save\&back/i)
112
+ actions[k] = {'type' => 'submit', 'caption' => 'drgcms.save&back'}
113
+ elsif v == 'save'
114
+ actions[k] = {'type' => 'submit', 'caption' => 'drgcms.save'}
115
+ end
116
+ end
117
+ end
118
+ # remove standard option and sort so that standard actions come first
119
+ actions.delete('standard')
120
+ actions = actions.to_a.sort {|x,y| x[0] <=> y[0]}
121
+ # Add spinner to the beginning
122
+ html = %Q[<span class="dc-spinner">#{fa_icon('spinner lg spin')}</span><ul class="dc-menu #{position}">]
123
+
124
+ actions.each do |key, options|
125
+ session[:form_processing] = "form:actions: #{key} #{options}"
126
+ next if options.nil? # yes it happends
127
+ parms = @parms.clone
128
+ if options.class == String
129
+ next if params[:readonly] and !(options == 'back')
130
+
131
+ html << '<li class="dc-link dc-animate">'
132
+ html << case
133
+ when (options == 'back' or options == 'cancle') then
134
+ # If return_to is present link directly to URL
135
+ if parms['xreturn_to'] # disabled for now
136
+ dc_link_to( 'drgcms.back','arrow-left', parms['return_to'] )
137
+ else
138
+ parms['action'] = 'index'
139
+ parms['readonly'] = parms['readonly'].to_s.to_i < 2 ? nil : 1
140
+ dc_link_to( 'drgcms.back','arrow-left', parms )
141
+ end
142
+
143
+ when options == 'delete' then
144
+ parms['operation'] = options
145
+ parms['id'] = @record.id
146
+ dc_link_to( 'drgcms.delete','remove', parms, data: { confirm: t('drgcms.confirm_delete') }, method: :delete )
147
+
148
+ when options == 'new' then
149
+ parms['action'] = options
150
+ dc_link_to( 'drgcms.new', 'plus', parms)
151
+
152
+ when (options == 'enable' or options == 'disable') then
153
+ parms['operation'] = options
154
+ parms['id'] = @record.id
155
+ icon = (options == 'enable' ? 'thumbs-o-up' : 'thumbs-o-down')
156
+ dc_link_to( "drgcms.#{options}",icon, parms, method: :delete )
157
+
158
+ when options == 'edit' then
159
+ parms['operation'] = options
160
+ parms['id'] = @record.id
161
+ dc_link_to( "drgcms.#{options}",options, parms )
162
+
163
+ when options == 'refresh' then
164
+ "<div onclick='window.location.href=window.location.href;'>#{fa_icon('refresh')} #{t('drgcms.refresh')}</div></li>"
165
+ else
166
+ "err1 #{key}=>#{options}"
167
+ end
168
+ html << '</td>'
169
+ # non standard actions
170
+ else
171
+ options['title'] = t("#{options['title'].downcase}", options['title']) if options['title']
172
+ html << case
173
+ # submit button
174
+ when options['type'] == 'submit'
175
+ caption = options['caption'] || 'drgcms.save'
176
+ icon = options['icon'] || 'save'
177
+ prms = {}
178
+ options['params'].each { |k,v| prms[k] = dc_value_for_parameter(v) } if options['params']
179
+ if dc_is_action_active?(options)
180
+ '<li class="dc-link-submit dc-animate">' +
181
+ dc_submit_tag(caption, icon, {:data => prms, :title => options['title'] }) +
182
+ '</li>'
183
+ else
184
+ "<li class=\"dc-link-no\">#{fa_icon(icon)} #{caption}</li>"
185
+ end
186
+
187
+ # delete with some sugar added
188
+ when options['type'] == 'delete'
189
+ parms['id'] = @record.id
190
+ parms.merge!(options['params'])
191
+ caption = options['caption'] || 'drgcms.delete'
192
+ icon = options['icon'] || 'remove'
193
+ '<li class="dc-link dc-animate">' +
194
+ dc_link_to( caption, icon, parms, data: t('drgcms.confirm_delete'), method: :delete ) +
195
+ '</li>'
196
+
197
+ # ajax or link button
198
+ when %w(ajax link window).include?(options['type'])
199
+ dc_link_ajax_window_submit_action(options, @record)
200
+
201
+ # Javascript action
202
+ when options['type'] == 'script'
203
+ dc_script_action(options)
204
+ else
205
+ '<li>err2</li>'
206
+ end
207
+ end
208
+ end
209
+ (html << '</ul>').html_safe
210
+ end
211
+
212
+ ############################################################################
213
+ # Create background div and table definitions for result set.
214
+ ############################################################################
215
+ def dc_background_for_result(start)
216
+ if start == :start
217
+ html = '<div class="dc-result-div" '
218
+ html << (@form['result_set']['table_style'] ? 'style="overflow-x: scroll;" >' : '>')
219
+ #
220
+ html << "\n<div class=\"dc-result #{@form['result_set']['table_class']}\" "
221
+ html << (@form['result_set']['table_style'] ? "style=\"#{@form['result_set']['table_style']}\" >" : '>')
222
+ else
223
+ html = '</div></div>'
224
+ end
225
+ html.html_safe
226
+ end
227
+
228
+ ############################################################################
229
+ # Checks if value is defined and sets default. If values are sent it also checks
230
+ # if value is found in values. If not it will report error and set value to default.
231
+ # Subroutine of dc_fields_for_tab.
232
+ ############################################################################
233
+ def dc_check_and_default(value, default, values=nil) #:nodoc:
234
+ return default if value.nil?
235
+ # check if value is within allowed values
236
+ if values
237
+ if !values.index(value)
238
+ # parameters should be in downcase. Check downcase version.
239
+ if n = values.index(value.downcase)
240
+ return values[n]
241
+ else
242
+ logger.error("DRG Forms: Value #{value} not within values [#{values.join(',')}]. Default #{default} used!")
243
+ return default
244
+ end
245
+ end
246
+ end
247
+ value
248
+ end
249
+
250
+ ############################################################################
251
+ # Creates top or bottom horizontal line on form.
252
+ ############################################################################
253
+ def dc_top_bottom_line(options)
254
+ '<div class="dc-separator"></div>'
255
+ end
256
+
257
+ ############################################################################
258
+ # Creates input fields for one tab. Subroutine of dc_fields_for_form.
259
+ ############################################################################
260
+ def dc_fields_for_tab(fields_on_tab) #:nodoc:
261
+ html = '<div class="dc-form">'
262
+ labels_pos = dc_check_and_default(@form['form']['labels_pos'], 'right', ['top','left','right'])
263
+ hidden_fields = ''
264
+ odd_even = nil
265
+ group_option, group_count = 0, 0
266
+ reset_cycle()
267
+ # Select form fields and sort them by key
268
+ form_fields = fields_on_tab.select {|field| field.class == Integer }
269
+ form_fields.to_a.sort.each do |number, options|
270
+ session[:form_processing] = "form:fields: #{number}=#{options}"
271
+ # ignore if edit_only singe field is required
272
+ next if params[:edit_only] and params[:edit_only] != options['name']
273
+ # hidden_fields. Add them at the end
274
+ if options['type'] == 'hidden_field'
275
+ hidden_fields << DrgcmsFormFields::HiddenField.new(self, @record, options).render
276
+ next
277
+ end
278
+ # label
279
+ field_html,label,help = dc_field_label_help(options)
280
+ # Line separator
281
+ html << dc_top_bottom_line(options['top-line']) if options['top-line']
282
+ # Begining of new row
283
+ if group_count == 0
284
+ html << '<div class="row-div">'
285
+ odd_even = cycle('odd','even')
286
+ group_count = options['group'] || 1
287
+ group_option = options['group'] || 1
288
+ end
289
+ #
290
+ html << if labels_pos == 'top'
291
+ %Q[
292
+ <div class="dc-form-label-top dc-color-#{odd_even} dc-align-left" title="#{help}">
293
+ <label for="record_#{options['name']}">#{label} </label>
294
+ <div id="td_record_#{options['name']}">#{field_html}</div>
295
+ </div> ]
296
+ else
297
+ # no label
298
+ if dc_dont?(options['caption'])
299
+ label = ''
300
+ label_width = 0
301
+ data_width = 100
302
+ elsif group_option > 1
303
+ label_width = group_option != group_count ? 10 : 14
304
+ data_width = 21
305
+ else
306
+ label_width = 14
307
+ data_width = 85
308
+ end
309
+ %Q[
310
+ <div class="dc-form-label dc-color-#{odd_even} dc-align-#{labels_pos} dc-width-#{label_width}" title="#{help}">
311
+ <label for="record_#{options['name']}">#{label} </label>
312
+ </div>
313
+ <div id="td_record_#{options['name']}" class="dc-form-field dc-color-#{odd_even} dc-width-#{data_width}">#{field_html}</div>
314
+ ]
315
+ end
316
+ # check if group end
317
+ if (group_count -= 1) == 0
318
+ html << '</div>'
319
+ # insert dummy div when only two fields in group
320
+ html << '<div></div>' if group_option == 2
321
+ end
322
+
323
+ html << dc_top_bottom_line(options['bottom-line']) if options['bottom-line']
324
+ end
325
+ html << '</div>' << hidden_fields
326
+ end
327
+
328
+ ############################################################################
329
+ # Creates edit form div.
330
+ ############################################################################
331
+ def dc_fields_for_form()
332
+ html, tabs, tab_data = '',[], ''
333
+ @js ||= ''
334
+ @css ||= ''
335
+ # Only fields defined
336
+ if (form_fields = @form['form']['fields'])
337
+ html << "<div id='data_fields' " + (@form['form']['height'] ? "style=\"height: #{@form['form']['height']}px;\">" : '>')
338
+ html << dc_fields_for_tab(form_fields) + '</div>'
339
+ else
340
+ # there are multiple tabs on form
341
+ first = true # first tab
342
+ @form['form']['tabs'].keys.sort.each do |tab_name|
343
+ next if tab_name.match('actions')
344
+ # Tricky. If field name is not on the tab skip to next tab
345
+ if params[:edit_only]
346
+ is_on_tab = false
347
+ @form['form']['tabs'][tab_name].each {|k,v| is_on_tab = true if params[:edit_only] == v['name'] }
348
+ next unless is_on_tab
349
+ end
350
+ # first div is displayed, all others are hidden
351
+ tab_data << "<div id=\"data_#{tab_name.delete("\s\n")}\""
352
+ tab_data << ' class="div-hidden"' unless first
353
+ tab_data << " style=\"height: #{@form['form']['height']}px;\"" if @form['form']['height']
354
+ tab_data << ">#{dc_fields_for_tab(@form['form']['tabs'][tab_name])}</div>"
355
+ tab_label = @form['form']['tabs'][tab_name]['caption'] || tab_name
356
+ tabs << [tab_name, tab_label]
357
+ first = false
358
+ end
359
+ # make it all work together
360
+ html << '<ul class="dc-form-ul" >'
361
+ first = true # first tab must be selected
362
+ tabs.each do |tab_name, tab_label|
363
+ html << "<li id=\"li_#{tab_name}\" data-div=\"#{tab_name.delete("\s\n")}\" class=\"dc-form-li"
364
+ html << ' dc-form-li-selected' if first
365
+ html << "\">#{t(tab_label, t_name(tab_label,tab_label))}</li>"
366
+ first = false
367
+ end
368
+ html << '</ul>'
369
+ html << tab_data
370
+ end
371
+ # add last_updated_at hidden field so controller can check if record was updated in db during editing
372
+ html << hidden_field(nil, :last_updated_at, value: @record.updated_at.to_i) if @record.respond_to?(:updated_at)
373
+ # add form time stamp to prevent double form submit
374
+ html << hidden_field(nil, :form_time_stamp, value: Time.now.to_i)
375
+ # add javascript code if defined by form
376
+ @js << "\n#{@form['script']}"
377
+ @css << "\n#{@form['css']}"
378
+ html.html_safe
379
+ end
380
+
381
+
382
+ ############################################################################
383
+ # Creates head form div. Head form div is used to display header datausefull
384
+ # to be seen even when tabs are switched.
385
+ ############################################################################
386
+ def dc_head_for_form()
387
+ @css ||= ''
388
+ head = @form['form']['head']
389
+ return '' if head.nil?
390
+ html = %Q[<div class="dc-head #{head['class']}">\n<div class="dc-row">]
391
+ split = head['split'] || 4
392
+ percent = 100/split
393
+ current = 0
394
+ head_fields = head.select {|field| field.class == Integer }
395
+ head_fields.to_a.sort.each do |number, options|
396
+ session[:form_processing] = "form: head: #{number}=#{options}"
397
+ # Label
398
+ caption = options['caption']
399
+ span = options['span'] || 1
400
+ @css << "\n#{options['css']}" unless options['css'].blank?
401
+ label = if caption.blank?
402
+ ''
403
+ elsif options['name'] == caption
404
+ t_name(options['name'], options['name'].capitalize.gsub('_',' ') )
405
+ else
406
+ t(caption, caption)
407
+ end
408
+ # Field value
409
+ begin
410
+ field = if options['eval']
411
+ dc_process_column_eval(options, @record)
412
+ else
413
+ @record.send(options['name'])
414
+ end
415
+ rescue Exception => e
416
+ dc_log_exception(e)
417
+ field = '!!!Error'
418
+ end
419
+ #
420
+ klass = dc_style_or_class(nil, options['class'], field, @record)
421
+ style = dc_style_or_class(nil, options['style'], field, @record)
422
+ html << %Q[<div class="dc-column #{klass}" style="width:#{percent*span}%;#{style}">
423
+ #{label.blank? ? '' : "<span class=\"label\">#{label}</span>"}
424
+ <span class="field">#{field}</span>
425
+ </div>]
426
+ current += span
427
+ if current == split
428
+ html << %Q[</div>\n<div class="dc-row">]
429
+ current = 0
430
+ end
431
+ end
432
+ html << '</div></div>'
433
+ html.html_safe
434
+ end
435
+
436
+ ############################################################################
437
+ # Returns username for id. Subroutine of dc_document_statistics
438
+ ###########################################################################
439
+ def dc_document_user_for(field_name) #:nodoc:
440
+ if @record[field_name]
441
+ u = DcUser.find(@record[field_name])
442
+ return u ? u.name : @record[field_name]
443
+ end
444
+ # nil
445
+ end
446
+
447
+ ############################################################################
448
+ # Creates current document statistics div (created_by, created_at, ....) at the bottom of edit form.
449
+ # + lots of more. At the moment also adds icon for dumping current document as json text.
450
+ ############################################################################
451
+ def dc_document_statistics
452
+ return '' if @record.new_record? or dc_dont?(@form['form']['info'])
453
+ html = %Q[<div id="dc-document-info">#{fa_icon('info-circle lg')}</div> <div id="dc-document-info-popup" class="div-hidden"> ]
454
+ #
455
+ u = dc_document_user_for('created_by')
456
+ html << %Q[<div><span>#{t('drgcms.created_by', 'Created by')}: </span><span>#{u}</span></div>] if u
457
+ u = dc_document_user_for('updated_by')
458
+ html << %Q[<div><span>#{t('drgcms.updated_by', 'Updated by')}: </span><span>#{u}</span></div>] if u
459
+ html << %Q[<div><span>#{t('drgcms.created_at', 'Created at')}: </span><span>#{dc_format_value(@record.created_at)}</span></div>] if @record['created_at']
460
+ html << %Q[<div><span>#{t('drgcms.updated_at', 'Updated at')}: </span><span>#{dc_format_value(@record.updated_at)}</span></div>] if @record['updated_at']
461
+ # copy to clipboard icon
462
+ parms = params.clone
463
+ parms[:controller] = 'dc_common'
464
+ parms[:action] = 'copy_clipboard'
465
+ url = url_for(parms.permit!)
466
+ html << fa_icon('copy 2x', class: 'dc-link-img dc-link-ajax dc-animate',
467
+ 'data-url' => url, 'data-request' => 'get', title: t('drgcms.doc_copy_clipboard') )
468
+ (html << '</div></div>').html_safe
469
+ end
470
+
471
+ end