drg_cms 0.6.0.3 → 0.6.0.6

Sign up to get free protection for your applications and to get access to all the features.
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,61 @@
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 action DRG CMS form field. Actions can also be inserted on
27
+ # the form like just like on action pane.
28
+ #
29
+ # ===Form options:
30
+ # * +type:+ action (required)
31
+ # * +action_type:+ link, submit or ajax action (default link)
32
+ # * +caption:+ Caption for action
33
+ # * +icon:+ Action icon
34
+ # * +url:+ direct url link
35
+ # * +controller:+ controller name
36
+ # * +action:+ action name
37
+ # * +html:+ html options which apply to link_to (optional)
38
+ #
39
+ # Form example:
40
+ # 30:
41
+ # type: link_to
42
+ # caption: Some action
43
+ # icon: cogs
44
+ # controller: my_controller
45
+ # action: my_action
46
+ # id: id # will be replaced by record._id
47
+ ###########################################################################
48
+ class Action < DrgcmsField
49
+
50
+ ###########################################################################
51
+ # Render link_to field html code
52
+ ###########################################################################
53
+ def render
54
+ @yaml['type'] = @yaml['action_type'] || 'link'
55
+ #
56
+ @html << '<ul class="action">' + @parent.dc_link_ajax_window_submit_action(@yaml,@record) + '</ul>'
57
+ self
58
+ end
59
+
60
+ end
61
+ end
@@ -29,11 +29,14 @@ module DrgcmsFormFields
29
29
  # ===Form options:
30
30
  # * +text:+ any text. Text will be translated if key is found in translations. (required)
31
31
  # * +type:+ comment (required)
32
- #
32
+ # * +caption:+ Caption text written in label place. If set to false comment
33
+ # will occupy whole row. (required)
34
+ #
33
35
  # Form example:
34
36
  # 30:
35
- # name: active
36
- # type: check_box
37
+ # type: comment
38
+ # text: myapp.comment_text
39
+ # caption: false
37
40
  ###########################################################################
38
41
  class Comment < DrgcmsField
39
42
 
@@ -41,7 +44,8 @@ class Comment < DrgcmsField
41
44
  # Render comment field html code
42
45
  ###########################################################################
43
46
  def render
44
- @html << t(@yaml['comment'], @yaml['comment'])
47
+ comment = @yaml['comment'] || @yaml['text']
48
+ @html << "<div class=\"dc-comment\">#{t(comment, comment).gsub("\n",'<br>')}</div>"
45
49
  self
46
50
  end
47
51
  end
@@ -65,13 +65,14 @@ 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
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
70
  #
71
71
  @yaml['options'] ||= {}
72
72
  set_initial_value
73
- @yaml['html']['size'] ||= 10
74
- @yaml['html']['value'] = value
73
+ @yaml['html']['size'] ||= @yaml['size'] || 10
74
+ @yaml['html']['value'] ||= value
75
+ @yaml['html']['autocomplete'] ||= 'off'
75
76
  #
76
77
  @yaml['options']['lang'] ||= "'#{I18n.locale}'"
77
78
  @yaml['options']['format'] ||= "'#{t('datetimepicker.formats.date')}'"
@@ -79,13 +80,13 @@ def render
79
80
  #
80
81
  record = record_text_for(@yaml['name'])
81
82
  @html << @parent.text_field(record, @yaml['name'], @yaml['html'])
82
- @js << <<EOJS
83
+ @js << %Q[
83
84
  $(document).ready(function() {
84
85
  $("##{record}_#{@yaml['name']}").datetimepicker( {
85
86
  #{hash_to_options(@yaml['options'])}
86
87
  });
87
88
  });
88
- EOJS
89
+ ] unless @readonly
89
90
 
90
91
  self
91
92
  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,27 @@ 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
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
56
  #
57
57
  @yaml['options'] ||= {}
58
58
  set_initial_value
59
- @yaml['html']['size'] ||= 14
60
- @yaml['html']['value'] = value if @record[@yaml['name']]
59
+ @yaml['html']['size'] ||= @yaml['size'] || 14
60
+ @yaml['html']['value'] ||= value if @record[@yaml['name']]
61
+ @yaml['html']['autocomplete'] ||= 'off'
61
62
  #
