drg_cms 0.6.0.1 → 0.6.1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/drg_cms/drg_cms.js +454 -145
  3. data/app/assets/javascripts/drg_cms_application.js +1 -1
  4. data/app/assets/stylesheets/drg_cms/drg_cms.css +635 -244
  5. data/app/assets/stylesheets/drg_cms/select-multiple.css +18 -12
  6. data/app/assets/stylesheets/drg_cms_cms.css +1 -1
  7. data/app/controllers/cmsedit_controller.rb +515 -335
  8. data/app/controllers/dc_application_controller.rb +378 -111
  9. data/app/controllers/dc_common_controller.rb +105 -14
  10. data/app/{controllers → controls}/browse_models_control.rb +0 -0
  11. data/app/controls/dc_help_control.rb +126 -0
  12. data/app/{controllers → controls}/dc_page_control.rb +24 -8
  13. data/app/controls/dc_poll_result_control.rb +88 -0
  14. data/app/controls/dc_report.rb +223 -0
  15. data/app/{controllers → controls}/design_element_settings_control.rb +0 -0
  16. data/app/forms/all_options.yml +44 -9
  17. data/app/forms/cms_menu.yml +28 -18
  18. data/app/forms/dc_ad.yml +11 -22
  19. data/app/forms/dc_big_table.yml +1 -0
  20. data/app/forms/dc_big_table_value.yml +1 -0
  21. data/app/forms/dc_category.yml +2 -1
  22. data/app/forms/dc_design.yml +20 -16
  23. data/app/forms/dc_filter.yml +3 -6
  24. data/app/forms/dc_help_1.yml +109 -0
  25. data/app/forms/dc_journal.yml +3 -1
  26. data/app/forms/dc_json_ld.yml +59 -0
  27. data/app/forms/dc_key_value.yml +32 -0
  28. data/app/forms/dc_link.yml +1 -1
  29. data/app/forms/dc_menu.yml +2 -0
  30. data/app/forms/dc_menu_item.yml +2 -0
  31. data/app/forms/dc_page.yml +3 -5
  32. data/app/forms/dc_part.yml +1 -0
  33. data/app/forms/dc_piece.yml +1 -0
  34. data/app/forms/dc_poll.yml +15 -5
  35. data/app/forms/dc_poll_item.yml +2 -1
  36. data/app/forms/dc_poll_result.yml +83 -0
  37. data/app/forms/dc_poll_result_export.yml +35 -0
  38. data/app/forms/dc_seo.yml +33 -0
  39. data/app/forms/dc_simple_menu.yml +2 -0
  40. data/app/forms/dc_site.yml +4 -12
  41. data/app/forms/dc_user.yml +27 -11
  42. data/app/forms/dc_user_role.yml +3 -0
  43. data/app/forms/json_ld_schema.yml +168 -0
  44. data/app/helpers/cms_common_helper.rb +375 -0
  45. data/app/helpers/cms_edit_helper.rb +506 -0
  46. data/app/helpers/cms_helper.rb +268 -0
  47. data/app/helpers/cms_index_helper.rb +580 -0
  48. data/app/helpers/dc_application_helper.rb +218 -306
  49. data/app/models/concerns/dc_page_concern.rb +40 -6
  50. data/app/models/concerns/dc_policy_rule_concern.rb +20 -8
  51. data/app/models/concerns/dc_seo_concern.rb +66 -0
  52. data/app/models/concerns/dc_site_concern.rb +67 -44
  53. data/app/models/concerns/dc_user_concern.rb +57 -18
  54. data/app/models/dc_design.rb +30 -18
  55. data/app/models/dc_filter.rb +22 -13
  56. data/app/models/dc_json_ld.rb +152 -0
  57. data/app/models/dc_key_value.rb +48 -0
  58. data/app/models/dc_key_value_store.rb +1 -0
  59. data/app/models/dc_memory.rb +8 -1
  60. data/app/models/dc_page.rb +0 -1
  61. data/app/models/dc_permission.rb +49 -9
  62. data/app/models/dc_policy.rb +25 -14
  63. data/app/models/dc_policy_role.rb +22 -11
  64. data/app/models/dc_poll.rb +39 -19
  65. data/app/models/dc_poll_result.rb +46 -0
  66. data/app/models/dc_temp.rb +140 -0
  67. data/app/models/dc_user_role.rb +2 -2
  68. data/app/models/drgcms_form_fields.rb +12 -1
  69. data/app/models/drgcms_form_fields/action.rb +61 -0
  70. data/app/models/drgcms_form_fields/comment.rb +8 -4
  71. data/app/models/drgcms_form_fields/date_picker.rb +11 -9
  72. data/app/models/drgcms_form_fields/date_select.rb +1 -1
  73. data/app/models/drgcms_form_fields/datetime_picker.rb +12 -10
  74. data/app/models/drgcms_form_fields/datetime_select.rb +1 -1
  75. data/app/models/drgcms_form_fields/drgcms_field.rb +55 -9
  76. data/app/models/drgcms_form_fields/embedded.rb +26 -16
  77. data/app/models/drgcms_form_fields/file_field.rb +52 -0
  78. data/app/models/drgcms_form_fields/file_select.rb +2 -2
  79. data/app/models/drgcms_form_fields/hash_field.rb +90 -0
  80. data/app/models/drgcms_form_fields/hidden_field.rb +1 -1
  81. data/app/models/drgcms_form_fields/html_field.rb +1 -1
  82. data/app/models/drgcms_form_fields/link_to.rb +2 -2
  83. data/app/models/drgcms_form_fields/method.rb +66 -0
  84. data/app/models/drgcms_form_fields/multitext_autocomplete.rb +23 -14
  85. data/app/models/drgcms_form_fields/number_field.rb +15 -6
  86. data/app/models/drgcms_form_fields/radio.rb +96 -0
  87. data/app/models/drgcms_form_fields/readonly.rb +2 -2
  88. data/app/models/drgcms_form_fields/select.rb +92 -29
  89. data/app/models/drgcms_form_fields/text_area.rb +1 -1
  90. data/app/models/drgcms_form_fields/text_autocomplete.rb +31 -17
  91. data/app/models/drgcms_form_fields/text_field.rb +1 -1
  92. data/app/models/drgcms_form_fields/text_with_select.rb +6 -3
  93. data/app/models/drgcms_form_fields/tree_select.rb +15 -4
  94. data/app/{helpers → renderers}/dc_ad_renderer.rb +0 -0
  95. data/app/{helpers → renderers}/dc_big_menu_renderer.rb +1 -0
  96. data/app/{helpers → renderers}/dc_captcha_renderer.rb +0 -0
  97. data/app/{helpers → renderers}/dc_common_renderer.rb +0 -0
  98. data/app/{helpers → renderers}/dc_gallery_renderer.rb +1 -0
  99. data/app/{helpers → renderers}/dc_menu_renderer.rb +11 -4
  100. data/app/{helpers → renderers}/dc_page_renderer.rb +1 -0
  101. data/app/{helpers → renderers}/dc_part_renderer.rb +5 -4
  102. data/app/{helpers → renderers}/dc_piece_renderer.rb +1 -1
  103. data/app/{helpers → renderers}/dc_poll_renderer.rb +91 -64
  104. data/app/{helpers → renderers}/dc_renderer.rb +1 -0
  105. data/app/{helpers → renderers}/dc_simple_menu_renderer.rb +1 -0
  106. data/app/views/cmsedit/{remove_edit_stuff.js.erb → __remove_edit_stuff.js.erb} +0 -0
  107. data/app/views/cmsedit/{show.html.erb → __show.html.erb} +0 -0
  108. data/app/views/cmsedit/_edit_stuff.html.erb +4 -25
  109. data/app/views/cmsedit/_form.html.erb +4 -3
  110. data/app/views/cmsedit/_result.html.erb +2 -3
  111. data/app/views/cmsedit/edit.html.erb +4 -1
  112. data/app/views/cmsedit/index.html.erb +7 -1
  113. data/app/views/cmsedit/new.html.erb +3 -1
  114. data/app/views/dc_common/_help.html.erb +17 -0
  115. data/app/views/layouts/models.html.erb +2 -1
  116. data/config/locales/drgcms_en.yml +27 -3
  117. data/config/locales/drgcms_sl.yml +32 -5
  118. data/config/locales/models_en.yml +65 -17
  119. data/config/locales/models_sl.yml +69 -18
  120. data/drg_cms.gemspec +1 -1
  121. data/lib/drg_cms.rb +61 -1
  122. data/lib/drg_cms/version.rb +1 -1
  123. data/lib/generators/new_drg_form/new_drg_form_generator.rb +9 -2
  124. data/lib/tasks/database.rake +6 -56
  125. metadata +73 -54
  126. data/app/assets/stylesheets/drg_cms/__jquery-ui.css +0 -339
  127. data/app/helpers/application_helper.rb +0 -2
  128. data/app/helpers/cmsedit_helper.rb +0 -888
  129. data/app/models/dc_dummy.rb +0 -102
  130. data/test/fixtures/drg_cms_test_data.rb +0 -87
