drg_cms 0.6.0.1 → 0.6.1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -52,7 +52,7 @@ end
52
52
  # Render text_area 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
  # @yaml['html'] ||= {}
@@ -29,6 +29,8 @@ module DrgcmsFormFields
29
29
  # * +name:+ field name (required)
30
30
  # * +type:+ text_autocomplete (required)
31
31
  # * +table+ Collection (table) name. When defined search must contain field name
32
+ # * +with_new+ Will add an icon for shortcut to add new document to collection
33
+ # * +is_id+ Field value represent value as id. If false, field will use entered value and not value selected with autocomplete. Default is true.
32
34
  # * +search:+ Search may consist of three parameters from which are separated either by dot (.)
33
35
  # * search_field_name; when table option is defined search must define field name which will be used for search query
34
36
  # * collection_name.search_field_name; Same as above except that table options must be ommited.
@@ -40,6 +42,7 @@ module DrgcmsFormFields
40
42
  # name: user_id
41
43
  # type: text_autocomplete
42
44
  # search: dc_user.name
45
+ # is_id: false
43
46
  # html:
44
47
  # size: 30
45
48
  ###########################################################################
@@ -49,62 +52,69 @@ class TextAutocomplete < DrgcmsField
49
52
  # Render text_autocomplete field html code
50
53
  ###########################################################################
51
54
  def render
52
- # Return descriptive text and put it into input field
53
- # search field name
55
+ # Return descriptive text and put it into input field
56
+ # search field name
54
57
  if @yaml['search'].class == Hash
55
58
  table = @yaml['search']['table']
56
59
  ret_name = @yaml['search']['field']
57
60
  method = @yaml['search']['method']
58
61
  elsif @yaml['search'].match(/\./)
59
- table, ret_name, method = @yaml['search'].split('.')
62
+ table, ret_name, method = @yaml['search'].split(/\.|\,/).map(&:strip)
60
63
  else
61
64
  ret_name = @yaml['search']
62
65
  end
63
- # determine table name
66
+ # determine table name
64
67
  if @yaml['table']
65
68
  table = if @yaml['table'].class == String
66
69
  @yaml['table']
67
- # eval(how_to_get_my_table_name)
68
70
  elsif @yaml['table']['eval']
69
71
  eval @yaml['table']['eval']
70
72
  else
71
- Rails.logger.error "Field #{@yaml['name']}: Invalid table parameter!"
73
+ Rails.logger.error "Field #{ @yaml['name'] }: Invalid table parameter!"
72
74
  nil
73
75
  end
74
76
  end
75
- return 'Table or field keyword not defined!' unless (table and ret_name)
76
- # TODO check if table exists
77
+ return ro_standard 'Table or field keyword not defined!' unless (table && ret_name)
78
+ # TODO check if table exists
77
79
  t = table.classify.constantize
78
- # find record and return value of field
80
+ # find record and return value of field
79
81
  value_send_as = 'p_' + @yaml['name']
80
82
  value = if @parent.params[value_send_as]
81
83
  @parent.params[value_send_as]
82
84
  elsif @record and @record[@yaml['name']]
83
85
  @record[@yaml['name']]
84
86
  end
85
- # Found value to be written in field. If field is not found write out value.
87
+ # Found value to be written in field. If field is not found write out value.
86
88
  if value
87
- record = t.find(value)
89
+ record = t.find(value) unless @yaml['not_id'] # don't if it's is not an id
88
90
  value_displayed = record ? record.send(ret_name) : value
89
91
  end
90
- # return if readonly
92
+ # return if readonly
91
93
  return ro_standard(value_displayed) if @readonly
92
- # Add method back, so autocomplete will know that it must search for method inside class
94
+ # Add method back, so autocomplete will know that it must search for method inside class
93
95
  ret_name = "#{ret_name}.#{method}" if method
94
96
  @yaml['html'] ||= {}
95
97
  @yaml['html']['value'] = value_displayed
96
98
  @yaml['html']['placeholder'] ||= t('drgcms.search_placeholder') || nil
97
- #
99
+ #
98
100
  _name = '_' + @yaml['name']
