cama_contact_form 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/javascripts/plugins/cama_contact_form/admin_editor.js.coffee +48 -0
  6. data/app/controllers/plugins/cama_contact_form/admin_forms_controller.rb +76 -0
  7. data/app/controllers/plugins/cama_contact_form/front_controller.rb +101 -0
  8. data/app/helpers/plugins/cama_contact_form/main_helper.rb +156 -0
  9. data/app/models/plugins/cama_contact_form/cama_contact_form.rb +43 -0
  10. data/app/views/plugins/cama_contact_form/admin_forms/_form.html.erb +24 -0
  11. data/app/views/plugins/cama_contact_form/admin_forms/_item_field.html.erb +72 -0
  12. data/app/views/plugins/cama_contact_form/admin_forms/edit.html.erb +183 -0
  13. data/app/views/plugins/cama_contact_form/admin_forms/index.html.erb +64 -0
  14. data/app/views/plugins/cama_contact_form/admin_forms/responses.html.erb +54 -0
  15. data/app/views/plugins/cama_contact_form/contact_form/_email_content.html.erb +19 -0
  16. data/app/views/plugins/cama_contact_form/forms_shorcode.html.erb +26 -0
  17. data/config/camaleon_plugin.json +29 -0
  18. data/config/initializers/custom_models.rb +5 -0
  19. data/config/locales/es.yml +98 -0
  20. data/config/routes.rb +25 -0
  21. data/db/migrate/20160517143441_create_db_structure.rb +12 -0
  22. data/db/migrate/20160518193106_rename_plugin_name.rb +7 -0
  23. data/lib/cama_contact_form.rb +4 -0
  24. data/lib/cama_contact_form/engine.rb +4 -0
  25. data/lib/cama_contact_form/version.rb +3 -0
  26. data/lib/tasks/cama_contact_form_tasks.rake +4 -0
  27. data/test/cama_contact_form_test.rb +7 -0
  28. data/test/dummy/README.rdoc +28 -0
  29. data/test/dummy/Rakefile +6 -0
  30. data/test/dummy/app/assets/javascripts/application.js +13 -0
  31. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  32. data/test/dummy/app/controllers/application_controller.rb +5 -0
  33. data/test/dummy/app/helpers/application_helper.rb +2 -0
  34. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  35. data/test/dummy/bin/bundle +3 -0
  36. data/test/dummy/bin/rails +4 -0
  37. data/test/dummy/bin/rake +4 -0
  38. data/test/dummy/bin/setup +29 -0
  39. data/test/dummy/config.ru +4 -0
  40. data/test/dummy/config/application.rb +26 -0
  41. data/test/dummy/config/boot.rb +5 -0
  42. data/test/dummy/config/database.yml +25 -0
  43. data/test/dummy/config/environment.rb +5 -0
  44. data/test/dummy/config/environments/development.rb +41 -0
  45. data/test/dummy/config/environments/production.rb +79 -0
  46. data/test/dummy/config/environments/test.rb +42 -0
  47. data/test/dummy/config/initializers/assets.rb +11 -0
  48. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  49. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  50. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  51. data/test/dummy/config/initializers/inflections.rb +16 -0
  52. data/test/dummy/config/initializers/mime_types.rb +4 -0
  53. data/test/dummy/config/initializers/session_store.rb +3 -0
  54. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  55. data/test/dummy/config/locales/en.yml +23 -0
  56. data/test/dummy/config/routes.rb +56 -0
  57. data/test/dummy/config/secrets.yml +22 -0
  58. data/test/dummy/public/404.html +67 -0
  59. data/test/dummy/public/422.html +67 -0
  60. data/test/dummy/public/500.html +66 -0
  61. data/test/dummy/public/favicon.ico +0 -0
  62. data/test/integration/navigation_test.rb +8 -0
  63. data/test/test_helper.rb +20 -0
  64. metadata +171 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7222a6e0b4ad1c7b09abb6656f16d5d2f07d2924