@@ -65,27 +65,29 @@ class DatePicker < DrgcmsField
65
65
  # Render date_picker field html code
66
66
  ###########################################################################
67
67
  def render
68
- value = (@record and @record[@yaml['name']]) ? I18n.localize(@record[@yaml['name']].to_date) : nil
69
- return ro_standard( @parent.dc_format_value(value)) if @readonly
70
- #
68
+ value = @record.try(@yaml['name']) ? I18n.localize(@record[@yaml['name']].to_date) : nil
69
+ #return ro_standard( @parent.dc_format_value(value)) if @readonly
70
+
71
71
  @yaml['options'] ||= {}
72
72
  set_initial_value
73
- @yaml['html']['size'] ||= 10
74
- @yaml['html']['value'] = value
75
- #
73
+ @yaml['html']['size'] ||= @yaml['size'] || 10
74
+ @yaml['html']['value'] ||= value
75
+ @yaml['html']['autocomplete'] ||= 'off'
76
+ @yaml['html']['class'] = @yaml['html']['class'].to_s + ' date-picker'
77
+
76
78
  @yaml['options']['lang'] ||= "'#{I18n.locale}'"
77
79
  @yaml['options']['format'] ||= "'#{t('datetimepicker.formats.date')}'"
78
80
  @yaml['options']['timepicker'] = false
