drg_cms 0.6.0.6 → 0.6.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -10
- data/app/assets/javascripts/drg_cms/drg_cms.js +281 -106
- data/app/assets/stylesheets/drg_cms/drg_cms.css +417 -152
- data/app/assets/stylesheets/drg_cms/select-multiple.css +9 -12
- data/app/assets/stylesheets/drg_cms_cms.css +1 -1
- data/app/controllers/cmsedit_controller.rb +247 -175
- data/app/controllers/dc_application_controller.rb +251 -173
- data/app/controllers/dc_common_controller.rb +81 -48
- data/app/controls/dc_help_control.rb +126 -0
- data/app/controls/dc_report.rb +223 -0
- data/app/forms/all_options.yml +38 -10
- data/app/forms/cms_menu.yml +7 -1
- data/app/forms/dc_big_table.yml +1 -0
- data/app/forms/dc_big_table_value.yml +1 -0
- data/app/forms/dc_category.yml +2 -1
- data/app/forms/dc_design.yml +1 -0
- data/app/forms/dc_help_1.yml +109 -0
- data/app/forms/dc_journal.yml +3 -1
- data/app/forms/dc_link.yml +1 -1
- data/app/forms/dc_menu.yml +2 -0
- data/app/forms/dc_menu_item.yml +1 -0
- data/app/forms/dc_page.yml +6 -0
- data/app/forms/dc_part.yml +1 -0
- data/app/forms/dc_piece.yml +1 -0
- data/app/forms/dc_poll.yml +15 -5
- data/app/forms/dc_poll_item.yml +2 -1
- data/app/forms/dc_poll_result.yml +9 -0
- data/app/forms/dc_simple_menu.yml +2 -0
- data/app/forms/dc_site.yml +4 -12
- data/app/forms/dc_user.yml +27 -11
- data/app/forms/dc_user_role.yml +3 -0
- data/app/helpers/cms_common_helper.rb +375 -0
- data/app/helpers/{cmsedit_edit_helper.rb → cms_edit_helper.rb} +109 -65
- data/app/helpers/{cmsedit_helper.rb → cms_helper.rb} +93 -48
- data/app/helpers/{cmsedit_index_helper.rb → cms_index_helper.rb} +240 -206
- data/app/helpers/dc_application_helper.rb +108 -327
- data/app/models/concerns/dc_page_concern.rb +14 -4
- data/app/models/concerns/dc_piece_concern.rb +1 -1
- data/app/models/concerns/dc_policy_rule_concern.rb +20 -8
- data/app/models/concerns/dc_site_concern.rb +67 -44
- data/app/models/concerns/dc_user_concern.rb +58 -19
- data/app/models/dc_design.rb +29 -19
- data/app/models/dc_filter.rb +26 -18
- data/app/models/dc_key_value_store.rb +1 -0
- data/app/models/dc_permission.rb +49 -9
- data/app/models/dc_policy.rb +25 -14
- data/app/models/dc_policy_role.rb +22 -11
- data/app/models/dc_poll.rb +1 -0
- data/app/models/dc_poll_result.rb +4 -2
- data/app/models/dc_temp.rb +6 -3
- data/app/models/dc_user_role.rb +2 -2
- data/app/models/drgcms_form_fields/date_picker.rb +6 -3
- data/app/models/drgcms_form_fields/datetime_picker.rb +4 -3
- data/app/models/drgcms_form_fields/drgcms_field.rb +20 -5
- data/app/models/drgcms_form_fields/embedded.rb +23 -16
- data/app/models/drgcms_form_fields/file_field.rb +2 -2
- data/app/models/drgcms_form_fields/file_select.rb +2 -2
- data/app/models/drgcms_form_fields/hash_field.rb +11 -7
- data/app/models/drgcms_form_fields/hidden_field.rb +1 -1
- data/app/models/drgcms_form_fields/link_to.rb +2 -2
- data/app/models/drgcms_form_fields/method.rb +66 -0
- data/app/models/drgcms_form_fields/multitext_autocomplete.rb +18 -12
- data/app/models/drgcms_form_fields/number_field.rb +4 -3
- data/app/models/drgcms_form_fields/radio.rb +10 -5
- data/app/models/drgcms_form_fields/readonly.rb +13 -17
- data/app/models/drgcms_form_fields/select.rb +58 -41
- data/app/models/drgcms_form_fields/text_autocomplete.rb +41 -33
- data/app/models/drgcms_form_fields.rb +12 -1
- data/app/renderers/dc_big_menu_renderer.rb +1 -0
- data/app/renderers/dc_gallery_renderer.rb +1 -0
- data/app/renderers/dc_menu_renderer.rb +1 -0
- data/app/renderers/dc_page_renderer.rb +8 -6
- data/app/renderers/dc_part_renderer.rb +1 -0
- data/app/renderers/dc_piece_renderer.rb +1 -1
- data/app/renderers/dc_poll_renderer.rb +56 -55
- data/app/renderers/dc_renderer.rb +1 -0
- data/app/renderers/dc_simple_menu_renderer.rb +1 -0
- data/app/views/cmsedit/_edit_stuff.html.erb +5 -2
- data/app/views/cmsedit/edit.html.erb +4 -1
- data/app/views/cmsedit/index.html.erb +3 -2
- data/app/views/cmsedit/new.html.erb +5 -2
- data/app/views/dc_common/_help.html.erb +17 -0
- data/app/views/layouts/models.html.erb +2 -1
- data/config/locales/drgcms_en.yml +17 -2
- data/config/locales/drgcms_sl.yml +22 -4
- data/config/locales/models_en.yml +16 -7
- data/config/locales/models_sl.yml +21 -12
- data/drg_cms.gemspec +16 -16
- data/lib/drg_cms/version.rb +1 -1
- data/lib/drg_cms.rb +98 -0
- data/lib/generators/new_drg_form/new_drg_form_generator.rb +5 -3
- data/lib/tasks/database.rake +6 -56
- metadata +39 -35
- data/app/helpers/application_helper.rb +0 -2
- data/app/models/__dc_dummy.rb +0 -102
@@ -38,18 +38,29 @@
|
|
38
38
|
# which can be persistent, when application is used as Rails plugin.
|
39
39
|
#########################################################################
|
40
40
|
class DcPolicyRole
|
41
|
-
|
42
|
-
|
41
|
+
include Mongoid::Document
|
42
|
+
include Mongoid::Timestamps
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
44
|
+
field :name, type: String
|
45
|
+
field :system_name, type: String
|
46
|
+
field :active, type: Boolean, default: true
|
47
|
+
|
48
|
+
index( { name: 1 }, { unique: true } )
|
49
|
+
index( system_name: 1 )
|
50
|
+
|
51
|
+
validates :name, :length => { :minimum => 4 }
|
52
|
+
validates :name, uniqueness: true
|
53
|
+
|
54
|
+
after_save :cache_clear
|
55
|
+
after_destroy :cache_clear
|
56
|
+
|
57
|
+
####################################################################
|
58
|
+
# Clear cache if cache is configured
|
59
|
+
####################################################################
|
60
|
+
def cache_clear
|
61
|
+
DrgCms.cache_clear(:dc_permission)
|
62
|
+
DrgCms.cache_clear(:dc_site)
|
63
|
+
end
|
53
64
|
|
54
65
|
########################################################################
|
55
66
|
# Return all defined roles as choices for use in select field.
|
data/app/models/dc_poll.rb
CHANGED
@@ -63,6 +63,7 @@ field :operation, type: String
|
|
63
63
|
field :parameters, type: String
|
64
64
|
field :display, type: String, default: '1'
|
65
65
|
field :css, type: String
|
66
|
+
field :js, type: String
|
66
67
|
field :form, type: String
|
67
68
|
field :valid_from, type: DateTime
|
68
69
|
field :valid_to, type: DateTime
|
@@ -29,15 +29,17 @@
|
|
29
29
|
# _id BSON::ObjectId _id
|
30
30
|
# dc_poll_id BSON::ObjectId poll id
|
31
31
|
# data String Data saved as YAML
|
32
|
-
#
|
32
|
+
# confirmed Boolean Poll entry was confirmed
|
33
|
+
#
|
33
34
|
# Results of polls saved as YAML structure.
|
34
35
|
########################################################################
|
35
36
|
class DcPollResult
|
36
37
|
include Mongoid::Document
|
37
38
|
include Mongoid::Timestamps
|
38
39
|
|
39
|
-
field :data, type: String
|
40
40
|
belongs_to :dc_poll
|
41
|
+
field :data, type: String
|
42
|
+
field :confirmed, type: Boolean, default: false
|
41
43
|
|
42
44
|
index( { dc_poll_id: 1 } )
|
43
45
|
|
data/app/models/dc_temp.rb
CHANGED
@@ -33,9 +33,11 @@
|
|
33
33
|
class DcTemp
|
34
34
|
include Mongoid::Document
|
35
35
|
include Mongoid::Timestamps
|
36
|
+
|
36
37
|
field :key, type: String
|
37
38
|
field :data, type: Hash, default: {}
|
38
39
|
field :active, type: Time, default: Time.now
|
40
|
+
field :order, type: String
|
39
41
|
|
40
42
|
index key: 1
|
41
43
|
|
@@ -44,9 +46,10 @@ class DcTemp
|
|
44
46
|
########################################################################
|
45
47
|
def initialize(parms = {})
|
46
48
|
super()
|
47
|
-
parms.stringify_keys
|
48
|
-
self.key
|
49
|
-
self.
|
49
|
+
parms = parms.nil? ? {} : parms.stringify_keys
|
50
|
+
self.key = parms.delete('key') if parms['key']
|
51
|
+
self.active = parms.delete('active') if parms['active']
|
52
|
+
self.order = parms.delete('order') if parms['order']
|
50
53
|
parms.each { |k, value| self.data[k] = value }
|
51
54
|
end
|
52
55
|
|
data/app/models/dc_user_role.rb
CHANGED
@@ -57,8 +57,8 @@ class DcUserRole
|
|
57
57
|
# Determine of role is still active
|
58
58
|
###############################################################################
|
59
59
|
def active?
|
60
|
-
now = Time.
|
61
|
-
|
60
|
+
now = Time.current
|
61
|
+
active && (valid_from.nil? || now > valid_from) && (valid_to.nil? || now < valid_to)
|
62
62
|
end
|
63
63
|
|
64
64
|
end
|
@@ -67,17 +67,20 @@ class DatePicker < DrgcmsField
|
|
67
67
|
def render
|
68
68
|
value = @record.try(@yaml['name']) ? I18n.localize(@record[@yaml['name']].to_date) : nil
|
69
69
|
#return ro_standard( @parent.dc_format_value(value)) if @readonly
|
70
|
-
|
70
|
+
|
71
71
|
@yaml['options'] ||= {}
|
72
72
|
set_initial_value
|
73
73
|
@yaml['html']['size'] ||= @yaml['size'] || 10
|
74
74
|
@yaml['html']['value'] ||= value
|
75
75
|
@yaml['html']['autocomplete'] ||= 'off'
|
76
|
-
|
76
|
+
@yaml['html']['class'] = @yaml['html']['class'].to_s + ' date-picker'
|
77
|
+
|
77
78
|
@yaml['options']['lang'] ||= "'#{I18n.locale}'"
|
78
79
|
@yaml['options']['format'] ||= "'#{t('datetimepicker.formats.date')}'"
|
79
80
|
@yaml['options']['timepicker'] = false
|
80
|
-
|
81
|
+
@yaml['options']['scrollMonth'] ||= false
|
82
|
+
@yaml['options']['scrollInput'] ||= false
|
83
|
+
|
81
84
|
record = record_text_for(@yaml['name'])
|
82
85
|
@html << @parent.text_field(record, @yaml['name'], @yaml['html'])
|
83
86
|
@js << %Q[
|
@@ -53,16 +53,17 @@ class DatetimePicker < DrgcmsField
|
|
53
53
|
def render
|
54
54
|
value = @record.try(@yaml['name']) ? I18n.localize(@record[@yaml['name']].localtime) : nil
|
55
55
|
#return ro_standard( @parent.dc_format_value(value)) if @readonly
|
56
|
-
|
56
|
+
|
57
57
|
@yaml['options'] ||= {}
|
58
58
|
set_initial_value
|
59
59
|
@yaml['html']['size'] ||= @yaml['size'] || 14
|
60
60
|
@yaml['html']['value'] ||= value if @record[@yaml['name']]
|
61
61
|
@yaml['html']['autocomplete'] ||= 'off'
|
62
|
-
|
62
|
+
@yaml['html']['class'] = @yaml['html']['class'].to_s + ' date-picker'
|
63
|
+
|
63
64
|
@yaml['options']['lang'] ||= "'#{I18n.locale}'"
|
64
65
|
@yaml['options']['format'] ||= "'#{t('datetimepicker.formats.datetime')}'"
|
65
|
-
|
66
|
+
|
66
67
|
record = record_text_for(@yaml['name'])
|
67
68
|
@html << @parent.text_field(record, @yaml['name'], @yaml['html'])
|
68
69
|
@js << %Q[
|
@@ -128,7 +128,6 @@ end
|
|
128
128
|
# Standard code for returning readonly field.
|
129
129
|
####################################################################
|
130
130
|
def ro_standard(value=nil)
|
131
|
-
p @yaml['name'],value
|
132
131
|
if value.nil?
|
133
132
|
value = if @yaml['html']['value']
|
134
133
|
@yaml['html']['value']
|
@@ -136,7 +135,8 @@ def ro_standard(value=nil)
|
|
136
135
|
@record.respond_to?(@yaml['name']) ? @record.send(@yaml['name']) : nil
|
137
136
|
end
|
138
137
|
end
|
139
|
-
|
138
|
+
#@html << (value.blank? ? '' : "<div class='dc-readonly'>#{value}</div>")
|
139
|
+
@html << %(<div id="#{@yaml['name']}" class="dc-readonly">#{value}</div>)
|
140
140
|
self
|
141
141
|
end
|
142
142
|
|
@@ -152,7 +152,7 @@ end
|
|
152
152
|
# flash[:record] = {}
|
153
153
|
# flash[:record]['picture'] = '/path/to_picture'
|
154
154
|
####################################################################
|
155
|
-
def set_initial_value(opt1='html', opt2='value')
|
155
|
+
def set_initial_value(opt1 = 'html', opt2 = 'value')
|
156
156
|
@yaml['html'] ||= {}
|
157
157
|
value_send_as = 'p_' + @yaml['name']
|
158
158
|
if @parent.params[value_send_as]
|
@@ -160,11 +160,26 @@ def set_initial_value(opt1='html', opt2='value')
|
|
160
160
|
elsif @parent.flash[:record] and @parent.flash[:record][@yaml['name']]
|
161
161
|
@yaml[opt1][opt2] = @parent.flash[:record][@yaml['name']]
|
162
162
|
end
|
163
|
+
set_default_value(opt1, opt2) if @yaml['default']
|
164
|
+
end
|
165
|
+
|
166
|
+
####################################################################
|
167
|
+
# Will set default value
|
168
|
+
####################################################################
|
169
|
+
def set_default_value(opt1, opt2)
|
170
|
+
return if @yaml[opt1][opt2].present?
|
171
|
+
return if @record && @record[@yaml['name']].present?
|
172
|
+
|
173
|
+
@yaml[opt1][opt2] = if @yaml['default'].class == Hash
|
174
|
+
eval(@yaml['default']['eval'])
|
175
|
+
else
|
176
|
+
@yaml['default']
|
177
|
+
end
|
163
178
|
end
|
164
179
|
|
165
180
|
####################################################################
|
166
181
|
# Returns style html code for DRGForm object if style directive is present in field definition.
|
167
|
-
#
|
182
|
+
# Otherwise returns empty string.
|
168
183
|
#
|
169
184
|
# Style may be defined like:
|
170
185
|
# style:
|
@@ -202,7 +217,7 @@ end
|
|
202
217
|
# Returns css code for the field if specified. It replaces all occurences of '# '
|
203
218
|
# with field name id, as defined on form.
|
204
219
|
####################################################################
|
205
|
-
def
|
220
|
+
def __css_code
|
206
221
|
return '' if @css.blank?
|
207
222
|
@css.gsub!('# ',"#td_record_#{@yaml['name']} ")
|
208
223
|
"\n<style type=\"text/css\">#{@css}</style>"
|
@@ -31,6 +31,7 @@ module DrgcmsFormFields
|
|
31
31
|
# * +name:+ field name (required)
|
32
32
|
# * +type:+ embedded (required)
|
33
33
|
# * +form_name:+ name of form which will be used for editing
|
34
|
+
# * +load:+ when is embedded iframe loaded. default=on form load, delay=on tab select, always=every time tab is selected)
|
34
35
|
# * +html:+ html options (optional)
|
35
36
|
# * +height:+ height of embedded object in pixels (1000)
|
36
37
|
# * +width:+ width of embedded object in pixels (500)
|
@@ -40,6 +41,7 @@ module DrgcmsFormFields
|
|
40
41
|
# name: dc_parts
|
41
42
|
# type: embedded
|
42
43
|
# form_name: dc_part
|
44
|
+
# refresh: delay
|
43
45
|
# html:
|
44
46
|
# height: 1000
|
45
47
|
###########################################################################
|
@@ -47,35 +49,40 @@ class Embedded < DrgcmsField
|
|
47
49
|
###########################################################################
|
48
50
|
# Render embedded field html code
|
49
51
|
###########################################################################
|
50
|
-
def render
|
51
|
-
#
|
52
|
-
# HTML defaults. Some must be set
|
52
|
+
def render
|
53
|
+
# HTML defaults. Some must be set
|
53
54
|
@yaml['html'] ||= {}
|
54
|
-
@yaml['html']['
|
55
|
-
@yaml['html']
|
56
|
-
|
55
|
+
@yaml['html']['width'] ||= '99%'
|
56
|
+
html = @yaml['html'].inject('') { |r, val| r << "#{val.first}=\"#{val.last}\" " }
|
57
|
+
|
58
|
+
@yaml['action'] ||= 'index'
|
59
|
+
# defaults both way
|
57
60
|
@yaml['table'] ||= @yaml['form_name'] if @yaml['form_name']
|
58
61
|
@yaml['form_name'] ||= @yaml['table'] if @yaml['table']
|
59
|
-
|
60
|
-
html = ''
|
61
|
-
@yaml['html'].each {|k,v| html << "#{k}=\"#{v}\" "}
|
62
|
-
#
|
62
|
+
|
63
63
|
if @yaml['name'] == @yaml['table'] or @yaml['table'] == 'dc_memory'
|
64
64
|
tables = @yaml['table']
|
65
|
-
ids
|
65
|
+
ids = @record.id
|
66
66
|
else
|
67
|
-
tables
|
68
|
-
ids
|
67
|
+
tables = @parent.tables.inject('') { |r,v| r << "#{v[1]};" } + @yaml['table']
|
68
|
+
ids = @parent.ids.inject('') { |r,v| r << "#{v};" } + @record.id
|
69
69
|
end
|
70
|
-
|
71
|
-
|
70
|
+
# edit enabled embedded form on a readonly form
|
71
|
+
readonly = @yaml['readonly'].class == FalseClass ? nil : @readonly
|
72
|
+
opts = { controller: 'cmsedit', action: @yaml['action'],
|
73
|
+
ids: ids, table: tables, form_name: @yaml['form_name'],
|
74
|
+
field_name: @yaml['name'], iframe: "if_#{@yaml['name']}", readonly: readonly }
|
72
75
|
# additional parameters if specified
|
73
76
|
@yaml['params'].each { |k,v| opts[k] = @parent.dc_value_for_parameter(v) } if @yaml['params']
|
74
77
|
|
75
78
|
@html << "<iframe class='iframe_embedded' id='if_#{@yaml['name']}' name='if_#{@yaml['name']}' #{html}></iframe>"
|
76
79
|
unless @record.new_record?
|
77
80
|
url = @parent.url_for(opts)
|
78
|
-
data = @yaml['
|
81
|
+
data = if @yaml['load'].nil? || @yaml['load'].match('default')
|
82
|
+
"src"
|
83
|
+
else
|
84
|
+
"data-src-#{@yaml['load']}"
|
85
|
+
end
|
79
86
|
@js << %Q[
|
80
87
|
$(document).ready( function() {
|
81
88
|
$('#if_#{@yaml['name']}').attr('#{data}', '#{url}');
|
@@ -43,8 +43,8 @@ class FileField < DrgcmsField
|
|
43
43
|
###########################################################################
|
44
44
|
def render
|
45
45
|
return self if @readonly
|
46
|
-
|
47
|
-
@html << @parent.file_field(
|
46
|
+
|
47
|
+
@html << @parent.file_field(nil,@yaml['name'], @yaml['html'])
|
48
48
|
self
|
49
49
|
end
|
50
50
|
|
@@ -50,10 +50,10 @@ class FileSelect < DrgcmsField
|
|
50
50
|
###########################################################################
|
51
51
|
def render
|
52
52
|
return ro_standard if @readonly
|
53
|
-
# retrieve
|
53
|
+
# retrieve file_select component from site settings
|
54
54
|
selector_string = @parent.dc_get_site.params['file_select'] if @parent.dc_get_site
|
55
55
|
selector_string ||= 'elfinder'
|
56
|
-
|
56
|
+
|
57
57
|
klas_string = selector_string.camelize
|
58
58
|
if DrgcmsFormFields.const_defined?(klas_string)
|
59
59
|
klas = DrgcmsFormFields::const_get(klas_string)
|
@@ -45,6 +45,7 @@ class HashField < DrgcmsField
|
|
45
45
|
###########################################################################
|
46
46
|
def ro_standard()
|
47
47
|
return self if @record[@yaml['name']].nil?
|
48
|
+
|
48
49
|
html = ''
|
49
50
|
@record[@yaml['name']].each do |key, value|
|
50
51
|
html << "#{key}:#{value}<br>"
|
@@ -57,10 +58,10 @@ end
|
|
57
58
|
###########################################################################
|
58
59
|
def render
|
59
60
|
return ro_standard if @readonly
|
61
|
+
|
60
62
|
set_initial_value
|
61
|
-
#
|
62
63
|
record = record_text_for(@yaml['name'])
|
63
|
-
# Convert Hash to values separated by colon
|
64
|
+
# Convert Hash to values separated by colon
|
64
65
|
if @record[@yaml['name']]
|
65
66
|
@yaml['html']['value'] = @record[@yaml['name']].to_a.inject('') {|r, e| r << "#{e.first}:#{e.last}\n"}
|
66
67
|
end
|
@@ -73,12 +74,15 @@ end
|
|
73
74
|
###########################################################################
|
74
75
|
def self.get_data(params, name)
|
75
76
|
return nil if params['record'][name].blank?
|
76
|
-
|
77
|
-
result = params['record'][name].split("\n").select {|e| !e.blank? }
|
78
|
-
return
|
79
|
-
# convert to Hash
|
77
|
+
|
78
|
+
result = params['record'][name].split("\n").select { |e| !e.blank? }
|
79
|
+
return if result.size == 0
|
80
|
+
# convert to Hash
|
80
81
|
ret = {}
|
81
|
-
result.map
|
82
|
+
result.map do |e|
|
83
|
+
key, value = e.chomp.split(':')
|
84
|
+
ret[key.strip] = value.strip if value.present?
|
85
|
+
end
|
82
86
|
ret
|
83
87
|
end
|
84
88
|
|
@@ -42,7 +42,7 @@ class HiddenField < DrgcmsField
|
|
42
42
|
###########################################################################
|
43
43
|
def render
|
44
44
|
set_initial_value
|
45
|
-
value = @yaml['html']['value'] ? @yaml['html']['value'] : @record
|
45
|
+
value = @yaml['html']['value'] ? @yaml['html']['value'] : @record.send(@yaml['name'])
|
46
46
|
record = record_text_for(@yaml['name'])
|
47
47
|
@parent.hidden_field(record, @yaml['name'], value: value)
|
48
48
|
end
|
@@ -53,13 +53,13 @@ def render
|
|
53
53
|
@yaml['html'] ||= {}
|
54
54
|
@yaml['html']['class'] ||= 'dc-link dc-animate'
|
55
55
|
@yaml['html'].symbolize_keys!
|
56
|
-
|
56
|
+
|
57
57
|
@yaml[:id] = record._id if @yaml[:id] == 'id'
|
58
58
|
url = @yaml['url'] || "#{@yaml[:controller]}/#{@yaml[:action]}/#{@yaml[:id]}"
|
59
59
|
url.gsub!('//','/') # no action and id
|
60
60
|
url = '/' + @yaml['url'] unless url[0,1] == '/' # no leading /
|
61
61
|
url.chop if url[0,-1] == '/' # remove trailing /
|
62
|
-
|
62
|
+
|
63
63
|
caption = @yaml['caption'] || @yaml['text']
|
64
64
|
@html << @parent.dc_link_to(caption, @yaml['icon'], url, @yaml['html'])
|
65
65
|
self
|
@@ -0,0 +1,66 @@
|
|
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
|
+
module DrgcmsFormFields
|
24
|
+
|
25
|
+
###########################################################################
|
26
|
+
# Implementation of custom DRG CMS form field. Method field will call method or class method
|
27
|
+
# defined in eval option and add returned code to HTML output code.
|
28
|
+
#
|
29
|
+
# It can be used in case when form contains complex data structure. For example set of pictures which can not
|
30
|
+
# be simply displayed by any other DRG Forms field.
|
31
|
+
#
|
32
|
+
# Form example:
|
33
|
+
# 50:
|
34
|
+
# name: galery
|
35
|
+
# type: method
|
36
|
+
# eval: show_gallery
|
37
|
+
# or
|
38
|
+
# eval: MyClass.show_gallery
|
39
|
+
#
|
40
|
+
###########################################################################
|
41
|
+
class Method < DrgcmsField
|
42
|
+
|
43
|
+
###########################################################################
|
44
|
+
# Render file_select field html code
|
45
|
+
###########################################################################
|
46
|
+
def render
|
47
|
+
# might be defined as my_method or MyClass.my_method
|
48
|
+
clas, method = @yaml['eval'].split(/\.|\,/).map(&:strip)
|
49
|
+
if method.nil?
|
50
|
+
if @parent.respond_to?(clas)
|
51
|
+
@html << @parent.send(clas, @record, @yaml, @readonly)
|
52
|
+
return self
|
53
|
+
end
|
54
|
+
else
|
55
|
+
klass = clas.camelize.constantize
|
56
|
+
if klass.respond_to?(method)
|
57
|
+
@html << klass.send(method, @record, @yaml, @readonly)
|
58
|
+
return self
|
59
|
+
end
|
60
|
+
end
|
61
|
+
@html << "Error: #{@yaml['name']} : #{@yaml['eval']} not defined!"
|
62
|
+
self
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -23,7 +23,7 @@
|
|
23
23
|
module DrgcmsFormFields
|
24
24
|
|
25
25
|
###########################################################################
|
26
|
-
# Implementation of multitext_autocomplete DRG
|
26
|
+
# Implementation of multitext_autocomplete DRG Form field.
|
27
27
|
#
|
28
28
|
# multitext_autocomplete field is complex data entry field which uses autocomplete
|
29
29
|
# function when selecting multiple values for MongoDB Array field. Array typically holds
|
@@ -33,20 +33,21 @@ module DrgcmsFormFields
|
|
33
33
|
# ===Form options:
|
34
34
|
# * +name:+ field name (required)
|
35
35
|
# * +type:+ multitext_autocomplete (required)
|
36
|
-
# * +table+
|
36
|
+
# * +table+ Model (table) name which must contain searched field name.
|
37
37
|
# * +search:+ Search may consist of three parameters from which are separated either by dot (.) or comma(,)
|
38
38
|
# * search_field_name; when table option is defined search must define field name which will be used for search query
|
39
39
|
# * collection_name.search_field_name; Same as above except that table options must be ommited.
|
40
40
|
# * collection_name.search_field_name.method_name; When searching is more complex custom search
|
41
41
|
# method may be defined in CollectionName model which will provide result set for search.
|
42
|
+
# * +with_new+ Will add an icon for shortcut to add new document to collection
|
42
43
|
#
|
43
44
|
# Form example:
|
44
45
|
# 90:
|
45
46
|
# name: kats
|
46
47
|
# type: multitext_autocomplete
|
47
48
|
# search: dc_category.name
|
48
|
-
#
|
49
|
-
#
|
49
|
+
# with_new: model_name
|
50
|
+
# size: 30
|
50
51
|
###########################################################################
|
51
52
|
class MultitextAutocomplete < DrgcmsField
|
52
53
|
|
@@ -76,7 +77,7 @@ def render
|
|
76
77
|
method = @yaml['search']['method']
|
77
78
|
search = method.nil? ? field_name : "#{field_name}.#{method}"
|
78
79
|
elsif @yaml['search'].to_s.match(/\./)
|
79
|
-
table, field_name, method = @yaml['search'].split(/\.|\,/)
|
80
|
+
table, field_name, method = @yaml['search'].split(/\.|\,/).map(&:strip)
|
80
81
|
search = method.nil? ? field_name : "#{field_name}.#{method}"
|
81
82
|
else # search and table name are separated
|
82
83
|
search = field_name = @yaml['search']
|
@@ -89,7 +90,7 @@ def render
|
|
89
90
|
elsif @yaml['table']['eval']
|
90
91
|
eval @yaml['table']['eval']
|
91
92
|
else
|
92
|
-
|
93
|
+
@parent.logger.error "Field #{@yaml['name']}: Invalid table parameter!"
|
93
94
|
nil
|
94
95
|
end
|
95
96
|
end
|
@@ -97,15 +98,14 @@ def render
|
|
97
98
|
@html << 'Table or search field not defined!'
|
98
99
|
return self
|
99
100
|
end
|
100
|
-
#
|
101
|
-
#
|
102
|
-
# TODO check if table exists
|
101
|
+
#
|
102
|
+
# TODO check if table exists
|
103
103
|
collection = table.classify.constantize
|
104
104
|
unless @record.respond_to?(@yaml['name'])
|
105
105
|
@html << "Invalid field name: #{@yaml['name']}"
|
106
106
|
return self
|
107
107
|
end
|
108
|
-
# put field to enter search data on form
|
108
|
+
# put field to enter search data on form
|
109
109
|
@yaml['html'] ||= {}
|
110
110
|
@yaml['html']['value'] = '' # must be. Otherwise it will look into record and return error
|
111
111
|
@yaml['html']['placeholder'] = t('drgcms.search_placeholder')
|
@@ -115,10 +115,16 @@ def render
|
|
115
115
|
|
116
116
|
record = record_text_for(@yaml['name'])
|
117
117
|
# text field for autocomplete
|
118
|
-
@html << ' ' << @parent.text_field(record, _name, @yaml['html'])
|
118
|
+
@html << '<span class="dc-text-autocomplete">' << @parent.text_field(record, _name, @yaml['html']) << '<span></span></span>'
|
119
|
+
# direct link for adding new documents to collection
|
120
|
+
if @yaml['with_new'] and !@readonly
|
121
|
+
@html << ' ' +
|
122
|
+
@parent.fa_icon('plus-square lg', class: 'in-edit-add', title: t('drgcms.new'),
|
123
|
+
style: "vertical-align: top;", 'data-table' => @yaml['with_new'] )
|
124
|
+
end
|
119
125
|
# div to list active selections
|
120
126
|
@html << "<div id =\"#{record}#{@yaml['name']}\">"
|
121
|
-
# find value for each field inside categories
|
127
|
+
# find value for each field inside categories
|
122
128
|
unless @record[@yaml['name']].nil?
|
123
129
|
@record[@yaml['name']].each do |element|
|
124
130
|
# this is quick and dirty trick. We have model dc_big_table which can be used for retrive
|
@@ -69,14 +69,14 @@ def render
|
|
69
69
|
@yaml['html']['data-delimiter'] = @yaml.dig('format','delimiter') || I18n.t('number.currency.format.delimiter')
|
70
70
|
@yaml['html']['data-separator'] = @yaml.dig('format','separator') || I18n.t('number.currency.format.separator')
|
71
71
|
# @yaml['html']['data-currency'] = @yaml.dig('format','currency') == 'yes' ? I18n.t('number.currency.format.currency') : @yaml.dig('format','currency')
|
72
|
-
value = @record[@yaml['name']] || 0
|
72
|
+
value = @yaml['html']['value'] || @record[@yaml['name']] || 0
|
73
73
|
@yaml['html']['value'] = @parent.dc_format_number(value, @yaml['html']['data-decimal'], @yaml['html']['data-separator'], @yaml['html']['data-delimiter'] )
|
74
74
|
|
75
75
|
return ro_standard(@yaml['html']['value']) if @readonly
|
76
76
|
|
77
77
|
@yaml['html']['autocomplete'] ||= 'off'
|
78
78
|
@html << @parent.hidden_field( record, @yaml['name'], value: value )
|
79
|
-
@html << @parent.text_field( nil,"record_#{@yaml['name']}_", @yaml['html'])
|
79
|
+
@html << @parent.text_field( nil, "record_#{@yaml['name']}_", @yaml['html'])
|
80
80
|
self
|
81
81
|
end
|
82
82
|
|
@@ -85,7 +85,8 @@ end
|
|
85
85
|
###########################################################################
|
86
86
|
def self.get_data(params, name)
|
87
87
|
return 0 if params['record'][name].blank?
|
88
|
-
|
88
|
+
|
89
|
+
params['record'][name].match('.') ? params['record'][name].to_f : params['record'][name].to_i
|
89
90
|
end
|
90
91
|
|
91
92
|
end
|
@@ -61,10 +61,9 @@ module DrgcmsFormFields
|
|
61
61
|
class Radio < Select
|
62
62
|
|
63
63
|
###########################################################################
|
64
|
-
# Render
|
64
|
+
# Render radio DRG Form field
|
65
65
|
###########################################################################
|
66
66
|
def render
|
67
|
-
#return ro_standard if @readonly
|
68
67
|
set_initial_value('html','value')
|
69
68
|
|
70
69
|
record = record_text_for(@yaml['name'])
|
@@ -73,13 +72,19 @@ def render
|
|
73
72
|
@html << "<div class=\"#{clas}\">"
|
74
73
|
choices = get_choices
|
75
74
|
# When error and boolean field
|
76
|
-
if choices.size == 1 and (@record[@yaml['name']].class == TrueClass or @record[@yaml['name']].class == FalseClass)
|
77
|
-
|
75
|
+
#if choices.size == 1 and (@record[@yaml['name']].class == TrueClass or @record[@yaml['name']].class == FalseClass)
|
76
|
+
# choices = [[I18n.t('drgcms.true'), true], [I18n.t('drgcms.false'), false]]
|
77
|
+
#end
|
78
|
+
# Should select first button if no value provided
|
79
|
+
value = if @record.nil? || @record[@yaml['name']].blank?
|
80
|
+
choices.first.class == String ? choices.first : choices.first.last
|
81
|
+
else
|
82
|
+
@record[@yaml['name']]
|
78
83
|
end
|
79
84
|
choices.each do |choice|
|
80
85
|
choice = [choice, choice] if choice.class == String
|
81
86
|
@html << "<div>"
|
82
|
-
@html << @parent.radio_button_tag("#{record}[#{@yaml['name']}]",choice.last, choice.last.to_s ==
|
87
|
+
@html << @parent.radio_button_tag("#{record}[#{@yaml['name']}]",choice.last, choice.last.to_s == value.to_s)
|
83
88
|
@html << choice.first
|
84
89
|
@html << "</div>"
|
85
90
|
end
|
@@ -51,29 +51,25 @@ class Readonly < DrgcmsField
|
|
51
51
|
###########################################################################
|
52
52
|
# Render readonly field html code
|
53
53
|
###########################################################################
|
54
|
-
def render
|
54
|
+
def render
|
55
55
|
@html << @parent.hidden_field('record', @yaml['name']) # retain field as hidden field
|
56
56
|
@html << '<div class="dc-readonly">'
|
57
|
-
|
57
|
+
|
58
58
|
@html << if @yaml['eval']
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
eval( "#{@yaml['eval']} '#{@record[ @yaml['name'] ]}'")
|
70
|
-
end
|
71
|
-
else
|
72
|
-
@parent.dc_format_value(@record.send(@yaml['name']),@yaml['format'])
|
73
|
-
end
|
59
|
+
if @yaml['eval'].match(/dc_name4_id|dc_name_for_id/)
|
60
|
+
parms = @parent.dc_eval_to_array(@yaml['eval'])
|
61
|
+
parms << nil if parms.size == 3
|
62
|
+
@parent.dc_name_for_id(parms[1], parms[2], parms[3], @record[@yaml['name']])
|
63
|
+
else
|
64
|
+
eval( "#{@yaml['eval']} '#{@record.send(@yaml['name'])}'")
|
65
|
+
end
|
66
|
+
else
|
67
|
+
@parent.dc_format_value(@record.send(@yaml['name']), @yaml['format'])
|
68
|
+
end
|
74
69
|
@html << '</div>'
|
75
70
|
self
|
76
71
|
end
|
72
|
+
|
77
73
|
end
|
78
74
|
|
79
75
|
end
|