99
101
  record = record_text_for(@yaml['name'])
100
- @html << @parent.text_field(record, _name, @yaml['html'])
102
+ @html << '<span class="dc-text-autocomplete">' + @parent.text_field(record, _name, @yaml['html']) + '<span></span>'
101
103
  if @yaml['with_new']
102
104
  @html << ' ' +
103
105
  @parent.fa_icon('plus-square lg', class: 'in-edit-add', title: t('drgcms.new'),
104
106
  style: "vertical-align: top;", 'data-table' => @yaml['with_new'] )
105
107
  end
106
- @html << @parent.hidden_field(record, @yaml['name'], value: value) # actual value will be in hidden field
107
- # JS stuff
108
+ @html << '</span>' + @parent.hidden_field(record, @yaml['name'], value: value) # actual value will be in hidden field
109
+ # JS stuff
110
+ # allow unselected values on is_id: false option
111
+ not_id = @parent.dc_dont?(@yaml['is_id'], false)
112
+ not_id_code = %(
113
+ if (ui.item == null) {
114
+ $("##{record}_#{@yaml['name']}").val($("##{record}__#{@yaml['name']}").val() );
115
+ return;
116
+ } ) if not_id
117
+ #
108
118
  @js << <<EOJS
109
119
  $(document).ready(function() {
110
120
  $("##{record}_#{_name}").autocomplete( {
@@ -121,9 +131,13 @@ $(document).ready(function() {
121
131
  }
122
132
  });
123
133
  },
134
+
124
135
  change: function (event, ui) {
136
+ #{not_id_code}
137
+ if (ui.item == null) return;
125
138
  $("##{record}_#{@yaml['name']}").val(ui.item.id);
126
139
  },
140
+
127
141
  minLength: 2
128
142
  });
129
143
  });
@@ -44,7 +44,7 @@ class TextField < DrgcmsField
44
44
  # Render text_field field html code
45
45
  ###########################################################################
46
46
  def render
47
- return ro_standard if @readonly
47
+ #return ro_standard if @readonly
48
48
  set_initial_value
49
49
  #
50
50
  record = record_text_for(@yaml['name'])
@@ -65,14 +65,17 @@ class TextWithSelect < Select
65
65
  # Render text_with_select field html code
66
66
  ###########################################################################
67
67
  def render
68
- return ro_standard if @readonly
68
+ #return ro_standard if @readonly
69
69
  set_initial_value('html','value')
70
70
 
71
71
  record = record_text_for(@yaml['name'])
72
72
  @html << @parent.text_field( record, @yaml['name'], @yaml['html'])
73
- @yaml['html']['class'] = 'text-with-select'
73
+ @yaml['html']['class'] ||= ''
74
+ @yaml['html']['class'] << ' text-with-select'
74
75
  @yaml['html'].symbolize_keys!
75
- @html << @parent.select( @yaml['name'] + '_', nil, get_choices, { include_blank: true }, { class: 'text-with-select' })
76
+ unless @readonly
77
+ @html << @parent.select( @yaml['name'] + '_', nil, get_choices, { include_blank: true }, { class: 'text-with-select' })
78
+ end
76
79
 
77
80
  # javascript to update text field if new value is selected in select field
78
81
  @js =<<EOJS
@@ -87,15 +87,19 @@ end
87
87
  # Render tree_select field html code
88
88
  ###########################################################################
89
89
  def render
90
- return ro_standard if @readonly
90
+ #return ro_standard if @readonly
91
91
  set_initial_value('html','value')
92
92
  require 'sort_alphabetical'
93
93
 
94
94
  record = record_text_for(@yaml['name'])
95
- @html << "<div id=\"#{@yaml['name']}\" class=\"tree-select\" #{set_style()} >"
95
+ clas = 'tree-select' + (@readonly ? ' dc-readonly' : '')
96
+ @html << "<div id=\"#{@yaml['name']}\" class=\"#{clas}\" #{set_style()} >"
96
97
  # Fill @choices hash. The key is parent object id
97
98
  @choices = {}
