cama_contact_form 0.0.24 → 0.0.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/plugins/cama_contact_form/contact_form_controller_concern.rb +20 -10
- data/app/controllers/plugins/cama_contact_form/front_controller.rb +6 -3
- data/app/helpers/plugins/cama_contact_form/main_helper.rb +1 -1
- data/app/models/plugins/cama_contact_form/cama_contact_form.rb +16 -0
- data/app/views/plugins/cama_contact_form/admin_forms/responses.html.erb +6 -1
- data/lib/cama_contact_form/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe2363fedca3389a35c18dd01afa5f3490cd3388
|
4
|
+
data.tar.gz: 874ff2d71598d58c8fddc2cc08396557ca718aaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40120eed98b0562e75542e158e5ed9fabbb67ec1783ed885490a6c53ac80995d88365df3c0721df9c3372be00b18921619ce72d723b52cada74f0d76e89a09da
|
7
|
+
data.tar.gz: 94465e8e2e4c07d0efc8e5fb18382dc9603431e4d4802aa064cebf9a9e53a1e7beb350205b00411ef93fafc28220099e39b0151aa72fad08da892bab941a23d0
|
@@ -4,13 +4,22 @@ module Plugins::CamaContactForm::ContactFormControllerConcern
|
|
4
4
|
if validate_to_save_form(form, fields, errors)
|
5
5
|
form.fields.each do |f|
|
6
6
|
if f[:field_type] == 'file'
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
file_paths = []
|
8
|
+
fields[f[:cid].to_sym].each do |file|
|
9
|
+
res = cama_tmp_upload(file, {
|
10
|
+
maximum: current_site.get_option('filesystem_max_size', 100).megabytes,
|
11
|
+
path: Rails.public_path.join("contact_form", current_site.id.to_s),
|
12
|
+
name: file.original_filename
|
13
|
+
}
|
14
|
+
)
|
15
|
+
if res[:error].present?
|
16
|
+
errors << res[:error].to_s.translate
|
17
|
+
else
|
18
|
+
attachments << res[:file_path]
|
19
|
+
file_paths << res[:file_path].sub(Rails.public_path.to_s, cama_root_url)
|
20
|
+
end
|
13
21
|
end
|
22
|
+
fields[f[:cid].to_sym] = file_paths
|
14
23
|
end
|
15
24
|
end
|
16
25
|
new_settings = {"fields" => fields, "created_at" => Time.current.strftime("%Y-%m-%d %H:%M:%S").to_s}.to_json
|
@@ -27,7 +36,7 @@ module Plugins::CamaContactForm::ContactFormControllerConcern
|
|
27
36
|
cama_send_email(answer_to, form.the_settings[:railscf_mail][:subject_answer].to_s.translate.cama_replace_codes(fields), {content: content})
|
28
37
|
end
|
29
38
|
else
|
30
|
-
errors << form.the_message('mail_sent_ng', t('.error_form_val', default: '
|
39
|
+
errors << form.the_message('mail_sent_ng', t('.error_form_val', default: 'An error occurred, please try again.'))
|
31
40
|
end
|
32
41
|
end
|
33
42
|
end
|
@@ -44,8 +53,8 @@ module Plugins::CamaContactForm::ContactFormControllerConcern
|
|
44
53
|
errors << "#{label.to_s.translate}: #{form.the_message('invalid_required', t('.error_validation_val', default: 'This value is required'))}"
|
45
54
|
validate = false
|
46
55
|
end
|
47
|
-
if f[:field_type].to_s ==
|
48
|
-
|
56
|
+
if f[:field_type].to_s == 'email'
|
57
|
+
unless fields[cid].match(/@/)
|
49
58
|
errors << "#{label.to_s.translate}: #{form.the_message('invalid_email', t('.email_invalid_val', default: 'The e-mail address appears invalid'))}"
|
50
59
|
validate = false
|
51
60
|
end
|
@@ -70,7 +79,8 @@ module Plugins::CamaContactForm::ContactFormControllerConcern
|
|
70
79
|
label = values.keys.include?(field[:label]) ? "#{field[:label]} (#{cid})" : field[:label].to_s.translate
|
71
80
|
values[label] = []
|
72
81
|
if ft == 'file'
|
73
|
-
|
82
|
+
nr_files = fields[cid].size
|
83
|
+
values[label] << "#{nr_files} #{"file".pluralize(nr_files)} (attached)" if fields[cid].present?
|
74
84
|
elsif ft == 'radio' || ft == 'checkboxes'
|
75
85
|
values[label] << fields[cid].map { |f| f.to_s.translate }.join(', ') if fields[cid].present?
|
76
86
|
else
|
@@ -20,7 +20,10 @@ class Plugins::CamaContactForm::FrontController < CamaleonCms::Apps::PluginsFron
|
|
20
20
|
flash[:values] = fields.delete_if{|k, v| v.class.name == 'ActionDispatch::Http::UploadedFile' }
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
23
|
+
if Rails::VERSION::MAJOR >= 5
|
24
|
+
params[:format] == 'json' ? render(json: flash.discard(:contact_form).to_hash) : (redirect_back fallback_location: cama_root_path)
|
25
|
+
else
|
26
|
+
params[:format] == 'json' ? render(json: flash.discard(:contact_form).to_hash) : (redirect_to :back)
|
27
|
+
end
|
24
28
|
end
|
25
|
-
|
26
|
-
end
|
29
|
+
end
|
@@ -111,7 +111,7 @@ module Plugins::CamaContactForm::MainHelper
|
|
111
111
|
when 'captcha'
|
112
112
|
temp2 = cama_captcha_tag(5, {}, {class: "#{ob[:custom_class].presence || 'form-control'} field-captcha required"}.merge(ob[:custom_attrs]))
|
113
113
|
when 'file'
|
114
|
-
temp2 = "<input multiple=\"multiple\" type=\"file\" value=\"\" name=\"#{f_name}\" #{ob[:custom_attrs].to_attr_format} class=\"#{ob[:custom_class].presence || 'form-control'}\">"
|
114
|
+
temp2 = "<input multiple=\"multiple\" type=\"file\" value=\"\" name=\"#{f_name}[]\" #{ob[:custom_attrs].to_attr_format} class=\"#{ob[:custom_class].presence || 'form-control'}\">"
|
115
115
|
when 'dropdown'
|
116
116
|
temp2 = cama_form_select_multiple_bootstrap(ob, ob[:label], "select",values)
|
117
117
|
else
|
@@ -1,4 +1,5 @@
|
|
1
1
|
class Plugins::CamaContactForm::CamaContactForm < ActiveRecord::Base
|
2
|
+
include Plugins::CamaContactForm::MainHelper
|
2
3
|
self.table_name = 'plugins_contact_forms'
|
3
4
|
belongs_to :site, class_name: "CamaleonCms::Site"
|
4
5
|
# attr_accessible :site_id, :name, :description, :count, :slug, :value, :settings, :parent_id
|
@@ -9,6 +10,7 @@ class Plugins::CamaContactForm::CamaContactForm < ActiveRecord::Base
|
|
9
10
|
|
10
11
|
before_validation :before_validating
|
11
12
|
before_create :fix_save_settings
|
13
|
+
before_destroy :delete_uploaded_files
|
12
14
|
|
13
15
|
default_scope { order(created_at: :desc) }
|
14
16
|
|
@@ -42,4 +44,18 @@ class Plugins::CamaContactForm::CamaContactForm < ActiveRecord::Base
|
|
42
44
|
self.value = {"fields" => []}.to_json unless self.value.present?
|
43
45
|
self.settings = {}.to_json unless self.settings.present?
|
44
46
|
end
|
47
|
+
|
48
|
+
def delete_uploaded_files
|
49
|
+
return if self.parent_id.nil?
|
50
|
+
form = self.class.find_by_id self.parent_id
|
51
|
+
response_data = the_settings[:fields]
|
52
|
+
file_cids = form.fields
|
53
|
+
.select { |f| f[:field_type] == 'file' }
|
54
|
+
.map { |f| f[:cid].to_sym }
|
55
|
+
|
56
|
+
file_cids
|
57
|
+
.flat_map { |cid| response_data[cid] }
|
58
|
+
.map { |file| file.sub Rails.application.routes.url_helpers.cama_root_url, Rails.public_path.to_s }
|
59
|
+
.each { |file| File.delete file if File.exists? file }
|
60
|
+
end
|
45
61
|
end
|
@@ -32,7 +32,12 @@
|
|
32
32
|
<% @op_fields.each do |default| %>
|
33
33
|
<% cid = default[:cid].to_sym %>
|
34
34
|
<% if default[:field_type] == "file" %>
|
35
|
-
<td
|
35
|
+
<td>
|
36
|
+
<%# flatten is necessary for backwards compatibility: ["file"].flatten == [["file]].flatten %>
|
37
|
+
<% [value[:fields][cid]].flatten.each do |file| %>
|
38
|
+
<%= link_to file.split('/').last, file, target: '_blank' %><br>
|
39
|
+
<% end %>
|
40
|
+
</td>
|
36
41
|
<% elsif default[:field_type] == "radio" || default[:field_type] == "checkboxes" %>
|
37
42
|
<td><%= value[:fields][cid].map { |f| f.to_s.translate }.join(', ') if value[:fields][cid].present? %></td>
|
38
43
|
<% else %>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cama_contact_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Owen Peredo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|