62
63
  @yaml['options']['lang'] ||= "'#{I18n.locale}'"
63
64
  @yaml['options']['format'] ||= "'#{t('datetimepicker.formats.datetime')}'"
64
65
  #
65
66
  record = record_text_for(@yaml['name'])
66
67
  @html << @parent.text_field(record, @yaml['name'], @yaml['html'])
67
- @js << <<EOJS
68
+ @js << %Q[
68
69
  $(document).ready(function() {
69
70
  $("##{record}_#{@yaml['name']}").datetimepicker( {
70
71
  #{hash_to_options(@yaml['options'])}
71
72
  });
72
- });
73
- EOJS
73
+ });
74
+ ] unless @readonly
74
75
 
75
76
  self
76
77
  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,14 @@ 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
+ p @yaml['name'],value
132
+ if value.nil?
133
+ value = if @yaml['html']['value']
134
+ @yaml['html']['value']
135
+ else
136
+ @record.respond_to?(@yaml['name']) ? @record.send(@yaml['name']) : nil
137
+ end
138
+ end
129
139
  @html << (value.blank? ? '' : "<div class='dc-readonly'>#{value}</div>")
130
140
  self
131
141
  end
@@ -186,6 +196,28 @@ def set_style()
186
196
  end
187
197
  end
188
198
 
199
+ ####################################################################
200
+ # DEPRECATED!
201
+ #
202
+ # Returns css code for the field if specified. It replaces all occurences of '# '
203
+ # with field name id, as defined on form.
204
+ ####################################################################
205
+ def css_code
206
+ return '' if @css.blank?
207
+ @css.gsub!('# ',"#td_record_#{@yaml['name']} ")
208
+ "\n<style type=\"text/css\">#{@css}</style>"
209
+ end
210
+
211
+ ####################################################################
212
+ # Sets css code for the field if specified. It replaces all occurences of '# '
213
+ # with field name id, as defined on form.
214
+ ####################################################################
215
+ def set_css_code(css)
216
+ return '' if css.blank?
217
+ css.gsub!('# ',"#td_record_#{@yaml['name']} ") if css.match('# ')
218
+ css
219
+ end
220
+
189
221
  ####################################################################
190
222
  # Will return ruby hash formated as javascript string which can be used
191
223
  # for passing parameters in javascript code.
@@ -60,7 +60,7 @@ def render
60
60
  html = ''
61
61
  @yaml['html'].each {|k,v| html << "#{k}=\"#{v}\" "}
62
62
  #
63
- if @yaml['name'] == @yaml['table']
63
+ if @yaml['name'] == @yaml['table'] or @yaml['table'] == 'dc_memory'
64
64
  tables = @yaml['table']
65
65
  ids = @record._id
66
66
  else
@@ -69,11 +69,16 @@ def render
69
69
  end
70
70
  opts = { controller: 'cmsedit', action: 'index', ids: ids, table: tables, form_name: @yaml['form_name'],
71
71
  field_name: @yaml['name'], iframe: "if_#{@yaml['name']}", readonly: @readonly }
72
+ # additional parameters if specified
73
+ @yaml['params'].each { |k,v| opts[k] = @parent.dc_value_for_parameter(v) } if @yaml['params']
74
+
72
75
  @html << "<iframe class='iframe_embedded' id='if_#{@yaml['name']}' name='if_#{@yaml['name']}' #{html}></iframe>"
73
76
  unless @record.new_record?
77
+ url = @parent.url_for(opts)
78
+ data = @yaml['delay'] ? 'data-src-delay' : 'src'
74
79
  @js << %Q[
75
80
  $(document).ready( function() {
76
- $('#if_#{@yaml['name']}').attr('src', '#{@parent.url_for(opts)}');
81
+ $('#if_#{@yaml['name']}').attr('#{data}', '#{url}');
77
82
  });]
78
83
  end
79
84
  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
+ #record = record_text_for(@yaml['name'])
47
+ @html << @parent.file_field( @yaml['name'], @yaml['html'])
48
+ self
49
+ end
50
+
51
+ end
52
+ end
@@ -49,7 +49,7 @@ class HtmlField < DrgcmsField
49
49
  # Render html_field field html code
50
50
  ###########################################################################
51
51
  def render