4
+ data.tar.gz: 1ebb3d84852e04006e714873594ba8aa68c0a23b
5
+ SHA512:
6
+ metadata.gz: 6453f4926263322bf5d5394ac2d48ec5a378bbdab93b783105f4a3dbd06afda3df13e674c264d2723e5b71e00717348b66c265260a3674c938871540e9f66186
7
+ data.tar.gz: e88d924247c57fb62b1530edd891808c066338f4c2ba860a006dbfa5314328af880e86c0e12b72c2fccca8435659555a3d2be8c240d5efd30ca2b3336587bd4f
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Owen Peredo
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = CamaContactForm
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'CamaContactForm'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,48 @@
1
+ $ ->
2
+ panel = $('#contact_form_editor')
3
+ my_fields = panel.find('#my_fields')
4
+ my_fields.sortable({handle: ".panel-sortable"})
5
+ panel.find('#fields_available a').click ->
6
+ showLoading()
7
+ my_fields.attr('data-cid', parseInt(my_fields.attr('data-cid')) + 1)
8
+ $.get(panel.find('#fields_available').attr('data-remote_url'), {kind: $(this).attr('data-field-type'), cid: my_fields.attr('data-cid')}, (res)->
9
+ res = $(res)
10
+ my_fields.append(res)
11
+ res.find('.options_sortable').sortable({handle: ".options-sortable"})
12
+ res.find('.add_option').click().click()
13
+ res.find('.translatable').Translatable(ADMIN_TRANSLATIONS)
14
+ hideLoading()
15
+ )
16
+ return false
17
+
18
+ panel.on('click', '.add_option', ->
19
+ list = $(this).prev('ul')
20
+ list.attr('data-options-count', parseInt(list.attr('data-options-count'))+1)
21
+ clone = list.children().first().clone().removeClass('hidden')
22
+ clone.find('input').prop('disabled', false).each(->
23
+ $(this).attr('name', $(this).attr('name').replace('[0]', '['+list.attr('data-options-count')+']'))
24
+ )
25
+ list.append(clone)
26
+ clone.find('.translatable').Translatable(ADMIN_TRANSLATIONS)
27
+ return false
28
+ )
29
+
30
+ panel.on('click', '.option-delete', ->
31
+ $(this).closest('li').remove()
32
+ return false
33
+ )
34
+
35
+ panel.on('click', '.panel-delete', ->
36
+ $(this).closest('li.panel').fadeOut('slow', ->
37
+ $(this).remove()
38
+ )
39
+ return false
40
+ )
41
+
42
+ panel.on('click', '.html_btn', ->
43
+ $(this).hide().next().hide().removeClass('hidden').fadeIn()
44
+ return false
45
+ )
46
+
47
+ my_fields.find('.options_sortable').sortable({handle: ".options-sortable"})
48
+ panel.find('.translatable').Translatable(ADMIN_TRANSLATIONS)
@@ -0,0 +1,76 @@
1
+ class Plugins::CamaContactForm::AdminFormsController < CamaleonCms::Apps::PluginsAdminController
2
+ include Plugins::CamaContactForm::MainHelper
3
+ before_action :set_form, only: ['show','edit','update','destroy']
4
+ add_breadcrumb I18n.t("plugins.cama_contact_form.title"), :admin_plugins_cama_contact_form_admin_forms_path
5
+
6
+ def index
7
+ @forms = current_site.contact_forms.where("parent_id is null").all
8
+ @forms = @forms.paginate(:page => params[:page], :per_page => current_site.admin_per_page)
9
+ end
10
+
11
+ def edit
12
+ add_breadcrumb I18n.t("plugins.cama_contact_form.edit_view")
13
+ append_asset_libraries({"plugin_contact_form"=> { js: [plugin_asset_path("js/contact_form.js")], css: [plugin_asset_path("css/contact-form.css")] }})
14
+ render "edit"
15
+ end
16
+
17
+ def update
18
+ if @form.update(params.require(:plugins_cama_contact_form_cama_contact_form).permit(:name, :slug))
19
+ settings = {"railscf_mail" => params[:railscf_mail], "railscf_message" => params[:railscf_message], "railscf_form_button" => params[:railscf_form_button]}
20
+ fields = []
21
+ (params[:fields] || {}).each{|k, v|
22
+ v[:field_options][:options] = v[:field_options][:options].values if v[:field_options][:options].present?
23
+ fields << v
24
+ }
25
+ @form.update({settings: settings.to_json, value: {fields: fields}.to_json})
26
+ flash[:notice] = t('.updated_success')
27
+ redirect_to action: :edit, id: @form.id
28
+ else
29
+ edit
30
+ end
31
+ end
32
+
33
+ def create
34
+ @form = current_site.contact_forms.new(params.require(:plugins_cama_contact_form_cama_contact_form).permit(:name, :slug))
35
+ if @form.save
36
+ flash[:notice] = "#{t('.created')}"
37
+ redirect_to action: :edit, id: @form.id
38
+ else
39
+ flash[:error] = @form.errors.full_messages.join(', ')
40
+ redirect_to action: :index
41
+ end
42
+ end
43
+
44
+ def destroy
45
+ flash[:notice] = "#{t('.deleted')}" if @form.destroy
46
+ redirect_to action: :index
47
+ end
48
+
49
+ def responses
50
+ add_breadcrumb I18n.t("plugins.cama_contact_form.list_responses")
51
+ @form = current_site.contact_forms.where({id: params[:admin_form_id]}).first
52
+ values = JSON.parse(@form.value).to_sym
53
+ @op_fields = values[:fields]
54
+ @forms = current_site.contact_forms.where({parent_id: @form.id})
55
+ @forms = @forms.paginate(:page => params[:page], :per_page => current_site.admin_per_page)
56
+ end
57
+
58
+ def manual
59
+
60
+ end
61
+
62
+ def item_field
63
+ render partial: 'item_field', locals:{ field_type: params[:kind], cid: params[:cid] }
64
+ end
65
+
66
+ # here add your custom functions
67
+ private
68
+ def set_form
69
+ begin
70
+ @form = current_site.contact_forms.find_by_id(params[:id])
71
+ rescue
72
+ flash[:error] = "Error form class"
73
+ redirect_to cama_admin_path
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,101 @@
1
+ class Plugins::CamaContactForm::FrontController < CamaleonCms::Apps::PluginsFrontController
2
+ include Plugins::CamaContactForm::MainHelper
3
+ # here add your custom functions
4
+ def save_form
5
+ @form = current_site.contact_forms.find_by_id(params[:id])
6
+ fields = params[:fields]
7
+ errors = []
8
+ success = []
9
+
10
+ perform_save_form(@form, fields, success, errors)
11
+ if success.present?
12
+ flash[:notice] = success.join('<br>')
13
+ else
14
+ flash[:error] = errors.join('<br>')
15
+ flash[:values] = fields.delete_if{|k, v| v.class.name == 'ActionDispatch::Http::UploadedFile' }
16
+ end
17
+ redirect_to :back
18
+ end
19
+
20
+ def perform_save_form(form, fields, success, errors)
21
+ attachments = []
22
+ if validate_to_save_form(form, fields, errors)
23
+ form.fields.each do |f|
24
+ if f[:field_type] == 'file'
25
+ res = cama_tmp_upload(fields[f[:cid].to_sym], {maximum: 5.megabytes, path: Rails.public_path.join("contact_form", current_site.id.to_s)})
26
+ if res[:error].present?
27
+ errors << res[:error]
28
+ else
29
+ attachments << res[:file_path]
30
+ fields[f[:cid].to_sym] = res[:file_path].sub(Rails.public_path.to_s, cama_root_url)
31
+ end
32
+ end
33
+ end
34
+ new_settings = {"fields" => fields, "created_at" => Time.current.strftime("%Y-%m-%d %H:%M:%S").to_s}.to_json
35
+ form_new = current_site.contact_forms.new(name: "response-#{Time.now}", description: form.description, settings: new_settings, site_id: form.site_id, parent_id: form.id)
36
+ if form_new.save
37
+ fields_data = convert_form_values(form, fields)
38
+ message_body = form.the_settings[:railscf_mail][:body].to_s.translate.cama_replace_codes(fields)
39
+ content = render_to_string(partial: plugin_view('contact_form/email_content'), layout: false, locals: {file_attachments: attachments, fields: fields_data, values: fields, message_body: message_body, form: form})
40
+ cama_send_email(form.the_settings[:railscf_mail][:to], form.the_settings[:railscf_mail][:subject].to_s.translate.cama_replace_codes(fields), {attachments: attachments, content: content, extra_data: {fields: fields_data}})
41
+ success << form.the_message('mail_sent_ok', t('.success_form_val', default: 'Your message has been sent successfully. Thank you very much!'))
42
+ args = {form: form, values: fields}; hooks_run("contact_form_after_submit", args)
43
+ if form.the_settings[:railscf_mail][:to_answer].present? && (answer_to = fields[form.the_settings[:railscf_mail][:to_answer].gsub(/(\[|\])/, '').to_sym]).present?
44
+ content = form.the_settings[:railscf_mail][:body_answer].to_s.translate.cama_replace_codes(fields)
45
+ cama_send_email(answer_to, form.the_settings[:railscf_mail][:subject_answer].to_s.translate.cama_replace_codes(fields), {content: content})
46
+ end
47
+ else
48
+ errors << form.the_message('mail_sent_ng', t('.error_form_val', default: 'Occurred an error, please try again.'))
49
+ end
50
+ end
51
+ end
52
+
53
+ # form validations
54
+ def validate_to_save_form(form, fields, errors)
55
+ validate = true
56
+ form.fields.each do |f|
57
+ cid = f[:cid].to_sym
58
+ label = f[:label].to_sym
59
+ case f[:field_type].to_s
60
+ when 'text', 'website', 'paragraph', 'textarea', 'email', 'radio', 'checkboxes', 'dropdown', 'file'
61
+ if f[:required].to_s.cama_true? && !fields[cid].present?
62
+ errors << "#{label}: #{form.the_message('invalid_required', t('.error_validation_val', default: 'This value is required'))}"
63
+ validate = false
64
+ end
65
+ if f[:field_type].to_s == "email"
66
+ if !fields[cid].match(/@/)
67
+ errors << "#{label}: #{form.the_message('invalid_email', t('.email_invalid_val', default: 'The e-mail address appears invalid'))}"
68
+ validate = false
69
+ end
70
+ end
71
+ when 'captcha'
72
+ unless cama_captcha_verified?
73
+ errors << "#{label}: #{form.the_message('captcha_not_match', t('.captch_error_val', default: 'The entered code is incorrect'))}"
74
+ validate = false
75
+ end
76
+ end
77
+ end
78
+ validate
79
+ end
80
+
81
+ # form values with labels + values to save
82
+ def convert_form_values(form, fields)
83
+ values = {}
84
+ form.fields.each do |field|
85
+ cid = field[:cid].to_sym
86
+ label = values.keys.include?(field[:label]) ? "#{field[:label]} (#{cid})" : field[:label]
87
+ values[label] = []
88
+ if field[:field_type] == 'submit' || field[:field_type] == 'button'
89
+ elsif field[:field_type] == 'file'
90
+ values[label] << fields[cid].split('/').last if fields[cid].present?
91
+ elsif field[:field_type] == 'captcha'
92
+ values[label] << '--'
93
+ elsif field[:field_type] == 'radio' || field[:field_type] == 'checkboxes'
94
+ values[label] << fields[cid].join(',') if fields[cid].present?
95
+ else
96
+ values[label] << fields[cid] if fields[cid].present?
97
+ end
98
+ end
99
+ return values
100
+ end
101
+ end
@@ -0,0 +1,156 @@
1
+ module Plugins::CamaContactForm::MainHelper
2
+ def self.included(klass)
3
+ klass.helper_method [:cama_form_element_bootstrap_object, :cama_form_shortcode] rescue "" # here your methods accessible from views
4
+ end
5
+
6
+ def contact_form_on_export(args)
7
+ args[:obj][:plugins][self_plugin_key] = JSON.parse(current_site.contact_forms.to_json(:include => [:responses]))
8
+ end
9
+
10
+ def contact_form_on_import(args)
11
+ plugins = args[:data][:plugins]
12
+ if plugins[self_plugin_key.to_sym].present?
13
+ plugins[self_plugin_key.to_sym].each do |contact|
14
+ unless current_site.contact_forms.where(slug: contact[:slug]).first.present?
15
+ sba_data = ActionController::Parameters.new(contact)
16
+ contact_new = current_site.contact_forms.new(sba_data.permit(:name, :slug, :count, :description, :value, :settings))
17
+ if contact_new.save!
18
+ if contact[:get_field_groups] # save group fields
19
+ save_field_group(contact_new, contact[:get_field_groups])
20
+ end
21
+ save_field_values(contact_new, contact[:field_values])
22
+
23
+ if contact[:responses].present? # saving responses for this contact
24
+ contact[:responses].each do |response|
25
+ sba_data = ActionController::Parameters.new(response)
26
+ contact_new.responses.create!(sba_data.permit(:name, :slug, :count, :description, :value, :settings))
27
+ end
28
+ end
29
+ args[:messages] << "Saved Plugin Contact Form: #{contact_new.name}"
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ # here all actions on plugin destroying
37
+ # plugin: plugin model
38
+ def contact_form_on_destroy(plugin)
39
+
40
+ end
41
+
42
+ # here all actions on going to active
43
+ # you can run sql commands like this:
44
+ # results = ActiveRecord::Base.connection.execute(query);
45
+ # plugin: plugin model
46
+ def contact_form_on_active(plugin)
47
+
48
+ end
49
+
50
+ # here all actions on going to inactive
51
+ # plugin: plugin model
52
+ def contact_form_on_inactive(plugin)
53
+
54
+ end
55
+
56
+ def contact_form_admin_before_load
57
+ admin_menu_append_menu_item("settings", {icon: "envelope-o", title: t('plugins.cama_contact_form.title', default: 'Contact Form'), url: admin_plugins_cama_contact_form_admin_forms_path, datas: "data-intro='This plugin permit you to create you contact forms with desired fields and paste your short_code in any content.' data-position='right'"})
58
+ end
59
+
60
+ def contact_form_app_before_load
61
+ shortcode_add('forms', plugin_view("forms_shorcode"), "This is a shortocode for contact form to permit you to put your contact form in any content. Sample: [forms slug='key-for-my-form']")
62
+ end
63
+
64
+ def contact_form_front_before_load
65
+
66
+ end
67
+
68
+ # ============== HTML ==================
69
+ # This returns the format of the plugin shortcode.
70
+ def cama_form_shortcode(slug)
71
+ "[forms slug=#{slug}]"
72
+ end
73
+
74
+ # form contact with css bootstrap
75
+ def cama_form_element_bootstrap_object(form, object, values)
76
+ html = ""
77
+ object.each do |ob|
78
+ ob[:label] = ob[:label].to_s.translate
79
+ ob[:description] = ob[:description].to_s.translate
80
+ r = {field: ob, form: form, template: (ob[:field_options][:template].present? ? ob[:field_options][:template] : Plugins::CamaContactForm::CamaContactForm::field_template), custom_class: "#{'form-control' unless ['submit', 'checkboxes', 'radio', 'file'].include?(ob[:field_type].to_s)} #{ob[:field_options][:field_class]}", custom_attrs: {id: ob[:cid] }.merge((JSON.parse(ob[:field_options][:field_attributes]) rescue {})) }
81
+ hooks_run("contact_form_item_render", r)
82
+ ob = r[:field]
83
+ ob[:custom_class] = r[:custom_class]
84
+ ob[:custom_attrs] = r[:custom_attrs]
85
+ field_options = ob[:field_options]
86
+ for_name = ob[:label].to_s
87
+ f_name = "fields[#{ob[:cid]}]"
88
+ cid = ob[:cid].to_sym
89
+
90
+ temp2 = ""
91
+
92
+ case ob[:field_type].to_s
93
+ when 'paragraph','textarea'
94
+ temp2 = "<textarea #{ob[:custom_attrs].to_attr_format} name=\"#{f_name}\" maxlength=\"#{field_options[:maxlength] || 500 }\" class=\"#{ob[:custom_class]} \">#{values[cid]}</textarea>"
95
+ when 'radio'
96
+ temp2= cama_form_select_multiple_bootstrap(ob, ob[:label], ob[:field_type],values)
97
+ when 'checkboxes'
98
+ temp2= cama_form_select_multiple_bootstrap(ob, ob[:label], "checkbox",values)
99
+ when 'submit'
100
+ temp2 = "<button #{ob[:custom_attrs].to_attr_format} type=\"#{ob[:field_type]}\" name=\"#{f_name}\" class=\"#{ob[:custom_class].present? ? ob[:custom_class] : 'btn btn-default'}\">#{ob[:label]}</button>"
101
+ when 'text', 'website', 'email'
102
+ class_type = ""
103
+ class_type = "railscf-field-#{ob[:field_type]}" if ob[:field_type]=="website"
104
+ class_type = "railscf-field-#{ob[:field_type]}" if ob[:field_type]=="email"
105
+ temp2 = "<input #{ob[:custom_attrs].to_attr_format} type=\"#{ob[:field_type]}\" value=\"#{values[cid]}\" name=\"#{f_name}\" class=\"#{ob[:custom_class]} #{class_type}\">"
106
+ when 'captcha'
107
+ temp2 = cama_captcha_tag(5, {}, {class: "#{ob[:custom_class]} field-captcha required"}.merge(ob[:custom_attrs]))
108
+ when 'file'
109
+ class_type = "railscf-field-#{ob[:field_type]}" if ob[:field_type]=="website"
110
+ temp2 = "<input multiple=\"multiple\" type=\"file\" value=\"\" name=\"#{f_name}\" #{ob[:custom_attrs].to_attr_format} class=\"#{class_type} #{ob[:custom_class]}\">"
111
+ when 'dropdown'
112
+ temp2 = cama_form_select_multiple_bootstrap(ob, ob[:label], "select",values)
113
+ else
114
+ end
115
+ r[:template] = r[:template].sub('[label ci]', for_name).sub('[ci]', temp2)
116
+ r[:template] = r[:template].sub('[descr ci]', field_options[:description] || "").sub('<p></p>', '')
117
+ html += r[:template]
118
+ end
119
+ html
120
+ end
121
+
122
+ def cama_form_select_multiple_bootstrap(ob, title, type, values)
123
+ options = ob[:field_options][:options]
124
+ include_other_option = ob[:field_options][:include_other_option]
125
+ other_input = ""
126
+
127
+ f_name = "fields[#{ob[:cid]}]"
128
+ cid = ob[:cid].to_sym
129
+ html = ""
130
+
131
+ if type == "radio" || type == "checkbox"
132
+ other_input = (include_other_option)? "<div class=\"#{type} #{ob[:custom_class]}\"> <label for=\"#{ob[:cid]}\"><input id=\"#{ob[:cid]}-other\" type=\"#{type}\" name=\"#{title.downcase}[]\" class=\"\">Other <input type=\"text\" /></label></div>" : " "
133
+ else
134
+ html = "<select #{ob[:custom_attrs].to_attr_format} name=\"#{f_name}\" class=\"#{ob[:custom_class]}\">"
135
+ end
136
+
137
+ options.each do |op|
138
+ if type == "radio" || type == "checkbox"
139
+ html += "<div class=\"#{type} #{ob[:custom_class]}\">
140
+ <label for=\"#{ob[:cid]}\">
141
+ <input #{ob[:custom_attrs].to_attr_format} type=\"#{type}\" #{'checked' if op[:checked].to_s.cama_true?} name=\"#{f_name}[]\" class=\"\" value=\"#{op[:label].downcase}\">
142
+ #{op[:label]}
143
+ </label>
144
+ </div>"
145
+ else
146
+ html += "<option value=\"#{op[:label].downcase.gsub(" ", "_")}\" #{"selected" if "#{op[:label].downcase.gsub(" ", "_")}" == values[cid] || op[:checked].to_s.cama_true? } >#{op[:label]}</option>"
147
+ end
148
+ end
149
+
150
+ if type == "radio" || type == "checkbox"
151
+ html += other_input
152
+ else
153
+ html += " </select>"
154
+ end
155
+ end
156
+ end