drg_cms 0.5.52.16 → 0.6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/drg_cms/drg_cms.js +446 -144
- data/app/assets/javascripts/drg_cms/jstree.min.js +6 -6
- data/app/assets/javascripts/drg_cms_application.js +1 -1
- data/app/assets/stylesheets/drg_cms/drg_cms.css +625 -243
- data/app/assets/stylesheets/drg_cms/jstree.css +6 -12
- data/app/assets/stylesheets/drg_cms/select-multiple.css +18 -12
- data/app/assets/stylesheets/drg_cms_cms.css +1 -1
- data/app/controllers/cmsedit_controller.rb +536 -331
- data/app/controllers/dc_application_controller.rb +380 -117
- data/app/controllers/dc_common_controller.rb +105 -14
- data/app/{controllers → controls}/browse_models_control.rb +0 -0
- data/app/controls/dc_help_control.rb +126 -0
- data/app/{controllers → controls}/dc_page_control.rb +24 -8
- data/app/controls/dc_poll_result_control.rb +88 -0
- data/app/controls/dc_report.rb +225 -0
- data/app/{controllers → controls}/design_element_settings_control.rb +0 -0
- data/app/forms/all_options.yml +50 -9
- data/app/forms/cms_menu.yml +28 -18
- data/app/forms/dc_ad.yml +11 -22
- 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 +20 -16
- data/app/forms/dc_filter.yml +3 -6
- data/app/forms/dc_help_1.yml +109 -0
- data/app/forms/dc_journal.yml +3 -1
- data/app/forms/dc_json_ld.yml +59 -0
- data/app/forms/dc_key_value.yml +32 -0
- data/app/forms/dc_link.yml +1 -1
- data/app/forms/dc_menu.yml +2 -0
- data/app/forms/dc_menu_item.yml +2 -0
- data/app/forms/dc_page.yml +3 -5
- data/app/forms/dc_part.yml +1 -0
- data/app/forms/dc_piece.yml +1 -0
- data/app/forms/dc_poll.yml +19 -9
- data/app/forms/dc_poll_item.yml +2 -1
- data/app/forms/dc_poll_result.yml +83 -0
- data/app/forms/dc_poll_result_export.yml +35 -0
- data/app/forms/dc_seo.yml +33 -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/forms/json_ld_schema.yml +168 -0
- data/app/helpers/cms_common_helper.rb +376 -0
- data/app/helpers/cms_edit_helper.rb +506 -0
- data/app/helpers/cms_helper.rb +268 -0
- data/app/helpers/cms_index_helper.rb +576 -0
- data/app/helpers/dc_application_helper.rb +183 -271
- data/app/models/concerns/dc_page_concern.rb +40 -6
- data/app/models/concerns/dc_policy_rule_concern.rb +20 -8
- data/app/models/concerns/dc_seo_concern.rb +66 -0
- data/app/models/concerns/dc_site_concern.rb +67 -44
- data/app/models/concerns/dc_user_concern.rb +62 -21
- data/app/models/dc_design.rb +30 -18
- data/app/models/dc_filter.rb +22 -13
- data/app/models/dc_json_ld.rb +152 -0
- data/app/models/dc_key_value.rb +48 -0
- data/app/models/dc_key_value_store.rb +1 -0
- data/app/models/dc_memory.rb +8 -1
- data/app/models/dc_page.rb +0 -1
- 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 +39 -19
- data/app/models/{drgcms_form_fields/drgcms_form_fields.rb → dc_poll_result.rb} +23 -2
- data/app/models/dc_temp.rb +140 -0
- data/app/models/dc_user_role.rb +2 -2
- data/app/models/drgcms_form_fields.rb +14 -6
- data/app/models/drgcms_form_fields/action.rb +61 -0
- data/app/models/drgcms_form_fields/check_box.rb +3 -0
- data/app/models/drgcms_form_fields/comment.rb +8 -4
- data/app/models/drgcms_form_fields/date_picker.rb +11 -9
- data/app/models/drgcms_form_fields/date_select.rb +1 -1
- data/app/models/drgcms_form_fields/{date_time_picker.rb → datetime_picker.rb} +12 -10
- data/app/models/drgcms_form_fields/datetime_select.rb +1 -1
- data/app/models/drgcms_form_fields/drgcms_field.rb +55 -9
- data/app/models/drgcms_form_fields/embedded.rb +26 -16
- data/app/models/drgcms_form_fields/file_field.rb +52 -0
- data/app/models/drgcms_form_fields/file_select.rb +2 -2
- data/app/models/drgcms_form_fields/hash_field.rb +90 -0
- data/app/models/drgcms_form_fields/hidden_field.rb +1 -1
- data/app/models/drgcms_form_fields/html_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 +23 -14
- data/app/models/drgcms_form_fields/number_field.rb +15 -6
- data/app/models/drgcms_form_fields/radio.rb +96 -0
- data/app/models/drgcms_form_fields/readonly.rb +2 -2
- data/app/models/drgcms_form_fields/select.rb +92 -29
- data/app/models/drgcms_form_fields/text_area.rb +1 -1
- data/app/models/drgcms_form_fields/text_autocomplete.rb +29 -17
- data/app/models/drgcms_form_fields/text_field.rb +1 -1
- data/app/models/drgcms_form_fields/text_with_select.rb +6 -3
- data/app/models/drgcms_form_fields/tree_select.rb +29 -10
- data/app/{helpers → renderers}/dc_ad_renderer.rb +0 -0
- data/app/{helpers → renderers}/dc_big_menu_renderer.rb +1 -0
- data/app/{helpers → renderers}/dc_captcha_renderer.rb +0 -0
- data/app/{helpers → renderers}/dc_common_renderer.rb +0 -0
- data/app/{helpers → renderers}/dc_gallery_renderer.rb +1 -0
- data/app/{helpers → renderers}/dc_menu_renderer.rb +11 -4
- data/app/{helpers → renderers}/dc_page_renderer.rb +1 -0
- data/app/{helpers → renderers}/dc_part_renderer.rb +5 -4
- data/app/{helpers → renderers}/dc_piece_renderer.rb +1 -1
- data/app/{helpers → renderers}/dc_poll_renderer.rb +84 -48
- data/app/{helpers → renderers}/dc_renderer.rb +1 -0
- data/app/{helpers → renderers}/dc_simple_menu_renderer.rb +1 -0
- data/app/views/cmsedit/{remove_edit_stuff.js.erb → __remove_edit_stuff.js.erb} +0 -0
- data/app/views/cmsedit/{show.html.erb → __show.html.erb} +0 -0
- data/app/views/cmsedit/_edit_stuff.html.erb +4 -25
- data/app/views/cmsedit/_form.html.erb +4 -3
- data/app/views/cmsedit/_result.html.erb +2 -3
- data/app/views/cmsedit/edit.html.erb +4 -1
- data/app/views/cmsedit/index.html.erb +7 -1
- data/app/views/cmsedit/new.html.erb +3 -1
- data/app/views/dc_common/_help.html.erb +8 -0
- data/app/views/layouts/models.html.erb +2 -1
- data/config/locales/drgcms_en.yml +26 -3
- data/config/locales/drgcms_sl.yml +31 -5
- data/config/locales/models_en.yml +66 -18
- data/config/locales/models_sl.yml +71 -20
- data/drg_cms.gemspec +3 -3
- data/lib/drg_cms.rb +63 -1
- data/lib/drg_cms/version.rb +2 -2
- data/lib/generators/new_drg_form/new_drg_form_generator.rb +9 -2
- data/lib/tasks/database.rake +6 -56
- metadata +81 -63
- data/app/assets/stylesheets/drg_cms/__jquery-ui.css +0 -339
- data/app/helpers/application_helper.rb +0 -2
- data/app/helpers/cmsedit_helper.rb +0 -885
- data/app/models/dc_dummy.rb +0 -102
- data/test/fixtures/drg_cms_test_data.rb +0 -87
@@ -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
|
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( {
|
@@ -122,7 +132,9 @@ $(document).ready(function() {
|
|
122
132
|
});
|
123
133
|
},
|
124
134
|
change: function (event, ui) {
|
135
|
+
#{not_id_code}
|
125
136
|
$("##{record}_#{@yaml['name']}").val(ui.item.id);
|
137
|
+
|
126
138
|
},
|
127
139
|
minLength: 2
|
128
140
|
});
|
@@ -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']
|
73
|
+
@yaml['html']['class'] ||= ''
|
74
|
+
@yaml['html']['class'] << ' text-with-select'
|
74
75
|
@yaml['html'].symbolize_keys!
|
75
|
-
|
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
|
@@ -47,6 +47,8 @@ module DrgcmsFormFields
|
|
47
47
|
# name: categories
|
48
48
|
# type: tree_select
|
49
49
|
# eval: 'Categories.all_categories'
|
50
|
+
# multiple: true
|
51
|
+
# select_parent: false
|
50
52
|
# html:
|
51
53
|
# size: 50x10
|
52
54
|
###########################################################################
|
@@ -60,15 +62,21 @@ def make_tree(parent)
|
|
60
62
|
@html << '<ul>'
|
61
63
|
choices = if @choices[parent.to_s].first[3] != 0
|
62
64
|
@choices[parent.to_s].sort_by {|e| e[3].to_i } # sort by order if first is not 0
|
63
|
-
# @choices[parent.to_s].sort_alphabetical_by(&:first) # use UTF-8 sort
|
64
65
|
else
|
65
66
|
@choices[parent.to_s].sort_alphabetical_by(&:first) # use UTF-8 sort
|
66
67
|
end
|
67
68
|
choices.each do |choice|
|
68
|
-
|
69
|
-
#
|
70
|
-
@
|
71
|
-
#
|
69
|
+
data = [ %Q["selected" : #{choice.last ? 'true' : 'false'} ] ]
|
70
|
+
# only for parent objects
|
71
|
+
if @choices[ choice[1].to_s ]
|
72
|
+
# parent is not selectable
|
73
|
+
data << '"disabled" : true' unless @parent.dc_dont?(@yaml['parent_disabled'], true)
|
74
|
+
# parents are opened on start
|
75
|
+
data << '"opened" : true' unless @parent.dc_dont?(@yaml['parent_opened'], true)
|
76
|
+
end
|
77
|
+
# data-jstree must be singe quoted
|
78
|
+
@html << %Q[<li data-id="#{choice[1]}" data-jstree='{#{data.join(' , ')}}'>#{choice.first}\n]
|
79
|
+
# call recursively for children
|
72
80
|
make_tree(choice[1]) if @choices[ choice[1].to_s ]
|
73
81
|
@html << "</li>"
|
74
82
|
end
|
@@ -79,15 +87,19 @@ end
|
|
79
87
|
# Render tree_select field html code
|
80
88
|
###########################################################################
|
81
89
|
def render
|
82
|
-
return ro_standard if @readonly
|
90
|
+
#return ro_standard if @readonly
|
83
91
|
set_initial_value('html','value')
|
84
92
|
require 'sort_alphabetical'
|
85
93
|
|
86
94
|
record = record_text_for(@yaml['name'])
|
87
|
-
|
95
|
+
clas = 'tree-select' + (@readonly ? ' dc-readonly' : '')
|
96
|
+
@html << "<div id=\"#{@yaml['name']}\" class=\"#{clas}\" #{set_style()} >"
|
88
97
|
# Fill @choices hash. The key is parent object id
|
89
98
|
@choices = {}
|
90
|
-
|
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
|
91
103
|
# put current values hash with. To speed up selection when there is a lot of categories
|
92
104
|
current_values = {}
|
93
105
|
current = @record[@yaml['name']] || []
|
@@ -101,19 +113,26 @@ def render
|
|
101
113
|
end
|
102
114
|
end
|
103
115
|
make_tree(nil)
|
104
|
-
@html << '</
|
116
|
+
@html << '</div>'
|
105
117
|
# add hidden communication field
|
106
118
|
@html << @parent.hidden_field(record, @yaml['name'], value: current.join(','))
|
107
119
|
# save multiple indicator for data processing on return
|
108
120
|
@html << @parent.hidden_field(record, "#{@yaml['name']}_multiple", value: 1) if @yaml['multiple']
|
109
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
|
+
|
110
128
|
@js =<<EOJS
|
111
129
|
$(function(){
|
112
130
|
$("##{@yaml['name']}").jstree( {
|
113
131
|
"checkbox" : {"three_state" : false},
|
114
132
|
"core" : { "themes" : { "icons": false },
|
115
133
|
"multiple" : #{@yaml['multiple'] ? 'true' : 'false'} },
|
116
|
-
"plugins" : ["checkbox"]
|
134
|
+
"plugins" : ["checkbox","conditionalselect"]
|
135
|
+
#{@readonly ? readonly_code : ''}
|
117
136
|
});
|
118
137
|
});
|
119
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
|
@@ -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
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
########################################################################
|
@@ -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.
|
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.
|
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.
|
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.
|
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
|
30
|
+
include CmsCommonHelper
|
31
31
|
include DcApplicationHelper
|
32
|
-
include ActionView::Helpers::FormHelper # for form
|
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,46 +57,56 @@ 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' ? ' *' : '<font color="red"> *</font>' )
|
63
64
|
yaml['html'] ||= {}
|
64
65
|
yaml['html']['required'] = true
|
66
|
+
else
|
67
|
+
text << " " 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
|
-
"<div class='row-div'><div class='dc-form-label poll-data-text'>#{text}</div></div>"
|
73
|
+
"<div class='row-div'><div class='dc-form-label poll-data-text comment'>#{text}</div></div>"
|
71
74
|
else
|
72
|
-
"<div class='poll-data-text'>#{text}</div>"
|
75
|
+
"<div class='poll-data-text comment'>#{text}</div>"
|
73
76
|
end
|
74
77
|
return html
|
75
78
|
end
|
76
|
-
|
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
|
-
#
|
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
|
-
|
90
|
-
|
91
|
-
|
92
|
-
else #
|
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
111
|
html << if poll.display == 'lr'
|
101
112
|
"</div><br>\n"
|
@@ -109,108 +120,133 @@ def do_one_item(poll, yaml)
|
|
109
120
|
html << captcha.render_html
|
110
121
|
@part_css = captcha.render_css
|
111
122
|
end
|
112
|
-
@
|
123
|
+
@end_of_data = true
|
113
124
|
end
|
114
|
-
# submit and link tag
|
125
|
+
# submit and link tag
|
115
126
|
clas = yaml['type'].match(/submit_tag/) ? '' : 'dc-link-submit'
|
116
127
|
html << "<span class='#{clas} dc-animate'>#{field_html}#{yaml['separator']}</span>"
|
117
|
-
# other
|
128
|
+
# other fields
|
118
129
|
else
|
119
|
-
html <<
|
120
|
-
|
121
|
-
|
122
|
-
|
130
|
+
html << case
|
131
|
+
when poll.display == 'lr' then
|
132
|
+
"<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"
|
133
|
+
when poll.display == 'td' then
|
134
|
+
"<div class='poll-data-text td #{yaml['class']}'>#{text}</div><div class='poll-data-field td #{yaml['class']}'>#{field_html}#{yaml['separator']}</div>\n"
|
135
|
+
else
|
136
|
+
"<div class='poll-data-field in #{yaml['class']}'>#{field_html}#{yaml['separator']}</div>\n"
|
123
137
|
end
|
124
138
|
end
|
125
139
|
end
|
126
140
|
|
141
|
+
########################################################################
|
142
|
+
# Call method before poll is displayed. Usefull for filling predefined values into flash[:record][value]
|
143
|
+
# Method cane be defined as ClassName.method or only method.
|
144
|
+
# If only method is defined then method name must exist in helpers.
|
145
|
+
#
|
146
|
+
# Called method must return at least one result if process can continue.
|
147
|
+
########################################################################
|
148
|
+
def eval_pre_display(code)
|
149
|
+
a = code.strip.split('.')
|
150
|
+
if a.size == 1
|
151
|
+
continue, message = @parent.send(a.first)
|
152
|
+
else
|
153
|
+
klass = a.first.classify.constantize
|
154
|
+
continue, message = klass.send(a.last,@parent)
|
155
|
+
end
|
156
|
+
[continue, message]
|
157
|
+
end
|
158
|
+
|
127
159
|
########################################################################
|
128
160
|
# Default poll renderer method. Renders data for specified pool.
|
129
161
|
########################################################################
|
130
162
|
def default
|
131
|
-
# poll_id may be defined in params or opts
|
163
|
+
# poll_id may be defined in params or opts
|
132
164
|
poll_id = @opts[:poll_id] || @parent.params[:poll_id]
|
133
165
|
return '<br>Poll id is not defined?<br>' if poll_id.nil?
|
134
|
-
|
166
|
+
|
135
167
|
poll = DcPoll.find(poll_id)
|
136
168
|
poll = DcPoll.find_by(name: poll_id) if poll.nil? # name instead of id
|
137
169
|
return "<div class=\"dc-form-error\">Invalid Poll id #{poll_id}</div>" if poll.nil?
|
170
|
+
# If parent cant be seen. so cant be polls
|
171
|
+
can_view, message = dc_user_can_view(@parent, @parent.page)
|
172
|
+
return "<div class=\"dc-form-error\">#{message}</div>" unless can_view
|
173
|
+
|
138
174
|
html = @opts[:div] ? "<div id='#{@opts[:div]}'>" : ''
|
139
175
|
html << '<a name="poll-top"></a>'
|
140
|
-
|
141
|
-
# Operation called before poll is displayed. Usefull for filling predefined values into flash[:record][value]
|
142
|
-
# Called method must return at least one result if process can continue.
|
143
|
-
if poll.pre_display.to_s.size > 1
|
176
|
+
unless poll.pre_display.blank?
|
144
177
|
begin
|
145
|
-
continue, message =
|
178
|
+
continue, message = eval_pre_display(poll.pre_display)
|
146
179
|
rescue Exception => e
|
147
180
|
return "<div class=\"dc-form-error\">Error! Poll pre display. Error: #{e.message}</div>"
|
148
181
|
end
|
149
182
|
return message unless continue
|
183
|
+
|
150
184
|
html << message if message
|
151
185
|
end
|
152
|
-
# there might be more than one poll displayed on page. Check if messages and values are for me
|
153
|
-
if @parent.flash[:poll_id].nil?
|
154
|
-
# If flash[:record] is present copy content to params record hash
|
186
|
+
# there might be more than one poll displayed on page. Check if messages and values are for me
|
187
|
+
if @parent.flash[:poll_id].nil? || @parent.flash[:poll_id].to_s == poll_id.to_s
|
188
|
+
# If flash[:record] is present copy content to params record hash
|
155
189
|
@parent.flash[:record].each {|k,v| @parent.params["p_#{k}"] = v } if @parent.flash[:record]
|
156
|
-
# Error during procesing request
|
190
|
+
# Error during procesing request
|
157
191
|
html << "<div class=\"dc-form-error\">#{@parent.flash[:error]}</div>\n" if @parent.flash[:error].to_s.size > 0
|
158
192
|
html << "<div class=\"dc-form-info\">#{@parent.flash[:info]}</div>\n" if @parent.flash[:info]
|
159
193
|
end
|
160
|
-
# div and form tag
|
194
|
+
# div and form tag
|
161
195
|
html << "<div class=\"poll-div\">\n"
|
162
|
-
# edit link
|
196
|
+
# edit link
|
163
197
|
if @opts[:edit_mode] > 1
|
164
198
|
@opts[:editparams].merge!( controller: 'cmsedit', action: 'edit', id: poll._id, table: 'dc_poll', form_name: 'dc_poll' )
|
165
199
|
@opts[:editparams].merge!(title: "#{t('drgcms.edit')}: #{poll.name}")
|
166
200
|
@opts[:editparams].delete(:ids) # this is from page, but it gets in a way
|
167
201
|
html << dc_link_for_edit( @opts[:editparams] )
|
168
202
|
end
|
169
|
-
|
203
|
+
|
170
204
|
html << case
|
171
205
|
when poll.operation == 'poll_submit' then
|
172
206
|
@parent.form_tag(action: poll.operation, method: :put)
|
173
207
|
when poll.operation == 'link' then
|
174
208
|
@parent.form_tag( poll.parameters, method: :put)
|
175
209
|
end
|
176
|
-
# header
|
177
|
-
html << "<div class='poll-title'>#{poll.title}</div>" unless poll.title[0] == '-'
|
178
|
-
html << poll.sub_text.to_s
|
210
|
+
# header, - on first position will not display title
|
211
|
+
html << "<div class='poll-title'>#{poll.title}</div>" unless poll.title[0] == '-'
|
212
|
+
html << poll.sub_text.to_s
|
179
213
|
html << if poll.display == 'lr'
|
180
214
|
"\n" + '<div class="poll-data-table">'
|
181
215
|
else
|
182
216
|
'<div class="poll-data-div">' + "\n"
|
183
217
|
end
|
184
|
-
# items. Convert each item to yaml
|
218
|
+
# items. Convert each item to yaml
|
185
219
|
@end_od_data = false
|
186
220
|
if poll.form.to_s.size < 10
|
187
221
|
items = poll.dc_poll_items
|
188
|
-
items.sort! {|a,b| a.order <=> b.order }
|
222
|
+
items.sort! { |a,b| a.order <=> b.order }
|
189
223
|
items.each do |item|
|
190
224
|
next unless item.active # disabled items
|
191
|
-
|
225
|
+
# convert options to yaml
|
192
226
|
yaml = YAML.load(item.options) || {}
|
227
|
+
yaml = {} if yaml.class == String
|
193
228
|
yaml['name'] = item.name
|
194
229
|
yaml['html'] ||= {}
|
195
230
|
yaml['html']['size'] = item.size
|
196
231
|
(yaml['html']['class'] ||= 'dc-submit') if item.type == 'submit_tag'
|
197
232
|
yaml['text'] = item.text
|
198
|
-
yaml['mandatory']
|
199
|
-
yaml['type']
|
233
|
+
yaml['mandatory'] = item.mandatory
|
234
|
+
yaml['type'] = item.type
|
200
235
|
html << do_one_item(poll, yaml)
|
201
236
|
end
|
202
|
-
#
|
237
|
+
# FORM. Just call do_one_item for each form item
|
203
238
|
else
|
204
239
|
yaml = YAML.load(poll.form.gsub(' ',' ')) # very annoying. They come with copy&paste ;-)
|
205
|
-
# if entered without numbering yaml is returned as Hash otherwise as Array
|
240
|
+
# if entered without numbering yaml is returned as Hash otherwise as Array
|
206
241
|
yaml.each { |i| html << do_one_item(poll, (i.class == Hash ? i : i.last)) } #
|
207
242
|
end
|
208
|
-
# hide some fields usefull as parameters
|
209
|
-
# was html << @parent.hidden_field_tag('return_to', @opts[:return_to] || @parent.params[:return_to] || '/')
|
243
|
+
# hide some fields usefull as parameters
|
210
244
|
html << @parent.hidden_field_tag('return_to', @opts[:return_to] || @parent.params[:return_to] || @parent.request.url)
|
211
245
|
html << @parent.hidden_field_tag('return_to_error', @parent.request.url )
|
212
246
|
html << @parent.hidden_field_tag('poll_id', poll_id )
|
213
247
|
html << @parent.hidden_field_tag('page_id', @parent.page.id )
|
248
|
+
# Add javascript code
|
249
|
+
html << @parent.javascript_tag(@part_js + poll.js.to_s)
|
214
250
|
html << "</form></div>"
|
215
251
|
html << '</div>' if @opts[:div]
|
216
252
|
|