79
- #
81
+
80
82
  record = record_text_for(@yaml['name'])
81
83
  @html << @parent.text_field(record, @yaml['name'], @yaml['html'])
82
- @js << <<EOJS
84
+ @js << %Q[
83
85
  $(document).ready(function() {
84
86
  $("##{record}_#{@yaml['name']}").datetimepicker( {
85
87
  #{hash_to_options(@yaml['options'])}
86
88
  });
87
89
  });
88
- EOJS
90
+ ] unless @readonly
89
91
 
90
92
  self
91
93
  end
@@ -46,7 +46,7 @@ class DateSelect < DrgcmsField
46
46
  # Render date_select field html code
47
47
  ###########################################################################
48
48
  def render
49
- return ro_standard( @parent.dc_format_value(@record[@yaml['name']])) if @readonly
49
+ #return ro_standard( @parent.dc_format_value(@record[@yaml['name']])) if @readonly
50
50
  #
51
51
  @yaml['options'] ||= {}
52
52
  set_initial_value('options','default')
@@ -51,26 +51,28 @@ class DatetimePicker < DrgcmsField
51
51
  # Render date_time_picker field html code
52
52
  ###########################################################################
53
53
  def render
54
- value = (@record and @record[@yaml['name']]) ? I18n.localize(@record[@yaml['name']].localtime) : nil
55
- return ro_standard( @parent.dc_format_value(value)) if @readonly
56
- #
54
+ value = @record.try(@yaml['name']) ? I18n.localize(@record[@yaml['name']].localtime) : nil
55
+ #return ro_standard( @parent.dc_format_value(value)) if @readonly
56
+
57
57
  @yaml['options'] ||= {}
58
58
  set_initial_value
