Commit f60de0fe2cd9d185c892fe1f0a16542d788f1e48
1 parent
70f9eff6
Exists in
master
and in
3 other branches
Add the institution table and references.
Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com> Signed-off-by: Thiago Ribeiro <thiagitosouza@hotmail.com>
Showing
41 changed files
with
1913 additions
and
1 deletions
Show diff stats
... | ... | @@ -0,0 +1,210 @@ |
1 | +#aqui deve ter so usuario e instituicao | |
2 | +class GovUserPluginController < ApplicationController | |
3 | + | |
4 | + def hide_registration_incomplete_percentage | |
5 | + response = false | |
6 | + | |
7 | + if request.xhr? && params[:hide] | |
8 | + session[:hide_incomplete_percentage] = true | |
9 | + response = session[:hide_incomplete_percentage] | |
10 | + end | |
11 | + | |
12 | + render :json=>response.to_json | |
13 | + end | |
14 | + | |
15 | + def create_institution | |
16 | + @show_sisp_field = environment.admins.include?(current_user.person) | |
17 | + @state_list = get_state_list() | |
18 | + | |
19 | + if request.xhr? | |
20 | + render :layout=>false | |
21 | + else | |
22 | + redirect_to "/" | |
23 | + end | |
24 | + end | |
25 | + | |
26 | + def split_http_referer http_referer | |
27 | + split_list = [] | |
28 | + split_list = http_referer.split("/") | |
29 | + @url_token = split_list.last | |
30 | + return @url_token | |
31 | + end | |
32 | + | |
33 | + def create_institution_admin | |
34 | + @show_sisp_field = environment.admins.include?(current_user.person) | |
35 | + @state_list = get_state_list() | |
36 | + | |
37 | + @url_token = split_http_referer request.original_url() | |
38 | + end | |
39 | + | |
40 | + def new_institution | |
41 | + redirect_to "/" if params[:community].blank? || params[:institutions].blank? | |
42 | + | |
43 | + response_message = {} | |
44 | + | |
45 | + institution_template = Community["institution"] | |
46 | + add_template_in_params institution_template | |
47 | + | |
48 | + institution = private_create_institution | |
49 | + add_environment_admins_to_institution institution | |
50 | + | |
51 | + response_message = save_institution institution | |
52 | + | |
53 | + if request.xhr? #User create institution | |
54 | + render :json => response_message.to_json | |
55 | + else #Admin create institution | |
56 | + session[:notice] = response_message[:message] # consume the notice | |
57 | + | |
58 | + redirect_depending_on_institution_creation response_message | |
59 | + end | |
60 | + end | |
61 | + | |
62 | + def institution_already_exists | |
63 | + redirect_to "/" if !request.xhr? || params[:name].blank? | |
64 | + | |
65 | + already_exists = !Community.where(:name=>params[:name]).empty? | |
66 | + | |
67 | + render :json=>already_exists.to_json | |
68 | + end | |
69 | + | |
70 | + def get_institutions | |
71 | + redirect_to "/" if !request.xhr? || params[:query].blank? | |
72 | + | |
73 | + list = Institution.search_institution(params[:query]).map{ |institution| | |
74 | + {:value=>institution.name, :id=>institution.id} | |
75 | + } | |
76 | + | |
77 | + render :json => list.to_json | |
78 | + end | |
79 | + | |
80 | + def get_brazil_states | |
81 | + redirect_to "/" unless request.xhr? | |
82 | + | |
83 | + state_list = get_state_list() | |
84 | + render :json=>state_list.collect {|state| state.name }.to_json | |
85 | + end | |
86 | + | |
87 | + def get_field_data | |
88 | + condition = !request.xhr? || params[:query].nil? || params[:field].nil? | |
89 | + return render :json=>{} if condition | |
90 | + | |
91 | + model = get_model_by_params_field | |
92 | + | |
93 | + data = model.where("name ILIKE ?", "%#{params[:query]}%").select("id, name") | |
94 | + .collect { |db| | |
95 | + {:id=>db.id, :label=>db.name} | |
96 | + } | |
97 | + | |
98 | + other = [model.select("id, name").last].collect { |db| | |
99 | + {:id=>db.id, :label=>db.name} | |
100 | + } | |
101 | + | |
102 | + # Always has other in the list | |
103 | + data |= other | |
104 | + | |
105 | + render :json=> data | |
106 | + end | |
107 | + | |
108 | + protected | |
109 | + | |
110 | + def get_state_list | |
111 | + NationalRegion.find( | |
112 | + :all, | |
113 | + :conditions=>["national_region_type_id = ?", 2], | |
114 | + :order=>"name" | |
115 | + ) | |
116 | + end | |
117 | + | |
118 | + def set_institution_type | |
119 | + institution_params = params[:institutions].except( | |
120 | + :governmental_power, | |
121 | + :governmental_sphere, | |
122 | + :juridical_nature | |
123 | + ) | |
124 | + if params[:institutions][:type] == "PublicInstitution" | |
125 | + PublicInstitution::new institution_params | |
126 | + else | |
127 | + PrivateInstitution::new institution_params | |
128 | + end | |
129 | + end | |
130 | + | |
131 | + def set_public_institution_fields institution | |
132 | + inst_fields = params[:institutions] | |
133 | + | |
134 | + begin | |
135 | + gov_power = GovernmentalPower.find inst_fields[:governmental_power] | |
136 | + gov_sphere = GovernmentalSphere.find inst_fields[:governmental_sphere] | |
137 | + jur_nature = JuridicalNature.find inst_fields[:juridical_nature] | |
138 | + | |
139 | + institution.juridical_nature = jur_nature | |
140 | + institution.governmental_power = gov_power | |
141 | + institution.governmental_sphere = gov_sphere | |
142 | + rescue | |
143 | + institution.errors.add( | |
144 | + :governmental_fields, | |
145 | + _("Could not find Governmental Power or Governmental Sphere") | |
146 | + ) | |
147 | + end | |
148 | + end | |
149 | + | |
150 | + def private_create_institution | |
151 | + community = Community.new(params[:community]) | |
152 | + community.environment = environment | |
153 | + institution = set_institution_type | |
154 | + | |
155 | + institution.name = community[:name] | |
156 | + institution.community = community | |
157 | + | |
158 | + if institution.type == "PublicInstitution" | |
159 | + set_public_institution_fields institution | |
160 | + end | |
161 | + | |
162 | + institution.date_modification = DateTime.now | |
163 | + institution.save | |
164 | + | |
165 | + institution | |
166 | + end | |
167 | + | |
168 | + def add_template_in_params institution_template | |
169 | + com_fields = params[:community] | |
170 | + if !institution_template.blank? && institution_template.is_template | |
171 | + com_fields[:template_id]= institution_template.id unless com_fields.blank? | |
172 | + end | |
173 | + end | |
174 | + | |
175 | + def add_environment_admins_to_institution institution | |
176 | + edit_page = params[:edit_institution_page] == false | |
177 | + if environment.admins.include?(current_user.person) && edit_page | |
178 | + environment.admins.each do |adm| | |
179 | + institution.community.add_admin(adm) | |
180 | + end | |
181 | + end | |
182 | + end | |
183 | + | |
184 | + def save_institution institution | |
185 | + inst_errors = institution.errors.full_messages | |
186 | + com_errors = institution.community.errors.full_messages | |
187 | + | |
188 | + if inst_errors.empty? && com_errors.empty? && institution.valid? && institution.save | |
189 | + { :success => true, | |
190 | + :message => _("Institution successful created!"), | |
191 | + :institution_data => {:name=>institution.name, :id=>institution.id} | |
192 | + } | |
193 | + else | |
194 | + { :success => false, | |
195 | + :message => _("Institution could not be created!"), | |
196 | + :errors => inst_errors << com_errors | |
197 | + } | |
198 | + end | |
199 | + end | |
200 | + | |
201 | + def redirect_depending_on_institution_creation response_message | |
202 | + if response_message[:success] | |
203 | + redirect_to :controller => "/admin_panel", :action => "index" | |
204 | + else | |
205 | + flash[:errors] = response_message[:errors] | |
206 | + redirect_to :controller => "software_communities_plugin", :action => "create_institution_admin" | |
207 | + end | |
208 | + end | |
209 | + | |
210 | +end | ... | ... |
... | ... | @@ -0,0 +1,44 @@ |
1 | +class GovUserPluginMyprofileController < MyProfileController | |
2 | + append_view_path File.join(File.dirname(__FILE__) + '/../views') | |
3 | + | |
4 | + def index | |
5 | + end | |
6 | + | |
7 | + def edit_institution | |
8 | + @show_sisp_field = environment.admins.include?(current_user.person) | |
9 | + @state_list = NationalRegion.find(:all, :conditions => | |
10 | + { :national_region_type_id => 2 }, | |
11 | + :order => 'name') | |
12 | + @institution = @profile.institution | |
13 | + update_institution if request.post? | |
14 | + end | |
15 | + | |
16 | + private | |
17 | + | |
18 | + def update_institution | |
19 | + @institution.community.update_attributes(params[:community]) | |
20 | + @institution.update_attributes(params[:institutions].except(:governmental_power, :governmental_sphere, :juridical_nature)) | |
21 | + if @institution.type == "PublicInstitution" | |
22 | + begin | |
23 | + governmental_updates | |
24 | + rescue | |
25 | + @institution.errors.add(:governmental_fields, | |
26 | + _("Could not find Governmental Power or Governmental Sphere")) | |
27 | + end | |
28 | + end | |
29 | + flash[:errors] = @institution.errors.full_messages unless @institution.valid? | |
30 | + end | |
31 | + | |
32 | + def governmental_updates | |
33 | + gov_power = GovernmentalPower.find params[:institutions][:governmental_power] | |
34 | + gov_sphere = GovernmentalSphere.find params[:institutions][:governmental_sphere] | |
35 | + jur_nature = JuridicalNature.find params[:institutions][:juridical_nature] | |
36 | + | |
37 | + @institution.juridical_nature = jur_nature | |
38 | + @institution.governmental_power = gov_power | |
39 | + @institution.governmental_sphere = gov_sphere | |
40 | + @institution.save | |
41 | + end | |
42 | + | |
43 | + | |
44 | +end | ... | ... |
... | ... | @@ -0,0 +1,27 @@ |
1 | +class AddNewFieldsInstitution < ActiveRecord::Migration | |
2 | + def up | |
3 | + add_column :institutions, :acronym, :string | |
4 | + add_column :institutions, :unit_code, :integer | |
5 | + add_column :institutions, :parent_code, :integer | |
6 | + add_column :institutions, :unit_type, :string | |
7 | + add_column :institutions, :juridical_nature, :string | |
8 | + add_column :institutions, :sub_juridical_nature, :string | |
9 | + add_column :institutions, :normalization_level, :string | |
10 | + add_column :institutions, :version, :string | |
11 | + add_column :institutions, :cnpj, :string | |
12 | + add_column :institutions, :type, :string | |
13 | + end | |
14 | + | |
15 | + def down | |
16 | + remove_column :institutions, :acronym | |
17 | + remove_column :institutions, :unit_code | |
18 | + remove_column :institutions, :parent_code | |
19 | + remove_column :institutions, :unit_type | |
20 | + remove_column :institutions, :juridical_nature | |
21 | + remove_column :institutions, :sub_juridical_nature | |
22 | + remove_column :institutions, :normalization_level | |
23 | + remove_column :institutions, :version | |
24 | + remove_column :institutions, :cnpj | |
25 | + remove_column :institutions, :type | |
26 | + end | |
27 | +end | ... | ... |
db/migrate/20140617132133_create_governmental_spheres.rb
0 → 100644
... | ... | @@ -0,0 +1,19 @@ |
1 | +class CreateGovernmentalSpheres < ActiveRecord::Migration | |
2 | + def change | |
3 | + create_table :governmental_spheres do |t| | |
4 | + t.string :name | |
5 | + t.string :acronym | |
6 | + t.integer :unit_code | |
7 | + t.integer :parent_code | |
8 | + t.string :unit_type | |
9 | + t.string :juridical_nature | |
10 | + t.string :sub_juridical_nature | |
11 | + t.string :normalization_level | |
12 | + t.string :version | |
13 | + t.string :cnpj | |
14 | + t.string :type | |
15 | + | |
16 | + t.timestamps | |
17 | + end | |
18 | + end | |
19 | +end | ... | ... |
db/migrate/20140617134556_add_references_to_institution.rb
0 → 100644
... | ... | @@ -0,0 +1,15 @@ |
1 | +class AddReferencesToInstitution < ActiveRecord::Migration | |
2 | + def up | |
3 | + change_table :institutions do |t| | |
4 | + t.references :governmental_power | |
5 | + t.references :governmental_sphere | |
6 | + end | |
7 | + end | |
8 | + | |
9 | + def down | |
10 | + change_table :institutions do |t| | |
11 | + t.remove_references :governmental_power | |
12 | + t.remove_references :governmental_sphere | |
13 | + end | |
14 | + end | |
15 | +end | ... | ... |
db/migrate/20140630183326_add_relation_between_community_and_institution.rb
0 → 100644
... | ... | @@ -0,0 +1,13 @@ |
1 | +class AddRelationBetweenCommunityAndInstitution < ActiveRecord::Migration | |
2 | + def up | |
3 | + change_table :institutions do |t| | |
4 | + t.references :community | |
5 | + end | |
6 | + end | |
7 | + | |
8 | + def down | |
9 | + change_table :institutions do |t| | |
10 | + t.remove_references :community | |
11 | + end | |
12 | + end | |
13 | +end | ... | ... |
db/migrate/20140812143218_remove_field_role_from_user.rb
0 → 100644
db/migrate/20140814125947_add_new_fields_to_public_institution.rb
0 → 100644
... | ... | @@ -0,0 +1,11 @@ |
1 | +class AddNewFieldsToPublicInstitution < ActiveRecord::Migration | |
2 | + def up | |
3 | + add_column :institutions, :sisp, :boolean, :default => false | |
4 | + remove_column :institutions, :juridical_nature | |
5 | + end | |
6 | + | |
7 | + def down | |
8 | + remove_column :institutions, :sisp | |
9 | + add_column :institutions, :juridical_nature, :string | |
10 | + end | |
11 | +end | ... | ... |
db/migrate/20140814131606_create_juridical_natures_table.rb
0 → 100644
db/migrate/20140814134827_add_juridical_nature_reference_to_institutions_table.rb
0 → 100644
... | ... | @@ -0,0 +1,13 @@ |
1 | +class AddJuridicalNatureReferenceToInstitutionsTable < ActiveRecord::Migration | |
2 | + def up | |
3 | + change_table :institutions do |t| | |
4 | + t.references :juridical_nature | |
5 | + end | |
6 | + end | |
7 | + | |
8 | + def down | |
9 | + change_table :institutions do |t| | |
10 | + t.remove_references :juridical_nature | |
11 | + end | |
12 | + end | |
13 | +end | ... | ... |
db/migrate/20140815194530_register_institution_modification.rb
0 → 100644
... | ... | @@ -0,0 +1,13 @@ |
1 | +class RegisterInstitutionModification < ActiveRecord::Migration | |
2 | + def up | |
3 | + change_table :institutions do |t| | |
4 | + t.string :date_modification | |
5 | + end | |
6 | + end | |
7 | + | |
8 | + def down | |
9 | + change_table :institutions do |t| | |
10 | + t.remove :date_modification | |
11 | + end | |
12 | + end | |
13 | +end | ... | ... |
db/migrate/20140818195821_remove_institution_from_user.rb
0 → 100644
db/migrate/20140818200738_create_institution_user_relation_table.rb
0 → 100644
db/migrate/20141103183013_add_corporate_name_to_institution.rb
0 → 100644
... | ... | @@ -0,0 +1,19 @@ |
1 | +# encoding: UTF-8 | |
2 | +powers = ["Executivo", "Legislativo", "Judiciario", "Não se aplica"] | |
3 | +spheres = ["Federal", "Estadual", "Distrital", "Municipal"] | |
4 | +jur_natures = ["Administracao Direta", "Autarquia", "Empresa Publica", "Fundacao", | |
5 | + "Orgao Autonomo", "Sociedade", "Sociedade Civil", | |
6 | + "Sociedade de Economia Mista" | |
7 | + ] | |
8 | + | |
9 | +powers.each do |power| | |
10 | + GovernmentalPower.create(:name => power) | |
11 | +end | |
12 | + | |
13 | +spheres.each do |sphere| | |
14 | + GovernmentalSphere.create(:name => sphere) | |
15 | +end | |
16 | + | |
17 | +jur_natures.each do |jur_nature| | |
18 | + JuridicalNature.create(:name => jur_nature) | |
19 | +end | ... | ... |
... | ... | @@ -0,0 +1,40 @@ |
1 | +require_dependency 'search_controller' | |
2 | + | |
3 | +class SearchController | |
4 | + | |
5 | + def communities | |
6 | + results = filter_communities_list do |community| | |
7 | + !community.institution? | |
8 | + end | |
9 | + results = results.paginate(:per_page => 24, :page => params[:page]) | |
10 | + @searches[@asset] = {:results => results} | |
11 | + @search = results | |
12 | + end | |
13 | + | |
14 | + def institutions | |
15 | + @titles[:institutions] = _("Institution Catalog") | |
16 | + results = filter_communities_list{|community| community.institution?} | |
17 | + results = results.paginate(:per_page => 24, :page => params[:page]) | |
18 | + @searches[@asset] = {:results => results} | |
19 | + @search = results | |
20 | + end | |
21 | + | |
22 | + def filter_communities_list | |
23 | + unfiltered_list = visible_profiles(Community) | |
24 | + | |
25 | + unless params[:query].nil? | |
26 | + unfiltered_list = unfiltered_list.select do |com| | |
27 | + com.name.downcase =~ /#{params[:query].downcase}/ | |
28 | + end | |
29 | + end | |
30 | + | |
31 | + communities_list = [] | |
32 | + unfiltered_list.each do |profile| | |
33 | + if profile.class == Community && !profile.is_template? && yield(profile) | |
34 | + communities_list << profile | |
35 | + end | |
36 | + end | |
37 | + | |
38 | + communities_list | |
39 | + end | |
40 | +end | ... | ... |
lib/gov_user_plugin.rb
... | ... | @@ -37,7 +37,7 @@ class GovUserPlugin < Noosfero::Plugin |
37 | 37 | |
38 | 38 | def profile_editor_transaction_extras |
39 | 39 | single_hash_transactions = { :user => 'user', |
40 | - :instituton => 'instituton' | |
40 | + :instituton => 'instituton' | |
41 | 41 | } |
42 | 42 | |
43 | 43 | single_hash_transactions.each do |model, transaction| |
... | ... | @@ -45,6 +45,61 @@ class GovUserPlugin < Noosfero::Plugin |
45 | 45 | end |
46 | 46 | end |
47 | 47 | |
48 | + def profile_editor_controller_filters | |
49 | + block = proc do | |
50 | + if request.post? && params[:institution] | |
51 | + is_admin = environment.admins.include?(current_user.person) | |
52 | + | |
53 | + unless is_admin | |
54 | + institution = profile.user.institutions | |
55 | + | |
56 | + if !params[:institution].blank? && !params[:institution][:sisp].nil? | |
57 | + if params[:institution][:sisp] != institution.sisp | |
58 | + params[:institution][:sisp] = institution.sisp | |
59 | + end | |
60 | + end | |
61 | + end | |
62 | + end | |
63 | + end | |
64 | + | |
65 | + [{ | |
66 | + :type => 'before_filter', | |
67 | + :method_name => 'validate_institution_sisp_field_access', | |
68 | + :options => { :only => :edit }, | |
69 | + :block => block | |
70 | + }] | |
71 | + end | |
72 | + | |
73 | + def profile_tabs | |
74 | + if context.profile.community? | |
75 | + return profile_tabs_institution if context.profile.institution? | |
76 | + end | |
77 | + end | |
78 | + | |
79 | + def control_panel_buttons | |
80 | + if context.profile.institution? | |
81 | + return institution_info_button | |
82 | + end | |
83 | + end | |
84 | + | |
85 | + def self.extra_blocks | |
86 | + { | |
87 | + InstitutionsBlock => { :type => [Environment, Person] } | |
88 | + } | |
89 | + end | |
90 | + | |
91 | + def custom_user_registration_attributes(user) | |
92 | + return if context.params[:user][:institution_ids].nil? | |
93 | + context.params[:user][:institution_ids].delete('') | |
94 | + | |
95 | + update_user_institutions(user) | |
96 | + | |
97 | + user.institutions.each do |institution| | |
98 | + community = institution.community | |
99 | + community.add_member user.person | |
100 | + end | |
101 | + end | |
102 | + | |
48 | 103 | def profile_editor_extras |
49 | 104 | profile = context.profile |
50 | 105 | |
... | ... | @@ -108,6 +163,9 @@ class GovUserPlugin < Noosfero::Plugin |
108 | 163 | empty_fields |
109 | 164 | end |
110 | 165 | |
166 | + | |
167 | + protected | |
168 | + | |
111 | 169 | def user_transaction |
112 | 170 | user_editor_institution_actions |
113 | 171 | |
... | ... | @@ -116,10 +174,95 @@ class GovUserPlugin < Noosfero::Plugin |
116 | 174 | end |
117 | 175 | end |
118 | 176 | |
177 | + def institution_transaction | |
178 | + institution.date_modification = DateTime.now | |
179 | + institution.save | |
180 | + institution_models = %w(governmental_power governmental_sphere | |
181 | + juridical_nature) | |
182 | + | |
183 | + institution_models.each do |model| | |
184 | + call_institution_transaction(model) | |
185 | + end | |
186 | + | |
187 | + if context.params.has_key?(:institution) | |
188 | + Institution.transaction do | |
189 | + context.profile. | |
190 | + institution. | |
191 | + update_attributes!(context.params[:institution]) | |
192 | + end | |
193 | + end | |
194 | + end | |
195 | + | |
119 | 196 | private |
120 | 197 | |
121 | 198 | def call_model_transaction(model,name) |
122 | 199 | send(name + '_transaction') if context.params.key?(model.to_sym) |
123 | 200 | end |
124 | 201 | |
202 | + # Add and remove the user from it's institutions communities | |
203 | + def user_editor_institution_actions | |
204 | + user = context.profile.user | |
205 | + | |
206 | + old_communities = [] | |
207 | + context.profile.user.institutions.each do |institution| | |
208 | + old_communities << institution.community | |
209 | + end | |
210 | + | |
211 | + new_communities = [] | |
212 | + unless context.params[:user][:institution_ids].nil? | |
213 | + context.params[:user][:institution_ids].delete('') | |
214 | + | |
215 | + context.params[:user][:institution_ids].each do |id| | |
216 | + new_communities << Institution.find(id).community | |
217 | + end | |
218 | + end | |
219 | + | |
220 | + manage_user_institutions(user, old_communities, new_communities) | |
221 | + end | |
222 | + | |
223 | + def institution_info_button | |
224 | + { | |
225 | + :title => _('Institution Info'), | |
226 | + :icon => 'edit-profile-group control-panel-instituton-link', | |
227 | + :url => { | |
228 | + :controller => 'software_communities_plugin_myprofile', | |
229 | + :action => 'edit_institution' | |
230 | + } | |
231 | + } | |
232 | + end | |
233 | + | |
234 | + def manage_user_institutions(user, old_communities, new_communities) | |
235 | + leave_communities = (old_communities - new_communities) | |
236 | + enter_communities = (new_communities - old_communities) | |
237 | + | |
238 | + leave_communities.each do |community| | |
239 | + community.remove_member(user.person) | |
240 | + user.institutions.delete(community.institution) | |
241 | + end | |
242 | + | |
243 | + enter_communities.each do |community| | |
244 | + community.add_member(user.person) | |
245 | + user.institutions << community.institution | |
246 | + end | |
247 | + end | |
248 | + | |
249 | + def profile_tabs_institution | |
250 | + { :title => _('Institution'), | |
251 | + :id => 'intitution-fields', | |
252 | + :content => Proc::new do render :partial => 'profile/institution_tab' end, | |
253 | + :start => true | |
254 | + } | |
255 | + end | |
256 | + | |
257 | + def update_user_institutions(user) | |
258 | + context.params[:user][:institution_ids].each do |institution_id| | |
259 | + institution = Institution.find institution_id | |
260 | + user.institutions << institution | |
261 | + | |
262 | + if institution.community.admins.blank? | |
263 | + institution.community.add_admin(user.person) | |
264 | + end | |
265 | + end | |
266 | + user.save unless user.institution_ids.empty? | |
267 | + end | |
125 | 268 | end | ... | ... |
... | ... | @@ -0,0 +1,13 @@ |
1 | +class GovernmentalPower < ActiveRecord::Base | |
2 | + attr_accessible :name | |
3 | + | |
4 | + validates :name, :presence=>true, :uniqueness=>true | |
5 | + has_many :institutions | |
6 | + | |
7 | + def public_institutions | |
8 | + Institution.where( | |
9 | + :type=>"PublicInstitution", | |
10 | + :governmental_power_id=>self.id | |
11 | + ) | |
12 | + end | |
13 | +end | ... | ... |
... | ... | @@ -0,0 +1,122 @@ |
1 | +class Institution < ActiveRecord::Base | |
2 | + | |
3 | + SEARCH_FILTERS = { | |
4 | + :order => %w[], | |
5 | + :display => %w[compact] | |
6 | + } | |
7 | + | |
8 | + def self.default_search_display | |
9 | + 'compact' | |
10 | + end | |
11 | + | |
12 | + belongs_to :governmental_power | |
13 | + belongs_to :governmental_sphere | |
14 | + belongs_to :juridical_nature | |
15 | + | |
16 | + has_and_belongs_to_many :users | |
17 | + | |
18 | + attr_accessible :name, :acronym, :unit_code, :parent_code, :unit_type, | |
19 | + :sub_juridical_nature, :normalization_level, | |
20 | + :version, :cnpj, :type, :governmental_power, | |
21 | + :governmental_sphere, :sisp, :juridical_nature, | |
22 | + :corporate_name | |
23 | + | |
24 | + validates :name, :presence=>true, :uniqueness=>true | |
25 | + | |
26 | + validates :corporate_name, :presence => true | |
27 | + | |
28 | + before_save :verify_institution_type | |
29 | + | |
30 | + belongs_to :community | |
31 | + | |
32 | + scope :search_institution, lambda{ |value| | |
33 | + where("name ilike ? OR acronym ilike ?", "%#{value}%", "%#{value}%" ) | |
34 | + } | |
35 | + | |
36 | + validate :validate_country, :validate_state, :validate_city, | |
37 | + :verify_institution_type, :validate_cnpj, :validate_format_cnpj | |
38 | + | |
39 | + | |
40 | + protected | |
41 | + | |
42 | + def verify_institution_type | |
43 | + valid_institutions_type = ["PublicInstitution", "PrivateInstitution"] | |
44 | + | |
45 | + unless valid_institutions_type.include? self.type | |
46 | + self.errors.add( | |
47 | + :type, | |
48 | + _("invalid, only public and private institutions are allowed.") | |
49 | + ) | |
50 | + | |
51 | + return false | |
52 | + end | |
53 | + return true | |
54 | + end | |
55 | + | |
56 | + def validate_country | |
57 | + if(self.community.blank? || | |
58 | + self.community.country.blank? && | |
59 | + self.errors[:country].blank?) | |
60 | + | |
61 | + self.errors.add(:country, _("can't be blank")) | |
62 | + return false | |
63 | + end | |
64 | + return true | |
65 | + end | |
66 | + | |
67 | + def validate_state | |
68 | + if(self.community.blank? || | |
69 | + self.errors[:state].blank? && | |
70 | + self.community.state.blank?) | |
71 | + | |
72 | + if self.community.country == "BR" | |
73 | + self.errors.add(:state, _("can't be blank")) | |
74 | + return false | |
75 | + else | |
76 | + return true | |
77 | + end | |
78 | + end | |
79 | + return true | |
80 | + end | |
81 | + | |
82 | + def validate_city | |
83 | + if(self.community.blank? || | |
84 | + self.errors[:city].blank? && | |
85 | + self.community.city.blank?) | |
86 | + | |
87 | + if self.community.country == "BR" | |
88 | + self.errors.add(:city, _("can't be blank")) | |
89 | + return false | |
90 | + else | |
91 | + return true | |
92 | + end | |
93 | + end | |
94 | + return true | |
95 | + end | |
96 | + | |
97 | + def validate_format_cnpj | |
98 | + return true if !self.community.blank? && self.community.country != "BR" | |
99 | + | |
100 | + format = /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/ | |
101 | + | |
102 | + if !self.cnpj.blank? && format.match(self.cnpj) | |
103 | + return true | |
104 | + else | |
105 | + self.errors.add(:cnpj, _("invalid format")) | |
106 | + return false | |
107 | + end | |
108 | + end | |
109 | + | |
110 | + def validate_cnpj | |
111 | + if !self.community.blank? && self.community.country == "BR" | |
112 | + if self.errors[:cnpj].blank? && self.cnpj.blank? | |
113 | + self.errors.add(:cnpj, _("can't be blank")) | |
114 | + return false | |
115 | + else | |
116 | + return true | |
117 | + end | |
118 | + else | |
119 | + return true | |
120 | + end | |
121 | + end | |
122 | +end | ... | ... |
... | ... | @@ -0,0 +1,71 @@ |
1 | +class InstitutionsBlock < CommunitiesBlock | |
2 | + | |
3 | + def self.description | |
4 | + _('Institutions') | |
5 | + end | |
6 | + | |
7 | + def profile_count | |
8 | + profile_list.count | |
9 | + end | |
10 | + | |
11 | + def default_title | |
12 | + n_('{#} institution', '{#} institutions', profile_count) | |
13 | + end | |
14 | + | |
15 | + def help | |
16 | + _('This block displays the institutions in which the user is a member.') | |
17 | + end | |
18 | + | |
19 | + def footer | |
20 | + owner = self.owner | |
21 | + case owner | |
22 | + when Profile | |
23 | + lambda do |context| | |
24 | + link_to s_('institutions|View all'), :profile => owner.identifier, | |
25 | + :controller => 'profile', :action => 'communities', | |
26 | + :type => 'Institution' | |
27 | + end | |
28 | + when Environment | |
29 | + lambda do |context| | |
30 | + link_to s_('institutions|View all'), :controller => 'search', | |
31 | + :action => 'communities', :type => 'Institution' | |
32 | + end | |
33 | + else | |
34 | + '' | |
35 | + end | |
36 | + end | |
37 | + | |
38 | + def profile_list | |
39 | + result = get_visible_profiles | |
40 | + | |
41 | + result = result.select { |p| p.class == Community && p.institution? } | |
42 | + | |
43 | + result.slice(0..get_limit-1) | |
44 | + end | |
45 | + | |
46 | + def profiles | |
47 | + owner.communities | |
48 | + end | |
49 | + | |
50 | + private | |
51 | + | |
52 | + def get_visible_profiles | |
53 | + include_list = [:image,:domains,:preferred_domain,:environment] | |
54 | + visible_profiles = profiles.visible.includes(include_list) | |
55 | + | |
56 | + if !prioritize_profiles_with_image | |
57 | + visible_profiles.all(:limit => get_limit, | |
58 | + :order => 'profiles.updated_at DESC' | |
59 | + ).sort_by{ rand } | |
60 | + elsif profiles.visible.with_image.count >= get_limit | |
61 | + visible_profiles.with_image.all(:limit => get_limit * 5, | |
62 | + :order => 'profiles.updated_at DESC' | |
63 | + ).sort_by{ rand } | |
64 | + else | |
65 | + visible_profiles.with_image.sort_by{ rand } + | |
66 | + visible_profiles.without_image.all(:limit => get_limit * 5, | |
67 | + :order => 'profiles.updated_at DESC' | |
68 | + ).sort_by{ rand } | |
69 | + end | |
70 | + end | |
71 | +end | ... | ... |
... | ... | @@ -0,0 +1,15 @@ |
1 | +class JuridicalNature < ActiveRecord::Base | |
2 | + attr_accessible :name | |
3 | + | |
4 | + has_many :institutions | |
5 | + | |
6 | + validates_presence_of :name | |
7 | + validates_uniqueness_of :name | |
8 | + | |
9 | + def public_institutions | |
10 | + Institution.where( | |
11 | + :type=>"PublicInstitution", | |
12 | + :juridical_nature_id=>self.id | |
13 | + ) | |
14 | + end | |
15 | +end | ... | ... |
... | ... | @@ -0,0 +1,15 @@ |
1 | +class PublicInstitution < Institution | |
2 | + validates :governmental_power, :governmental_sphere, :juridical_nature, | |
3 | + :presence=>true | |
4 | + | |
5 | + validates :acronym, :allow_blank => true, :allow_nil => true, | |
6 | + :uniqueness=>true | |
7 | + | |
8 | + validates :cnpj, :uniqueness=>true | |
9 | + | |
10 | + validates_format_of( | |
11 | + :cnpj, | |
12 | + :with => /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/, | |
13 | + :allow_nil => true, :allow_blank => true | |
14 | + ) | |
15 | +end | ... | ... |
... | ... | @@ -0,0 +1,257 @@ |
1 | +require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
2 | +require File.dirname(__FILE__) + '/../helpers/institution_test_helper' | |
3 | +require File.dirname(__FILE__) + '/../../controllers/gov_user_plugin_controller' | |
4 | + | |
5 | +class GovUserPluginController; def rescue_action(e) raise e end; end | |
6 | +class GovUserPluginControllerTest < ActionController::TestCase | |
7 | + | |
8 | + | |
9 | + def setup | |
10 | + @admin = create_user("adminuser").person | |
11 | + @admin.stubs(:has_permission?).returns("true") | |
12 | + @controller.stubs(:current_user).returns(@admin.user) | |
13 | + | |
14 | + @environment = Environment.default | |
15 | + @environment.enabled_plugins = ['SoftwareCommunitiesPlugin'] | |
16 | + @environment.add_admin(@admin) | |
17 | + @environment.save | |
18 | + | |
19 | + @gov_power = GovernmentalPower.create(:name=>"Some Gov Power") | |
20 | + @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
21 | + @juridical_nature = JuridicalNature.create(:name => "Autarquia") | |
22 | + @response = ActionController::TestResponse.new | |
23 | + | |
24 | + @institution_list = [] | |
25 | + @institution_list << InstitutionTestHelper.create_public_institution( | |
26 | + "Ministerio Publico da Uniao", | |
27 | + "MPU", | |
28 | + "BR", | |
29 | + "DF", | |
30 | + "Gama", | |
31 | + @juridical_nature, | |
32 | + @gov_power, | |
33 | + @gov_sphere, | |
34 | + "12.345.678/9012-45" | |
35 | + ) | |
36 | + @institution_list << InstitutionTestHelper.create_public_institution( | |
37 | + "Tribunal Regional da Uniao", | |
38 | + "TRU", | |
39 | + "BR", | |
40 | + "DF", | |
41 | + "Brasilia", | |
42 | + @juridical_nature, | |
43 | + @gov_power, | |
44 | + @gov_sphere, | |
45 | + "12.345.678/9012-90" | |
46 | + ) | |
47 | + end | |
48 | + | |
49 | + should "Search for institution with acronym" do | |
50 | + xhr :get, :get_institutions, :query=>"TRU" | |
51 | + | |
52 | + json_response = ActiveSupport::JSON.decode(@response.body) | |
53 | + | |
54 | + assert_equal "Tribunal Regional da Uniao", json_response[0]["value"] | |
55 | + end | |
56 | + | |
57 | + should "Search for institution with name" do | |
58 | + xhr :get, :get_institutions, :query=>"Minis" | |
59 | + | |
60 | + json_response = ActiveSupport::JSON.decode(@response.body) | |
61 | + | |
62 | + assert_equal "Ministerio Publico da Uniao", json_response[0]["value"] | |
63 | + end | |
64 | + | |
65 | + should "search with name or acronym and return a list with institutions" do | |
66 | + xhr :get, :get_institutions, :query=>"uni" | |
67 | + | |
68 | + json_response = ActiveSupport::JSON.decode(@response.body) | |
69 | + | |
70 | + assert_equal "Ministerio Publico da Uniao", json_response[0]["value"] | |
71 | + assert_equal "Tribunal Regional da Uniao", json_response[1]["value"] | |
72 | + end | |
73 | + | |
74 | + should "method create_institution return the html for modal" do | |
75 | + @controller.stubs(:current_user).returns(@admin.user) | |
76 | + xhr :get, :create_institution | |
77 | + assert_template 'create_institution' | |
78 | + end | |
79 | + | |
80 | + should "create new institution with ajax without acronym" do | |
81 | + @controller.stubs(:verify_recaptcha).returns(true) | |
82 | + | |
83 | + fields = InstitutionTestHelper.generate_form_fields( | |
84 | + "foo bar", | |
85 | + "BR", | |
86 | + "DF", | |
87 | + "Brasilia", | |
88 | + "12.234.567/8900-10", | |
89 | + "PublicInstitution" | |
90 | + ) | |
91 | + fields[:institutions][:governmental_power] = @gov_power.id | |
92 | + fields[:institutions][:governmental_sphere] = @gov_sphere.id | |
93 | + fields[:institutions][:juridical_nature] = @juridical_nature.id | |
94 | + | |
95 | + xhr :get, :new_institution, fields | |
96 | + | |
97 | + json_response = ActiveSupport::JSON.decode(@response.body) | |
98 | + | |
99 | + assert json_response["success"] | |
100 | + end | |
101 | + | |
102 | + should "not create a institution that already exists" do | |
103 | + @controller.stubs(:verify_recaptcha).returns(true) | |
104 | + | |
105 | + fields = InstitutionTestHelper.generate_form_fields( | |
106 | + "Ministerio Publico da Uniao", | |
107 | + "BR", | |
108 | + "DF", | |
109 | + "Brasilia", | |
110 | + "12.234.567/8900-10", | |
111 | + "PublicInstitution" | |
112 | + ) | |
113 | + fields[:institutions][:governmental_power] = @gov_power.id | |
114 | + fields[:institutions][:governmental_sphere] = @gov_sphere.id | |
115 | + fields[:institutions][:juridical_nature] = @juridical_nature.id | |
116 | + | |
117 | + xhr :get, :new_institution, fields | |
118 | + | |
119 | + json_response = ActiveSupport::JSON.decode(@response.body) | |
120 | + | |
121 | + assert !json_response["success"] | |
122 | + end | |
123 | + | |
124 | + should "not create a institution without cnpj" do | |
125 | + @controller.stubs(:verify_recaptcha).returns(true) | |
126 | + | |
127 | + fields = InstitutionTestHelper.generate_form_fields( | |
128 | + "Some Private Institution", | |
129 | + "BR", | |
130 | + "DF", | |
131 | + "Brasilia", | |
132 | + "", | |
133 | + "PrivateInstitution" | |
134 | + ) | |
135 | + fields[:institutions][:acronym] = "SPI" | |
136 | + | |
137 | + xhr :get, :new_institution, fields | |
138 | + | |
139 | + json_response = ActiveSupport::JSON.decode(@response.body) | |
140 | + | |
141 | + assert !json_response["success"] | |
142 | + end | |
143 | + | |
144 | + should "verify if institution name already exists" do | |
145 | + xhr :get, :institution_already_exists, :name=>"Ministerio Publico da Uniao" | |
146 | + assert_equal "true", @response.body | |
147 | + | |
148 | + xhr :get, :institution_already_exists, :name=>"Another name here" | |
149 | + assert_equal "false", @response.body | |
150 | + end | |
151 | + | |
152 | + should "hide registration incomplete message" do | |
153 | + xhr :get, :hide_registration_incomplete_percentage, :hide=>true | |
154 | + assert_equal "true", @response.body | |
155 | + end | |
156 | + | |
157 | + should "not hide registration incomplete message" do | |
158 | + xhr :get, :hide_registration_incomplete_percentage, :hide=>false | |
159 | + assert_equal "false", @response.body | |
160 | + end | |
161 | + | |
162 | + should "Create new institution with method post" do | |
163 | + @controller.stubs(:verify_recaptcha).returns(true) | |
164 | + | |
165 | + fields = InstitutionTestHelper.generate_form_fields( | |
166 | + "Some Private Institution", | |
167 | + "BR", | |
168 | + "DF", | |
169 | + "Brasilia", | |
170 | + "12.345.567/8900-10", | |
171 | + "PrivateInstitution" | |
172 | + ) | |
173 | + fields[:institutions][:acronym] = "SPI" | |
174 | + | |
175 | + post :new_institution, fields | |
176 | + | |
177 | + assert_redirected_to(controller: "admin_panel", action: "index") | |
178 | + end | |
179 | + | |
180 | + should "not create new institution with method post without cnpj" do | |
181 | + @controller.stubs(:verify_recaptcha).returns(true) | |
182 | + | |
183 | + fields = InstitutionTestHelper.generate_form_fields( | |
184 | + "Some Private Institution", | |
185 | + "BR", | |
186 | + "DF", | |
187 | + "Brasilia", | |
188 | + "", | |
189 | + "PrivateInstitution" | |
190 | + ) | |
191 | + fields[:institutions][:acronym] = "SPI" | |
192 | + | |
193 | + post :new_institution, fields | |
194 | + | |
195 | + assert_redirected_to(controller: "software_communities_plugin", action: "create_institution_admin") | |
196 | + end | |
197 | + | |
198 | + should "Create foreign institution without city, state and cnpj by post" do | |
199 | + @controller.stubs(:verify_recaptcha).returns(true) | |
200 | + | |
201 | + fields = InstitutionTestHelper.generate_form_fields( | |
202 | + "Foreign institution", | |
203 | + "AZ", | |
204 | + "", | |
205 | + "", | |
206 | + "", | |
207 | + "PrivateInstitution" | |
208 | + ) | |
209 | + fields[:institutions][:acronym] = "FI" | |
210 | + | |
211 | + post :new_institution, fields | |
212 | + | |
213 | + assert_redirected_to(controller: "admin_panel", action: "index") | |
214 | + end | |
215 | + | |
216 | + should "Create foreign institution without city, state and cnpj by ajax" do | |
217 | + @controller.stubs(:verify_recaptcha).returns(true) | |
218 | + | |
219 | + fields = InstitutionTestHelper.generate_form_fields( | |
220 | + "Foreign institution", | |
221 | + "AZ", | |
222 | + "", | |
223 | + "", | |
224 | + "", | |
225 | + "PrivateInstitution" | |
226 | + ) | |
227 | + fields[:institutions][:acronym] = "FI" | |
228 | + | |
229 | + xhr :post, :new_institution, fields | |
230 | + | |
231 | + json_response = ActiveSupport::JSON.decode(@response.body) | |
232 | + assert json_response["success"] | |
233 | + end | |
234 | + | |
235 | + should "add environment admins to institution when created via admin panel" do | |
236 | + @controller.stubs(:verify_recaptcha).returns(true) | |
237 | + admin2 = create_user("another_admin").person | |
238 | + admin2.stubs(:has_permission?).returns("true") | |
239 | + @environment.add_admin(admin2) | |
240 | + @environment.save | |
241 | + | |
242 | + fields = InstitutionTestHelper.generate_form_fields( | |
243 | + "Private Institution", | |
244 | + "BR", | |
245 | + "DF", | |
246 | + "Brasilia", | |
247 | + "12.323.557/8900-10", | |
248 | + "PrivateInstitution" | |
249 | + ) | |
250 | + fields[:institutions][:acronym] = "PI" | |
251 | + fields[:edit_institution_page] = false | |
252 | + post :new_institution, fields | |
253 | + | |
254 | + assert(Institution.last.community.admins.include?(admin2) ) | |
255 | + end | |
256 | + | |
257 | +end | ... | ... |
... | ... | @@ -0,0 +1,105 @@ |
1 | +require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
2 | +require File.dirname(__FILE__) + '/../helpers/institution_test_helper' | |
3 | +require( | |
4 | +File.dirname(__FILE__) + | |
5 | +'/../../controllers/gov_user_plugin_myprofile_controller' | |
6 | +) | |
7 | + | |
8 | +class GovUserPluginMyprofileController; def rescue_action(e) raise e end; | |
9 | +end | |
10 | + | |
11 | +class GovUserPluginMyprofileControllerTest < ActionController::TestCase | |
12 | + def setup | |
13 | + @controller = GovUserPluginMyprofileController.new | |
14 | + @request = ActionController::TestRequest.new | |
15 | + @response = ActionController::TestResponse.new | |
16 | + @person = create_user('person').person | |
17 | + @offer = create_user('Angela Silva') | |
18 | + @offer_1 = create_user('Ana de Souza') | |
19 | + @offer_2 = create_user('Angelo Roberto') | |
20 | + | |
21 | + login_as(@person.user_login) | |
22 | + @environment = Environment.default | |
23 | + @environment.enable_plugin('GovUserPlugin') | |
24 | + @environment.save! | |
25 | + end | |
26 | + should "user edit its community institution" do | |
27 | + govPower = GovernmentalPower.create(:name=>"Some Gov Power") | |
28 | + govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
29 | + juridical_nature = JuridicalNature.create(:name => "Autarquia") | |
30 | + | |
31 | + institution = InstitutionTestHelper.create_public_institution( | |
32 | + "Ministerio Publico da Uniao", | |
33 | + "MPU", | |
34 | + "BR", | |
35 | + "DF", | |
36 | + "Gama", | |
37 | + juridical_nature, | |
38 | + govPower, | |
39 | + govSphere, | |
40 | + "12.345.678/9012-45" | |
41 | + ) | |
42 | + | |
43 | + identifier = institution.community.identifier | |
44 | + | |
45 | + fields = InstitutionTestHelper.generate_form_fields( | |
46 | + "institution new name", | |
47 | + "BR", | |
48 | + "DF", | |
49 | + "Gama", | |
50 | + "12.345.678/9012-45", | |
51 | + "PrivateInstitution" | |
52 | + ) | |
53 | + | |
54 | + post( | |
55 | + :edit_institution, | |
56 | + :profile=>institution.community.identifier, | |
57 | + :community=>fields[:community], | |
58 | + :institutions=>fields[:institutions] | |
59 | + ) | |
60 | + | |
61 | + institution = Community[identifier].institution | |
62 | + assert_not_equal "Ministerio Publico da Uniao", institution.community.name | |
63 | + end | |
64 | + | |
65 | + should "not user edit its community institution with wrong values" do | |
66 | + govPower = GovernmentalPower.create(:name=>"Some Gov Power") | |
67 | + govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
68 | + juridical_nature = JuridicalNature.create(:name => "Autarquia") | |
69 | + | |
70 | + institution = InstitutionTestHelper.create_public_institution( | |
71 | + "Ministerio Publico da Uniao", | |
72 | + "MPU", | |
73 | + "BR", | |
74 | + "DF", | |
75 | + "Gama", | |
76 | + juridical_nature, | |
77 | + govPower, | |
78 | + govSphere, | |
79 | + "12.345.678/9012-45" | |
80 | + ) | |
81 | + | |
82 | + identifier = institution.community.identifier | |
83 | + | |
84 | + fields = InstitutionTestHelper.generate_form_fields( | |
85 | + "", | |
86 | + "BR", | |
87 | + "DF", | |
88 | + "Gama", | |
89 | + "6465465465", | |
90 | + "PrivateInstitution" | |
91 | + ) | |
92 | + | |
93 | + post( | |
94 | + :edit_institution, | |
95 | + :profile=>institution.community.identifier, | |
96 | + :community=>fields[:community], | |
97 | + :institutions=>fields[:institutions] | |
98 | + ) | |
99 | + | |
100 | + institution = Community[identifier].institution | |
101 | + assert_equal "Ministerio Publico da Uniao", institution.community.name | |
102 | + assert_equal "12.345.678/9012-45", institution.cnpj | |
103 | + end | |
104 | + | |
105 | +end | ... | ... |
... | ... | @@ -0,0 +1,112 @@ |
1 | +require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
2 | +require File.dirname(__FILE__) + '/../helpers/institution_test_helper' | |
3 | +require( | |
4 | +File.dirname(__FILE__) + | |
5 | +'/../../../../app/controllers/my_profile/profile_editor_controller' | |
6 | +) | |
7 | + | |
8 | +class ProfileEditorController; def rescue_action(e) raise e end; end | |
9 | + | |
10 | +class ProfileEditorControllerTest < ActionController::TestCase | |
11 | + | |
12 | + def setup | |
13 | + @controller = ProfileEditorController.new | |
14 | + @request = ActionController::TestRequest.new | |
15 | + @response = ActionController::TestResponse.new | |
16 | + @profile = create_user('default_user').person | |
17 | + | |
18 | + Environment.default.affiliate( | |
19 | + @profile, | |
20 | + [Environment::Roles.admin(Environment.default.id)] + | |
21 | + Profile::Roles.all_roles(Environment.default.id) | |
22 | + ) | |
23 | + | |
24 | + @environment = Environment.default | |
25 | + @environment.enabled_plugins = ['GovUserPlugin'] | |
26 | + admin = create_user("adminuser").person | |
27 | + admin.stubs(:has_permission?).returns("true") | |
28 | + login_as('adminuser') | |
29 | + @environment.add_admin(admin) | |
30 | + @environment.save | |
31 | + | |
32 | + @govPower = GovernmentalPower.create(:name=>"Some Gov Power") | |
33 | + @govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
34 | + @juridical_nature = JuridicalNature.create(:name => "Autarquia") | |
35 | + | |
36 | + @institution_list = [] | |
37 | + @institution_list << InstitutionTestHelper.create_public_institution( | |
38 | + "Ministerio Publico da Uniao", | |
39 | + "MPU", | |
40 | + "BR", | |
41 | + "DF", | |
42 | + "Gama", | |
43 | + @juridical_nature, | |
44 | + @govPower, | |
45 | + @govSphere, | |
46 | + "12.345.678/9012-45" | |
47 | + ) | |
48 | + | |
49 | + @institution_list << InstitutionTestHelper.create_public_institution( | |
50 | + "Tribunal Regional da Uniao", | |
51 | + "TRU", | |
52 | + "BR", | |
53 | + "DF", | |
54 | + "Brasilia", | |
55 | + @juridical_nature, | |
56 | + @govPower, | |
57 | + @govSphere, | |
58 | + "12.345.678/9012-90" | |
59 | + ) | |
60 | + end | |
61 | + | |
62 | + should "add new institution for user into edit profile" do | |
63 | + user = create_basic_user | |
64 | + | |
65 | + params_user = Hash.new | |
66 | + params_user[:institution_ids] = [] | |
67 | + | |
68 | + @institution_list.each do |institution| | |
69 | + params_user[:institution_ids] << institution.id | |
70 | + end | |
71 | + | |
72 | + post :edit, :profile => User.last.person.identifier, :user => params_user | |
73 | + | |
74 | + assert_equal @institution_list.count, User.last.institutions.count | |
75 | + end | |
76 | + | |
77 | + should "remove institutions for user into edit profile" do | |
78 | + user = create_basic_user | |
79 | + | |
80 | + @institution_list.each do |institution| | |
81 | + user.institutions << institution | |
82 | + end | |
83 | + user.save! | |
84 | + | |
85 | + params_user = Hash.new | |
86 | + params_user[:institution_ids] = [] | |
87 | + | |
88 | + assert_equal @institution_list.count, User.last.institutions.count | |
89 | + | |
90 | + post :edit, :profile => User.last.person.identifier, :user => params_user | |
91 | + | |
92 | + assert_equal 0, User.last.institutions.count | |
93 | + end | |
94 | + | |
95 | + protected | |
96 | + | |
97 | + def create_basic_user | |
98 | + user = fast_create(User) | |
99 | + user.person = fast_create(Person) | |
100 | + user.person.user = user | |
101 | + user.save! | |
102 | + user.person.save! | |
103 | + user | |
104 | + end | |
105 | + | |
106 | + def create_community name | |
107 | + community = fast_create(Community) | |
108 | + community.name = name | |
109 | + community.save | |
110 | + community | |
111 | + end | |
112 | +end | ... | ... |
... | ... | @@ -0,0 +1,60 @@ |
1 | +require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
2 | +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' | |
3 | +require( | |
4 | +File.dirname(__FILE__) + | |
5 | +'/../../../../app/controllers/public/search_controller' | |
6 | +) | |
7 | + | |
8 | +class SearchController; def rescue_action(e) raise e end; end | |
9 | + | |
10 | +class SearchControllerTest < ActionController::TestCase | |
11 | + include PluginTestHelper | |
12 | + | |
13 | + def setup | |
14 | + @environment = Environment.default | |
15 | + @environment.enabled_plugins = ['SoftwareCommunitiesPlugin'] | |
16 | + @environment.save | |
17 | + | |
18 | + @controller = SearchController.new | |
19 | + @request = ActionController::TestRequest.new | |
20 | + @request.stubs(:ssl?).returns(:false) | |
21 | + @response = ActionController::TestResponse.new | |
22 | + end | |
23 | + | |
24 | + should "communities searches don't have institution" do | |
25 | + community = create_community("New Community") | |
26 | + institution = create_private_institution( | |
27 | + "New Private Institution", | |
28 | + "NPI" , | |
29 | + "Brazil", | |
30 | + "DF", | |
31 | + "Gama", | |
32 | + "66.544.314/0001-63" | |
33 | + ) | |
34 | + | |
35 | + get :communities, :query => "New" | |
36 | + | |
37 | + assert_includes assigns(:searches)[:communities][:results], community | |
38 | + assert_not_includes assigns(:searches)[:communities][:results], institution | |
39 | + end | |
40 | + | |
41 | + should "institutions_search don't have community" do | |
42 | + community = create_community("New Community") | |
43 | + institution = create_private_institution( | |
44 | + "New Private Institution", | |
45 | + "NPI" , | |
46 | + "Brazil", | |
47 | + "DF", | |
48 | + "Gama", | |
49 | + "66.544.314/0001-63" | |
50 | + ) | |
51 | + | |
52 | + get :institutions, :query => "New" | |
53 | + | |
54 | + assert_includes( | |
55 | + assigns(:searches)[:institutions][:results], | |
56 | + institution.community | |
57 | + ) | |
58 | + assert_not_includes assigns(:searches)[:institutions][:results], community | |
59 | + end | |
60 | +end | ... | ... |
... | ... | @@ -0,0 +1,59 @@ |
1 | +module InstitutionTestHelper | |
2 | + | |
3 | + def self.generate_form_fields name, country, state, city, cnpj, type | |
4 | + fields = { | |
5 | + :community => { | |
6 | + :name => name, | |
7 | + :country => country, | |
8 | + :state => state, | |
9 | + :city => city | |
10 | + }, | |
11 | + :institutions => { | |
12 | + :cnpj=> cnpj, | |
13 | + :type => type, | |
14 | + :acronym => "", | |
15 | + :governmental_power => "", | |
16 | + :governmental_sphere => "", | |
17 | + :juridical_nature => "", | |
18 | + :corporate_name => "coporate default" | |
19 | + } | |
20 | + } | |
21 | + fields | |
22 | + end | |
23 | + | |
24 | + def self.create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s, cnpj | |
25 | + institution = PublicInstitution.new | |
26 | + institution.community = institution_community(name, country, state, city) | |
27 | + institution.name = name | |
28 | + institution.juridical_nature = juridical_nature | |
29 | + institution.acronym = acronym | |
30 | + institution.governmental_power = gov_p | |
31 | + institution.governmental_sphere = gov_s | |
32 | + institution.cnpj = cnpj | |
33 | + institution.corporate_name = "corporate default" | |
34 | + institution.save | |
35 | + institution | |
36 | + end | |
37 | + | |
38 | + def self.create_private_institution name, acronym, country, state, city, cnpj | |
39 | + institution = PrivateInstitution.new | |
40 | + institution.community = institution_community(name, country, state, city) | |
41 | + institution.name = name | |
42 | + institution.acronym = acronym | |
43 | + institution.cnpj = cnpj | |
44 | + institution.corporate_name = "corporate default" | |
45 | + institution.save | |
46 | + | |
47 | + institution | |
48 | + end | |
49 | + | |
50 | + def self.institution_community name, country, state, city | |
51 | + institution_community = Community::new | |
52 | + institution_community.name = name | |
53 | + institution_community.country = country | |
54 | + institution_community.state = state | |
55 | + institution_community.city = city | |
56 | + institution_community.save | |
57 | + institution_community | |
58 | + end | |
59 | +end | |
0 | 60 | \ No newline at end of file | ... | ... |
test/helpers/plugin_test_helper.rb
1 | +require File.dirname(__FILE__) + '/../helpers/institution_test_helper' | |
2 | + | |
1 | 3 | module PluginTestHelper |
4 | + | |
2 | 5 | def create_person name, email, password, password_confirmation, secondary_email, state, city |
3 | 6 | user = create_user( |
4 | 7 | name.to_slug, |
... | ... | @@ -34,4 +37,41 @@ module PluginTestHelper |
34 | 37 | |
35 | 38 | user |
36 | 39 | end |
40 | + | |
41 | + def create_public_institution *params | |
42 | + InstitutionTestHelper.create_public_institution *params | |
43 | + end | |
44 | + | |
45 | + def create_community name | |
46 | + community = fast_create(Community) | |
47 | + community.name = name | |
48 | + community.save | |
49 | + community | |
50 | + end | |
51 | + | |
52 | + | |
53 | + def create_private_institution name, acronym, country, state, city, cnpj | |
54 | + InstitutionTestHelper.create_private_institution( | |
55 | + name, | |
56 | + acronym, | |
57 | + country, | |
58 | + state, | |
59 | + city, | |
60 | + cnpj | |
61 | + ) | |
62 | + end | |
63 | + | |
64 | + def create_public_institution *params | |
65 | + InstitutionTestHelper.create_public_institution *params | |
66 | + end | |
67 | + | |
68 | + def create_community_institution name, country, state, city | |
69 | + community = fast_create(Community) | |
70 | + community.name = name | |
71 | + community.country = country | |
72 | + community.state = state | |
73 | + community.city = city | |
74 | + community.save | |
75 | + community | |
76 | + end | |
37 | 77 | end | ... | ... |
... | ... | @@ -0,0 +1,129 @@ |
1 | +<h1><%= _('New Institution') %></h1> | |
2 | + | |
3 | +<% if environment.enabled?('admin_must_approve_new_communities') %> | |
4 | + <div class='explanation'> | |
5 | + <%= _("Note that the creation of communities in this environment is restricted. Your request to create this new community will be sent to %{environment} administrators and will be approved or rejected according to their methods and criteria.") % { :environment => environment.name }%> | |
6 | + </div> | |
7 | +<%end %> | |
8 | + | |
9 | +<% unless flash[:errors].nil? %> | |
10 | +<div class="errorExplanation" id="errorExplanation"> | |
11 | + <h2> <%= _("Can`t create new Institution: #{flash[:errors].length} errors") %> </h2> | |
12 | + <ul> | |
13 | + <% flash[:errors].each do |error| %> | |
14 | + <li> <%= error %> </li> | |
15 | + <% end %> | |
16 | + </ul> | |
17 | +</div> | |
18 | +<% end %> | |
19 | + | |
20 | +<div id = 'create_institution_errors' class='errorExplanation hide-field'></div> | |
21 | + | |
22 | +<div> | |
23 | + <div class="fields-required"> | |
24 | + <span class="errorExplanation"><%= _("All fields with (*) are mandatory") %></span> | |
25 | + </div> | |
26 | + <br/> | |
27 | + <%= labelled_form_for :community, :url => {:action=>"new_institution"}, :html => { :multipart => true, :id=>"institution_form" } do |f| %> | |
28 | + <%= hidden_field_tag "edit_institution_page", false %> | |
29 | + <%= fields_for :institutions do |inst| %> | |
30 | + <span class=''> | |
31 | + <div class='formfield type-radio'> | |
32 | + <label> <%= _("Public Institution") %> | |
33 | + <%= radio_button_tag("institutions[type]", "PublicInstitution") %> | |
34 | + </label> | |
35 | + | |
36 | + <label> | |
37 | + <%= _("Private Institution") %> | |
38 | + <%= radio_button_tag("institutions[type]" ,"PrivateInstitution", true)%> | |
39 | + </label> | |
40 | + </div> | |
41 | + </span> | |
42 | + | |
43 | + <%= required f.text_field(:name) %> | |
44 | + <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %> | |
45 | + | |
46 | + <span class='required-field'> | |
47 | + <div class="formfield type-text"> | |
48 | + <%= inst.label "corporate_name", _("Corporate Name"), :class=>"formlabel" %> | |
49 | + <%= required inst.text_field(:corporate_name) %> | |
50 | + </div> | |
51 | + </span> | |
52 | + | |
53 | + <%= required select_country(_('Country'), 'community', 'country', {:class => 'type-select', :id => "community_country"}) %> | |
54 | + | |
55 | + <span class='required-field'> | |
56 | + <div class="formfield"> | |
57 | + <label for="community_state" class="formlabel"><%= _("State") %></label> | |
58 | + <%= f.select(:state, @state_list.collect {|state| [state.name, state.name]}) %> | |
59 | + </div> | |
60 | + </span> | |
61 | + | |
62 | + <%= required f.text_field(:city) %> | |
63 | + | |
64 | + | |
65 | + <span class='required-field'> | |
66 | + <div class="formfield type-text"> | |
67 | + <%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %> | |
68 | + <%= required inst.text_field(:cnpj, :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field") %> | |
69 | + </div> | |
70 | + </span> | |
71 | + | |
72 | + <span class='optional-field'> | |
73 | + <div class="formfield type-text"> | |
74 | + <%= hidden_field_tag "acronym_translate", _("Acronym") %> | |
75 | + <%= hidden_field_tag "fantasy_name_translate", _("Fantasy name") %> | |
76 | + <%= inst.label("acronym" ,_("Acronym"), :class=>"formlabel") %> | |
77 | + <%= inst.text_field(:acronym) %> | |
78 | + </div> | |
79 | + </span> | |
80 | + | |
81 | + <span class='required-field public-institutions-fields'> | |
82 | + <div class="formfield type-text"> | |
83 | + <%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %> | |
84 | + <%= inst.select(:governmental_sphere, [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}, {:selected=>0})%> | |
85 | + </div> | |
86 | + </span> | |
87 | + | |
88 | + <span class='required-field public-institutions-fields'> | |
89 | + <div class="formfield type-text"> | |
90 | + <%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %> | |
91 | + <%= inst.select(:governmental_power, [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}, {:selected=>0})%> | |
92 | + </div> | |
93 | + </span> | |
94 | + <span class='required-field public-institutions-fields'> | |
95 | + <div class="formfield type-text"> | |
96 | + <%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %> | |
97 | + <%= inst.select(:juridical_nature, [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}, {:selected=>0})%> | |
98 | + </div> | |
99 | + </span> | |
100 | + | |
101 | + <span class='required-field public-institutions-fields'> | |
102 | + <div class="formfield type-text"> | |
103 | + <%= _("SISP?") %> | |
104 | + <% if @show_sisp_field %> | |
105 | + <%= inst.label("sisp" ,_("Yes")) %> | |
106 | + <%= inst.radio_button(:sisp, true) %> | |
107 | + <%= inst.label("sisp" ,_("No")) %> | |
108 | + <%= inst.radio_button(:sisp, false, :checked=>"checked") %> | |
109 | + <% else %> | |
110 | + <%= inst.label("sisp", _("No")) %> | |
111 | + <% end %> | |
112 | + </div> | |
113 | + </span> | |
114 | + <br /> | |
115 | + | |
116 | + <% if @url_token == "create_institution_admin" %> | |
117 | + <%= submit_button :save, _('Save') %> | |
118 | + <%else%> | |
119 | + <div> | |
120 | + <%= link_to(_('Save'), '#', :id=>'save_institution_button', :class=>'button with-text icon-add') %> | |
121 | + </div> | |
122 | + <%= hidden_field_tag :institution_error_message, _("Could not send the form data to the server") %> | |
123 | + <%end%> | |
124 | + | |
125 | + <% end %> | |
126 | + | |
127 | + <% end %> | |
128 | +</div> | |
129 | +<%= hidden_field_tag :loading_message, _("Creating institution") %> | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +<%= render :partial => "institution" %> | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +<%= render :partial => "institution" %> | ... | ... |
views/gov_user_plugin_myprofile/_public_software_info.html.erb
0 → 100644
... | ... | @@ -0,0 +1,102 @@ |
1 | +<div id = "public_software"> | |
2 | + <% if @disabled_public_software_field == true %> | |
3 | + <%= check_box_tag("software[public_software]", "true", @software_info.public_software?, :disabled => "disabled") %> | |
4 | + <%= label_tag _("Public Software"), _("Public software"), :class => "public_software_disabled" %> | |
5 | + <% else %> | |
6 | + <%= check_box_tag("software[public_software]", "true", @software_info.public_software?) %> | |
7 | + <%= label_tag _("Public Software"), _("Public software"), :class => "public_software_enabled" %> | |
8 | + <% end %> | |
9 | + <div class="public-software-fields"> | |
10 | + <h4> <%= _("Public Software") %> </h4> | |
11 | + <div class="formfieldline"> | |
12 | + <%= label_tag _("Adherent to e-PING ?") %> | |
13 | + | |
14 | + <%= label_tag "e_ping_true", "Yes" %> | |
15 | + <%= radio_button_tag("software[e_ping]", true, @software_info.e_ping)%> | |
16 | + <%= label_tag "e_ping_false", "No"%> | |
17 | + <%= radio_button_tag("software[e_ping]", false, !@software_info.e_ping)%> | |
18 | + </div> | |
19 | + | |
20 | + <div class="formfieldline"> | |
21 | + <%= label_tag _("Adherent to e-MAG ?") %> | |
22 | + | |
23 | + <%= label_tag "e_mag_true", "Yes"%> | |
24 | + <%= radio_button_tag("software[e_mag]", true, @software_info.e_mag)%> | |
25 | + <%= label_tag "e_mag_false", "No"%> | |
26 | + <%= radio_button_tag("software[e_mag]", false, !@software_info.e_mag)%> | |
27 | + </div> | |
28 | + | |
29 | + <div class="formfieldline"> | |
30 | + <%= label_tag _("Adherent to ICP-Brasil ?") %> | |
31 | + | |
32 | + <%= label_tag "icp_brasil_true", "Yes"%> | |
33 | + <%= radio_button_tag("software[icp_brasil]", true, @software_info.icp_brasil)%> | |
34 | + <%= label_tag "icp_brasil_false", "No"%> | |
35 | + <%= radio_button_tag("software[icp_brasil]", false, !@software_info.icp_brasil)%> | |
36 | + </div> | |
37 | + | |
38 | + <div class="formfieldline"> | |
39 | + <%= label_tag _("Adherent to e-ARQ ?") %> | |
40 | + | |
41 | + <%= label_tag "e_arq_true", "Yes"%> | |
42 | + <%= radio_button_tag("software[e_arq]", true, @software_info.e_arq)%> | |
43 | + <%= label_tag "e_arq_false", "No"%> | |
44 | + <%= radio_button_tag("software[e_arq]", false, !@software_info.e_arq)%> | |
45 | + </div> | |
46 | + | |
47 | + <div class="formfieldline"> | |
48 | + <%= label_tag _("Internacionalizable ?") %> | |
49 | + | |
50 | + <%= label_tag "intern_true", "Yes" %> | |
51 | + <%= radio_button_tag("software[intern]", true, @software_info.intern)%> | |
52 | + <%= label_tag "intern_false", "No"%> | |
53 | + <%= radio_button_tag("software[intern]", false, !@software_info.intern)%> | |
54 | + </div> | |
55 | + </div> | |
56 | +</div> | |
57 | + | |
58 | +<div class="formfieldline"> | |
59 | + <h4> <%= _("Operating Platform") %> </h4> | |
60 | + <%= text_area_tag "software[operating_platform]", @software_info.operating_platform, :cols => 40, :rows => 5%> | |
61 | +</div> | |
62 | + | |
63 | +<div class="formfieldline"> | |
64 | + <h4> <%= _("Features") %> </h4> | |
65 | + <%= text_area_tag "software[features]", @software_info.features, :maxlength=>"4000", :cols => 40, :rows => 5%> | |
66 | +</div> | |
67 | + | |
68 | +<div id = "demonstration_url"> | |
69 | + <h4> <%= _("Demonstration url") %> </h4> | |
70 | + <%= text_field_tag("software[demonstration_url]", @software_info.demonstration_url) %> | |
71 | +</div> | |
72 | + | |
73 | +<div id='libraries_fields'> | |
74 | + <h4> <%= _("Libraries") %> </h4> | |
75 | + | |
76 | + <%= render :partial => 'library_fields', :locals => {:object_name => 'community', :profile => @community, :libraries => @list_libraries } %> | |
77 | +</div> | |
78 | + | |
79 | +<br /> | |
80 | + | |
81 | +<div id='operating_system_fields'> | |
82 | + <h4> <%= _("Operating Systems") %> </h4> | |
83 | + | |
84 | + <%= render :partial => 'operating_system_fields', :locals => {:object_name => 'community', :profile => @community, :operating_systems_fields => @list_operating_systems} %> | |
85 | +</div> | |
86 | +<br /> | |
87 | + | |
88 | +<br /> | |
89 | +<div id='programming_languages_fields'> | |
90 | + <h4> <%= _("Programming languages") %> </h4> | |
91 | + | |
92 | + <%= render :partial => 'language_fields', :locals => { :object_name => 'community', :profile => @community, :languages => @list_languages } %> | |
93 | +</div> | |
94 | + | |
95 | +<br /> | |
96 | +<div id='database_fields'> | |
97 | + <h4> <%= _("Databases") %> </h4> | |
98 | + | |
99 | + <%= render :partial => 'database_fields', :locals => {:object_name => 'community', :profile => @community, :database => @list_databases } %> | |
100 | +</div> | |
101 | + | |
102 | +<br> | ... | ... |
views/gov_user_plugin_myprofile/edit_institution.html.erb
0 → 100644
... | ... | @@ -0,0 +1,119 @@ |
1 | +<h1><%= _('Edit Institution') %></h1> | |
2 | + | |
3 | +<% if environment.enabled?('admin_must_approve_new_communities') %> | |
4 | + <div class='explanation'> | |
5 | + <%= _("Note that the creation of communities in this environment is restricted. Your request to create this new community will be sent to %{environment} administrators and will be approved or rejected according to their methods and criteria.") % { :environment => environment.name }%> | |
6 | + </div> | |
7 | +<%end %> | |
8 | + | |
9 | +<% unless flash[:errors].nil? %> | |
10 | +<div class="errorExplanation" id="errorExplanation"> | |
11 | + <h2> <%= _("Can`t create new Institution: #{flash[:errors].length} errors") %> </h2> | |
12 | + <ul> | |
13 | + <% flash[:errors].each do |error| %> | |
14 | + <li> <%= error %> </li> | |
15 | + <% end %> | |
16 | + </ul> | |
17 | +</div> | |
18 | +<% end %> | |
19 | + | |
20 | +<div id = 'create_institution_errors' class='errorExplanation hide-field'></div> | |
21 | + | |
22 | +<div> | |
23 | + <div class="fields-required"> | |
24 | + <span class="errorExplanation"><%= _("All fields with (*) are mandatory") %></span> | |
25 | + </div> | |
26 | + <br/> | |
27 | + <%= labelled_form_for :community,:html => { :multipart => true, :id=>"institution_form" } do |f| %> | |
28 | + <%= hidden_field_tag "edit_institution_page", true %> | |
29 | + <%= fields_for :institutions do |inst| %> | |
30 | + <span class=''> | |
31 | + <div class='formfield type-radio'> | |
32 | + <label> <%= _("Public Institution") %> | |
33 | + <%= radio_button_tag("institutions[type]", "PublicInstitution", (@institution.type == "PublicInstitution" ? true : false)) %> | |
34 | + </label> | |
35 | + | |
36 | + <label> | |
37 | + <%= _("Private Institution") %> | |
38 | + <%= radio_button_tag("institutions[type]" ,"PrivateInstitution", (@institution.type == "PrivateInstitution" ? true : false))%> | |
39 | + </label> | |
40 | + </div> | |
41 | + </span> | |
42 | + | |
43 | + <%= required f.text_field(:name, :value => @institution.community.name) %> | |
44 | + <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %> | |
45 | + | |
46 | + <span class='required-field'> | |
47 | + <div class="formfield type-text"> | |
48 | + <%= inst.label "corporate_name", _("Corporate Name"), :class=>"formlabel" %> | |
49 | + <%= required inst.text_field(:corporate_name, :value => @institution.corporate_name) %> | |
50 | + </div> | |
51 | + </span> | |
52 | + | |
53 | + <%= required select_country(_('Country'), 'community', 'country', {:class => 'type-select', :id => "community_country"}, :selected => @institution.community.country) %> | |
54 | + | |
55 | + <span class='required-field'> | |
56 | + <div class="formfield"> | |
57 | + <label for="community_state" class="formlabel"><%= _("State") %></label> | |
58 | + <%= f.select(:state, @state_list.collect {|state| [state.name, state.name]}, :selected => @institution.community.state) %> | |
59 | + </div> | |
60 | + </span> | |
61 | + | |
62 | + <%= required f.text_field(:city, :value => @institution.community.city) %> | |
63 | + | |
64 | + | |
65 | + <span class='required-field'> | |
66 | + <div class="formfield type-text"> | |
67 | + <%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %> | |
68 | + <%= required inst.text_field(:cnpj, :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field", :value => @institution.cnpj) %> | |
69 | + </div> | |
70 | + </span> | |
71 | + | |
72 | + <span class='optional-field'> | |
73 | + <div class="formfield type-text"> | |
74 | + <%= hidden_field_tag "acronym_translate", _("Acronym") %> | |
75 | + <%= hidden_field_tag "fantasy_name_translate", _("Fantasy name") %> | |
76 | + <%= inst.label("acronym" ,_("Acronym"), :class=>"formlabel") %> | |
77 | + <%= inst.text_field(:acronym, :value => @institution.acronym) %> | |
78 | + </div> | |
79 | + </span> | |
80 | + | |
81 | + <span class='required-field public-institutions-fields'> | |
82 | + <div class="formfield type-text"> | |
83 | + <%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %> | |
84 | + <%= inst.select(:governmental_sphere, [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}, {:selected=>@institution.governmental_power_id})%> | |
85 | + </div> | |
86 | + </span> | |
87 | + | |
88 | + <span class='required-field public-institutions-fields'> | |
89 | + <div class="formfield type-text"> | |
90 | + <%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %> | |
91 | + <%= inst.select(:governmental_power, [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}, {:selected=> @institution.governmental_sphere_id})%> | |
92 | + </div> | |
93 | + </span> | |
94 | + <span class='required-field public-institutions-fields'> | |
95 | + <div class="formfield type-text"> | |
96 | + <%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %> | |
97 | + <%= inst.select(:juridical_nature, [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}, {:selected=> @institution.juridical_nature_id})%> | |
98 | + </div> | |
99 | + </span> | |
100 | + | |
101 | + <span class='required-field public-institutions-fields'> | |
102 | + <div class="formfield type-text"> | |
103 | + <%= _("SISP?") %> | |
104 | + <% if @show_sisp_field %> | |
105 | + <%= inst.label("sisp" ,_("Yes")) %> | |
106 | + <%= inst.radio_button(:sisp, true, :checked=>(@institution.sisp ? true : false)) %> | |
107 | + <%= inst.label("sisp" ,_("No")) %> | |
108 | + <%= inst.radio_button(:sisp, false, :checked=>(@institution.sisp ? false : true)) %> | |
109 | + <% else %> | |
110 | + <%= inst.label("sisp", _("No")) %> | |
111 | + <% end %> | |
112 | + </div> | |
113 | + </span> | |
114 | + <br /> | |
115 | + | |
116 | + <%= submit_button :save, _('Save') %> | |
117 | + <% end %> | |
118 | +<% end %> | |
119 | + | ... | ... |
... | ... | @@ -0,0 +1,16 @@ |
1 | +<%= search_page_title( @titles[@asset], @category ) %> | |
2 | + | |
3 | +<%= render :partial => 'search_form', :locals => { :hint => _("Type words about the %s you're looking for") % @asset.to_s.singularize } %> | |
4 | + | |
5 | +<%= display_results(@searches, @asset) %> | |
6 | +<% if params[:display] != 'map' %> | |
7 | + <%= pagination_links @searches[@asset][:results] %> | |
8 | +<% end %> | |
9 | + | |
10 | +<div style="clear: both"></div> | |
11 | + | |
12 | +<% if @asset == :product %> | |
13 | + <%= javascript_tag do %> | |
14 | + jQuery('.search-product-price-details').altBeautify(); | |
15 | + <% end %> | |
16 | +<% end %> | ... | ... |