98
- do_eval(@yaml['eval']).each {|data| @choices[ data[2].to_s ] ||= []; @choices[ data[2].to_s ] << (data << false)}
99
+ choices_in_eval(@yaml['eval']).each do |data|
100
+ @choices[ data[2].to_s ] ||= []
101
+ @choices[ data[2].to_s ] << (data << false)
102
+ end
99
103
  # put current values hash with. To speed up selection when there is a lot of categories
100
104
  current_values = {}
101
105
  current = @record[@yaml['name']] || []
@@ -115,13 +119,20 @@ def render
115
119
  # save multiple indicator for data processing on return
116
120
  @html << @parent.hidden_field(record, "#{@yaml['name']}_multiple", value: 1) if @yaml['multiple']
117
121
  # javascript to update hidden record field when tree looses focus
122
+ readonly_code = %Q[
123
+ ,
124
+ "conditionalselect" : function (node) {
125
+ return false; }
126
+ ]
127
+
118
128
  @js =<<EOJS
119
129
  $(function(){
120
130
  $("##{@yaml['name']}").jstree( {
121
131
  "checkbox" : {"three_state" : false},
122
132
  "core" : { "themes" : { "icons": false },
123
133
  "multiple" : #{@yaml['multiple'] ? 'true' : 'false'} },
124
- "plugins" : ["checkbox"]
134
+ "plugins" : ["checkbox","conditionalselect"]
135
+ #{@readonly ? readonly_code : ''}
125
136
  });
126
137
  });
127
138
 
File without changes
@@ -32,6 +32,7 @@
32
32
  class DcBigMenuRenderer
33
33
 
34
34
  include DcApplicationHelper
35
+ include CmsCommonHelper
35
36
  ########################################################################
36
37
  # Object initialization.
37
38
  ########################################################################
File without changes
File without changes
@@ -33,6 +33,7 @@
33
33
  class DcGalleryRenderer
34
34
 
35
35
  include DcApplicationHelper
36
+ include CmsCommonHelper
36
37
 
37
38
  ########################################################################
38
39
  # Object initialization.
@@ -35,6 +35,7 @@
35
35
  class DcMenuRenderer
36
36
 
37
37
  include DcApplicationHelper
38
+ include CmsCommonHelper
38
39
  ########################################################################
39
40
  # Object initialization. Will also prepare DcMenu document.
40
41
  ########################################################################
@@ -97,10 +98,16 @@ def link_4menu(item)
97
98
  caption = item.caption[0] == '-' ? '' : item.caption.to_s
98
99
  img_title = item.caption.to_s.sub('-','')
99
100
  # add picture if picture is not blank
100
- (item.picture.blank? ? '' :
101
- @parent.link_to( @parent.image_tag(item.picture), link, {title: img_title, target: target} )) +
102
- (caption.blank? ? '' :
103
- @parent.link_to(caption, link, {target: target}) )
101
+ html = ''
102
+ if !item.picture.blank?
103
+ if item.picture[0,3] == 'fa-'
104
+ caption << @parent.fa_icon(item.picture[3,20])
105
+ else
106
+ html = @parent.link_to( @parent.image_tag(item.picture), link, {title: img_title, target: target} ) rescue ''
107
+ end
108
+ end
109
+ html << @parent.link_to(caption.html_safe, link, {target: target}) unless caption.blank?
110
+ html
104
111
  end
105
112
 
106
113
  ########################################################################
@@ -36,6 +36,7 @@
36
36
  class DcPageRenderer
37
37
 
38
38
  include DcApplicationHelper
39
+ include CmsCommonHelper
39
40
 
40
41
  ########################################################################
41
42
  # Object initialization.
@@ -42,6 +42,7 @@
42
42
  class DcPartRenderer
43
43
 
44
44
  include DcApplicationHelper
45
+ include CmsCommonHelper
45
46
 
46
47
  ########################################################################
47
48
  # Object initialization.
@@ -98,7 +99,7 @@ def load_parts #:nodoc:
98
99
  # add parts in page
99
100
  @parent.page.dc_parts.where(active: true).each do |part|
100
101
  type = decamelize_type(part._type) || 'dc_part'
101
- @parent.parts << [part, @parent.page.id, type, "#{@parent.site.page_table};#{type}"]
102
+ @parent.parts << [part, @parent.page.id, type, "#{@parent.site.page_class.underscore};#{type}"]
102
103
  end
103
104
  # add parts in site
104
105
  @parent.site.dc_parts.where(active: true).each do |part|
@@ -161,11 +162,11 @@ end
161
162
  def in_page
162
163
  # Part is in page with id
163
164
  page = if @opts[:page_id]
164
- pageclass = @parent.site.page_table.classify.constantize
165
+ pageclass = @parent.site.page_klass
165
166
  pageclass.find(@opts[:page_id])
166
167
  # Part is in page with subject link
167
168
  elsif @opts[:page_link]
168
- pageclass = @parent.site.page_table.classify.constantize
169
+ pageclass = @parent.site.page_klass
169
170
  @page = pageclass.find_by(dc_site_id: @parent.site._id, subject_link: @opts[:page_link])
170
171
  # Part is in current page
171
172
  else
@@ -174,7 +175,7 @@ def in_page
174
175
  return "Error DcPart: Page not found!" if page.nil?
175
176
  #
176
177
  if part = page.dc_parts.find_by(name: @opts[:name])
177
- @opts[:editparams].merge!(id: part, ids: page._id, form_name: 'dc_part', table: "#{@parent.site.page_table};dc_part" )
178
+ @opts[:editparams].merge!(id: part, ids: page._id, form_name: 'dc_part', table: "#{@parent.site.page_class.underscore};dc_part" )
178
179
  render_particle(part, @opts)
179
180
  else
180
181
  "Part with name #{@opts[:name]} not found in page!"
@@ -33,7 +33,7 @@
33
33
  class DcPieceRenderer
34
34
 
35
35
  include DcApplicationHelper
36
-
36
+ include CmsCommonHelper
37
37
  ########################################################################
38
38
  # Object initialization. It also loads requested dc_piece document.
39
39
  ########################################################################
@@ -27,9 +27,9 @@
27
27
  ########################################################################
28
28
  class DcPollRenderer
29
29
 
30
- include CmseditHelper
30
+ include CmsCommonHelper
31
31
  include DcApplicationHelper
32
- include ActionView::Helpers::FormHelper # for form hepers
32
+ include ActionView::Helpers::FormHelper # for form helpers
33
33
  include ActionView::Helpers::FormOptionsHelper # for select helper
34
34
 
35
35
  ########################################################################
@@ -39,6 +39,7 @@ def initialize( parent, opts={} ) #:nodoc:
39
39
  @parent = parent
40
40
  @opts = opts
41
41
  @part_css = ''
42
+ @part_js = ''
42
43
  self
43
44
  end
44
45
 
@@ -56,15 +57,17 @@ def do_one_item(poll, yaml)
56
57
  html = ''
57
58
  yaml['separator'] ||= ''
58
59
  yaml['text'] ||= ''
59
- #
60
+ # label
60
61
  text = yaml['text'].match(/\./) ? t(yaml['text']) : yaml['text']
61
62
  if yaml['mandatory']
62
- text << '<font color="red"> *</font>'
63
+ text << ( poll.display == 'in' ? ' *' : '<span class="required"> *</span>' )
63
64
  yaml['html'] ||= {}
64
65
  yaml['html']['required'] = true
66
+ else
67
+ text << " &nbsp;" if poll.display == 'lr' and !yaml['type'].match(/submit_tag|link_to/)
65
68
  end
66
69
 
67
- # Just add text if comment and go to next one
70
+ # Just add text if comment and go to next one
68
71
  if yaml['type'] == 'comment'
69
72
  html << if poll.display == 'lr'
70
73
  "<div class='row-div'><div class='dc-form-label poll-data-text comment'>#{text}</div></div>"
@@ -73,35 +76,39 @@ def do_one_item(poll, yaml)
73
76
  end
74
77
  return html
75
78
  end
76
- # Set default value, if not already set
79
+
80
+ # Set default value, if not already set
77
81
  if yaml['default']
78
82
  if yaml['default'].match('eval')
79
83
  e = yaml['default'].match(/\((.*?)\)/)[1]
80
84
  yaml['default'] = eval e
85
+ elsif yaml['default'].match('params')
86
+ param_name = yaml['default'].split(/\.|\ |\,/)[1]
87
+ yaml['default'] = @parent.params[param_name]
81
88
  end
82
89
  key = "p_#{yaml['name']}"
83
90
  params[key] = yaml['default'] unless params[key]
84
91
  end
85
- # create form_field object and retrieve html code
92
+ # Label as placeholder
93
+ if poll.display == 'in'
94
+ yaml['html'] ||= {}
95
+ yaml['html']['placeholder'] = text
96
+ end
97
+ # create form_field object and retrieve html code
86
98
  clas_string = yaml['type'].camelize
87
99
  field_html = if DrgcmsFormFields.const_defined?(clas_string)
88
100
  clas = DrgcmsFormFields.const_get(clas_string)
89
- o = clas.new(@parent, @record, yaml).render
90
- #TODO collect all javascript and add it at the end
91
- o.html + (o.js.size > 0 ? @parent.javascript_tag(o.js) : '')
92
- else # litle error string
101
+ field = clas.new(@parent, @record, yaml).render
102
+ @part_js << field.js
103
+ field.html
104
+ else # error string
93
105
  "Error: Code for field type #{yaml['type']} not defined!"
94
106
  end
95
107
 
96
- # field = send('dc_' + yaml['type'], yaml) # call dc_xxx method to get field html code
97
108
  if yaml['type'].match(/submit_tag|link_to/)
98
- # There can be more than one links on form. End the data at first link or submit.
109
+ # There can be more than one links on form. End the data at first link or submit.
99
110
  if !@end_of_data
100
- html << if poll.display == 'lr'
101
- "</div><br>\n"
102
- else
103
- "</div>\n"
104
- end
111
+ html << (poll.display == 'lr' ? "</div><br>\n" : "</div>\n")
105
112
  # captcha
106
113
  if poll.captcha_type.to_s.size > 1
107
114
  @opts.merge!(:captcha_type => poll.captcha_type)
@@ -109,90 +116,109 @@ def do_one_item(poll, yaml)
109
116
  html << captcha.render_html
110
117
  @part_css = captcha.render_css
111
118
  end
112
- @end_od_data = true
119
+ @end_of_data = true
113
120
  end
114
- # submit and link tag
121
+ # submit and link tag
115
122
  clas = yaml['type'].match(/submit_tag/) ? '' : 'dc-link-submit'
116
123
  html << "<span class='#{clas} dc-animate'>#{field_html}#{yaml['separator']}</span>"
117
- # other elements
124
+ # other fields
118
125
  else
119
- html << if poll.display == 'lr'
120
- "<div class='row-div'><div class='dc-form-label poll-data-text #{yaml['class']}'>#{text}</div><div class='dc-form-field poll-data-field #{yaml['class']}'>#{field_html}</div></div>\n"
121
- else
122
- "<div class='poll-data-text #{yaml['class']}'>#{text}</div><div class='poll-data-field #{yaml['class']}'>#{field_html}#{yaml['separator']}</div>\n"
126
+ html << case
127
+ when poll.display == 'lr' then
128
+ "<div class='row-div'><div class='dc-form-label poll-data-text lr #{yaml['class']}'>#{text}</div><div class='poll-data-field td #{yaml['class']}'>#{field_html}</div></div>\n"
129
+ when poll.display == 'td' then
130
+ "<div class='poll-data-text td #{yaml['class']}'>#{text}</div><div class='poll-data-field td #{yaml['class']}'>#{field_html}#{yaml['separator']}</div>\n"
131
+ else
132
+ "<div class='poll-data-field in #{yaml['class']}'>#{field_html}#{yaml['separator']}</div>\n"
123
133
  end
124
134
  end
125
135
  end
126
136
 
137
+ ########################################################################
138
+ # Call method before poll is displayed. Usefull for filling predefined values into flash[:record][value]
139
+ # Method cane be defined as ClassName.method or only method.
140
+ # If only method is defined then method name must exist in helpers.
141
+ #
142
+ # Called method must return at least one result if process can continue.
143
+ ########################################################################
144
+ def eval_pre_display(code)
145
+ a = code.strip.split('.')
146
+ if a.size == 1
147
+ continue, message = @parent.send(a.first)
148
+ else
149
+ klass = a.first.classify.constantize
150
+ continue, message = klass.send(a.last,@parent)
151
+ end
152
+ [continue, message]
153
+ end
154
+
127
155
  ########################################################################
128
156
  # Default poll renderer method. Renders data for specified pool.
129
157
  ########################################################################
130
158
  def default
131
- # poll_id may be defined in params or opts
159
+ # poll_id may be defined in params or opts
132
160
  poll_id = @opts[:poll_id] || @parent.params[:poll_id]
133
161
  return '<br>Poll id is not defined?<br>' if poll_id.nil?
134
- #
162
+
135
163
  poll = DcPoll.find(poll_id)
136
164
  poll = DcPoll.find_by(name: poll_id) if poll.nil? # name instead of id
137
- return "<div class=\"dc-form-error\">Invalid Poll id #{poll_id}</div>" if poll.nil?
138
- # If parent cant be seen. so cant be polls
165
+ return %(<div class="dc-form-error">Invalid Poll id #{poll_id}</div>) if poll.nil?
166
+ # If parent cant be seen. so cant be polls
139
167
  can_view, message = dc_user_can_view(@parent, @parent.page)
140
- return "<div class=\"dc-form-error\">#{message}</div>" unless can_view
141
-
142
- html = @opts[:div] ? "<div id='#{@opts[:div]}'>" : ''
143
- html << '<a name="poll-top"></a>'
168
+ return %(<div class="dc-form-error">#{message}</div>) unless can_view
144
169
 
145
- # Operation called before poll is displayed. Usefull for filling predefined values into flash[:record][value]
146
- # Called method must return at least one result if process can continue.
147
- if poll.pre_display.to_s.size > 1
170
+ html = @opts[:div] ? %(<div id="#{@opts[:div]}"'>) : ''
171
+ html << '<a name="poll-top"></a>'
172
+ unless poll.pre_display.blank?
148
173
  begin
149
- continue, message = eval(poll.pre_display.strip + '(@parent)')
174
+ continue, message = eval_pre_display(poll.pre_display)
150
175
  rescue Exception => e
151
- return "<div class=\"dc-form-error\">Error! Poll pre display. Error: #{e.message}</div>"
176
+ return %(<div class="dc-form-error">Error! Poll pre display. Error: #{e.message}</div>)
152
177
  end
153
178
  return message unless continue
179
+
154
180
  html << message if message
155
181
  end
156
- # there might be more than one poll displayed on page. Check if messages and values are for me
157
- if @parent.flash[:poll_id].nil? or @parent.flash[:poll_id].to_s == poll_id.to_s
158
- # If flash[:record] is present copy content to params record hash
182
+ # there might be more than one poll displayed on page. Check if messages and values are for me
183
+ if @parent.flash[:poll_id].nil? || @parent.flash[:poll_id].to_s == poll_id.to_s
184
+ # If flash[:record] is present copy content to params record hash
159
185
  @parent.flash[:record].each {|k,v| @parent.params["p_#{k}"] = v } if @parent.flash[:record]
160
- # Error during procesing request
161
- html << "<div class=\"dc-form-error\">#{@parent.flash[:error]}</div>\n" if @parent.flash[:error].to_s.size > 0
162
- html << "<div class=\"dc-form-info\">#{@parent.flash[:info]}</div>\n" if @parent.flash[:info]
186
+ # Error during procesing request
187
+ html << %(<div class="dc-form-error">#{@parent.flash[:error]}</div>\n) if @parent.flash[:error].to_s.size > 0
188
+ html << %(<div class="dc-form-info">#{@parent.flash[:info]}</div>\n) if @parent.flash[:info]
163
189
  end
164
- # div and form tag
165
- html << "<div class=\"poll-div\">\n"
166
- # edit link
190
+ # div and form tag
191
+ html << %(<div class="poll-div">\n)
192
+ # edit link
167
193
  if @opts[:edit_mode] > 1
168
194
  @opts[:editparams].merge!( controller: 'cmsedit', action: 'edit', id: poll._id, table: 'dc_poll', form_name: 'dc_poll' )
169
195
  @opts[:editparams].merge!(title: "#{t('drgcms.edit')}: #{poll.name}")
170
196
  @opts[:editparams].delete(:ids) # this is from page, but it gets in a way
171
197
  html << dc_link_for_edit( @opts[:editparams] )
172
198
  end
173
- #
199
+
174
200
  html << case
175
201
  when poll.operation == 'poll_submit' then
176
202
  @parent.form_tag(action: poll.operation, method: :put)
177
203
  when poll.operation == 'link' then
178
204
  @parent.form_tag( poll.parameters, method: :put)
179
205
  end
180
- # header
181
- html << "<div class='poll-title'>#{poll.title}</div>" unless poll.title[0] == '-' # - on first position will not display title
182
- html << poll.sub_text.to_s # if poll.sub_text.to_s.size > 5
206
+ # header, - on first position will not display title
207
+ html << %(<div class="poll-title">#{poll.title}</div>) unless poll.title[0] == '-'
208
+ html << %(<div class="poll-text">#{poll.sub_text}</div>)
183
209
  html << if poll.display == 'lr'
184
- "\n" + '<div class="poll-data-table">'
185
- else
186
- '<div class="poll-data-div">' + "\n"
187
- end
188
- # items. Convert each item to yaml
210
+ %(\n<div class="poll-data-table">)
211
+ else
212
+ %(<div class="poll-data-div">\n)
213
+ end
214
+ # items. Convert each item to yaml
189
215
  @end_od_data = false
190
216
  if poll.form.to_s.size < 10
191
217
  items = poll.dc_poll_items
192
- items.sort! {|a,b| a.order <=> b.order }
218
+ items.sort! { |a,b| a.order <=> b.order }
193
219
  items.each do |item|
194
220
  next unless item.active # disabled items
195
- # convert options to yaml
221
+ # convert options to yaml
196
222
  yaml = YAML.load(item.options) || {}
197
223
  yaml = {} if yaml.class == String
198
224
  yaml['name'] = item.name
@@ -200,22 +226,23 @@ def default
200
226
  yaml['html']['size'] = item.size
201
227
  (yaml['html']['class'] ||= 'dc-submit') if item.type == 'submit_tag'
202
228
  yaml['text'] = item.text
203
- yaml['mandatory'] = item.mandatory
204
- yaml['type'] = item.type
229
+ yaml['mandatory'] = item.mandatory
230
+ yaml['type'] = item.type
231
+
205
232
  html << do_one_item(poll, yaml)
206
233
  end
207
- # Form. Just call do_one_item for each form item
208
234
  else
209
235
  yaml = YAML.load(poll.form.gsub('&nbsp;',' ')) # very annoying. They come with copy&paste ;-)
210
- # if entered without numbering yaml is returned as Hash otherwise as Array
236
+ # if entered without numbering yaml is returned as Hash otherwise as Array
211
237
  yaml.each { |i| html << do_one_item(poll, (i.class == Hash ? i : i.last)) } #
212
238
  end
213
- # hide some fields usefull as parameters
214
- # was html << @parent.hidden_field_tag('return_to', @opts[:return_to] || @parent.params[:return_to] || '/')
239
+ # hide some fields usefull as parameters
215
240
  html << @parent.hidden_field_tag('return_to', @opts[:return_to] || @parent.params[:return_to] || @parent.request.url)
216
241
  html << @parent.hidden_field_tag('return_to_error', @parent.request.url )
217
242
  html << @parent.hidden_field_tag('poll_id', poll_id )
218
243
  html << @parent.hidden_field_tag('page_id', @parent.page.id )
244
+ # Add javascript code
245
+ html << @parent.javascript_tag(@part_js + poll.js.to_s)
219
246
  html << "</form></div>"
220
247
  html << '</div>' if @opts[:div]
221
248