drg_cms 0.6.1.1.1 → 0.6.1.4
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 +25 -10
- data/app/assets/javascripts/drg_cms/drg_cms.js +99 -29
- data/app/assets/stylesheets/drg_cms/drg_cms.css +89 -12
- data/app/controllers/dc_application_controller.rb +60 -163
- data/app/controllers/dc_common_controller.rb +49 -45
- data/app/forms/all_options.yml +4 -1
- data/app/forms/dc_page.yml +4 -0
- data/app/helpers/cms_edit_helper.rb +31 -22
- data/app/helpers/cms_index_helper.rb +42 -21
- data/app/helpers/dc_application_helper.rb +31 -44
- data/app/models/concerns/dc_page_concern.rb +3 -2
- data/app/models/concerns/dc_piece_concern.rb +1 -1
- data/app/models/concerns/dc_site_concern.rb +1 -1
- data/app/models/concerns/dc_user_concern.rb +3 -3
- data/app/models/dc_filter.rb +16 -10
- data/app/models/drgcms_form_fields/date_picker.rb +2 -0
- data/app/models/drgcms_form_fields/drgcms_field.rb +2 -1
- data/app/models/drgcms_form_fields/embedded.rb +4 -2
- data/app/models/drgcms_form_fields/number_field.rb +4 -3
- data/app/models/drgcms_form_fields/readonly.rb +13 -17
- data/app/models/drgcms_form_fields/select.rb +8 -9
- data/app/models/drgcms_form_fields/text_autocomplete.rb +17 -11
- data/app/renderers/dc_page_renderer.rb +7 -6
- data/app/views/cmsedit/_edit_stuff.html.erb +5 -2
- data/app/views/cmsedit/edit.html.erb +2 -1
- data/app/views/cmsedit/index.html.erb +1 -1
- data/app/views/cmsedit/new.html.erb +3 -2
- data/config/locales/models_en.yml +2 -0
- data/config/locales/models_sl.yml +4 -3
- data/drg_cms.gemspec +16 -16
- data/lib/drg_cms/version.rb +1 -1
- data/lib/drg_cms.rb +44 -4
- metadata +29 -29
data/app/forms/all_options.yml
CHANGED
@@ -141,6 +141,7 @@ form:
|
|
141
141
|
caption: ajax_call
|
142
142
|
control: control_name.method_to_call
|
143
143
|
when_new: false
|
144
|
+
show: default always readonly
|
144
145
|
5:
|
145
146
|
type: window
|
146
147
|
controller: cmsedit
|
@@ -251,6 +252,7 @@ form:
|
|
251
252
|
type: embedded
|
252
253
|
load: default,delay,always
|
253
254
|
form_name: dc_poll_item
|
255
|
+
readonly: no
|
254
256
|
html:
|
255
257
|
height: 800
|
256
258
|
20:
|
@@ -264,7 +266,8 @@ form:
|
|
264
266
|
40:
|
265
267
|
name: customer_id
|
266
268
|
type: text_autocomplete
|
267
|
-
search:
|
269
|
+
search: model_name.method.additional_parameter
|
270
|
+
search:
|
268
271
|
table: customer
|
269
272
|
field: custumer_name
|
270
273
|
method: search
|
data/app/forms/dc_page.yml
CHANGED
@@ -91,32 +91,40 @@ end
|
|
91
91
|
# normal link.
|
92
92
|
############################################################################
|
93
93
|
def dc_actions_for_form(position)
|
94
|
-
# create standard actions
|
94
|
+
# create standard actions
|
95
95
|
std_actions = {1 => 'back', 2 => {'type' => 'submit', 'caption' => 'drgcms.save'},
|
96
96
|
3 => {'type' => 'submit', 'caption' => 'drgcms.save&back'} }
|
97
|
-
# when edit only
|
97
|
+
# when edit only
|
98
98
|
unless @record.try(:id).nil?
|
99
99
|
std_actions.merge!({6 => 'new'} )
|
100
100
|
std_actions.merge!(@record.active ? {5 => 'disable'} : {5 => 'enable'} ) if @record.respond_to?('active')
|
101
101
|
std_actions.merge!({7 => 'refresh'} )
|
102
102
|
end
|
103
|
+
# readonly
|
104
|
+
std_actions = { 1 => 'back' } if @form['readonly']
|
105
|
+
|
103
106
|
actions = @form['form']['actions']
|
104
|
-
# shortcut for actions: standard
|
107
|
+
# shortcut for actions: standard
|
105
108
|
actions = nil if actions.class == String && actions == 'standard'
|
106
|
-
# standard actions
|
107
109
|
actions = std_actions if actions.nil?
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
# Actions are strictly forbidden
|
112
|
-
if @form['form']['actions'] and dc_dont?(@form['form']['actions'])
|
110
|
+
|
111
|
+
# Actions are strictly forbidden
|
112
|
+
if @form['form']['actions'] && dc_dont?(@form['form']['actions'])
|
113
113
|
actions = []
|
114
114
|
elsif actions['standard']
|
115
115
|
actions.merge!(std_actions)
|
116
116
|
actions['standard'] = nil
|
117
117
|
end
|
118
|
-
#
|
119
|
-
actions.
|
118
|
+
# request for close window button present
|
119
|
+
if actions.class == Hash
|
120
|
+
case params[:window_close]
|
121
|
+
when '0' then actions[1] = 'close'; actions[3] = nil
|
122
|
+
when '1' then actions = { 1 => 'close' }
|
123
|
+
when '2' then actions = { 1 => 'close' }
|
124
|
+
end
|
125
|
+
end
|
126
|
+
# Update save and save&back
|
127
|
+
actions.each do |k, v|
|
120
128
|
if v.class == String
|
121
129
|
if v.match(/save\&back/i)
|
122
130
|
actions[k] = {'type' => 'submit', 'caption' => 'drgcms.save&back'}
|
@@ -125,10 +133,10 @@ def dc_actions_for_form(position)
|
|
125
133
|
end
|
126
134
|
end
|
127
135
|
end
|
128
|
-
# remove standard option and sort so that standard actions come first
|
136
|
+
# remove standard option and sort so that standard actions come first
|
129
137
|
actions.delete('standard')
|
130
|
-
actions = actions.to_a.sort {|x,y| x[0] <=> y[0]}
|
131
|
-
# Add spinner to the beginning
|
138
|
+
actions = actions.to_a.sort { |x, y| x[0] <=> y[0] }
|
139
|
+
# Add spinner to the beginning
|
132
140
|
html = %Q[<span class="dc-spinner">#{fa_icon('spinner lg spin')}</span><ul class="dc-menu #{position}">]
|
133
141
|
|
134
142
|
actions.each do |key, options|
|
@@ -136,12 +144,12 @@ def dc_actions_for_form(position)
|
|
136
144
|
next if options.nil? # yes it happends
|
137
145
|
parms = @parms.clone
|
138
146
|
if options.class == String
|
139
|
-
next if
|
147
|
+
next if @form['readonly'] and !options.match(/back|close/)
|
140
148
|
|
141
149
|
html << '<li class="dc-link dc-animate">'
|
142
150
|
html << case
|
143
151
|
when (options == 'back' or options == 'cancle') then
|
144
|
-
# If return_to is present link directly to URL
|
152
|
+
# If return_to is present link directly to URL
|
145
153
|
if parms['xreturn_to'] # disabled for now
|
146
154
|
dc_link_to( 'drgcms.back','arrow-left', parms['return_to'] )
|
147
155
|
else
|
@@ -186,6 +194,9 @@ def dc_actions_for_form(position)
|
|
186
194
|
html << '</td>'
|
187
195
|
# non standard actions
|
188
196
|
else
|
197
|
+
# action will be displayed when show: always or readonly option is declared and form is readonly
|
198
|
+
next if @form['readonly'] && !%w[readonly always].include?(options['show'].to_s)
|
199
|
+
|
189
200
|
options['title'] = t("#{options['title'].downcase}", options['title']) if options['title']
|
190
201
|
html << case
|
191
202
|
# submit button
|
@@ -447,11 +458,10 @@ end
|
|
447
458
|
# Returns username for id. Subroutine of dc_document_statistics
|
448
459
|
###########################################################################
|
449
460
|
def dc_document_user_for(field_name) #:nodoc:
|
450
|
-
if @record[field_name]
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
# nil
|
461
|
+
return if @record[field_name].nil?
|
462
|
+
|
463
|
+
user = DcUser.find(@record[field_name])
|
464
|
+
user ? user.name : @record[field_name]
|
455
465
|
end
|
456
466
|
|
457
467
|
############################################################################
|
@@ -502,5 +512,4 @@ def dc_top_bottom_line(location, options)
|
|
502
512
|
end
|
503
513
|
end
|
504
514
|
|
505
|
-
|
506
515
|
end
|
@@ -32,14 +32,17 @@ module CmsIndexHelper
|
|
32
32
|
############################################################################
|
33
33
|
# Creates action div for cmsedit index action.
|
34
34
|
############################################################################
|
35
|
-
def dc_actions_for_index
|
35
|
+
def dc_actions_for_index
|
36
36
|
@js = @form['script'] || @form['js'] || ''
|
37
37
|
@css = @form['css'] || ''
|
38
|
-
return '' if @form['index'].nil?
|
38
|
+
return '' if @form['index'].nil?
|
39
|
+
|
39
40
|
actions = @form['index']['actions']
|
40
41
|
return '' if actions.blank?
|
41
42
|
|
42
43
|
std_actions = {2 => 'new', 3 => 'sort', 4 => 'filter' }
|
44
|
+
std_actions.delete(2) if @form['readonly']
|
45
|
+
|
43
46
|
if actions.class == String
|
44
47
|
actions = dc_define_standard_actions(actions, std_actions)
|
45
48
|
elsif actions['standard']
|
@@ -60,6 +63,7 @@ def dc_actions_for_index()
|
|
60
63
|
only_actions.each do |key, options|
|
61
64
|
session[:form_processing] = "index:actions: #{key}=#{options}"
|
62
65
|
next if options.nil? # must be
|
66
|
+
|
63
67
|
url = @parms.clone
|
64
68
|
yaml = options.class == String ? {'type' => options} : options # if single definition simulate type parameter
|
65
69
|
action = yaml['type'].to_s.downcase
|
@@ -114,9 +118,13 @@ def dc_actions_for_index()
|
|
114
118
|
dc_link_to(caption,'plus', url, yhtml )
|
115
119
|
|
116
120
|
# menu
|
117
|
-
when action == 'menu' then
|
118
|
-
|
119
|
-
|
121
|
+
when action == 'menu' then
|
122
|
+
if options['caption']
|
123
|
+
caption = t(options['caption'], options['caption']) + ' ' + fa_icon('caret-down lg')
|
124
|
+
caption + eval(options['eval'])
|
125
|
+
else # when caption is false, provide own actions
|
126
|
+
eval(options['eval'])
|
127
|
+
end
|
120
128
|
=begin
|
121
129
|
# reorder
|
122
130
|
when action == 'reorder' then
|
@@ -262,7 +270,7 @@ end
|
|
262
270
|
############################################################################
|
263
271
|
def dc_actions_for_result(document)
|
264
272
|
actions = @form['result_set']['actions']
|
265
|
-
return '' if actions.nil?
|
273
|
+
return '' if actions.nil? || @form['readonly']
|
266
274
|
|
267
275
|
actions, width = dc_actions_column()
|
268
276
|
html = %Q[<ul class="actions" style="width: #{width}px;">]
|
@@ -278,21 +286,27 @@ def dc_actions_for_result(document)
|
|
278
286
|
else
|
279
287
|
html << '<li class="dc-link">'
|
280
288
|
html << case
|
289
|
+
when yaml['type'] == 'check' then
|
290
|
+
check_box_tag("check-#{document.id}", false,false,{ class: 'dc-check' })
|
291
|
+
|
281
292
|
when yaml['type'] == 'edit' then
|
282
293
|
parms['action'] = 'edit'
|
283
294
|
parms['id'] = document.id
|
284
295
|
dc_link_to( nil, 'pencil lg', parms )
|
296
|
+
|
285
297
|
when yaml['type'] == 'duplicate' then
|
286
298
|
parms['id'] = document.id
|
287
299
|
# duplicate string will be added to these fields.
|
288
300
|
parms['dup_fields'] = yaml['dup_fields']
|
289
301
|
parms['action'] = 'create'
|
290
302
|
dc_link_to( nil, 'copy lg', parms, data: { confirm: t('drgcms.confirm_dup') }, method: :post )
|
303
|
+
|
291
304
|
when yaml['type'] == 'delete' then
|
292
305
|
parms['action'] = 'destroy'
|
293
306
|
parms['id'] = document.id
|
294
307
|
#parms['return_to'] = request.url
|
295
308
|
dc_link_to( nil, 'remove lg', parms, data: { confirm: t('drgcms.confirm_delete') }, method: :delete )
|
309
|
+
|
296
310
|
# undocumented so far
|
297
311
|
when yaml['type'] == 'edit_embedded'
|
298
312
|
parms['controller'] = 'cmsedit'
|
@@ -314,11 +328,14 @@ end
|
|
314
328
|
############################################################################
|
315
329
|
# Creates header div for result set.
|
316
330
|
############################################################################
|
317
|
-
def dc_header_for_result
|
331
|
+
def dc_header_for_result
|
318
332
|
html = '<div class="dc-result-header">'
|
319
333
|
if @form['result_set']['actions'] and !@form['readonly']
|
320
334
|
ignore, width = dc_actions_column()
|
321
|
-
|
335
|
+
if width > 0 && @form['result_set']['actions'][0].to_s == 'check'
|
336
|
+
check_all = fa_icon('check-square-o', class: 'dc-check-all')
|
337
|
+
end
|
338
|
+
html << %Q[<div class="actions" style="width:#{width}px;">#{check_all}</div>]
|
322
339
|
end
|
323
340
|
# preparation for sort icon
|
324
341
|
sort_field, sort_direction = nil, nil
|
@@ -336,7 +353,8 @@ def dc_header_for_result()
|
|
336
353
|
label = (v['name'] ? "helpers.label.#{@form['table']}.#{v['name']}" : '') if label.nil?
|
337
354
|
label = t(label) if label.match(/\./)
|
338
355
|
# no sorting when embedded documents or custom filter is active
|
339
|
-
sort_ok = @form['result_set'].nil? || (@form['result_set'] && @form['result_set']['filter'].nil?)
|
356
|
+
#sort_ok = @form['result_set'].nil? || (@form['result_set'] && @form['result_set']['filter'].nil?)
|
357
|
+
sort_ok = true
|
340
358
|
sort_ok = sort_ok || (@form['index'] && @form['index']['sort'])
|
341
359
|
sort_ok = sort_ok && !dc_dont?(v['sort'], false)
|
342
360
|
if @tables.size == 1 and sort_ok
|
@@ -387,11 +405,13 @@ def dc_format_value(value, format=nil)
|
|
387
405
|
return '' if value.nil?
|
388
406
|
|
389
407
|
klass = value.class.to_s
|
390
|
-
if klass.match(/time|date/i)
|
391
|
-
|
392
|
-
|
393
|
-
|
408
|
+
return CmsCommonHelper.dc_format_date_time(value, format) if klass.match(/time|date/i)
|
409
|
+
|
410
|
+
format = format.to_s.upcase
|
411
|
+
if format[0] == 'N'
|
412
|
+
return '' if value == 0 && format.match('Z')
|
394
413
|
|
414
|
+
format.gsub!('Z', '')
|
395
415
|
dec = format[1].blank? ? nil : format[1].to_i
|
396
416
|
sep = format[2].blank? ? nil : format[2]
|
397
417
|
del = format[3].blank? ? nil : format[3]
|
@@ -416,6 +436,7 @@ end
|
|
416
436
|
############################################################################
|
417
437
|
def dc_columns_for_result(document)
|
418
438
|
return '' unless @form['result_set']['columns']
|
439
|
+
|
419
440
|
html = ''
|
420
441
|
@form['result_set']['columns'].sort.each do |k,v|
|
421
442
|
session[:form_processing] = "result_set:columns: #{k}=#{v}"
|
@@ -455,6 +476,14 @@ def dc_columns_for_result(document)
|
|
455
476
|
html.html_safe
|
456
477
|
end
|
457
478
|
|
479
|
+
############################################################################
|
480
|
+
# Split eval expression to array by parameters.
|
481
|
+
# Ex. Will split dc_name4_value(one ,"two") => ['dc_name4_value', 'one', 'two']
|
482
|
+
############################################################################
|
483
|
+
def dc_eval_to_array(expression)
|
484
|
+
expression.split(/\ |\,|\(|\)/).delete_if {|e| e.blank? }.map {|e| e.gsub(/\'|\"/,'').strip }
|
485
|
+
end
|
486
|
+
|
458
487
|
private
|
459
488
|
|
460
489
|
############################################################################
|
@@ -474,14 +503,6 @@ def dc_process_eval(evaluate, parameters)
|
|
474
503
|
end
|
475
504
|
end
|
476
505
|
|
477
|
-
############################################################################
|
478
|
-
# Split eval expression to array by parameters.
|
479
|
-
# Will split dc_name4_value(one ,"two") => ['dc_name4_value', 'one', 'two']
|
480
|
-
############################################################################
|
481
|
-
def dc_eval_to_array(expression)
|
482
|
-
expression.split(/\ |\,|\(|\)/).delete_if {|e| e.blank? }.map {|e| e.gsub(/\'|\"/,'').strip }
|
483
|
-
end
|
484
|
-
|
485
506
|
############################################################################
|
486
507
|
# Process eval option for field value.
|
487
508
|
# Used for processing single field column on result_set or form head.
|
@@ -1,4 +1,3 @@
|
|
1
|
-
#coding: utf-8
|
2
1
|
#--
|
3
2
|
# Copyright (c) 2012+ Damjan Rems
|
4
3
|
#
|
@@ -95,17 +94,17 @@ end
|
|
95
94
|
############################################################################
|
96
95
|
def dc_render(renderer, opts={})
|
97
96
|
return dc_render_design_part(renderer[:part]) if renderer.class == Hash
|
98
|
-
|
97
|
+
|
99
98
|
opts[:edit_mode] = session[:edit_mode]
|
100
99
|
opts[:editparams] = {}
|
101
100
|
|
102
101
|
opts = @options.merge(opts) # merge options with parameters passed on site, page, design ...
|
103
102
|
opts.symbolize_keys! # this makes lots of things easier
|
104
|
-
# Create renderer object
|
103
|
+
# Create renderer object
|
105
104
|
klass = renderer.to_s.downcase
|
106
105
|
klass += '_renderer' unless klass.match('_renderer') #
|
107
106
|
obj = Kernel.const_get(klass.classify, Class.new).new(self, opts) rescue nil
|
108
|
-
|
107
|
+
|
109
108
|
if obj
|
110
109
|
html = obj.render_html
|
111
110
|
@css << obj.render_css.to_s
|
@@ -133,7 +132,7 @@ def dc_replace_in_design(opts={})
|
|
133
132
|
design = opts[:piece] ? DcPiece.find(name: opts[:piece]).script : dc_get_site.design
|
134
133
|
layout = opts[:layout] || (dc_get_site.site_layout.size > 2 ? dc_get_site.site_layout : nil)
|
135
134
|
if opts[:replace]
|
136
|
-
# replace more than one part of code
|
135
|
+
# replace more than one part of code
|
137
136
|
if opts[:replace].class == Array
|
138
137
|
0.upto(opts[:replace].size - 1) {|i| design.sub!(opts[:replace][i], opts[:with][i])}
|
139
138
|
else
|
@@ -179,13 +178,12 @@ end
|
|
179
178
|
#
|
180
179
|
# This helper is replacement dc_render_from_site method which will soon be deprecated.
|
181
180
|
########################################################################
|
182
|
-
def dc_render_design_part(part)
|
183
|
-
|
181
|
+
def dc_render_design_part(part)
|
184
182
|
case
|
185
183
|
when part.nil? then logger.error('ERROR dc_render_design_part! part is NIL !'); ''
|
186
|
-
# Send as array. Part may be defined with options on page. First element has
|
187
|
-
# name of element which defines what to do. If not defined default behaviour is
|
188
|
-
# called. That is what is defined in second part of array.
|
184
|
+
# Send as array. Part may be defined with options on page. First element has
|
185
|
+
# name of element which defines what to do. If not defined default behaviour is
|
186
|
+
# called. That is what is defined in second part of array.
|
189
187
|
when part.class == Array then
|
190
188
|
if @options.dig(:settings, part.first)
|
191
189
|
#TODO to be defined
|
@@ -196,9 +194,9 @@ def dc_render_design_part(part)
|
|
196
194
|
when part.class == Proc then
|
197
195
|
result = part.call
|
198
196
|
result.class == Array ? result.first : result
|
199
|
-
# Send as string. Evaluate content of string
|
197
|
+
# Send as string. Evaluate content of string
|
200
198
|
when part.class == String then eval part
|
201
|
-
# For future maybe. Just call objects to_s method.
|
199
|
+
# For future maybe. Just call objects to_s method.
|
202
200
|
else
|
203
201
|
part.to_s
|
204
202
|
end.html_safe
|
@@ -231,9 +229,9 @@ end
|
|
231
229
|
########################################################################
|
232
230
|
# Helper for rendering top CMS menu when in editing mode
|
233
231
|
########################################################################
|
234
|
-
def dc_page_top
|
235
|
-
if @design
|
236
|
-
# Evaluate parameters in design body
|
232
|
+
def dc_page_top
|
233
|
+
if @design && @design.rails_view.present?
|
234
|
+
# Evaluate parameters in design body
|
237
235
|
eval(@design.body)
|
238
236
|
end
|
239
237
|
session[:edit_mode] > 0 ? render(partial: 'cmsedit/edit_stuff') : ''
|
@@ -282,18 +280,18 @@ end
|
|
282
280
|
def dc_edit_title
|
283
281
|
session[:form_processing] = "form:title:"
|
284
282
|
title = @form['form']['title']
|
285
|
-
# defined as form:title:edit
|
283
|
+
# defined as form:title:edit
|
286
284
|
if title and title['edit'] and !@form['readonly']
|
287
285
|
t( title['edit'], title['edit'] )
|
288
286
|
elsif title and title['show'] and @form['readonly']
|
289
287
|
t( title['show'], title['show'] )
|
290
288
|
else
|
291
|
-
# concatenate title
|
289
|
+
# concatenate title
|
292
290
|
c = (@form['readonly'] ? t('drgcms.show') : t('drgcms.edit')) + " : "
|
293
291
|
c << (@form['title'] ? t( @form['title'], @form['title'] ) : t_tablename(@form['table'])) + ' : '
|
294
292
|
title = (title and title['field']) ? title['field'] : @form['form']['edit_title']
|
295
293
|
dc_deprecate('form:edit_title will be deprecated. Use form:title:field instead.') if @form['form']['edit_title']
|
296
|
-
|
294
|
+
|
297
295
|
c << "#{@record[ title ]} : " if title and @record.respond_to?(title)
|
298
296
|
c << @record.id if @record
|
299
297
|
end
|
@@ -309,15 +307,11 @@ end
|
|
309
307
|
def dc_new_title()
|
310
308
|
session[:form_processing] = "form:title:"
|
311
309
|
title = @form['form']['title']
|
312
|
-
# defined as form:title:new
|
310
|
+
# defined as form:title:new
|
313
311
|
if title and title['new']
|
314
312
|
t( title['new'], title['new'] )
|
315
313
|
else
|
316
|
-
|
317
|
-
dc_deprecate('dc_dummy will be deprecated. Use dc_memory instead.')
|
318
|
-
@form['table'] = 'dc_memory'
|
319
|
-
end
|
320
|
-
# in memory variables
|
314
|
+
# in memory structures
|
321
315
|
if @form['table'] == 'dc_memory'
|
322
316
|
t( @form['title'], @form['title'] )
|
323
317
|
else
|
@@ -366,7 +360,8 @@ end
|
|
366
360
|
# Returns icon code if icon is specified
|
367
361
|
############################################################################
|
368
362
|
def dc_icon_for_link(icon)
|
369
|
-
return nil
|
363
|
+
return nil if icon.nil?
|
364
|
+
|
370
365
|
if icon.match(/\./)
|
371
366
|
_origin.image_tag(icon, class: 'dc-link-img dc-animate')
|
372
367
|
elsif icon.match('<i')
|
@@ -439,22 +434,13 @@ end
|
|
439
434
|
# Therefore it is very unwise to use non ascii chars for table (collection) names.
|
440
435
|
#
|
441
436
|
# Parameters:
|
442
|
-
# [
|
437
|
+
# [Object] model_string. String or model to be converted into decamelized string.
|
443
438
|
#
|
444
439
|
# Returns:
|
445
440
|
# String. Decamelized string.
|
446
441
|
########################################################################
|
447
|
-
def decamelize_type(
|
448
|
-
|
449
|
-
r = ''
|
450
|
-
string.to_s.each_char do |c|
|
451
|
-
r << case
|
452
|
-
when r.size == 0 then c.downcase
|
453
|
-
when c.downcase != c then '_' + c.downcase
|
454
|
-
else c
|
455
|
-
end
|
456
|
-
end
|
457
|
-
r
|
442
|
+
def decamelize_type(model_string)
|
443
|
+
model_string ? model_string.to_s.underscore : nil
|
458
444
|
end
|
459
445
|
|
460
446
|
####################################################################
|
@@ -468,11 +454,12 @@ end
|
|
468
454
|
# String. HTML code formatted for display.
|
469
455
|
####################################################################
|
470
456
|
def dc_error_messages_for(doc)
|
471
|
-
return '' unless doc
|
457
|
+
return '' unless doc && doc.errors.any?
|
458
|
+
|
472
459
|
msgs = ''
|
473
|
-
doc.errors.each do |
|
474
|
-
label = t("helpers.label.#{decamelize_type(doc.class)}.#{attribute}", attribute)
|
475
|
-
msgs << "<li>#{label} : #{
|
460
|
+
doc.errors.each do |error|
|
461
|
+
label = t("helpers.label.#{decamelize_type(doc.class)}.#{error.attribute}", error.attribute)
|
462
|
+
msgs << "<li>#{label} : #{error.message}</li>"
|
476
463
|
end
|
477
464
|
|
478
465
|
c = <<eot
|
@@ -555,14 +542,14 @@ end
|
|
555
542
|
# Create edit link with edit picture. Subroutine of dc_page_edit_menu.
|
556
543
|
####################################################################
|
557
544
|
def dc_link_menu_tag(title) #:nodoc:
|
558
|
-
html = %
|
545
|
+
html = %(
|
559
546
|
<dl>
|
560
547
|
<dt><div class='drgcms_popmenu' href="#">
|
561
548
|
#{_origin.fa_icon('file-text-o lg', class: 'dc-inline-link', title: title)}
|
562
549
|
</div></dt>
|
563
550
|
<dd>
|
564
551
|
<ul class=' div-hidden drgcms_popmenu_class'>
|
565
|
-
|
552
|
+
)
|
566
553
|
|
567
554
|
yield html
|
568
555
|
html << "</ul></dd></dl>"
|
@@ -756,7 +743,7 @@ end
|
|
756
743
|
##########################################################################
|
757
744
|
# Returns choices for creating collection edit select field on CMS top menu.
|
758
745
|
##########################################################################
|
759
|
-
def dc_choices4_cmsmenu
|
746
|
+
def dc_choices4_cmsmenu
|
760
747
|
menus = {}
|
761
748
|
DrgCms.paths(:forms).reverse.each do |path|
|
762
749
|
filename = "#{path}/cms_menu.yml"
|
@@ -36,11 +36,12 @@ field :subject_link, type: String, default: ''
|
|
36
36
|
field :alt_link, type: String, default: ''
|
37
37
|
field :sub_subject, type: String, default: ''
|
38
38
|
field :picture, type: String
|
39
|
-
field :gallery, type: Boolean, default: false
|
39
|
+
field :gallery, type: Mongoid::Boolean, default: false
|
40
40
|
field :body, type: String, default: ''
|
41
41
|
field :css, type: String, default: ''
|
42
42
|
field :script, type: String, default: ''
|
43
43
|
field :params, type: String
|
44
|
+
field :div_class, type: String
|
44
45
|
field :menu_id, type: String
|
45
46
|
field :author_id, type: BSON::ObjectId
|
46
47
|
field :dc_poll_id, type: BSON::ObjectId
|
@@ -50,7 +51,7 @@ field :user_name, type: String
|
|
50
51
|
field :valid_from, type: DateTime
|
51
52
|
field :valid_to, type: DateTime
|
52
53
|
field :comments, type: Integer, default: 1 # 0 => not allowed, 1 => allowed
|
53
|
-
field :active, type: Boolean, default: true
|
54
|
+
field :active, type: Mongoid::Boolean, default: true
|
54
55
|
field :created_by, type: BSON::ObjectId
|
55
56
|
field :updated_by, type: BSON::ObjectId
|
56
57
|
field :kats, type: Array # Categories
|
@@ -45,7 +45,7 @@ module DcPieceConcern
|
|
45
45
|
field :div_id, type: String
|
46
46
|
field :site_id, type: BSON::ObjectId
|
47
47
|
field :order, type: Integer, default: 0
|
48
|
-
field :active, type: Boolean, default: true
|
48
|
+
field :active, type: Mongoid::Boolean, default: true
|
49
49
|
field :valid_from, type: DateTime
|
50
50
|
field :valid_to, type: DateTime
|
51
51
|
|
@@ -47,7 +47,7 @@ field :menu_class, type: String, default: 'DcSimpleMenu'
|
|
47
47
|
field :request_processor, type: String
|
48
48
|
field :files_directory, type: String
|
49
49
|
field :logo, type: String
|
50
|
-
field :active, type: Boolean, default: true
|
50
|
+
field :active, type: Mongoid::Boolean, default: true
|
51
51
|
field :created_by, type: BSON::ObjectId
|
52
52
|
field :updated_by, type: BSON::ObjectId
|
53
53
|
field :menu_name, type: String
|
@@ -50,13 +50,13 @@ field :picture, type: String
|
|
50
50
|
field :birthdate, type: Date
|
51
51
|
field :about, type: String
|
52
52
|
field :last_visit, type: Time
|
53
|
-
field :active, type: Boolean, default: true
|
53
|
+
field :active, type: Mongoid::Boolean, default: true
|
54
54
|
field :valid_from, type: Date
|
55
55
|
field :valid_to, type: Date
|
56
56
|
field :created_by, type: BSON::ObjectId
|
57
57
|
field :updated_by, type: BSON::ObjectId
|
58
58
|
|
59
|
-
field :group, type: Boolean, default: false # false => User, true => Group
|
59
|
+
field :group, type: Mongoid::Boolean, default: false # false => User, true => Group
|
60
60
|
field :member, type: Array
|
61
61
|
|
62
62
|
embeds_many :dc_user_roles
|
@@ -151,7 +151,7 @@ private
|
|
151
151
|
# when entry is left empty.
|
152
152
|
##########################################################################
|
153
153
|
def do_before_save
|
154
|
-
self.name = "#{title} #{first_name} #{middle_name + ' ' unless middle_name.blank?}#{last_name}".
|
154
|
+
self.name = "#{title} #{first_name} #{middle_name + ' ' unless middle_name.blank?}#{last_name}".squish
|
155
155
|
# to ensure unique e-mail
|
156
156
|
self.email = "unknown@#{id}" if email.blank?
|
157
157
|
end
|
data/app/models/dc_filter.rb
CHANGED
@@ -106,8 +106,9 @@ end
|
|
106
106
|
############################################################################
|
107
107
|
# Return filter input field for entering variable filter values on index form
|
108
108
|
############################################################################
|
109
|
-
def self.get_filter_field(parent)
|
109
|
+
def self.get_filter_field(parent)
|
110
110
|
return '' if parent.session[ parent.form['table'] ].nil?
|
111
|
+
|
111
112
|
filter = parent.session[ parent.form['table'] ][:filter]
|
112
113
|
return '' if filter.nil?
|
113
114
|
|
@@ -115,8 +116,11 @@ def self.get_filter_field(parent)
|
|
115
116
|
return '' if filter.nil?
|
116
117
|
|
117
118
|
field = get_field_form_definition(filter['field'], parent)
|
118
|
-
return '' if field.nil?
|
119
|
-
|
119
|
+
return '' if field.nil? && filter['input'].nil?
|
120
|
+
|
121
|
+
saved_readonly = parent.form['readonly']
|
122
|
+
parent.form['readonly'] = nil # must be
|
123
|
+
field ||= {}
|
120
124
|
# If field has choices available in labels, use them. This is most likely select input field.
|
121
125
|
if field['name']
|
122
126
|
choices = parent.t('helpers.label.' + parent.form['table'] + '.choices4_' + field['name'] )
|
@@ -129,23 +133,25 @@ def self.get_filter_field(parent)
|
|
129
133
|
field['type'] = filter['input'] if filter['input'].to_s.size > 5
|
130
134
|
field['type'] ||= 'text_field'
|
131
135
|
field['readonly'] = false # must be
|
132
|
-
field['html'] ||= {}
|
133
|
-
field['html']['size']
|
136
|
+
field['html'] ||= {}
|
137
|
+
field['html']['size'] = 20
|
134
138
|
# Start with last entered value
|
135
139
|
field['html']['value'] = filter['value'] unless filter['value'] == '#NIL'
|
136
140
|
field['html']['selected'] = field['html']['value'] # for select field
|
137
141
|
# url for filter ON action
|
138
142
|
field['html']['data-url'] = parent.url_for(
|
139
|
-
controller: 'cmsedit',action: :index, filter: 'on',
|
143
|
+
controller: 'cmsedit', action: :index, filter: 'on',
|
140
144
|
table: parent.form['table'], form_name: parent.params['form_name'])
|
141
145
|
url = field['html']['data-url']
|
142
146
|
# remove if present
|
143
147
|
field['with_new'] = nil if field['with_new']
|
144
|
-
# create input field object
|
148
|
+
# create input field object
|
145
149
|
klas_string = field['type'].camelize
|
146
150
|
klas = DrgcmsFormFields::const_get(klas_string) rescue nil
|
151
|
+
parent.form['readonly'] = saved_readonly
|
147
152
|
return '' if klas.nil?
|
148
|
-
|
153
|
+
|
154
|
+
# return data from object and create html code to display field
|
149
155
|
object = klas.new(parent, nil, field).render rescue nil
|
150
156
|
# Error. Forget filter and return
|
151
157
|
if object.nil?
|
@@ -153,11 +159,11 @@ def self.get_filter_field(parent)
|
|
153
159
|
return ''
|
154
160
|
end
|
155
161
|
js = object.js.blank? ? '' : parent.javascript_tag(object.js)
|
156
|
-
%
|
162
|
+
%(<li class="no-background">
|
157
163
|
<span class="filter_field" data-url="#{url}">#{object.html}
|
158
164
|
#{parent.fa_icon('search lg', class: 'record_filter_field_icon')}
|
159
165
|
#{js}</span>
|
160
|
-
</li>
|
166
|
+
</li>)
|
161
167
|
end
|
162
168
|
|
163
169
|
######################################################################
|
@@ -78,6 +78,8 @@ def render
|
|
78
78
|
@yaml['options']['lang'] ||= "'#{I18n.locale}'"
|
79
79
|
@yaml['options']['format'] ||= "'#{t('datetimepicker.formats.date')}'"
|
80
80
|
@yaml['options']['timepicker'] = false
|
81
|
+
@yaml['options']['scrollMonth'] ||= false
|
82
|
+
@yaml['options']['scrollInput'] ||= false
|
81
83
|
|
82
84
|
record = record_text_for(@yaml['name'])
|
83
85
|
@html << @parent.text_field(record, @yaml['name'], @yaml['html'])
|
@@ -135,7 +135,8 @@ def ro_standard(value=nil)
|
|
135
135
|
@record.respond_to?(@yaml['name']) ? @record.send(@yaml['name']) : nil
|
136
136
|
end
|
137
137
|
end
|
138
|
-
|
138
|
+
#@html << (value.blank? ? '' : "<div class='dc-readonly'>#{value}</div>")
|
139
|
+
@html << %(<div id="#{@yaml['name']}" class="dc-readonly">#{value}</div>)
|
139
140
|
self
|
140
141
|
end
|
141
142
|
|