59
- @yaml['html']['size'] ||= 14
60
- @yaml['html']['value'] = value if @record[@yaml['name']]
61
- #
59
+ @yaml['html']['size'] ||= @yaml['size'] || 14
60
+ @yaml['html']['value'] ||= value if @record[@yaml['name']]
61
+ @yaml['html']['autocomplete'] ||= 'off'
62
+ @yaml['html']['class'] = @yaml['html']['class'].to_s + ' date-picker'
63
+
62
64
  @yaml['options']['lang'] ||= "'#{I18n.locale}'"
63
65
  @yaml['options']['format'] ||= "'#{t('datetimepicker.formats.datetime')}'"
64
- #
66
+
65
67
  record = record_text_for(@yaml['name'])
66
68
  @html << @parent.text_field(record, @yaml['name'], @yaml['html'])
67
- @js << <<EOJS
69
+ @js << %Q[
68
70
  $(document).ready(function() {
69
71
  $("##{record}_#{@yaml['name']}").datetimepicker( {
70
72
  #{hash_to_options(@yaml['options'])}
71
73
  });
72
- });
73
- EOJS
74
+ });
75
+ ] unless @readonly
74
76
 
75
77
  self
76
78
  end
@@ -45,7 +45,7 @@ class DatetimeSelect < DrgcmsField
45
45
  # Render datetime_select field html code
46
46
  ###########################################################################
47
47
  def render
48
- return ro_standard( @parent.dc_format_value(@record[@yaml['name']])) if @readonly
48
+ #return ro_standard( @parent.dc_format_value(@record[@yaml['name']])) if @readonly
49
49
  #
50
50
  @yaml['options'] ||= {}
51
51
  set_initial_value('options','default')
@@ -62,6 +62,7 @@ module DrgcmsFormFields
62
62
  ###########################################################################
63
63
  class DrgcmsField
64
64
  attr_reader :js
65
+ attr_reader :css
65
66
 
66
67
  ####################################################################
67
68
  # DrgcmsField initialization code.
@@ -79,14 +80,16 @@ def initialize( parent, record, yaml )
79
80
  @record = record
80
81
  @yaml = yaml
81
82
  @form = parent.form
83
+ @yaml['html'] ||= {}
84
+ # set readonly field
82
85
  @readonly = (@yaml and @yaml['readonly']) || (@form and @form['readonly'])
83
- if @yaml['size'] # move size to html element if not already there
84
- @yaml['html'] ||= {}
85
- @yaml['html']['size'] ||= @yaml['size']
86
- end
86
+ @yaml['html']['readonly'] = true if @readonly
87
+ # assign size to html element if not already there
88
+ @yaml['html']['size'] ||= @yaml['size'] if @yaml['size']
89
+
87
90
  @html = ''
88
91
  @js = ''
89
- @css = @yaml['css']
92
+ @css = set_css_code @yaml['css']
90
93
  self
91
94
  end
92
95
 
@@ -94,7 +97,7 @@ end
94
97
  # Returns html code together with CSS code.
95
98
  ####################################################################
96
99
  def html
97
- @html + (@css ? "\n<style type=\"text/css\">#{@css}</style>" : '')
100
+ @html
98
101
  end
99
102
 
100
103
  ####################################################################
@@ -125,7 +128,13 @@ end
125
128
  # Standard code for returning readonly field.
126
129
  ####################################################################
127
130
  def ro_standard(value=nil)
128
- value = @record[@yaml['name']] if value.nil? and @record.respond_to?(@yaml['name'])
131
+ if value.nil?
132
+ value = if @yaml['html']['value']
133
+ @yaml['html']['value']
134
+ else
135
+ @record.respond_to?(@yaml['name']) ? @record.send(@yaml['name']) : nil
136
+ end
137
+ end
129
138
  @html << (value.blank? ? '' : "<div class='dc-readonly'>#{value}</div>")
130
139
  self
131
140
  end
@@ -142,7 +151,7 @@ end
142
151
  # flash[:record] = {}
143
152
  # flash[:record]['picture'] = '/path/to_picture'
144
153
  ####################################################################
