refinerycms-contacts 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/Gemfile +73 -0
  2. data/Guardfile +27 -0
  3. data/LICENSE.md +8 -0
  4. data/Rakefile +20 -0
  5. data/app/assets/javascripts/refinery/contacts/admin/contacts.js +17 -0
  6. data/app/assets/javascripts/refinery/contacts/admin/jquery.chosen.min.js +10 -0
  7. data/app/assets/javascripts/refinery/contacts/contacts.js +23 -0
  8. data/app/assets/stylesheets/refinery/contacts/admin/chosen.css.scss +396 -0
  9. data/app/assets/stylesheets/refinery/contacts/contacts.css.scss +79 -0
  10. data/app/controllers/refinery/contacts/admin/contacts_controller.rb +14 -0
  11. data/app/controllers/refinery/contacts/mail_messages_controller.rb +26 -0
  12. data/app/helpers/refinery/contacts/admin/contacts_helper.rb +18 -0
  13. data/app/mailers/refinery/contacts/contact_mailer.rb +15 -0
  14. data/app/models/refinery/contact_page.rb +11 -0
  15. data/app/models/refinery/contacts/contact.rb +18 -0
  16. data/app/models/refinery/contacts/mail.rb +13 -0
  17. data/app/models/refinery/contacts/mail_message.rb +15 -0
  18. data/app/models/refinery/contacts/table_less_model.rb +23 -0
  19. data/app/sweepers/refinery/contacts/admin/contact_sweeper.rb +22 -0
  20. data/app/views/refinery/admin/pages/tabs/contacts/_contacts.html.erb +12 -0
  21. data/app/views/refinery/admin/pages/tabs/contacts/_contacts_bar.html.erb +4 -0
  22. data/app/views/refinery/admin/pages/tabs/contacts/_form.html.erb +24 -0
  23. data/app/views/refinery/contacts/admin/contacts/_actions.html.erb +25 -0
  24. data/app/views/refinery/contacts/admin/contacts/_contact.html.erb +17 -0
  25. data/app/views/refinery/contacts/admin/contacts/_contacts.html.erb +2 -0
  26. data/app/views/refinery/contacts/admin/contacts/_form.html.erb +93 -0
  27. data/app/views/refinery/contacts/admin/contacts/_mail_fields.html.erb +7 -0
  28. data/app/views/refinery/contacts/admin/contacts/_records.html.erb +18 -0
  29. data/app/views/refinery/contacts/admin/contacts/_sortable_list.html.erb +5 -0
  30. data/app/views/refinery/contacts/admin/contacts/edit.html.erb +1 -0
  31. data/app/views/refinery/contacts/admin/contacts/index.html.erb +7 -0
  32. data/app/views/refinery/contacts/admin/contacts/new.html.erb +1 -0
  33. data/app/views/refinery/contacts/contact_mailer/contact_form.html.erb +1 -0
  34. data/app/views/refinery/contacts/contact_mailer/contact_form.text.erb +1 -0
  35. data/app/views/refinery/contacts/contacts/_error_info.html.erb +15 -0
  36. data/app/views/refinery/contacts/contacts/_form.html.erb +47 -0
  37. data/app/views/refinery/contacts/contacts/_show.html.erb +50 -0
  38. data/app/views/refinery/contacts/contacts/_success_info.html.erb +8 -0
  39. data/changelog.md +2 -0
  40. data/config/initializers/recaptcha.rb +5 -0
  41. data/config/initializers/refinery/core.rb +4 -0
  42. data/config/locales/en.yml +80 -0
  43. data/config/locales/sk.yml +80 -0
  44. data/config/routes.rb +23 -0
  45. data/db/migrate/1_create_contacts_contacts.rb +36 -0
  46. data/db/migrate/2_create_contacts_mails.rb +17 -0
  47. data/db/migrate/3_create_contact_pages.rb +20 -0
  48. data/db/migrate/4_add_homepage_to_contacts.rb +11 -0
  49. data/db/seeds.rb +13 -0
  50. data/lib/generators/refinery/contacts_generator.rb +28 -0
  51. data/lib/generators/refinery/templates/config/initializers/recaptcha.rb.erb +7 -0
  52. data/lib/generators/refinery/templates/config/initializers/refinery/contacts.rb.erb +4 -0
  53. data/lib/refinery/contacts.rb +23 -0
  54. data/lib/refinery/contacts/configuration.rb +10 -0
  55. data/lib/refinery/contacts/engine.rb +44 -0
  56. data/lib/refinery/contacts/extensions/pages_extension.rb +40 -0
  57. data/lib/refinery/contacts/version.rb +17 -0
  58. data/lib/refinerycms-contacts.rb +1 -0
  59. data/lib/tasks/refinery/contacts.rake +13 -0
  60. data/readme.md +170 -0
  61. data/refinerycms-contacts.gemspec +27 -0
  62. data/script/rails +10 -0
  63. data/spec/models/refinery/contacts/contact_spec.rb +18 -0
  64. data/spec/models/refinery/contacts/mail_spec.rb +18 -0
  65. data/spec/requests/refinery/contacts/admin/contacts_spec.rb +101 -0
  66. data/spec/requests/refinery/contacts/admin/mails_spec.rb +101 -0
  67. data/spec/spec_helper.rb +55 -0
  68. data/spec/support/factories/refinery/contacts.rb +7 -0
  69. data/spec/support/factories/refinery/mails.rb +7 -0
  70. data/tasks/rspec.rake +6 -0
  71. data/tasks/testing.rake +8 -0
  72. metadata +147 -0
