spree_zaez_brazilian_fields 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +14 -0
- data/.rspec +1 -0
- data/.travis.yml +12 -0
- data/Gemfile +7 -0
- data/Guardfile +90 -0
- data/LICENSE +26 -0
- data/README.md +98 -0
- data/Rakefile +21 -0
- data/app/assets/javascripts/spree/backend/app/users/user_account_type.js.coffee +79 -0
- data/app/assets/javascripts/spree/backend/spree_zaez_brazilian_fields.js +4 -0
- data/app/assets/javascripts/spree/frontend/app/users/user_account_type.js.coffee +102 -0
- data/app/assets/javascripts/spree/frontend/spree_zaez_brazilian_fields.js +3 -0
- data/app/assets/stylesheets/spree/backend/spree_zaez_brazilian_fields.css +14 -0
- data/app/assets/stylesheets/spree/frontend/spree_zaez_brazilian_fields.css +5 -0
- data/app/helpers/spree/api/api_helpers_decorator.rb +4 -0
- data/app/models/spree/app_configuration_decorator.rb +6 -0
- data/app/models/spree/user_decorator.rb +87 -0
- data/app/overrides/spree/admin/general_settings/edit/add_sms_permission.html.erb.deface +23 -0
- data/app/overrides/spree/shared/_user_form/add_brazilian_fields.html.erb.deface +47 -0
- data/app/overrides/spree/shared/_user_form/add_name_to_form.html.erb.deface +4 -0
- data/app/overrides/spree/user_registrations/new/add_user_account_constructor.html.erb.deface +5 -0
- data/app/overrides/spree/users/edit/add_id_to_form.html.erb.deface +2 -0
- data/app/overrides/spree/users/edit/add_user_account_constructor.html.erb.deface +5 -0
- data/app/overrides/spree/users/show/add_brazilian_fields.html.erb.deface +20 -0
- data/app/views/spree/admin/users/_form.html.erb +139 -0
- data/bin/rails +7 -0
- data/config/locales/en.yml +20 -0
- data/config/locales/pt-br.yml +20 -0
- data/config/routes.rb +3 -0
- data/db/migrate/20150527162516_add_brazilian_fields_to_spree_users.rb +15 -0
- data/lib/generators/spree_zaez_brazilian_fields/install/install_generator.rb +31 -0
- data/lib/spree_zaez_brazilian_fields.rb +7 -0
- data/lib/spree_zaez_brazilian_fields/engine.rb +20 -0
- data/lib/spree_zaez_brazilian_fields/factories.rb +25 -0
- data/spec/features/account_spec.rb +31 -0
- data/spec/features/admin/general_settings_spec.rb +32 -0
- data/spec/features/admin/users_spec.rb +150 -0
- data/spec/features/sign_up_spec.rb +94 -0
- data/spec/models/spree/app_configuration_decorator_spec.rb +9 -0
- data/spec/models/spree/user_decorator_spec.rb +97 -0
- data/spec/spec_helper.rb +89 -0
- data/spec/support/capybara_login.rb +13 -0
- data/spec/support/controller_hacks.rb +34 -0
- data/spree_zaez_brazilian_fields.gemspec +38 -0
- data/vendor/assets/javascripts/inputmask/inputmask.min.js +10 -0
- data/vendor/assets/javascripts/inputmask/jquery.inputmask.min.js +8 -0
- data/vendor/assets/javascripts/jquery.validate/jquery.validate.min.js +12 -0
- metadata +59 -3
@@ -0,0 +1,87 @@
|
|
1
|
+
Spree::User.class_eval do
|
2
|
+
|
3
|
+
validates_inclusion_of :account_type, :in => %w(personal business)
|
4
|
+
validates_inclusion_of :gender, :in => %w(f m), allow_blank: true, allow_nil: true
|
5
|
+
validates_uniqueness_of :cpf, :cnpj, allow_blank: true, allow_nil: true
|
6
|
+
|
7
|
+
validate :validate_cpf, :validate_cnpj
|
8
|
+
|
9
|
+
# Sobrescreve o metodo para inserir
|
10
|
+
# o campo document (que retorna o CPF ou CNPJ, dependendo do tipo de usuario)
|
11
|
+
#
|
12
|
+
# @author Isabella Santos
|
13
|
+
#
|
14
|
+
# @return [Hash]
|
15
|
+
#
|
16
|
+
def attributes
|
17
|
+
fields = super
|
18
|
+
fields['document'] = document
|
19
|
+
fields
|
20
|
+
end
|
21
|
+
|
22
|
+
# Sobrescreve o metodo para inserir
|
23
|
+
# o campo document (que retorna o CPF ou CNPJ, dependendo do tipo de usuario)
|
24
|
+
#
|
25
|
+
# @author Isabella Santos
|
26
|
+
#
|
27
|
+
# @return [Array]
|
28
|
+
#
|
29
|
+
def attribute_names
|
30
|
+
fields = super
|
31
|
+
fields << 'document'
|
32
|
+
fields
|
33
|
+
end
|
34
|
+
|
35
|
+
# Retorna verdadeiro se for uma pessoa juridica (business)
|
36
|
+
#
|
37
|
+
# @author Isabella Santos
|
38
|
+
#
|
39
|
+
# @return [Boolean]
|
40
|
+
#
|
41
|
+
def business_account?
|
42
|
+
true if account_type == 'business'
|
43
|
+
end
|
44
|
+
|
45
|
+
# Retorna o documento de identidade do usuario
|
46
|
+
#
|
47
|
+
# @author Isabella Santos
|
48
|
+
#
|
49
|
+
# @return [String]
|
50
|
+
#
|
51
|
+
def document
|
52
|
+
return cpf if personal_account?
|
53
|
+
cnpj
|
54
|
+
end
|
55
|
+
|
56
|
+
# Retorna verdadeiro se for uma pessoa fisica (personal)
|
57
|
+
#
|
58
|
+
# @author Isabella Santos
|
59
|
+
#
|
60
|
+
# @return [Boolean]
|
61
|
+
#
|
62
|
+
def personal_account?
|
63
|
+
true if account_type == 'personal'
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
# Verifica se o CPF, se passado, e valido
|
69
|
+
#
|
70
|
+
# @author Isabella Santos
|
71
|
+
#
|
72
|
+
def validate_cpf
|
73
|
+
if self.cpf.present?
|
74
|
+
errors.add(:cpf, :invalid) unless CPF.valid?(self.cpf)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Verifica se o CNPJ, se passado, e valido
|
79
|
+
#
|
80
|
+
# @author Isabella Santos
|
81
|
+
#
|
82
|
+
def validate_cnpj
|
83
|
+
if self.cnpj.present?
|
84
|
+
errors.add(:cnpj, :invalid) unless CNPJ.valid?(self.cnpj)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<!-- insert_before "[data-hook='buttons']" -->
|
2
|
+
<%#-------------------------------------------------%>
|
3
|
+
<%# User registration settings %>
|
4
|
+
<%#-------------------------------------------------%>
|
5
|
+
<div class='row'>
|
6
|
+
<div class='col-sm-6'>
|
7
|
+
<div class='panel panel-default security'>
|
8
|
+
<div class='panel-heading'>
|
9
|
+
<h1 class='panel-title'>
|
10
|
+
<%= Spree.t(:user_registration_settings)%>
|
11
|
+
</h1>
|
12
|
+
</div>
|
13
|
+
<div class='panel-body'>
|
14
|
+
<div class='checkbox'>
|
15
|
+
<%= label_tag :sms_permission do %>
|
16
|
+
<%= preference_field_tag(:sms_permission, Spree::Config[:sms_permission], type: :boolean) %>
|
17
|
+
<%= Spree.t(:sms_permission) %>
|
18
|
+
<% end %>
|
19
|
+
</div>
|
20
|
+
</div>
|
21
|
+
</div>
|
22
|
+
</div>
|
23
|
+
</div>
|
@@ -0,0 +1,47 @@
|
|
1
|
+
<!-- insert_bottom '#password-credentials' -->
|
2
|
+
<hr />
|
3
|
+
<div class='form-group'>
|
4
|
+
<%= f.radio_button :account_type, 'personal' %>
|
5
|
+
<%= f.label :account_type_personal, Spree.t(:personal_account) %>
|
6
|
+
<%= f.radio_button :account_type, 'business' %>
|
7
|
+
<%= f.label :account_type_business, Spree.t(:business_account) %>
|
8
|
+
</div>
|
9
|
+
<div id='personal_account'>
|
10
|
+
<div class='form-group'>
|
11
|
+
<%= f.text_field :cpf, :class => 'form-control', :placeholder => Spree.t(:cpf) %>
|
12
|
+
</div>
|
13
|
+
<div class='form-group'>
|
14
|
+
<%= f.text_field :rg, :class => 'form-control', :placeholder => Spree.t(:rg) %>
|
15
|
+
</div>
|
16
|
+
<div class='form-group'>
|
17
|
+
<%= f.text_field :birth_date, :class => 'datepicker datepicker-from form-control', :placeholder => Spree.t(:birth_date) %>
|
18
|
+
</div>
|
19
|
+
<div class='form-group'>
|
20
|
+
<%= f.radio_button :gender, 'f' %>
|
21
|
+
<%= f.label :gender_f, Spree.t(:female) %>
|
22
|
+
<%= f.radio_button :gender, 'm' %>
|
23
|
+
<%= f.label :gender_m, Spree.t(:male) %>
|
24
|
+
</div>
|
25
|
+
</div>
|
26
|
+
<div id='business_account'>
|
27
|
+
<div class='form-group'>
|
28
|
+
<%= f.text_field :cnpj, :class => 'form-control', :placeholder => Spree.t(:cnpj) %>
|
29
|
+
</div>
|
30
|
+
<div class='form-group'>
|
31
|
+
<%= f.text_field :state_registry, :class => 'form-control', :placeholder => Spree.t(:state_registry) %>
|
32
|
+
</div>
|
33
|
+
<div class='form-group'>
|
34
|
+
<%= f.text_field :contact, :class => 'form-control', :placeholder => Spree.t(:contact) %>
|
35
|
+
</div>
|
36
|
+
</div>
|
37
|
+
<hr />
|
38
|
+
<div class='form-group'>
|
39
|
+
<%= f.check_box :newsletter %>
|
40
|
+
<%= f.label :newsletter, Spree.t(:newsletter) %>
|
41
|
+
</div>
|
42
|
+
<% if Spree::Config.sms_permission %>
|
43
|
+
<div class='form-group'>
|
44
|
+
<%= f.check_box :receive_sms %>
|
45
|
+
<%= f.label :receive_sms, Spree.t(:receive_sms) %>
|
46
|
+
</div>
|
47
|
+
<% end %>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<!-- insert_bottom '#user-info' -->
|
2
|
+
<dt><%= Spree.t(:name) %></dt>
|
3
|
+
<dd><%= @user.name %></dd>
|
4
|
+
<% if @user.personal_account? %>
|
5
|
+
<dt><%= Spree.t(:cpf) %></dt>
|
6
|
+
<dd><%= @user.cpf %></dd>
|
7
|
+
<dt><%= Spree.t(:rg) %></dt>
|
8
|
+
<dd><%= @user.rg %></dd>
|
9
|
+
<dt><%= Spree.t(:birth_date) %></dt>
|
10
|
+
<dd><%= @user.birth_date.strftime(I18n.t('date.formats.default')) if @user.birth_date.present? %></dd>
|
11
|
+
<dt><%= Spree.t(:gender) %></dt>
|
12
|
+
<dd><%= if @user.gender == 'f' then Spree.t(:female) else Spree.t(:male) end %></dd>
|
13
|
+
<% else %>
|
14
|
+
<dt><%= Spree.t(:cnpj) %></dt>
|
15
|
+
<dd><%= @user.cnpj %></dd>
|
16
|
+
<dt><%= Spree.t(:state_registry) %></dt>
|
17
|
+
<dd><%= @user.state_registry %></dd>
|
18
|
+
<dt><%= Spree.t(:contact) %></dt>
|
19
|
+
<dd><%= @user.contact %></dd>
|
20
|
+
<% end %>
|
@@ -0,0 +1,139 @@
|
|
1
|
+
<div data-hook="admin_user_form_fields" class="row">
|
2
|
+
<div class="col-md-6">
|
3
|
+
<%= f.field_container :email, class: ['form-group'] do %>
|
4
|
+
<%= f.label :email, Spree.t(:email) %>
|
5
|
+
<%= f.email_field :email, :class => 'form-control' %>
|
6
|
+
<%= error_message_on :user, :email %>
|
7
|
+
<% end %>
|
8
|
+
</div>
|
9
|
+
<div class="col-md-6">
|
10
|
+
<%= f.field_container :name, class: ['form-group'] do %>
|
11
|
+
<%= f.label :name, Spree.t(:name) %>
|
12
|
+
<%= f.text_field :name, :class => 'form-control' %>
|
13
|
+
<%= error_message_on :user, :name %>
|
14
|
+
<% end %>
|
15
|
+
</div>
|
16
|
+
<div data-hook="admin_user_form_password_fields">
|
17
|
+
<div class="col-md-6">
|
18
|
+
<%= f.field_container :password, class: ['form-group'] do %>
|
19
|
+
<%= f.label :password, Spree.t(:password) %>
|
20
|
+
<%= f.password_field :password, :class => 'form-control' %>
|
21
|
+
<%= f.error_message_on :password %>
|
22
|
+
<% end %>
|
23
|
+
</div>
|
24
|
+
<div class="col-md-6">
|
25
|
+
<%= f.field_container :password, class: ['form-group'] do %>
|
26
|
+
<%= f.label :password_confirmation, Spree.t(:confirm_password) %>
|
27
|
+
<%= f.password_field :password_confirmation, :class => 'form-control' %>
|
28
|
+
<%= f.error_message_on :password_confirmation %>
|
29
|
+
<% end %>
|
30
|
+
</div>
|
31
|
+
</div>
|
32
|
+
|
33
|
+
<div class="col-md-12">
|
34
|
+
<%= f.field_container :account_type, class: ['form-group'] do %>
|
35
|
+
<%= f.radio_button :account_type, 'personal' %>
|
36
|
+
<%= f.label :account_type_personal, Spree.t(:personal_account) %>
|
37
|
+
<%= f.radio_button :account_type, 'business' %>
|
38
|
+
<%= f.label :account_type_business, Spree.t(:business_account) %>
|
39
|
+
<% end %>
|
40
|
+
</div>
|
41
|
+
|
42
|
+
<!-- personal account fields -->
|
43
|
+
<div id="personal_account" data-hook="admin_user_form_personal_accounts_fields">
|
44
|
+
<div class="col-md-6">
|
45
|
+
<%= f.field_container :cpf, class: ['form-group'] do %>
|
46
|
+
<%= f.label :cpf, Spree.t(:cpf) %>
|
47
|
+
<%= f.text_field :cpf, :class => 'form-control' %>
|
48
|
+
<%= error_message_on :user, :cpf %>
|
49
|
+
<% end %>
|
50
|
+
</div>
|
51
|
+
<div class="col-md-6">
|
52
|
+
<%= f.field_container :rg, class: ['form-group'] do %>
|
53
|
+
<%= f.label :rg, Spree.t(:rg) %>
|
54
|
+
<%= f.text_field :rg, :class => 'form-control' %>
|
55
|
+
<%= error_message_on :user, :rg %>
|
56
|
+
<% end %>
|
57
|
+
</div>
|
58
|
+
<div class="col-md-6">
|
59
|
+
<%= f.field_container :birth_date, class: ['form-group'] do %>
|
60
|
+
<%= f.label :birth_date, Spree.t(:birth_date) %>
|
61
|
+
<%= f.text_field :birth_date, :class => 'datepicker datepicker-from form-control' %>
|
62
|
+
<%= error_message_on :user, :birth_date %>
|
63
|
+
<% end %>
|
64
|
+
</div>
|
65
|
+
<div class="col-md-6">
|
66
|
+
<%= f.field_container :gender, class: ['form-group'] do %>
|
67
|
+
<%= f.label :gender, Spree.t(:gender), class: 'block' %>
|
68
|
+
<%= f.radio_button :gender, 'f' %>
|
69
|
+
<%= f.label :gender_f, Spree.t(:female) %>
|
70
|
+
<br />
|
71
|
+
<%= f.radio_button :gender, 'm' %>
|
72
|
+
<%= f.label :gender_m, Spree.t(:male) %>
|
73
|
+
<% end %>
|
74
|
+
</div>
|
75
|
+
</div>
|
76
|
+
<!-- business accounts fields -->
|
77
|
+
<div id="business_account" data-hook="admin_user_form_business_accounts_fields">
|
78
|
+
<div class="col-md-6">
|
79
|
+
<%= f.field_container :cnpj, class: ['form-group'] do %>
|
80
|
+
<%= f.label :cnpj, Spree.t(:cnpj) %>
|
81
|
+
<%= f.text_field :cnpj, :class => 'form-control' %>
|
82
|
+
<%= error_message_on :user, :cnpj %>
|
83
|
+
<% end %>
|
84
|
+
</div>
|
85
|
+
<div class="col-md-6">
|
86
|
+
<%= f.field_container :state_registry, class: ['form-group'] do %>
|
87
|
+
<%= f.label :state_registry, Spree.t(:state_registry) %>
|
88
|
+
<%= f.text_field :state_registry, :class => 'form-control' %>
|
89
|
+
<%= error_message_on :user, :state_registry %>
|
90
|
+
<% end %>
|
91
|
+
</div>
|
92
|
+
<div class="col-md-6">
|
93
|
+
<%= f.field_container :contact, class: ['form-group'] do %>
|
94
|
+
<%= f.label :contact, Spree.t(:contact) %>
|
95
|
+
<%= f.text_field :contact, :class => 'form-control' %>
|
96
|
+
<%= error_message_on :user, :contact %>
|
97
|
+
<% end %>
|
98
|
+
</div>
|
99
|
+
</div>
|
100
|
+
|
101
|
+
<div class="col-md-12 p-l-n p-r-n">
|
102
|
+
<div class="col-md-6">
|
103
|
+
<%= f.field_container :newsletter, class: ['form-group'] do %>
|
104
|
+
<%= f.check_box :newsletter %>
|
105
|
+
<%= f.label :newsletter, Spree.t(:newsletter) %>
|
106
|
+
<% end %>
|
107
|
+
</div>
|
108
|
+
<% if Spree::Config.sms_permission %>
|
109
|
+
<div class="col-md-6">
|
110
|
+
<%= f.field_container :receive_sms, class: ['form-group'] do %>
|
111
|
+
<%= f.check_box :receive_sms %>
|
112
|
+
<%= f.label :receive_sms, Spree.t(:receive_sms) %>
|
113
|
+
<% end %>
|
114
|
+
</div>
|
115
|
+
<% end %>
|
116
|
+
</div>
|
117
|
+
|
118
|
+
<div class="col-md-12">
|
119
|
+
<div data-hook="admin_user_form_roles" class="form-group">
|
120
|
+
<strong><%= Spree.t(:roles) %></strong>
|
121
|
+
<% @roles.each do |role| %>
|
122
|
+
<div class="checkbox">
|
123
|
+
<%= label_tag "user_spree_role_#{role.name}" do %>
|
124
|
+
<%= check_box_tag 'user[spree_role_ids][]', role.id, @user.spree_roles.include?(role), :id => "user_spree_role_#{role.name}" %>
|
125
|
+
<%= role.name %>
|
126
|
+
<% end %>
|
127
|
+
</div>
|
128
|
+
<% end %>
|
129
|
+
<%= hidden_field_tag 'user[spree_role_ids][]', '' %>
|
130
|
+
</div>
|
131
|
+
</div>
|
132
|
+
</div>
|
133
|
+
|
134
|
+
<script type="text/javascript">
|
135
|
+
new window.UserAccountType();
|
136
|
+
|
137
|
+
Spree.translations.user_name_personal = '<%= Spree.t(:name) %>';
|
138
|
+
Spree.translations.user_name_business = '<%= Spree.t(:corporate_name) %>';
|
139
|
+
</script>
|
data/bin/rails
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
2
|
+
|
3
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
4
|
+
ENGINE_PATH = File.expand_path('../../lib/spree_zaez_brazilian_fields/engine', __FILE__)
|
5
|
+
|
6
|
+
require 'rails/all'
|
7
|
+
require 'rails/engine/commands'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
en:
|
2
|
+
spree:
|
3
|
+
account_type: Account type
|
4
|
+
personal_account: Personal account
|
5
|
+
business_account: Business account
|
6
|
+
name: Name
|
7
|
+
corporate_name: Corporate Name
|
8
|
+
cpf: CPF
|
9
|
+
cnpj: CNPJ
|
10
|
+
rg: RG
|
11
|
+
state_registry: State registry
|
12
|
+
birth_date: Birth Date
|
13
|
+
contact: Contact
|
14
|
+
gender: Gender
|
15
|
+
male: Male
|
16
|
+
female: Female
|
17
|
+
newsletter: Receive Newsletter
|
18
|
+
receive_sms: Receive SMS
|
19
|
+
user_registration_settings: User Registration Settings
|
20
|
+
sms_permission: Show SMS permission
|
@@ -0,0 +1,20 @@
|
|
1
|
+
pt-BR:
|
2
|
+
spree:
|
3
|
+
account_type: Tipo de pessoa
|
4
|
+
personal_account: Pessoa física
|
5
|
+
business_account: Pessoa jurídica
|
6
|
+
name: Nome
|
7
|
+
corporate_name: Razão social
|
8
|
+
cpf: CPF
|
9
|
+
cnpj: CNPJ
|
10
|
+
rg: RG
|
11
|
+
state_registry: Inscrição Estadual
|
12
|
+
birth_date: Data de nascimento
|
13
|
+
contact: Contato
|
14
|
+
gender: Gênero
|
15
|
+
male: Masculino
|
16
|
+
female: Feminino
|
17
|
+
newsletter: Assinar a newsletter
|
18
|
+
receive_sms: Receber SMS
|
19
|
+
user_registration_settings: Configurações do cadastro de usuários
|
20
|
+
sms_permission: Exibir campo para recebimento de SMS
|
data/config/routes.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
class AddBrazilianFieldsToSpreeUsers < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
add_column :spree_users, :name, :string
|
4
|
+
add_column :spree_users, :cpf, :string
|
5
|
+
add_column :spree_users, :cnpj, :string
|
6
|
+
add_column :spree_users, :account_type, :string, default: 'personal'
|
7
|
+
add_column :spree_users, :birth_date, :date
|
8
|
+
add_column :spree_users, :rg, :string
|
9
|
+
add_column :spree_users, :state_registry, :string
|
10
|
+
add_column :spree_users, :newsletter, :integer
|
11
|
+
add_column :spree_users, :receive_sms, :integer
|
12
|
+
add_column :spree_users, :contact, :string
|
13
|
+
add_column :spree_users, :gender, :string
|
14
|
+
end
|
15
|
+
end
|