145
- def set_initial_value(opt1='html', opt2='value')
154
+ def set_initial_value(opt1 = 'html', opt2 = 'value')
146
155
  @yaml['html'] ||= {}
147
156
  value_send_as = 'p_' + @yaml['name']
148
157
  if @parent.params[value_send_as]
@@ -150,11 +159,26 @@ def set_initial_value(opt1='html', opt2='value')
150
159
  elsif @parent.flash[:record] and @parent.flash[:record][@yaml['name']]
151
160
  @yaml[opt1][opt2] = @parent.flash[:record][@yaml['name']]
152
161
  end
162
+ set_default_value(opt1, opt2) if @yaml['default']
163
+ end
164
+
165
+ ####################################################################
166
+ # Will set default value
167
+ ####################################################################
168
+ def set_default_value(opt1, opt2)
169
+ return if @yaml[opt1][opt2].present?
170
+ return if @record && @record[@yaml['name']].present?
171
+
172
+ @yaml[opt1][opt2] = if @yaml['default'].class == Hash
173
+ eval(@yaml['default']['eval'])
174
+ else
175
+ @yaml['default']
176
+ end
153
177
  end
154
178
 
155
179
  ####################################################################
156
180
  # Returns style html code for DRGForm object if style directive is present in field definition.
157
- # Otherwiese returns empty string.
181
+ # Otherwise returns empty string.
158
182
  #
159
183
  # Style may be defined like:
160
184
  # style:
@@ -186,6 +210,28 @@ def set_style()
186
210
  end
187
211
  end
188
212
 
213
+ ####################################################################
214
+ # DEPRECATED!
215
+ #
216
+ # Returns css code for the field if specified. It replaces all occurences of '# '
217
+ # with field name id, as defined on form.
218
+ ####################################################################
219
+ def __css_code
220
+ return '' if @css.blank?
221
+ @css.gsub!('# ',"#td_record_#{@yaml['name']} ")
222
+ "\n<style type=\"text/css\">#{@css}</style>"
223
+ end
224
+
225
+ ####################################################################
226
+ # Sets css code for the field if specified. It replaces all occurences of '# '
227
+ # with field name id, as defined on form.
228
+ ####################################################################
229
+ def set_css_code(css)
230
+ return '' if css.blank?
231
+ css.gsub!('# ',"#td_record_#{@yaml['name']} ") if css.match('# ')
232
+ css
233
+ end
234
+
189
235
  ####################################################################
190
236
  # Will return ruby hash formated as javascript string which can be used
191
237
  # for passing parameters in javascript code.
@@ -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,33 +49,41 @@ class Embedded < DrgcmsField
47
49
  ###########################################################################
48
50
  # Render embedded field html code
49
51
  ###########################################################################
50
- def render
51
- #return self if @record.new_record? # would be in error otherwise
52
- # HTML defaults. Some must be set
52
+ def render
53
+ # HTML defaults. Some must be set
53
54
  @yaml['html'] ||= {}
54
- @yaml['html']['height'] ||= 300
55
- @yaml['html']['width'] ||= '99%'
56
- # defaults both way
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
- #
63
- if @yaml['name'] == @yaml['table']
62
+
63
+ if @yaml['name'] == @yaml['table'] or @yaml['table'] == 'dc_memory'
64
64
  tables = @yaml['table']
65
- ids = @record._id
65
+ ids = @record.id
66
66
  else