@@ -0,0 +1,79 @@
1
+ form#new_mail_message {
2
+ margin-top: 20px;
3
+
4
+ div.field {
5
+ margin-top: 10px;
6
+ }
7
+
8
+ div.field label:first-child { //label for input name
9
+ font-weight: bold;
10
+ display:block;
11
+ }
12
+
13
+ div.field_with_errors label { //both label
14
+ color: red;
15
+ }
16
+
17
+ div.field_with_errors:last-child label { //label for error
18
+ vertical-align: top;
19
+ padding-left: 5px ;
20
+ }
21
+ }
22
+
23
+
24
+ // From refinerycms-core
25
+ #message, .flash {
26
+ padding: 8px 8px 8px 30px;
27
+ margin-bottom: 15px;
28
+ position: relative;
29
+ }
30
+ .flash_notice, .flash_message {
31
+ border: 1px solid #00A017;
32
+ color: #00A017;
33
+ background: 7px 7px no-repeat image_url('refinery/icons/accept.png') #E0F5E0;
34
+ }
35
+ .flash_notice, .flash_notice * {
36
+ color: #00A017;
37
+ }
38
+ .flash_error, .flash_alert {
39
+ border: 1px solid #A00027;
40
+ color: #A00027;
41
+ background: 7px 7px no-repeat image_url('refinery/icons/cancel.png') #FFB1B1;
42
+ }
43
+ .flash.flash_notice #flash_close, .flash.flash_error #flash_close, .flash.flash_alert #flash_close {
44
+ text-transform: lowercase;
45
+ }
46
+ .flash.flash_message {
47
+ background: #E0F5E0;
48
+ padding: 9px;
49
+ position: relative;
50
+ margin-bottom: 32px;
51
+ h2 {
52
+ margin-top: 12px;
53
+ }
54
+ }
55
+ .flash.flash_message.flash_message, .flash_message * {
56
+ color: #262719;
57
+ font-size: 14px;
58
+ }
59
+ .flash a, .flash a:hover {
60
+ color: #e20003;
61
+ border-bottom-color: #e20003;
62
+ }
63
+ .flash.flash_error a, .flash.flash_error a:hover,
64
+ .flash.flash_alert a, .flash.flash_alert a:hover {
65
+ display: none;
66
+ }
67
+ noscript .flash.flash_error a, noscript .flash.flash_error a:hover,
68
+ noscript .flash.flash_alert a, noscript .flash.flash_alert a:hover {
69
+ display: inline;
70
+ font-weight: bold;
71
+ }
72
+ .flash a#flash_close {
73
+ position: absolute;
74
+ right: 9px;
75
+ top: 7px;
76
+ }
77
+ .flash.flash_message a#flash_close {
78
+ top: 21px;
79
+ }
@@ -0,0 +1,14 @@
1
+ module Refinery
2
+ module Contacts
3
+ module Admin
4
+ class ContactsController < ::Refinery::AdminController
5
+ include ContactsHelper
6
+ helper :"refinery/contacts/admin/contacts"
7
+ cache_sweeper ContactSweeper
8
+
9
+ crudify :'refinery/contacts/contact', :xhr_paging => true
10
+
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ module Refinery
2
+ module Contacts
3
+ class MailMessagesController < ::ApplicationController
4
+
5
+ def deliver
6
+ @mail_message = MailMessage.new(params[:mail_message])
7
+
8
+
9
+ if @mail_message.valid? && verify_recaptcha(:model => @mail_message)
10
+ mail = Refinery::Contacts::Mail.select("mail").find(@mail_message.recipient_id)
11
+ @mail_message.recipient_mail = mail[:mail].to_s
12
+
13
+ ContactMailer.contact_form(@mail_message).deliver
14
+
15
+
16
+ flash[:notice] = t('refinery.contacts.contacts.flash.successfull_delivery')
17
+ else
18
+ flash[:mail_message] = @mail_message # send back to form data from filled fields. this is not very good way, but better than monkey-patch Page's controller, I think
19
+ end
20
+
21
+ redirect_to :back
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ module Refinery
2
+ module Contacts
3
+ module Admin
4
+ module ContactsHelper
5
+
6
+ def link_to_add_fields(name, f, association)
7
+ new_object = f.object.send(association).klass.new
8
+ id = new_object.object_id
9
+ fields = f.fields_for(association, new_object, :child_index=> id) do |builder|
10
+ render(association.to_s.singularize + "_fields", :f=> builder)
11
+ end
12
+ link_to(name, '#', :class=> "add_fields", :data=> {:id=> id, :fields=> fields.gsub("\n", "")})
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ module Refinery
2
+ module Contacts
3
+ class ContactMailer < ActionMailer::Base
4
+
5
+ def contact_form(mail_message)
6
+ @mail_message= mail_message
7
+
8
+ mail :from => @mail_message.sender_mail ,
9
+ :to => @mail_message.recipient_mail ,
10
+ :subject => @mail_message.subject
11
+
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Refinery
2
+ class ContactPage < Refinery::Core::BaseModel
3
+
4
+ belongs_to :contact, :class_name => Refinery::Contacts::Contact
5
+ belongs_to :page, :polymorphic => true
6
+
7
+
8
+ attr_accessible :page_id, :page_type, :contact_id , :contact_info
9
+
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ module Refinery
2
+ module Contacts
3
+ class Contact < Refinery::Core::BaseModel
4
+ has_many :mails
5
+
6
+ accepts_nested_attributes_for :mails, :allow_destroy => true
7
+
8
+ self.table_name = 'refinery_contacts'
9
+
10
+ attr_accessible :title, :street, :city, :zip_code, :homepage, :company, :province, :country, :tel1, :tel2, :tel3, :fax, :position, :mails_attributes
11
+
12
+ acts_as_indexed :fields => [:title, :street, :city, :zip_code, :province, :country, :tel1, :tel2, :tel3, :fax]
13
+
14
+ validates :title, :presence => true, :uniqueness => true
15
+ validates_format_of :homepage, :with => URI.regexp(['http','https']), :allow_blank => true
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ module Refinery
2
+ module Contacts
3
+ class Mail < Refinery::Core::BaseModel
4
+ belongs_to :contact
5
+
6
+ attr_accessible :mail, :position
7
+
8
+ acts_as_indexed :fields => [:mail]
9
+
10
+ validates_format_of :mail, :with => /.+@.+\..+/i , :allow_blank => false
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ module Refinery
2
+ module Contacts
3
+ class MailMessage < TableLessModel
4
+ attr_accessor :name, :recipient_id, :subject, :text, :sender_mail, :code, :recipient_mail
5
+
6
+ validates :name, :presence => true
7
+ validates :recipient_id, :presence => true
8
+ validates_numericality_of :recipient_id, :if => Proc.new { |mail_message| mail_message.recipient_id.present? } # dont show recipient is not number, when that mail adress is not selected yet.
9
+
10
+ validates :subject, :presence => true
11
+ validates :text, :presence => true
12
+ validates_format_of :sender_mail, :with => /.+@.+\..+/i , :allow_blank => false
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ module Refinery
2
+ module Contacts
3
+ class TableLessModel
4
+ include ActiveModel::Validations
5
+ include ActiveModel::Conversion
6
+ extend ActiveModel::Naming
7
+ extend ActiveModel::Translation
8
+
9
+
10
+
11
+ def initialize(attributes = {})
12
+ attributes.each do |name, value|
13
+ send("#{name}=", value)
14
+ end
15
+ end
16
+
17
+ def persisted?
18
+ false
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ module Refinery
2
+ module Contacts
3
+ module Admin
4
+ class ContactSweeper < ActionController::Caching::Sweeper
5
+ =begin
6
+ # Because of server-side error rendering, caching is commented.
7
+ observe Contact
8
+
9
+
10
+ def sweep(contact)
11
+ expire_fragment("refinery/contacts/contact/#{contact.id}")
12
+ end
13
+
14
+
15
+ alias_method :after_create, :sweep
16
+ alias_method :after_update, :sweep
17
+ alias_method :after_destroy, :sweep
18
+ =end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ <div class='wym_skin_refinery page_part'>
2
+ <%= render '/refinery/admin/pages/tabs/contacts/contacts_bar' %>
3
+
4
+ <div id="contacts_wym_editation" class='wym_box field ' style="height: 300px;">
5
+ <% if @page.contact_page.nil?
6
+ @page.build_contact_page
7
+ end %>
8
+
9
+
10
+ <%= render "/refinery/admin/pages/tabs/contacts/form", :f => f %>
11
+ </div>
12
+ </div>
@@ -0,0 +1,4 @@
1
+ <div >
2
+ <span class='clearfix label_inline_with_link'></span>
3
+
4
+ </div>
@@ -0,0 +1,24 @@
1
+ <%= f.fields_for @page.contact_page do |contact_page_form| %>
2
+ <%= contact_page_form.label :contact_id, t('.show_contact_form_for') %>
3
+ <%= contact_page_form.collection_select( :contact_id, Refinery::Contacts::Contact.all, :id, :title,
4
+ { :include_blank => true},
5
+ { :data => {
6
+ :placeholder=> t('.choose_contact')},
7
+ :multiple=> false,
8
+ :class=> "chzn-select-deselect",
9
+ :style=>"min-width: 300px;"
10
+ }) %> <br/> <br/>
11
+
12
+ <div class='field'>
13
+ <span class='label_with_help'>
14
+ <%= contact_page_form.label :contact_info %>
15
+ <%= refinery_help_tag t('.contact_info_help') %>
16
+ </span>
17
+ <%= contact_page_form.check_box :contact_info %>
18
+ <%= contact_page_form.label :contact_info, t('.show_contact_info'), :style=>"display:inline;" %>
19
+ </div>
20
+ <% end %>
21
+
22
+
23
+
24
+
@@ -0,0 +1,25 @@
1
+ <ul>
2
+ <% if ::Refinery::Contacts::Admin::ContactsController.searchable? %>
3
+ <li>
4
+ <%= render '/refinery/admin/search', :url => refinery.contacts_admin_contacts_path %>
5
+ </li>
6
+ <% end %>
7
+ <li>
8
+ <%= link_to t('.create_new'), refinery.new_contacts_admin_contact_path,
9
+ :class => "add_icon" %>
10
+ </li>
11
+ <% if !searching? && ::Refinery::Contacts::Admin::ContactsController.sortable? && ::Refinery::Contacts::Contact.any? %>
12
+ <li>
13
+ <%= link_to t('.reorder', :what => "Contacts"),
14
+ refinery.contacts_admin_contacts_path,
15
+ :id => "reorder_action",
16
+ :class => "reorder_icon" %>
17
+
18
+ <%= link_to t('.reorder_done', :what => "Contacts"),
19
+ refinery.contacts_admin_contacts_path,
20
+ :id => "reorder_action_done",
21
+ :style => "display: none;",
22
+ :class => "reorder_icon" %>
23
+ </li>
24
+ <% end %>
25
+ </ul>
@@ -0,0 +1,17 @@
1
+ <li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(contact) -%>">
2
+ <span class='title'>
3
+ <%= contact.title %>
4
+
5
+ </span>
6
+ <span class='actions'>
7
+
8
+
9
+ <%= link_to refinery_icon_tag("application_edit.png"), refinery.edit_contacts_admin_contact_path(contact),
10
+ :title => t('.edit') %>
11
+ <%= link_to refinery_icon_tag("delete.png"), refinery.contacts_admin_contact_path(contact),
12
+ :class => "cancel confirm-delete",
13
+ :title => t('.delete'),
14
+ :confirm => t('message', :scope => 'refinery.admin.delete', :title => contact.title),
15
+ :method => :delete %>
16
+ </span>
17
+ </li>
@@ -0,0 +1,2 @@
1
+ <%= will_paginate @contacts if Refinery::Contacts::Admin::ContactsController.pageable? %>
2
+ <%= render 'sortable_list' %>
@@ -0,0 +1,93 @@
1
+ <%= form_for [refinery, :contacts_admin, @contact] do |f| -%>
2
+ <%= render '/refinery/admin/error_messages',
3
+ :object => @contact,
4
+ :include_object_name => true %>
5
+
6
+
7
+ <div class='field'>
8
+ <%= f.label :title -%>
9
+ <%= f.text_field :title, :class => 'larger widest' -%>
10
+ </div>
11
+
12
+ <fieldset>
13
+ <legend>E-mail</legend>
14
+
15
+ <%= f.fields_for :mails do |builder| %>
16
+ <%= render "mail_fields", :f=> builder %>
17
+ <% end %>
18
+
19
+ <%= link_to_add_fields t('.add_mail'), f, :mails %>
20
+ </fieldset>
21
+
22
+ <div class='field'>
23
+ <%= f.label :company -%>
24
+ <%= f.text_field :company -%>
25
+
26
+ </div>
27
+
28
+ <div class='field'>
29
+ <%= f.label :street -%>
30
+ <%= f.text_field :street -%>
31
+ </div>
32
+
33
+ <div class='field'>
34
+ <%= f.label :city -%>
35
+ <%= f.text_field :city -%>
36
+
37
+ </div>
38
+
39
+ <div class='field'>
40
+ <%= f.label :zip_code -%>
41
+ <%= f.text_field :zip_code -%>
42
+
43
+ </div>
44
+
45
+ <div class='field'>
46
+ <%= f.label :province -%>
47
+ <%= f.text_field :province -%>
48
+
49
+ </div>
50
+
51
+ <div class='field'>
52
+ <%= f.label :country -%>
53
+ <%= f.text_field :country -%>
54
+
55
+ </div>
56
+
57
+ <div class='field'>
58
+ <%= f.label :homepage -%>
59
+ <%= f.text_field :homepage -%>
60
+
61
+ </div>
62
+
63
+ <div class='field'>
64
+ <%= f.label :tel1 -%>
65
+ <%= f.text_field :tel1 -%>
66
+ </div>
67
+
68
+ <div class='field'>
69
+ <%= f.label :tel2 -%>
70
+ <%= f.text_field :tel2 -%>
71
+
72
+ </div>
73
+
74
+ <div class='field'>
75
+ <%= f.label :tel3 -%>
76
+ <%= f.text_field :tel3 -%>
77
+
78
+ </div>
79
+
80
+ <div class='field'>
81
+ <%= f.label :fax -%>
82
+ <%= f.text_field :fax -%>
83
+
84
+ </div>
85
+
86
+
87
+
88
+
89
+ <%= render '/refinery/admin/form_actions', :f => f,
90
+ :continue_editing => false,
91
+ :delete_title => t('delete', :scope => 'refinery.contacts.admin.contacts.contact'),
92
+ :delete_confirmation => t('message', :scope => 'refinery.admin.delete', :title => @contact.title) %>
93
+ <% end -%>