52
- return ro_standard if @readonly
52
+ #return ro_standard if @readonly
53
53
  # retrieve html editor from page settings
54
54
  editor_string = @parent.dc_get_site.params['html_editor'] if @parent.dc_get_site
55
55
  editor_string ||= 'ckeditor'
@@ -98,7 +98,7 @@ def render
98
98
  return self
99
99
  end
100
100
  #
101
- return ro_standard(table, search) if @readonly
101
+ #return ro_standard(table, search) if @readonly
102
102
  # TODO check if table exists
103
103
  collection = table.classify.constantize
104
104
  unless @record.respond_to?(@yaml['name'])
@@ -113,9 +113,11 @@ def render
113
113
  @html << '<div class="ui-autocomplete-border">'
114
114
  @html << @parent.link_to(@parent.fa_icon('plus-square lg', class: 'dc-animate dc-green'), '#',onclick: 'return false;') # dummy add. But it is usefull.
115
115
 
116
- record = record_text_for(@yaml['name'])
117
- @html << ' ' << @parent.text_field(record, _name, @yaml['html']) # text field for autocomplete
118
- @html << "<div id =\"#{record}#{@yaml['name']}\">" # div to list active records
116
+ record = record_text_for(@yaml['name'])
117
+ # text field for autocomplete
118
+ @html << ' ' << @parent.text_field(record, _name, @yaml['html'])
119
+ # div to list active selections
120
+ @html << "<div id =\"#{record}#{@yaml['name']}\">"
119
121
  # find value for each field inside categories
120
122
  unless @record[@yaml['name']].nil?
121
123
  @record[@yaml['name']].each do |element|
@@ -131,6 +133,7 @@ def render
131
133
  @html << if rec
132
134
  link = @parent.link_to(@parent.fa_icon('remove lg', class: 'dc-animate dc-red'), '#',
133
135
  onclick: "$('##{rec.id}').hide(); var v = $('##{record}_#{@yaml['name']}_#{rec.id}'); v.val(\"-\" + v.val());return false;")
136
+ link = @parent.fa_icon('check lg', class: 'dc-green') if @readonly
134
137
  field = @parent.hidden_field(record, "#{@yaml['name']}_#{rec.id}", value: element)
135
138
  "<div id=\"#{rec.id}\" style=\"padding:4px;\">#{link} #{rec.send(field_name)}<br>#{field}</div>"
136
139
  else
@@ -52,22 +52,31 @@ class NumberField < DrgcmsField
52
52
  # Render text_field field html code
53
53
  ###########################################################################
54
54
  def render
55
- return ro_standard if @readonly
55
+ #return ro_standard if @readonly
56
56
  set_initial_value
57
57
  #
58
58
  record = record_text_for(@yaml['name'])
59
59
  @yaml['html'] ||= {}
60
60
  @yaml['html']['class'] = 'dc-number'
61
+ if @yaml['format'].class == String
62
+ format = @yaml['format']
63
+ @yaml['format'] = {}
64
+ @yaml['format']['decimal'] = format[1].blank? ? 2 : format[1].to_i
65
+ @yaml['format']['separator'] = format[2].blank? ? I18n.t('number.currency.format.separator') : format[2]
66
+ @yaml['format']['delimiter'] = format[3].blank? ? I18n.t('number.currency.format.delimiter') : format[3]
67
+ end
61
68
  @yaml['html']['data-decimal'] = @yaml.dig('format','decimal') || 2
62
69
  @yaml['html']['data-delimiter'] = @yaml.dig('format','delimiter') || I18n.t('number.currency.format.delimiter')
63
70
  @yaml['html']['data-separator'] = @yaml.dig('format','separator') || I18n.t('number.currency.format.separator')
64
71
  # @yaml['html']['data-currency'] = @yaml.dig('format','currency') == 'yes' ? I18n.t('number.currency.format.currency') : @yaml.dig('format','currency')
65
72
  value = @record[@yaml['name']] || 0
66
-
67
- @html << @parent.hidden_field( record, @yaml['name'], value: value )
68
-
69
73
  @yaml['html']['value'] = @parent.dc_format_number(value, @yaml['html']['data-decimal'], @yaml['html']['data-separator'], @yaml['html']['data-delimiter'] )