67
- tables = @parent.tables.inject('') { |r,v| r << "#{v[1]};" } + @yaml['table']
68
- ids = @parent.ids.inject('') { |r,v| r << "#{v};" } + @record._id
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
- opts = { controller: 'cmsedit', action: 'index', ids: ids, table: tables, form_name: @yaml['form_name'],
70
+ opts = { controller: 'cmsedit', action: @yaml['action'],
71
+ ids: ids, table: tables, form_name: @yaml['form_name'],
71
72
  field_name: @yaml['name'], iframe: "if_#{@yaml['name']}", readonly: @readonly }
73
+ # additional parameters if specified
74
+ @yaml['params'].each { |k,v| opts[k] = @parent.dc_value_for_parameter(v) } if @yaml['params']
75
+
72
76
  @html << "<iframe class='iframe_embedded' id='if_#{@yaml['name']}' name='if_#{@yaml['name']}' #{html}></iframe>"
73
77
  unless @record.new_record?
78
+ url = @parent.url_for(opts)
79
+ data = if @yaml['load'].nil? || @yaml['load'].match('default')
80
+ "src"
81
+ else
82
+ "data-src-#{@yaml['load']}"
83
+ end
74
84
  @js << %Q[
75
85
  $(document).ready( function() {
76
- $('#if_#{@yaml['name']}').attr('src', '#{@parent.url_for(opts)}');
86
+ $('#if_#{@yaml['name']}').attr('#{data}', '#{url}');
77
87
  });]
78
88
  end
79
89
  self
@@ -0,0 +1,52 @@
1
+ #--
2
+ # Copyright (c) 2020+ 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 file_field DRG CMS form field.
27
+ #
28
+ # ===Form options:
29
+ # * +type:+ text_field (required)
30
+ # * +name:+ Field name (required)
31
+ # * +html:+ html options which apply to text_field field (optional)
32
+ #
33
+ # Form example:
34
+ # 10:
35
+ # name: title
36
+ # type: file_field
37
+ # size: 30
38
+ ###########################################################################
39
+ class FileField < DrgcmsField
40
+
41
+ ###########################################################################
42
+ # Render text_field field html code
43
+ ###########################################################################
44
+ def render
45
+ return self if @readonly
46
+
47
+ @html << @parent.file_field(nil,@yaml['name'], @yaml['html'])
48
+ self
49
+ end
50
+
51
+ end
52
+ end
@@ -50,10 +50,10 @@ class FileSelect < DrgcmsField
50
50
  ###########################################################################
51
51
  def render
52
52
  return ro_standard if @readonly
53
- # retrieve html editor from page settings
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)
@@ -0,0 +1,90 @@
1
+ #--
2
+ # Copyright (c) 2019+ 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 text_field DRG CMS form field.
27
+ #
28
+ # ===Form options:
29
+ # * +type:+ text_field (required)
30
+ # * +name:+ Field name (required)
31
+ # * +html:+ html options which apply to text_field field (optional)
32
+ #
33
+ # Form example:
34
+ # 10:
35
+ # name: title
36
+ # type: text_field
37
+ # size: 30
38
+ # html:
39
+ # required: yes
40
+ ###########################################################################
41
+ class HashField < DrgcmsField
42
+
43
+ ###########################################################################
44
+ # Returns value for readonly field
45
+ ###########################################################################
46
+ def ro_standard()
47
+ return self if @record[@yaml['name']].nil?
48
+
49
+ html = ''
50
+ @record[@yaml['name']].each do |key, value|
51
+ html << "#{key}:#{value}<br>"
52
+ end
53
+ super(html)
54
+ end
55
+
56
+ ###########################################################################
57
+ # Render text_field field html code
58
+ ###########################################################################
59
+ def render
60
+ return ro_standard if @readonly
61
+
62
+ set_initial_value
63
+ record = record_text_for(@yaml['name'])
64
+ # Convert Hash to values separated by colon
65
+ if @record[@yaml['name']]
66
+ @yaml['html']['value'] = @record[@yaml['name']].to_a.inject('') {|r, e| r << "#{e.first}:#{e.last}\n"}
67
+ end
68
+ @html << @parent.text_area( record, @yaml['name'], @yaml['html'])
69
+ self
70
+ end
71
+
72
+ ###########################################################################
73
+ # Return value. Return nil if input field is empty
74
+ ###########################################################################
75
+ def self.get_data(params, name)
76
+ return nil if params['record'][name].blank?
77
+
78
+ result = params['record'][name].split("\n").select { |e| !e.blank? }
79
+ return if result.size == 0
80
+ # convert to Hash
81
+ ret = {}
82
+ result.map do |e|
83
+ key, value = e.chomp.split(':')
84
+ ret[key.strip] = value.strip if value.present?
85
+ end
86
+ ret
87
+ end
88
+
89
+ end
90
+ end