70
- @html << @parent.text_field( nil,"record_#{@yaml['name']}1", @yaml['html'])
74
+
75
+ return ro_standard(@yaml['html']['value']) if @readonly
76
+
77
+ @yaml['html']['autocomplete'] ||= 'off'
78
+ @html << @parent.hidden_field( record, @yaml['name'], value: value )
79
+ @html << @parent.text_field( nil,"record_#{@yaml['name']}_", @yaml['html'])
71
80
  self
72
81
  end
73
82
 
@@ -76,7 +85,7 @@ end
76
85
  ###########################################################################
77
86
  def self.get_data(params, name)
78
87
  return 0 if params['record'][name].blank?
79
- params['record'][name].match('.') ? BigDecimal.new(params['record'][name]) : Integer.new(params['record'][name])
88
+ params['record'][name].match('.') ? params['record'][name].to_f : Integer.new(params['record'][name])
80
89
  end
81
90
 
82
91
  end
@@ -0,0 +1,91 @@
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 radio DRG CMS form field. Field provides radio button input
27
+ # structure.
28
+ # Form options are mostly same as in select field.
29
+ #
30
+ # ===Form options:
31
+ # * +name:+ field name (required)
32
+ # * +type:+ radio (required)
33
+ # * +choices:+ Values for choices separated by comma. Values can also be specified like description:value.
34
+ # In this case description will be shown to user, but value will be saved to document.
35
+ # choices: 'OK:0,Ready:1,Error:2'
36
+ # choices: Ruby,Pyton,PHP
37
+ # * +eval:+ Choices will be provided by evaluating expression
38
+ # eval: dc_choices4('model_name','description_field_name','_id'); dc_choices4 helper will provide data for select field.
39
+ # eval: ModelName.choices4_field; ModelName class will define method choices4_field which
40
+ # will provide data for select field. Since expression is evaluated in the context of Form Field object
41
+ # Even session session variables can be accessed.
42
+ # eval: 'MyClass.method(@parent.session[:user_id])'
43
+ # When searching is more complex custom search method may be defined in CollectionName
44
+ # model which will provide result set for search.
45
+ # eval: collection_name.search_field_name.method_name;
46
+ # If choices or eval is not defined choices will be provided from translation helpers. For example:
47
+ # Collection has field status. Choices for field will be provided by en.helpers.model_name.choices4_status
48
+ # entry of english translation. English is of course default translation. If you provide translations in
49
+ # your local language then select choices will be localized.
50
+ # en.helpers.model_name.choices4_status: 'OK:0,Ready:1,Error:2'
51
+ # sl.helpers.model_name.choices4_status: 'V redu:0,Pripravljen:1,Napaka:2'
52
+ # * +inline:+ Radio buttons will be presented inline instead of stacked on each other.
53
+ #
54
+ # Form example:
55
+ # 10:
56
+ # name: hifi
57
+ # type: radio
58
+ # choices: 'Marantz:1,Sony:2,Bose:3,Pioneer:4'
59
+ # inline: true
60
+ ###########################################################################
61
+ class Radio < Select
62
+
63
+ ###########################################################################
64
+ # Render text_with_select field html code
65
+ ###########################################################################
66
+ def render
67
+ #return ro_standard if @readonly
68
+ set_initial_value('html','value')
69
+
70
+ record = record_text_for(@yaml['name'])
71
+ @yaml['html'].symbolize_keys!
72
+ clas = 'dc-radio' + ( @yaml['inline'] ? ' dc-inline' : '')
73
+ @html << "<div class=\"#{clas}\">"
74
+ choices = get_choices
75
+ # When error and boolean field
76
+ if choices.size == 1 and (@record[@yaml['name']].class == TrueClass or @record[@yaml['name']].class == FalseClass)
77
+ choices = [[I18n.t('drgcms.true'), true], [I18n.t('drgcms.false'), false]]
78
+ end
79
+ choices.each do |choice|
80
+ choice = [choice, choice] if choice.class == String
81
+ @html << "<div>"
82
+ @html << @parent.radio_button_tag("#{record}[#{@yaml['name']}]",choice.last, choice.last.to_s == @record[@yaml['name']].to_s)
83
+ @html << choice.first
84
+ @html << "</div>"
85
+ end
86
+ @html << "</div>\n"
87
+ self
88
+ end
89
+
90
+ end
91
+ end