Commit d75a5073d6c7dba0df58557fb5f8bb002528abfa

Authored by Daniela Feitosa
1 parent 20d88496
Exists in master

move to src/gov_user/

Showing 174 changed files with 4782 additions and 4782 deletions   Show diff stats

Too many changes.

To preserve performance only 100 of 174 files displayed.

.gitignore
... ... @@ -1,2 +0,0 @@
1   -*.swp
2   -
controllers/gov_user_plugin_controller.rb
... ... @@ -1,251 +0,0 @@
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   - @governmental_sphere = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}
19   - @governmental_power = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}
20   - @juridical_nature = [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}
21   - @state_options = [[_('Select a state'), '-1']] | @state_list.collect {|state| [state.name, state.name]}
22   -
23   - params[:community] ||= {}
24   - params[:institutions] ||= {}
25   -
26   - if request.xhr?
27   - render :layout=>false
28   - else
29   - redirect_to "/"
30   - end
31   - end
32   -
33   - def split_http_referer http_referer
34   - split_list = []
35   - split_list = http_referer.split("/")
36   - @url_token = split_list.last
37   - return @url_token
38   - end
39   -
40   - def create_institution_admin
41   - @show_sisp_field = environment.admins.include?(current_user.person)
42   - @state_list = get_state_list()
43   - @governmental_sphere = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}
44   - @governmental_power = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}
45   - @juridical_nature = [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}
46   - @state_options = [[_('Select a state'), '-1']] | @state_list.collect {|state| [state.name, state.name]}
47   -
48   - @url_token = split_http_referer request.original_url()
49   -
50   - params[:community] ||= {}
51   - params[:institutions] ||= {}
52   -
53   - end
54   -
55   - def new_institution
56   - redirect_to "/" if params[:community].blank? || params[:institutions].blank?
57   -
58   - response_message = {}
59   -
60   - institution_template = Community["institution"]
61   - add_template_in_params institution_template
62   -
63   - @institutions = private_create_institution
64   - add_environment_admins_to_institution @institutions
65   -
66   - response_message = save_institution @institutions
67   -
68   - if request.xhr? #User create institution
69   - render :json => response_message.to_json
70   - else #Admin create institution
71   - session[:notice] = response_message[:message] # consume the notice
72   -
73   - redirect_depending_on_institution_creation response_message
74   - end
75   - end
76   -
77   - def institution_already_exists
78   - redirect_to "/" if !request.xhr? || params[:name].blank?
79   -
80   - already_exists = !Community.where(:name=>params[:name]).empty?
81   -
82   - render :json=>already_exists.to_json
83   - end
84   -
85   - def get_institutions
86   - redirect_to "/" if !request.xhr? || params[:query].blank?
87   -
88   - list = Institution.search_institution(params[:query]).map{ |institution|
89   - {:value=>institution.name, :id=>institution.id}
90   - }
91   -
92   - render :json => list.to_json
93   - end
94   -
95   - def get_brazil_states
96   - redirect_to "/" unless request.xhr?
97   -
98   - state_list = get_state_list()
99   - render :json=>state_list.collect {|state| state.name }.to_json
100   - end
101   -
102   - def get_field_data
103   - condition = !request.xhr? || params[:query].nil? || params[:field].nil?
104   - return render :json=>{} if condition
105   -
106   - model = get_model_by_params_field
107   -
108   - data = model.where("name ILIKE ?", "%#{params[:query]}%").select("id, name")
109   - .collect { |db|
110   - {:id=>db.id, :label=>db.name}
111   - }
112   -
113   - other = [model.select("id, name").last].collect { |db|
114   - {:id=>db.id, :label=>db.name}
115   - }
116   -
117   - # Always has other in the list
118   - data |= other
119   -
120   - render :json=> data
121   - end
122   -
123   - protected
124   -
125   - def get_model_by_params_field
126   - case params[:field]
127   - when "software_language"
128   - return ProgrammingLanguage
129   - else
130   - return DatabaseDescription
131   - end
132   - end
133   -
134   - def get_state_list
135   - NationalRegion.find(
136   - :all,
137   - :conditions=>["national_region_type_id = ?", 2],
138   - :order=>"name"
139   - )
140   - end
141   -
142   - def set_institution_type
143   - institution_params = params[:institutions].except(:governmental_power,
144   - :governmental_sphere,
145   - :juridical_nature
146   - )
147   - if params[:institutions][:type] == "PublicInstitution"
148   - PublicInstitution::new institution_params
149   - else
150   - PrivateInstitution::new institution_params
151   - end
152   - end
153   -
154   - def set_public_institution_fields institution
155   - inst_fields = params[:institutions]
156   -
157   - begin
158   - gov_power = GovernmentalPower.find inst_fields[:governmental_power]
159   - gov_sphere = GovernmentalSphere.find inst_fields[:governmental_sphere]
160   - jur_nature = JuridicalNature.find inst_fields[:juridical_nature]
161   -
162   - institution.juridical_nature = jur_nature
163   - institution.governmental_power = gov_power
164   - institution.governmental_sphere = gov_sphere
165   - rescue
166   - institution.errors.add(
167   - :governmental_fields,
168   - _("Could not find Governmental Power or Governmental Sphere")
169   - )
170   - end
171   - end
172   -
173   - def private_create_institution
174   - community = Community.new(params[:community])
175   - community.environment = environment
176   - institution = set_institution_type
177   -
178   - institution.name = community[:name]
179   - institution.community = community
180   -
181   - if institution.type == "PublicInstitution"
182   - set_public_institution_fields institution
183   - end
184   -
185   - institution.date_modification = DateTime.now
186   - institution.save
187   - institution
188   - end
189   -
190   - def add_template_in_params institution_template
191   - com_fields = params[:community]
192   - if !institution_template.blank? && institution_template.is_template
193   - com_fields[:template_id]= institution_template.id unless com_fields.blank?
194   - end
195   - end
196   -
197   - def add_environment_admins_to_institution institution
198   - edit_page = params[:edit_institution_page] == false
199   - if environment.admins.include?(current_user.person) && edit_page
200   - environment.admins.each do |adm|
201   - institution.community.add_admin(adm)
202   - end
203   - end
204   - end
205   -
206   - def save_institution institution
207   - inst_errors = institution.errors.messages
208   - com_errors = institution.community.errors.messages
209   -
210   - set_errors institution
211   -
212   - if inst_errors.empty? && com_errors.empty? && institution.valid? && institution.save
213   - { :success => true,
214   - :message => _("Institution successful created!"),
215   - :institution_data => {:name=>institution.name, :id=>institution.id}
216   - }
217   - else
218   - { :success => false,
219   - :message => _("Institution could not be created!"),
220   - :errors => inst_errors.merge(com_errors)
221   - }
222   - end
223   - end
224   -
225   - def redirect_depending_on_institution_creation response_message
226   - if response_message[:success]
227   - redirect_to :controller => "/admin_panel", :action => "index"
228   - else
229   - flash[:errors] = response_message[:errors]
230   -
231   - redirect_to :controller => "gov_user_plugin", :action => "create_institution_admin", :params => params
232   - end
233   - end
234   -
235   - def set_errors institution
236   - institution.valid? if institution
237   - institution.community.valid? if institution.community
238   -
239   - flash[:error_community_name] = institution.community.errors.include?(:name) ? "highlight-error" : ""
240   - flash[:error_community_country] = institution.errors.include?(:country) ? "highlight-error" : ""
241   - flash[:error_community_state] = institution.errors.include?(:state) ? "highlight-error" : ""
242   - flash[:error_community_city] = institution.errors.include?(:city) ? "highlight-error" : ""
243   - flash[:error_institution_corporate_name] = institution.errors.include?(:corporate_name) ? "highlight-error" : ""
244   - flash[:error_institution_cnpj] = institution.errors.include?(:cnpj) ? "highlight-error" : ""
245   - flash[:error_institution_governmental_sphere] = institution.errors.include?(:governmental_sphere) ? "highlight-error" : ""
246   - flash[:error_institution_governmental_power] = institution.errors.include?(:governmental_power) ? "highlight-error" : ""
247   - flash[:error_institution_juridical_nature] = institution.errors.include?(:juridical_nature) ? "highlight-error" : ""
248   - flash[:error_institution_sisp] = institution.errors.include?(:sisp) ? "highlight-error" : ""
249   - end
250   -
251   -end
controllers/gov_user_plugin_myprofile_controller.rb
... ... @@ -1,50 +0,0 @@
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(
10   - :all,
11   - :conditions => { :national_region_type_id => 2 },
12   - :order => 'name'
13   - )
14   - @institution = @profile.institution
15   - update_institution if request.post?
16   - end
17   -
18   - private
19   -
20   - def update_institution
21   - @institution.community.update_attributes(params[:community])
22   - @institution.update_attributes(params[:institutions].except(:governmental_power, :governmental_sphere, :juridical_nature))
23   - if @institution.type == "PublicInstitution"
24   - begin
25   - governmental_updates
26   - rescue
27   - @institution.errors.add(:governmental_fields,
28   - _("Could not find Governmental Power or Governmental Sphere"))
29   - end
30   - end
31   - if @institution.valid?
32   - redirect_to :controller => 'profile_editor', :action => 'index', :profile => profile.identifier
33   - else
34   - flash[:errors] = @institution.errors.full_messages
35   - end
36   - end
37   -
38   - def governmental_updates
39   - gov_power = GovernmentalPower.find params[:institutions][:governmental_power]
40   - gov_sphere = GovernmentalSphere.find params[:institutions][:governmental_sphere]
41   - jur_nature = JuridicalNature.find params[:institutions][:juridical_nature]
42   -
43   - @institution.juridical_nature = jur_nature
44   - @institution.governmental_power = gov_power
45   - @institution.governmental_sphere = gov_sphere
46   - @institution.save
47   - end
48   -
49   -
50   -end
db/migrate/20140528193816_add_extra_fields_to_user.rb
... ... @@ -1,17 +0,0 @@
1   -class AddExtraFieldsToUser < ActiveRecord::Migration
2   - def self.up
3   - change_table :users do |t|
4   - t.string :secondary_email
5   - t.references :institution
6   - t.string :role
7   - end
8   - end
9   -
10   - def self.down
11   - change_table :users do |t|
12   - t.remove :secondary_email
13   - t.remove_references :institution
14   - t.remove :role
15   - end
16   - end
17   -end
db/migrate/20140528193835_create_institutions_table.rb
... ... @@ -1,13 +0,0 @@
1   -class CreateInstitutionsTable < ActiveRecord::Migration
2   - def self.up
3   - create_table :institutions do |t|
4   - t.string :name
5   -
6   - t.timestamps
7   - end
8   - end
9   -
10   - def self.down
11   - drop_table :institutions
12   - end
13   -end
db/migrate/20140617125143_add_new_fields_institution.rb
... ... @@ -1,27 +0,0 @@
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
... ... @@ -1,19 +0,0 @@
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/20140617132451_create_governmental_powers.rb
... ... @@ -1,9 +0,0 @@
1   -class CreateGovernmentalPowers < ActiveRecord::Migration
2   - def change
3   - create_table :governmental_powers do |t|
4   - t.string :name
5   -
6   - t.timestamps
7   - end
8   - end
9   -end
db/migrate/20140617134556_add_references_to_institution.rb
... ... @@ -1,15 +0,0 @@
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
... ... @@ -1,13 +0,0 @@
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
... ... @@ -1,13 +0,0 @@
1   -class RemoveFieldRoleFromUser < ActiveRecord::Migration
2   - def up
3   - change_table :users do |t|
4   - t.remove :role
5   - end
6   - end
7   -
8   - def down
9   - change_table :users do |t|
10   - t.string :role
11   - end
12   - end
13   -end
db/migrate/20140814125947_add_new_fields_to_public_institution.rb
... ... @@ -1,11 +0,0 @@
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
... ... @@ -1,11 +0,0 @@
1   -class CreateJuridicalNaturesTable < ActiveRecord::Migration
2   - def up
3   - create_table :juridical_natures do |t|
4   - t.string :name
5   - end
6   - end
7   -
8   - def down
9   - drop_table :juridical_natures
10   - end
11   -end
db/migrate/20140814134827_add_juridical_nature_reference_to_institutions_table.rb
... ... @@ -1,13 +0,0 @@
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
... ... @@ -1,13 +0,0 @@
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
... ... @@ -1,9 +0,0 @@
1   -class RemoveInstitutionFromUser < ActiveRecord::Migration
2   - def up
3   - remove_column :users, :institution_id
4   - end
5   -
6   - def down
7   - add_column :users, :institution_id
8   - end
9   -end
db/migrate/20140818200738_create_institution_user_relation_table.rb
... ... @@ -1,12 +0,0 @@
1   -class CreateInstitutionUserRelationTable < ActiveRecord::Migration
2   - def up
3   - create_table :institutions_users do |t|
4   - t.belongs_to :user
5   - t.belongs_to :institution
6   - end
7   - end
8   -
9   - def down
10   - drop_table :institutions_users
11   - end
12   -end
db/migrate/20141103183013_add_corporate_name_to_institution.rb
... ... @@ -1,9 +0,0 @@
1   -class AddCorporateNameToInstitution < ActiveRecord::Migration
2   - def up
3   - add_column :institutions, :corporate_name, :string
4   - end
5   -
6   - def down
7   - remove_column :institutions, :corporate_name
8   - end
9   -end
db/migrate/20150910135510_add_siorg_code_to_institution.rb
... ... @@ -1,9 +0,0 @@
1   -class AddSiorgCodeToInstitution < ActiveRecord::Migration
2   - def up
3   - add_column :institutions, :siorg_code, :integer
4   - end
5   -
6   - def down
7   - remove_column :institutions, :siorg_code
8   - end
9   -end
db/migrate/20150910203559_add_institution_to_organization_rating.rb
... ... @@ -1,11 +0,0 @@
1   -class AddInstitutionToOrganizationRating < ActiveRecord::Migration
2   - def up
3   - change_table :organization_ratings do |t|
4   - t.belongs_to :institution
5   - end
6   - end
7   -
8   - def down
9   - remove_column :organization_ratings, :institution_id
10   - end
11   -end
12 0 \ No newline at end of file
db/seeds.rb
... ... @@ -1,19 +0,0 @@
1   -# encoding: UTF-8
2   -powers = ["Executivo", "Legislativo", "Judiciário", "Não se Aplica"]
3   -spheres = ["Federal", "Estadual", "Distrital", "Municipal"]
4   -jur_natures = ["Administração Direta", "Autarquia", "Empresa Pública", "Fundação",
5   - "Orgão Autônomo", "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
features/institution_registration.feature
... ... @@ -1,32 +0,0 @@
1   -Feature: Institution Field
2   - As a user
3   - I want to sign up resgistring my institution
4   - So others users can use it
5   -
6   - Background:
7   - Given "GovUserPlugin" plugin is enabled
8   - And I am logged in as mpog_admin
9   - And I go to /admin/plugins
10   - And I check "GovUserPlugin"
11   - And I press "Save changes"
12   - And Institutions has initial default values on database
13   - And I am logged in as mpog_admin
14   -
15   - @selenium
16   - Scenario: Show new institution fields when clicked in create new institution
17   - Given I follow "Edit Profile"
18   - When I follow "Create new institution"
19   - And I should see "New Institution"
20   - And I should see "Public Institution"
21   - And I should see "Private Institution"
22   - And I should see "Corporate Name"
23   - And I should see "Name"
24   - And I should see "State"
25   - And I should see "City"
26   - And I should see "Country"
27   - And I should see "CNPJ"
28   - And I should see "Acronym"
29   - And I choose "Public Institution"
30   - Then I should see "Governmental Sphere:"
31   - And I should see "Governmental Power:"
32   - And I should see "Juridical Nature:"
features/steps_definitions/gov_user_steps.rb
... ... @@ -1,90 +0,0 @@
1   -Given /^Institutions has initial default values on database$/ do
2   - GovernmentalPower.create(:name => "Executivo")
3   - GovernmentalPower.create(:name => "Legislativo")
4   - GovernmentalPower.create(:name => "Judiciario")
5   -
6   - GovernmentalSphere.create(:name => "Federal")
7   -
8   - JuridicalNature.create(:name => "Autarquia")
9   - JuridicalNature.create(:name => "Administracao Direta")
10   - JuridicalNature.create(:name => "Empresa Publica")
11   - JuridicalNature.create(:name => "Fundacao")
12   - JuridicalNature.create(:name => "Orgao Autonomo")
13   - JuridicalNature.create(:name => "Sociedade")
14   - JuridicalNature.create(:name => "Sociedade Civil")
15   - JuridicalNature.create(:name => "Sociedade de Economia Mista")
16   -
17   - national_region = NationalRegion.new
18   - national_region.name = "Distrito Federal"
19   - national_region.national_region_code = '35'
20   - national_region.national_region_type_id = NationalRegionType::STATE
21   - national_region.save
22   -end
23   -
24   -Given /^I type in "([^"]*)" in autocomplete list "([^"]*)" and I choose "([^"]*)"$/ do |typed, input_field_selector, should_select|
25   -# Wait the page javascript load
26   -sleep 1
27   -# Basicaly it, search for the input field, type something, wait for ajax end select an item
28   -page.driver.browser.execute_script %Q{
29   - var search_query = "#{input_field_selector}.ui-autocomplete-input";
30   - var input = jQuery(search_query).first();
31   -
32   - input.trigger('click');
33   - input.val('#{typed}');
34   - input.trigger('keydown');
35   -
36   - window.setTimeout(function(){
37   - search_query = ".ui-menu-item a:contains('#{should_select}')";
38   - var typed = jQuery(search_query).first();
39   -
40   - typed.trigger('mouseenter').trigger('click');
41   - console.log(jQuery('#license_info_id'));
42   - }, 1000);
43   - }
44   - sleep 1
45   -end
46   -
47   -Given /^the following public institutions?$/ do |table|
48   - # table is a Cucumber::Ast::Table
49   - table.hashes.each do |item|
50   - community = Community.new
51   - community.name = item[:name]
52   - community.country = item[:country]
53   - community.state = item[:state]
54   - community.city = item[:city]
55   - community.save!
56   -
57   - governmental_power = GovernmentalPower.where(:name => item[:governmental_power]).first
58   - governmental_sphere = GovernmentalSphere.where(:name => item[:governmental_sphere]).first
59   -
60   - juridical_nature = JuridicalNature.create(:name => item[:juridical_nature])
61   -
62   - institution = PublicInstitution.new(:name => item[:name], :type => "PublicInstitution", :acronym => item[:acronym], :cnpj => item[:cnpj], :juridical_nature => juridical_nature, :governmental_power => governmental_power, :governmental_sphere => governmental_sphere)
63   - institution.community = community
64   - institution.corporate_name = item[:corporate_name]
65   - institution.save!
66   - end
67   -end
68   -
69   -Given /^I sleep for (\d+) seconds$/ do |time|
70   - sleep time.to_i
71   -end
72   -
73   -Given /^I am logged in as mpog_admin$/ do
74   - visit('/account/logout')
75   -
76   - user = User.new(:login => 'admin_user', :password => '123456', :password_confirmation => '123456', :email => 'admin_user@example.com')
77   - person = Person.new :name=>"Mpog Admin", :identifier=>"mpog-admin"
78   - user.person = person
79   - user.save!
80   -
81   - user.activate
82   - e = Environment.default
83   - e.add_admin(user.person)
84   -
85   - visit('/account/login')
86   - fill_in("Username", :with => user.login)
87   - fill_in("Password", :with => '123456')
88   - click_button("Log in")
89   -end
90   -
features/user_profile_edition.feature
... ... @@ -1,77 +0,0 @@
1   -Feature: Institution Field
2   - As a user
3   - I want to update my update my user data
4   - So I can maintain my personal data updated
5   -
6   - Background:
7   - Given "GovUserPlugin" plugin is enabled
8   - And the following users
9   - | login | name |
10   - | joao | Joao Silva |
11   - And I am logged in as admin
12   - And I go to /admin/plugins
13   - And I check "GovUserPlugin"
14   - And I press "Save changes"
15   - And feature "skip_new_user_email_confirmation" is enabled on environment
16   - And I go to /admin/features/manage_fields
17   - And I check "person_fields_country_active"
18   - And I check "person_fields_state_active"
19   - And I check "person_fields_city_active"
20   - And I press "Save changes"
21   - And Institutions has initial default values on database
22   - And the following public institutions
23   - | name | acronym | country | state | city | cnpj | juridical_nature | governmental_power | governmental_sphere | corporate_name |
24   - | Ministerio das Cidades | MC | BR | DF | Gama | 58.745.189/0001-21 | Autarquia | Executivo | Federal | Ministerio das Cidades |
25   - | Governo do DF | GDF | BR | DF | Taguatinga | 12.645.166/0001-44 | Autarquia | Legislativo | Federal | Governo do DF |
26   - | Ministerio do Planejamento | MP | BR | DF | Brasilia | 41.769.591/0001-43 | Autarquia | Judiciario | Federal | Ministerio do Planejamento |
27   -
28   - Scenario: Go to control panel when clicked on 'Complete your profile' link
29   - Given I am logged in as "joao"
30   - And I am on joao's control panel
31   - When I follow "Complete your profile"
32   - Then I should see "Profile settings for "
33   - And I should see "Personal information"
34   -
35   - @selenium
36   - Scenario: Verify text information to use governmental e-mail
37   - Given I am logged in as "joao"
38   - And I am on joao's control panel
39   - When I follow "Edit Profile"
40   - Then I should see "If you work in a public agency use your government e-Mail"
41   -
42   - @selenium
43   - Scenario: Add more then one instituion on profile editor
44   - Given I am logged in as "joao"
45   - And I am on joao's control panel
46   - When I follow "Edit Profile"
47   - And I follow "Add new institution"
48   - And I type in "Minis" in autocomplete list "#input_institution" and I choose "Ministerio do Planejamento"
49   - And I follow "Add new institution"
50   - And I type in "Gover" in autocomplete list "#input_institution" and I choose "Governo do DF"
51   - And I follow "Add new institution"
52   - Then I should see "Ministerio do Planejamento" within ".institutions_added"
53   - And I should see "Governo do DF" within ".institutions_added"
54   -
55   - @selenium
56   - Scenario: Verify if field 'city' is shown when Brazil is selected
57   - Given I am logged in as "joao"
58   - And I am on joao's control panel
59   - When I follow "Edit Profile"
60   - Then I should see "City"
61   -
62   - @selenium
63   - Scenario: Verify if field 'city' does not appear when Brazil is not selected as country
64   - Given I am logged in as "joao"
65   - And I am on joao's control panel
66   - When I follow "Edit Profile"
67   - And I select "United States" from "profile_data_country"
68   - Then I should not see "City" within ".type-text"
69   -
70   - @selenium
71   - Scenario: Show message of institution not found
72   - Given I am logged in as "joao"
73   - And I am on joao's control panel
74   - When I follow "Edit Profile"
75   - And I fill in "input_institution" with "Some Nonexistent Institution"
76   - And I sleep for 1 seconds
77   - Then I should see "No institution found"
lib/ext/communities_block.rb
... ... @@ -1,45 +0,0 @@
1   -require_dependency 'communities_block'
2   -
3   -class CommunitiesBlock
4   -
5   - def profile_list
6   - result = get_visible_profiles
7   - result.slice(0..get_limit-1)
8   - end
9   -
10   - def profile_count
11   - profile_list.count
12   - end
13   -
14   - private
15   -
16   - def get_visible_profiles
17   - visible_profiles = profiles.visible.includes(
18   - [:image,:domains,:preferred_domain,:environment]
19   - )
20   -
21   - delete_communities = []
22   - valid_communities_string = Community.get_valid_communities_string
23   - Community.all.each{|community| delete_communities << community.id unless eval(valid_communities_string)}
24   -
25   - visible_profiles = visible_profiles.where(["profiles.id NOT IN (?)", delete_communities]) unless delete_communities.empty?
26   -
27   - if !prioritize_profiles_with_image
28   - return visible_profiles.all(
29   - :limit => get_limit,
30   - :order => 'profiles.updated_at DESC'
31   - ).sort_by {rand}
32   - elsif profiles.visible.with_image.count >= get_limit
33   - return visible_profiles.with_image.all(
34   - :limit => get_limit * 5,
35   - :order => 'profiles.updated_at DESC'
36   - ).sort_by {rand}
37   - else
38   - visible_profiles = visible_profiles.with_image.sort_by {rand} +
39   - visible_profiles.without_image.all(
40   - :limit => get_limit * 5, :order => 'profiles.updated_at DESC'
41   - ).sort_by {rand}
42   - return visible_profiles
43   - end
44   - end
45   -end
lib/ext/community.rb
... ... @@ -1,25 +0,0 @@
1   -require_dependency 'community'
2   -
3   -class Community
4   - has_one :institution, :dependent=>:destroy
5   -
6   - def institution?
7   - return !institution.nil?
8   - end
9   -
10   - def remove_of_community_search_institution?
11   - return institution?
12   - end
13   -
14   - def self.get_valid_communities_string
15   - remove_of_communities_methods = Community.instance_methods.select{|m| m =~ /remove_of_community_search/}
16   - valid_communities_string = "!("
17   - remove_of_communities_methods.each do |method|
18   - valid_communities_string += "community.send('#{method}') || "
19   - end
20   - valid_communities_string = valid_communities_string[0..-5]
21   - valid_communities_string += ")"
22   -
23   - valid_communities_string
24   - end
25   -end
lib/ext/organization_rating.rb
... ... @@ -1,20 +0,0 @@
1   -require_dependency "organization_rating"
2   -
3   -OrganizationRating.class_eval do
4   -
5   - belongs_to :institution
6   -
7   - attr_accessible :institution, :institution_id
8   -
9   - validate :verify_institution
10   -
11   - private
12   -
13   - def verify_institution
14   - if self.institution != nil
15   - institution = Institution.find_by_id self.institution.id
16   - self.errors.add :institution, _("not found") unless institution
17   - end
18   - end
19   -
20   -end
lib/ext/person.rb
... ... @@ -1,35 +0,0 @@
1   -# encoding: utf-8
2   -
3   -require_dependency 'person'
4   -
5   -class Person
6   -
7   - settings_items :percentage_incomplete, :type => :string, :default => ""
8   -
9   - attr_accessible :percentage_incomplete
10   -
11   - delegate :login, :to => :user, :prefix => true
12   -
13   - def institution?
14   - false
15   - end
16   -
17   - def secondary_email
18   - self.user.secondary_email unless self.user.nil?
19   - end
20   -
21   - def secondary_email= value
22   - self.user.secondary_email = value unless self.user.nil?
23   - end
24   -
25   - def institutions
26   - institutions = []
27   - unless self.user.institutions.nil?
28   - self.user.institutions.each do |institution|
29   - institutions << institution.name
30   - end
31   - end
32   - institutions
33   - end
34   -
35   -end
lib/ext/search_controller.rb
... ... @@ -1,42 +0,0 @@
1   -require_dependency 'search_controller'
2   -
3   -class SearchController
4   -
5   - def communities
6   - delete_communities = []
7   - valid_communities_string = Community.get_valid_communities_string
8   - Community.all.each{|community| delete_communities << community.id unless eval(valid_communities_string)}
9   -
10   - @scope = visible_profiles(Community)
11   - @scope = @scope.where(["id NOT IN (?)", delete_communities]) unless delete_communities.empty?
12   -
13   - full_text_search
14   - end
15   -
16   - def institutions
17   - @titles[:institutions] = _("Institution Catalog")
18   - results = filter_communities_list{|community| community.institution?}
19   - results = results.paginate(:per_page => 24, :page => params[:page])
20   - @searches[@asset] = {:results => results}
21   - @search = results
22   - end
23   -
24   - def filter_communities_list
25   - unfiltered_list = visible_profiles(Community)
26   -
27   - unless params[:query].nil?
28   - unfiltered_list = unfiltered_list.select do |com|
29   - com.name.downcase =~ /#{params[:query].downcase}/
30   - end
31   - end
32   -
33   - communities_list = []
34   - unfiltered_list.each do |profile|
35   - if profile.class == Community && !profile.is_template? && yield(profile)
36   - communities_list << profile
37   - end
38   - end
39   -
40   - communities_list
41   - end
42   -end
lib/ext/search_helper.rb
... ... @@ -1,8 +0,0 @@
1   -require_dependency 'search_helper'
2   -
3   -module SearchHelper
4   -
5   - COMMON_PROFILE_LIST_BLOCK ||= []
6   - COMMON_PROFILE_LIST_BLOCK << :institutions
7   -
8   -end
lib/ext/user.rb
... ... @@ -1,60 +0,0 @@
1   -require_dependency 'user'
2   -
3   -class User
4   -
5   - GOV_SUFFIX = /^.*@[gov.br|jus.br|leg.br|mp.br]+$/
6   -
7   - has_and_belongs_to_many :institutions
8   -
9   - validate :email_different_secondary?, :email_has_already_been_used?,
10   - :secondary_email_format
11   -
12   - scope :primary_or_secondary_email_already_used?, lambda { |email|
13   - where("email=? OR secondary_email=?", email, email)
14   - }
15   -
16   - def email_different_secondary?
17   - self.errors.add(
18   - :base,
19   - _("Email must be different from secondary email.")
20   - ) if self.email == self.secondary_email
21   - end
22   -
23   - def email_has_already_been_used?
24   - user_already_saved = User.find(:first,
25   - :conditions => ["email = ?", self.email])
26   -
27   - if user_already_saved.nil?
28   - primary_email_hasnt_been_used =
29   - User.primary_or_secondary_email_already_used?(self.email).empty?
30   -
31   - if !self.secondary_email.nil? and self.secondary_email.empty?
32   - self.secondary_email = nil
33   - end
34   -
35   - secondary_email_hasnt_been_used =
36   - User.primary_or_secondary_email_already_used?(self.secondary_email).
37   - empty?
38   -
39   - if !primary_email_hasnt_been_used or !secondary_email_hasnt_been_used
40   - self.errors.add(:base, _("E-mail or secondary e-mail already taken."))
41   - end
42   - end
43   - end
44   -
45   - def secondary_email_format
46   - if !self.secondary_email.nil? and self.secondary_email.length > 0
47   - test = /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/
48   -
49   - unless test.match(self.secondary_email)
50   - self.errors.add(:base, _("Invalid secondary email format."))
51   - end
52   - end
53   - end
54   -
55   - private
56   -
57   - def valid_format?(value, string_format)
58   - !value.nil? && value.length > 0 && !string_format.match(value).nil?
59   - end
60   -end
lib/gov_user_plugin.rb
... ... @@ -1,332 +0,0 @@
1   -class GovUserPlugin < Noosfero::Plugin
2   - include ActionView::Helpers::TagHelper
3   - include ActionView::Helpers::FormTagHelper
4   - include ActionView::Helpers::FormOptionsHelper
5   - include ActionView::Helpers::JavaScriptHelper
6   - include ActionView::Helpers::AssetTagHelper
7   - include FormsHelper
8   - include ActionView::Helpers
9   - include ActionDispatch::Routing
10   - include Rails.application.routes.url_helpers
11   -
12   - def self.plugin_name
13   - "GovUserPlugin"
14   - end
15   -
16   - def self.plugin_description
17   - _("Add features related to Brazilian government.")
18   - end
19   -
20   - def stylesheet?
21   - true
22   - end
23   -
24   - # Hotspot to insert html without an especific hotspot on view.
25   - def body_beginning
26   - return if context.session[:user].nil? or context.session[:hide_incomplete_percentage] == true
27   -
28   - person = context.environment.people.where(:user_id=>context.session[:user]).first
29   -
30   - if context.profile && context.profile.person? and !person.nil?
31   - @person = person
32   - @percentege = calc_percentage_registration(person)
33   -
34   - if @percentege >= 0 and @percentege < 100
35   - expanded_template('incomplete_registration.html.erb')
36   - end
37   - end
38   - end
39   -
40   - def profile_editor_transaction_extras
41   - single_hash_transactions = { :user => 'user',
42   - :instituton => 'instituton'
43   - }
44   -
45   - single_hash_transactions.each do |model, transaction|
46   - call_model_transaction(model, transaction)
47   - end
48   - end
49   -
50   - def profile_editor_controller_filters
51   - block = proc do
52   - if request.post? && params[:institution]
53   - is_admin = environment.admins.include?(current_user.person)
54   -
55   - unless is_admin
56   - institution = profile.user.institutions
57   -
58   - if !params[:institution].blank? && params[:institution].class == Hash && !params[:institution][:sisp].nil?
59   - if params[:institution][:sisp] != institution.sisp
60   - params[:institution][:sisp] = institution.sisp
61   - end
62   - end
63   - end
64   - end
65   - end
66   -
67   - [{
68   - :type => 'before_filter',
69   - :method_name => 'validate_institution_sisp_field_access',
70   - :options => { :only => :edit },
71   - :block => block
72   - }]
73   - end
74   -
75   - def profile_tabs
76   - if context.profile.community?
77   - return profile_tabs_institution if context.profile.institution?
78   - end
79   - end
80   -
81   - def control_panel_buttons
82   - if context.profile.institution?
83   - return institution_info_button
84   - end
85   - end
86   -
87   - def self.extra_blocks
88   - {
89   - InstitutionsBlock => { :type => [Environment, Person] }
90   - }
91   - end
92   -
93   - def custom_user_registration_attributes(user)
94   - return if context.params[:user][:institution_ids].nil?
95   - context.params[:user][:institution_ids].delete('')
96   -
97   - update_user_institutions(user)
98   -
99   - user.institutions.each do |institution|
100   - community = institution.community
101   - community.add_member user.person
102   - end
103   - end
104   -
105   - def profile_editor_extras
106   - profile = context.profile
107   -
108   - if profile.person?
109   - expanded_template('person_editor_extras.html.erb')
110   - end
111   - end
112   -
113   -
114   - def calc_percentage_registration(person)
115   - required_list = profile_required_list
116   - empty_fields = profile_required_empty_list person
117   - count = required_list[:person_fields].count +
118   - required_list[:user_fields].count
119   - percentege = 100 - ((empty_fields.count * 100) / count)
120   - person.percentage_incomplete = percentege
121   - person.save(validate: false)
122   - percentege
123   - end
124   -
125   - def stylesheet?
126   - true
127   - end
128   -
129   - def admin_panel_links
130   - [
131   - {
132   - :title => _('Create Institution'),
133   - :url => {
134   - :controller => 'gov_user_plugin',
135   - :action => 'create_institution_admin'
136   - }
137   - }
138   - ]
139   - end
140   -
141   -
142   - def js_files
143   - %w(
144   - vendor/modulejs-1.5.0.min.js
145   - vendor/jquery.js
146   - lib/noosfero-root.js
147   - lib/select-element.js
148   - lib/select-field-choices.js
149   - views/complete-registration.js
150   - views/control-panel.js
151   - views/create-institution.js
152   - views/new-community.js
153   - views/user-edit-profile.js
154   - views/gov-user-comments-extra-fields.js
155   - initializer.js
156   - app.js
157   - )
158   - end
159   -
160   - def admin_panel_links
161   - [
162   - {
163   - :title => _('Create Institution'),
164   - :url => {
165   - :controller => 'gov_user_plugin',
166   - :action => 'create_institution_admin'
167   - }
168   - }
169   - ]
170   - end
171   -
172   - protected
173   -
174   - def profile_required_list
175   - fields = {}
176   - fields[:person_fields] = %w(cell_phone
177   - contact_phone
178   - comercial_phone
179   - country
180   - city
181   - state
182   - organization_website
183   - image
184   - identifier
185   - name)
186   -
187   - fields[:user_fields] = %w(secondary_email email)
188   - fields
189   - end
190   -
191   - def profile_required_empty_list(person)
192   - empty_fields = []
193   - required_list = profile_required_list
194   -
195   - required_list[:person_fields].each do |field|
196   - empty_fields << field.sub('_',' ') if person.send(field).blank?
197   - end
198   - required_list[:user_fields].each do |field|
199   - empty_fields << field.sub('_',' ') if person.user.send(field).blank?
200   - end
201   - empty_fields
202   - end
203   -
204   -
205   - protected
206   -
207   - def user_transaction
208   - user_editor_institution_actions
209   -
210   - User.transaction do
211   - context.profile.user.update_attributes!(context.params[:user])
212   - end
213   - end
214   -
215   - def institution_transaction
216   - institution.date_modification = DateTime.now
217   - institution.save
218   - institution_models = %w(governmental_power governmental_sphere
219   - juridical_nature)
220   -
221   - institution_models.each do |model|
222   - call_institution_transaction(model)
223   - end
224   -
225   - if context.params.has_key?(:institution)
226   - Institution.transaction do
227   - context.profile.
228   - institution.
229   - update_attributes!(context.params[:institution])
230   - end
231   - end
232   - end
233   -
234   - def organization_ratings_plugin_comments_extra_fields
235   - Proc::new do render :file => 'ratings_extra_field' end
236   - end
237   -
238   - def organization_ratings_plugin_extra_fields_show_data user_rating
239   - gov_user_self = self
240   -
241   - Proc::new {
242   - if logged_in?
243   - is_admin = environment.admins.include?(current_user.person)
244   - is_admin ||= user_rating.organization.admins.include?(current_user.person)
245   -
246   - if is_admin and gov_user_self.context.profile.software?
247   - render :file => 'organization_ratings_extra_fields_show_institution',
248   - :locals => {:user_rating => user_rating}
249   - end
250   - end
251   - }
252   - end
253   -
254   - private
255   -
256   - def call_model_transaction(model,name)
257   - send(name + '_transaction') if context.params.key?(model.to_sym)
258   - end
259   -
260   - def call_institution_transaction(model)
261   - context.profile.institution.send(model + '_id = ',
262   - context.params[model.to_sym])
263   - context.profile.institution.save!
264   - end
265   -
266   - # Add and remove the user from it's institutions communities
267   - def user_editor_institution_actions
268   - user = context.profile.user
269   -
270   - old_communities = []
271   - context.profile.user.institutions.each do |institution|
272   - old_communities << institution.community
273   - end
274   -
275   - new_communities = []
276   - unless context.params[:user][:institution_ids].nil?
277   - context.params[:user][:institution_ids].delete('')
278   -
279   - context.params[:user][:institution_ids].each do |id|
280   - new_communities << Institution.find(id).community
281   - end
282   - end
283   -
284   - manage_user_institutions(user, old_communities, new_communities)
285   - end
286   -
287   - def institution_info_button
288   - {
289   - :title => _('Institution Info'),
290   - :icon => 'edit-profile-group control-panel-instituton-link',
291   - :url => {
292   - :controller => 'gov_user_plugin_myprofile',
293   - :action => 'edit_institution'
294   - }
295   - }
296   - end
297   -
298   - def manage_user_institutions(user, old_communities, new_communities)
299   - leave_communities = (old_communities - new_communities)
300   - enter_communities = (new_communities - old_communities)
301   -
302   - leave_communities.each do |community|
303   - community.remove_member(user.person)
304   - user.institutions.delete(community.institution)
305   - end
306   -
307   - enter_communities.each do |community|
308   - community.add_member(user.person)
309   - user.institutions << community.institution
310   - end
311   - end
312   -
313   - def profile_tabs_institution
314   - { :title => _('Institution'),
315   - :id => 'intitution-fields',
316   - :content => Proc::new do render :partial => 'profile/institution_tab' end,
317   - :start => true
318   - }
319   - end
320   -
321   - def update_user_institutions(user)
322   - context.params[:user][:institution_ids].each do |institution_id|
323   - institution = Institution.find institution_id
324   - user.institutions << institution
325   -
326   - if institution.community.admins.blank?
327   - institution.community.add_admin(user.person)
328   - end
329   - end
330   - user.save unless user.institution_ids.empty?
331   - end
332   -end
lib/governmental_power.rb
... ... @@ -1,13 +0,0 @@
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
lib/governmental_sphere.rb
... ... @@ -1,7 +0,0 @@
1   -class GovernmentalSphere < ActiveRecord::Base
2   - attr_accessible :name
3   -
4   - validates :name, :presence=>true, :uniqueness=>true
5   -
6   - has_many :institutions
7   -end
lib/institution.rb
... ... @@ -1,107 +0,0 @@
1   -class Institution < ActiveRecord::Base
2   - has_many :comments
3   -
4   - SEARCH_FILTERS = {
5   - :order => %w[],
6   - :display => %w[compact]
7   - }
8   -
9   - def self.default_search_display
10   - 'compact'
11   - end
12   -
13   - belongs_to :governmental_power
14   - belongs_to :governmental_sphere
15   - belongs_to :juridical_nature
16   -
17   - has_and_belongs_to_many :users
18   -
19   - attr_accessible :name, :acronym, :unit_code, :parent_code, :unit_type,
20   - :sub_juridical_nature, :normalization_level,
21   - :version, :cnpj, :type, :governmental_power,
22   - :governmental_sphere, :sisp, :juridical_nature,
23   - :corporate_name, :siorg_code, :community
24   -
25   - validates :name, :presence=>true, :uniqueness=>true
26   -
27   - before_save :verify_institution_type
28   -
29   - belongs_to :community
30   -
31   - scope :search_institution, lambda{ |value|
32   - where("name ilike ? OR acronym ilike ?", "%#{value}%", "%#{value}%" )
33   - }
34   -
35   - validate :validate_country, :validate_state, :validate_city,
36   - :verify_institution_type, :validate_format_cnpj
37   -
38   -
39   - protected
40   -
41   - def verify_institution_type
42   - valid_institutions_type = ["PublicInstitution", "PrivateInstitution"]
43   -
44   - unless valid_institutions_type.include? self.type
45   - self.errors.add(
46   - :type,
47   - _("invalid, only public and private institutions are allowed.")
48   - )
49   -
50   - return false
51   - end
52   -
53   - return true
54   - end
55   -
56   - def validate_country
57   - unless self.community.blank?
58   - if self.community.country.blank? && self.errors[:country].blank?
59   - self.errors.add(:country, _("can't be blank"))
60   - return false
61   - end
62   - end
63   -
64   - return true
65   - end
66   -
67   - def validate_state
68   - unless self.community.blank?
69   - if self.community.country == "BR" &&
70   - (self.community.state.blank? || self.community.state == "-1") &&
71   - self.errors[:state].blank?
72   -
73   - self.errors.add(:state, _("can't be blank"))
74   - return false
75   - end
76   - end
77   -
78   - return true
79   - end
80   -
81   - def validate_city
82   - unless self.community.blank?
83   - if self.community.country == "BR" && self.community.city.blank? &&
84   - self.errors[:city].blank?
85   -
86   - self.errors.add(:city, _("can't be blank"))
87   - return false
88   - end
89   - end
90   -
91   - return true
92   - end
93   -
94   - def validate_format_cnpj
95   - return true if self.community.blank? && self.community.country != "BR"
96   - return true if self.cnpj.blank?
97   -
98   - format = /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/
99   -
100   - if !self.cnpj.blank? && format.match(self.cnpj)
101   - return true
102   - else
103   - self.errors.add(:cnpj, _("invalid format"))
104   - return false
105   - end
106   - end
107   -end
lib/institutions_block.rb
... ... @@ -1,71 +0,0 @@
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
lib/institutions_users.rb
... ... @@ -1,4 +0,0 @@
1   -class InstitutionUser < ActiveRecord::Base
2   - belongs_to :user
3   - belongs_to :institution
4   -end
lib/juridical_nature.rb
... ... @@ -1,15 +0,0 @@
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
lib/private_institution.rb
... ... @@ -1,2 +0,0 @@
1   -class PrivateInstitution < Institution
2   -end
lib/public_institution.rb
... ... @@ -1,13 +0,0 @@
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_format_of(
9   - :cnpj,
10   - :with => /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/,
11   - :allow_nil => true, :allow_blank => true
12   - )
13   -end
po/gov_user.pot
... ... @@ -1,356 +0,0 @@
1   -# SOME DESCRIPTIVE TITLE.
2   -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3   -# This file is distributed under the same license as the PACKAGE package.
4   -# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5   -#
6   -#, fuzzy
7   -msgid ""
8   -msgstr ""
9   -"Project-Id-Version: 1.2-141-g2924904\n"
10   -"POT-Creation-Date: 2015-09-11 17:06-0000\n"
11   -"PO-Revision-Date: 2015-09-01 20:59-0000\n"
12   -"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13   -"Language-Team: LANGUAGE <LL@li.org>\n"
14   -"Language: \n"
15   -"MIME-Version: 1.0\n"
16   -"Content-Type: text/plain; charset=UTF-8\n"
17   -"Content-Transfer-Encoding: 8bit\n"
18   -"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
19   -
20   -#: plugins/gov_user/lib/ext/search_controller.rb:17
21   -msgid "Institution Catalog"
22   -msgstr ""
23   -
24   -#: plugins/gov_user/lib/ext/user.rb:19
25   -msgid "Email must be different from secondary email."
26   -msgstr ""
27   -
28   -#: plugins/gov_user/lib/ext/user.rb:40
29   -msgid "E-mail or secondary e-mail already taken."
30   -msgstr ""
31   -
32   -#: plugins/gov_user/lib/ext/user.rb:50
33   -msgid "Invalid secondary email format."
34   -msgstr ""
35   -
36   -#: plugins/gov_user/lib/ext/organization_rating.rb:16
37   -msgid "not found"
38   -msgstr ""
39   -
40   -#: plugins/gov_user/lib/gov_user_plugin.rb:17
41   -msgid "Add features related to Brazilian government."
42   -msgstr ""
43   -
44   -#: plugins/gov_user/lib/gov_user_plugin.rb:132
45   -#: plugins/gov_user/lib/gov_user_plugin.rb:163
46   -msgid "Create Institution"
47   -msgstr ""
48   -
49   -#: plugins/gov_user/lib/gov_user_plugin.rb:287
50   -msgid "Institution Info"
51   -msgstr ""
52   -
53   -#: plugins/gov_user/lib/gov_user_plugin.rb:312
54   -msgid "Institution"
55   -msgstr ""
56   -
57   -#: plugins/gov_user/lib/institutions_block.rb:4
58   -#: plugins/gov_user/views/person_editor_extras.html.erb:11
59   -msgid "Institutions"
60   -msgstr ""
61   -
62   -#: plugins/gov_user/lib/institutions_block.rb:12
63   -msgid "{#} institution"
64   -msgid_plural "{#} institutions"
65   -msgstr[0] ""
66   -msgstr[1] ""
67   -
68   -#: plugins/gov_user/lib/institutions_block.rb:16
69   -msgid "This block displays the institutions in which the user is a member."
70   -msgstr ""
71   -
72   -#: plugins/gov_user/lib/institutions_block.rb:24
73   -#: plugins/gov_user/lib/institutions_block.rb:30
74   -msgid "institutions|View all"
75   -msgstr ""
76   -
77   -#: plugins/gov_user/lib/institution.rb:47
78   -msgid "invalid, only public and private institutions are allowed."
79   -msgstr ""
80   -
81   -#: plugins/gov_user/lib/institution.rb:59
82   -#: plugins/gov_user/lib/institution.rb:73
83   -#: plugins/gov_user/lib/institution.rb:86
84   -msgid "can't be blank"
85   -msgstr ""
86   -
87   -#: plugins/gov_user/lib/institution.rb:103
88   -msgid "invalid format"
89   -msgstr ""
90   -
91   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:18
92   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:43
93   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:83
94   -msgid "Select a Governmental Sphere"
95   -msgstr ""
96   -
97   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:19
98   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:44
99   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:90
100   -msgid "Select a Governmental Power"
101   -msgstr ""
102   -
103   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:20
104   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:45
105   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:96
106   -msgid "Select a Juridical Nature"
107   -msgstr ""
108   -
109   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:21
110   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:46
111   -msgid "Select a state"
112   -msgstr ""
113   -
114   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:168
115   -#: plugins/gov_user/controllers/gov_user_plugin_myprofile_controller.rb:26
116   -msgid "Could not find Governmental Power or Governmental Sphere"
117   -msgstr ""
118   -
119   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:214
120   -msgid "Institution successful created!"
121   -msgstr ""
122   -
123   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:219
124   -msgid "Institution could not be created!"
125   -msgstr ""
126   -
127   -#: plugins/gov_user/test/unit/gov_user_person_test.rb:50
128   -#: plugins/gov_user/test/unit/gov_user_person_test.rb:56
129   -msgid "Name Should begin with a capital letter and no special characters"
130   -msgstr ""
131   -
132   -#: plugins/gov_user/views/search/institutions.html.erb:3
133   -msgid "Type words about the %s you're looking for"
134   -msgstr ""
135   -
136   -#: plugins/gov_user/views/ratings_extra_field.html.erb:2
137   -msgid "Organization name or Enterprise name"
138   -msgstr ""
139   -
140   -#: plugins/gov_user/views/ratings_extra_field.html.erb:6
141   -#: plugins/gov_user/views/person_editor_extras.html.erb:21
142   -msgid "No institution found"
143   -msgstr ""
144   -
145   -#: plugins/gov_user/views/incomplete_registration.html.erb:3
146   -msgid "Complete Profile"
147   -msgstr ""
148   -
149   -#: plugins/gov_user/views/incomplete_registration.html.erb:6
150   -msgid "Complete your profile"
151   -msgstr ""
152   -
153   -#: plugins/gov_user/views/incomplete_registration.html.erb:7
154   -msgid "Hide"
155   -msgstr ""
156   -
157   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:1
158   -msgid "Edit Institution"
159   -msgstr ""
160   -
161   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:5
162   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:5
163   -msgid ""
164   -"Note that the creation of communities in this environment is restricted. "
165   -"Your request to create this new community will be sent to %{environment} "
166   -"administrators and will be approved or rejected according to their methods "
167   -"and criteria."
168   -msgstr ""
169   -
170   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:11
171   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:11
172   -msgid "\"Can`t create new Institution: #{flash[:errors].length} errors\""
173   -msgstr ""
174   -
175   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:24
176   -msgid "All fields with (*) are mandatory"
177   -msgstr ""
178   -
179   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:31
180   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:37
181   -msgid "Public Institution"
182   -msgstr ""
183   -
184   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:36
185   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:33
186   -msgid "Private Institution"
187   -msgstr ""
188   -
189   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:43
190   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:44
191   -msgid "Institution name already exists"
192   -msgstr ""
193   -
194   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:47
195   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:48
196   -msgid "Corporate Name"
197   -msgstr ""
198   -
199   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:52
200   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:53
201   -msgid "Country"
202   -msgstr ""
203   -
204   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:56
205   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:57
206   -msgid "State"
207   -msgstr ""
208   -
209   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:66
210   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:66
211   -msgid "CNPJ"
212   -msgstr ""
213   -
214   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:73
215   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:75
216   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:72
217   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:74
218   -msgid "Acronym"
219   -msgstr ""
220   -
221   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:74
222   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:73
223   -msgid "Fantasy name"
224   -msgstr ""
225   -
226   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:82
227   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:17
228   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:81
229   -msgid "Governmental Sphere:"
230   -msgstr ""
231   -
232   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:89
233   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:16
234   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:88
235   -msgid "Governmental Power:"
236   -msgstr ""
237   -
238   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:95
239   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:18
240   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:94
241   -msgid "Juridical Nature:"
242   -msgstr ""
243   -
244   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:102
245   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:101
246   -msgid "SISP?"
247   -msgstr ""
248   -
249   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:104
250   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:19
251   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:104
252   -msgid "Yes"
253   -msgstr ""
254   -
255   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:106
256   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:109
257   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:19
258   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:106
259   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:108
260   -msgid "No"
261   -msgstr ""
262   -
263   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:114
264   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:114
265   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:118
266   -msgid "Save"
267   -msgstr ""
268   -
269   -#: plugins/gov_user/views/person_editor_extras.html.erb:2
270   -msgid "Secondary e-mail"
271   -msgstr ""
272   -
273   -#: plugins/gov_user/views/person_editor_extras.html.erb:22
274   -msgid "Add new institution"
275   -msgstr ""
276   -
277   -#: plugins/gov_user/views/person_editor_extras.html.erb:23
278   -msgid "Create new institution"
279   -msgstr ""
280   -
281   -#: plugins/gov_user/views/person_editor_extras.html.erb:39
282   -msgid "Should begin with a capital letter and no special characters"
283   -msgstr ""
284   -
285   -#: plugins/gov_user/views/person_editor_extras.html.erb:40
286   -msgid "Email should have the following format: name@host.br"
287   -msgstr ""
288   -
289   -#: plugins/gov_user/views/person_editor_extras.html.erb:41
290   -msgid "Site should have a valid format: http://name.hosts"
291   -msgstr ""
292   -
293   -#: plugins/gov_user/views/person_editor_extras.html.erb:42
294   -msgid "If you work in a public agency use your government e-Mail"
295   -msgstr ""
296   -
297   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:3
298   -msgid "Institution Information"
299   -msgstr ""
300   -
301   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:6
302   -msgid "Type:"
303   -msgstr ""
304   -
305   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:7
306   -msgid "CNPJ:"
307   -msgstr ""
308   -
309   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:8
310   -msgid "Last modification:"
311   -msgstr ""
312   -
313   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:9
314   -msgid "Country:"
315   -msgstr ""
316   -
317   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:10
318   -msgid "State:"
319   -msgstr ""
320   -
321   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:11
322   -msgid "City:"
323   -msgstr ""
324   -
325   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:13
326   -msgid "Fantasy Name:"
327   -msgstr ""
328   -
329   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:15
330   -msgid "Acronym:"
331   -msgstr ""
332   -
333   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:19
334   -msgid "SISP:"
335   -msgstr ""
336   -
337   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:1
338   -msgid "New Institution"
339   -msgstr ""
340   -
341   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:16
342   -msgid "\"<b>#{key_name.capitalize}</b> #{value.join()}\""
343   -msgstr ""
344   -
345   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:115
346   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:119
347   -msgid "Cancel"
348   -msgstr ""
349   -
350   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:121
351   -msgid "Could not send the form data to the server"
352   -msgstr ""
353   -
354   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:128
355   -msgid "Creating institution"
356   -msgstr ""
po/pt/gov_user.po
... ... @@ -1,370 +0,0 @@
1   -# SOME DESCRIPTIVE TITLE.
2   -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3   -# This file is distributed under the same license as the PACKAGE package.
4   -# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5   -#
6   -msgid ""
7   -msgstr ""
8   -"Project-Id-Version: 1.2-143-g8dfded9\n"
9   -"POT-Creation-Date: 2015-09-11 17:14-0000\n"
10   -"PO-Revision-Date: 2015-09-01 19:55-0000\n"
11   -"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
12   -"Language-Team: LANGUAGE <LL@li.org>\n"
13   -"Language: \n"
14   -"MIME-Version: 1.0\n"
15   -"Content-Type: text/plain; charset=UTF-8\n"
16   -"Content-Transfer-Encoding: 8bit\n"
17   -"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
18   -
19   -#: plugins/gov_user/test/unit/gov_user_person_test.rb:50
20   -#: plugins/gov_user/test/unit/gov_user_person_test.rb:56
21   -msgid "Name Should begin with a capital letter and no special characters"
22   -msgstr ""
23   -"Nome deve iniciar com letrar maiúscula e não deve conter carateres especiais"
24   -
25   -#: plugins/gov_user/controllers/gov_user_plugin_myprofile_controller.rb:26
26   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:168
27   -msgid "Could not find Governmental Power or Governmental Sphere"
28   -msgstr "Não foi possível encontrar o Poder ou Esfera Governamental"
29   -
30   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:18
31   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:43
32   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:83
33   -msgid "Select a Governmental Sphere"
34   -msgstr "Selecione uma Esfera Governamental"
35   -
36   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:19
37   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:44
38   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:90
39   -msgid "Select a Governmental Power"
40   -msgstr "Selecione um Poder Governamental"
41   -
42   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:20
43   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:45
44   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:96
45   -msgid "Select a Juridical Nature"
46   -msgstr "Seleciona uma Natureza Jurídica"
47   -
48   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:21
49   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:46
50   -msgid "Select a state"
51   -msgstr "Selecione um Estado"
52   -
53   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:214
54   -msgid "Institution successful created!"
55   -msgstr "Instituição criada com sucesso!"
56   -
57   -#: plugins/gov_user/controllers/gov_user_plugin_controller.rb:219
58   -msgid "Institution could not be created!"
59   -msgstr "Instituição não pode ser criada!"
60   -
61   -#: plugins/gov_user/lib/gov_user_plugin.rb:17
62   -msgid "Add features related to Brazilian government."
63   -msgstr "Adicionar funcionlidade relacionada com o governo brasileiro."
64   -
65   -#: plugins/gov_user/lib/gov_user_plugin.rb:132
66   -#: plugins/gov_user/lib/gov_user_plugin.rb:163
67   -msgid "Create Institution"
68   -msgstr "Criar Instituição"
69   -
70   -#: plugins/gov_user/lib/gov_user_plugin.rb:287
71   -msgid "Institution Info"
72   -msgstr "Informações da Instituição"
73   -
74   -#: plugins/gov_user/lib/gov_user_plugin.rb:312
75   -msgid "Institution"
76   -msgstr "Instituição"
77   -
78   -#: plugins/gov_user/lib/institution.rb:47
79   -msgid "invalid, only public and private institutions are allowed."
80   -msgstr "Inválido, somente instituições públicas e privadas são permitidas."
81   -
82   -#: plugins/gov_user/lib/institution.rb:59
83   -#: plugins/gov_user/lib/institution.rb:73
84   -#: plugins/gov_user/lib/institution.rb:86
85   -msgid "can't be blank"
86   -msgstr "não pode ficar em branco"
87   -
88   -#: plugins/gov_user/lib/institution.rb:103
89   -msgid "invalid format"
90   -msgstr "formato inválido"
91   -
92   -#: plugins/gov_user/lib/ext/user.rb:19
93   -msgid "Email must be different from secondary email."
94   -msgstr "Email deve ser diferente do email secundário"
95   -
96   -#: plugins/gov_user/lib/ext/user.rb:40
97   -msgid "E-mail or secondary e-mail already taken."
98   -msgstr "Email ou email secundário já estão sendo utilizados."
99   -
100   -#: plugins/gov_user/lib/ext/user.rb:50
101   -msgid "Invalid secondary email format."
102   -msgstr "Formato inválido do email sencundário"
103   -
104   -#: plugins/gov_user/lib/ext/search_controller.rb:17
105   -msgid "Institution Catalog"
106   -msgstr "Catálogo de Instituições"
107   -
108   -#: plugins/gov_user/lib/ext/organization_rating.rb:16
109   -msgid "not found"
110   -msgstr "não encontrada"
111   -
112   -#: plugins/gov_user/lib/institutions_block.rb:4
113   -#: plugins/gov_user/views/person_editor_extras.html.erb:11
114   -msgid "Institutions"
115   -msgstr "Instituições"
116   -
117   -#: plugins/gov_user/lib/institutions_block.rb:12
118   -msgid "{#} institution"
119   -msgid_plural "{#} institutions"
120   -msgstr[0] "{#} instituição"
121   -msgstr[1] "{#} instituições"
122   -
123   -#: plugins/gov_user/lib/institutions_block.rb:16
124   -msgid "This block displays the institutions in which the user is a member."
125   -msgstr "Esse bloco mostra as instituições em que o usuário faz parte."
126   -
127   -#: plugins/gov_user/lib/institutions_block.rb:24
128   -#: plugins/gov_user/lib/institutions_block.rb:30
129   -msgid "institutions|View all"
130   -msgstr "instituições|Ver todas"
131   -
132   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:1
133   -msgid "Edit Institution"
134   -msgstr "Editar Instituição"
135   -
136   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:5
137   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:5
138   -msgid ""
139   -"Note that the creation of communities in this environment is restricted. "
140   -"Your request to create this new community will be sent to %{environment} "
141   -"administrators and will be approved or rejected according to their methods "
142   -"and criteria."
143   -msgstr ""
144   -"Note que a criação de comunidades neste ambiente é restrita. Sua requisição "
145   -"para criar essa nova comunidade será enviada para os administradores "
146   -"%{environment} e será aprovada ou rejeitada de acordo com seus métodos e "
147   -"critérios."
148   -
149   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:11
150   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:11
151   -msgid "\"Can`t create new Institution: #{flash[:errors].length} errors\""
152   -msgstr ""
153   -"\"Não foi possível criar nova Instituição: #{flash[:errors].length} erros\""
154   -
155   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:24
156   -msgid "All fields with (*) are mandatory"
157   -msgstr "Todos os campos com (*) são obrigatórios"
158   -
159   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:31
160   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:37
161   -msgid "Public Institution"
162   -msgstr "Instituição Pública"
163   -
164   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:36
165   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:33
166   -msgid "Private Institution"
167   -msgstr "Instituição Privada"
168   -
169   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:43
170   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:44
171   -msgid "Institution name already exists"
172   -msgstr "Nome de Instituição já existe"
173   -
174   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:47
175   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:48
176   -msgid "Corporate Name"
177   -msgstr "Nome da Coorporação"
178   -
179   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:52
180   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:53
181   -msgid "Country"
182   -msgstr "País"
183   -
184   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:56
185   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:57
186   -msgid "State"
187   -msgstr "Estado"
188   -
189   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:66
190   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:66
191   -msgid "CNPJ"
192   -msgstr "CNPJ"
193   -
194   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:73
195   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:75
196   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:72
197   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:74
198   -msgid "Acronym"
199   -msgstr "Sigla"
200   -
201   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:74
202   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:73
203   -msgid "Fantasy name"
204   -msgstr "Nome Fantasia"
205   -
206   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:82
207   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:17
208   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:81
209   -msgid "Governmental Sphere:"
210   -msgstr "Esfera Governamental:"
211   -
212   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:89
213   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:16
214   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:88
215   -msgid "Governmental Power:"
216   -msgstr "Poder Governamental:"
217   -
218   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:95
219   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:18
220   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:94
221   -msgid "Juridical Nature:"
222   -msgstr "Natureza Jurídica:"
223   -
224   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:102
225   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:101
226   -msgid "SISP?"
227   -msgstr "SISP?"
228   -
229   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:104
230   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:19
231   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:104
232   -msgid "Yes"
233   -msgstr "Sim"
234   -
235   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:106
236   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:109
237   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:19
238   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:106
239   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:108
240   -msgid "No"
241   -msgstr "Não"
242   -
243   -#: plugins/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb:114
244   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:114
245   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:118
246   -msgid "Save"
247   -msgstr "Salvar"
248   -
249   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:3
250   -msgid "Institution Information"
251   -msgstr "Informação da Instituição"
252   -
253   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:6
254   -msgid "Type:"
255   -msgstr "Tipo:"
256   -
257   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:7
258   -msgid "CNPJ:"
259   -msgstr "CNPJ:"
260   -
261   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:8
262   -msgid "Last modification:"
263   -msgstr "Última modificação:"
264   -
265   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:9
266   -msgid "Country:"
267   -msgstr "País:"
268   -
269   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:10
270   -msgid "State:"
271   -msgstr "Estado:"
272   -
273   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:11
274   -msgid "City:"
275   -msgstr "Cidade:"
276   -
277   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:13
278   -msgid "Fantasy Name:"
279   -msgstr "Nome Fantasia:"
280   -
281   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:15
282   -msgid "Acronym:"
283   -msgstr "Sigla:"
284   -
285   -#: plugins/gov_user/views/profile/_institution_tab.html.erb:19
286   -msgid "SISP:"
287   -msgstr "SISP:"
288   -
289   -#: plugins/gov_user/views/ratings_extra_field.html.erb:2
290   -msgid "Organization name or Enterprise name"
291   -msgstr "Nome da organização ou empresa"
292   -
293   -#: plugins/gov_user/views/ratings_extra_field.html.erb:6
294   -#: plugins/gov_user/views/person_editor_extras.html.erb:21
295   -msgid "No institution found"
296   -msgstr "Nenhuma instituição encontrada"
297   -
298   -#: plugins/gov_user/views/person_editor_extras.html.erb:2
299   -msgid "Secondary e-mail"
300   -msgstr "Email secundário"
301   -
302   -#: plugins/gov_user/views/person_editor_extras.html.erb:22
303   -msgid "Add new institution"
304   -msgstr "Adicionar nova instituição"
305   -
306   -#: plugins/gov_user/views/person_editor_extras.html.erb:23
307   -msgid "Create new institution"
308   -msgstr "Criar nova instituição"
309   -
310   -#: plugins/gov_user/views/person_editor_extras.html.erb:39
311   -msgid "Should begin with a capital letter and no special characters"
312   -msgstr "Deve começar com letra maíscula e não conter caracteres especiais"
313   -
314   -#: plugins/gov_user/views/person_editor_extras.html.erb:40
315   -msgid "Email should have the following format: name@host.br"
316   -msgstr "Email deve ter o seguinte formato: name@host.br"
317   -
318   -#: plugins/gov_user/views/person_editor_extras.html.erb:41
319   -msgid "Site should have a valid format: http://name.hosts"
320   -msgstr "Site deve ter um formato válido: http://name.hosts"
321   -
322   -#: plugins/gov_user/views/person_editor_extras.html.erb:42
323   -msgid "If you work in a public agency use your government e-Mail"
324   -msgstr "Se você trabalha em uma agência pública use seu email governamental"
325   -
326   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:1
327   -msgid "New Institution"
328   -msgstr "Nova Instituição"
329   -
330   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:16
331   -msgid "\"<b>#{key_name.capitalize}</b> #{value.join()}\""
332   -msgstr "\"<b>#{key_name.capitalize}</b> #{value.join()}\""
333   -
334   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:115
335   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:119
336   -msgid "Cancel"
337   -msgstr "Cancelar"
338   -
339   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:121
340   -msgid "Could not send the form data to the server"
341   -msgstr "Não foi possível enviar os dados do formulário para o servidor"
342   -
343   -#: plugins/gov_user/views/gov_user_plugin/_institution.html.erb:128
344   -msgid "Creating institution"
345   -msgstr "Criar instituição"
346   -
347   -#: plugins/gov_user/views/search/institutions.html.erb:3
348   -msgid "Type words about the %s you're looking for"
349   -msgstr "Escreve palavras sobre o %s que você está procurando"
350   -
351   -#: plugins/gov_user/views/incomplete_registration.html.erb:3
352   -msgid "Complete Profile"
353   -msgstr "Complete o Perfil"
354   -
355   -#: plugins/gov_user/views/incomplete_registration.html.erb:6
356   -msgid "Complete your profile"
357   -msgstr "Complete seu perfil"
358   -
359   -#: plugins/gov_user/views/incomplete_registration.html.erb:7
360   -msgid "Hide"
361   -msgstr "Ocultar"
362   -
363   -#~ msgid "A plugin that does this and that."
364   -#~ msgstr "Um plugin que faz isso e aquilo"
365   -
366   -#~ msgid "The governamental email must be the primary one."
367   -#~ msgstr "O email governamental deve ser o principal"
368   -
369   -#~ msgid "Institution is obligatory if user has a government email."
370   -#~ msgstr "Instituição é obrigatória se o usuário tem email governamental."
public/app.js
... ... @@ -1,11 +0,0 @@
1   -(function() {
2   - 'use strict';
3   -
4   - var $ = modulejs.require('jquery');
5   - var Initializer = modulejs.require('Initializer');
6   -
7   -
8   - $(document).ready(function() {
9   - Initializer.init();
10   - });
11   -})();
public/initializer.js
... ... @@ -1,33 +0,0 @@
1   -(function() {
2   - 'use strict';
3   -
4   - var dependencies = [
5   - 'ControlPanel',
6   - 'CreateInstitution',
7   - 'CompleteRegistration',
8   - 'UserEditProfile',
9   - 'NewCommunity',
10   - 'GovUserCommentsExtraFields'
11   - ];
12   -
13   -
14   - modulejs.define('Initializer', dependencies, function() {
15   - var __dependencies = arguments;
16   -
17   -
18   - function call_dependency(dependency) {
19   - if( dependency.isCurrentPage() ) {
20   - dependency.init();
21   - }
22   - }
23   -
24   -
25   - return {
26   - init: function() {
27   - for(var i=0, len = __dependencies.length; i < len; i++) {
28   - call_dependency(__dependencies[i]);
29   - }
30   - }
31   - };
32   - });
33   -})();
public/lib/noosfero-root.js
... ... @@ -1,13 +0,0 @@
1   -modulejs.define('NoosferoRoot', function() {
2   - 'use strict';
3   -
4   -
5   - function url_with_subdirectory(url) {
6   - return noosfero_root() + url;
7   - }
8   -
9   -
10   - return {
11   - urlWithSubDirectory: url_with_subdirectory
12   - }
13   -});
public/lib/select-element.js
... ... @@ -1,35 +0,0 @@
1   -modulejs.define('SelectElement', function() {
2   - 'use strict';
3   -
4   -
5   - function SelectElement(name, id) {
6   - this.select = document.createElement("select");
7   - }
8   -
9   -
10   - SelectElement.prototype.setAttr = function(attr, value) {
11   - return this.select.setAttribute(attr, value);
12   - };
13   -
14   -
15   - SelectElement.prototype.addOption = function(option) {
16   - return this.select.add(option);
17   - };
18   -
19   -
20   - SelectElement.prototype.getSelect = function() {
21   - return this.select;
22   - };
23   -
24   -
25   - SelectElement.generateOption = function(value, text) {
26   - var option;
27   - option = document.createElement("option");
28   - option.setAttribute("value", value);
29   - option.text = text;
30   - return option;
31   - };
32   -
33   -
34   - return SelectElement;
35   -});
public/lib/select-field-choices.js
... ... @@ -1,81 +0,0 @@
1   -modulejs.define('SelectFieldChoices', ['jquery', 'SelectElement'], function($, SelectElement) {
2   - 'use strict';
3   -
4   -
5   - function SelectFieldChoices(state_id, city_id, state_url) {
6   - this.state_id = state_id;
7   - this.input_html = $(state_id).parent().html();
8   - this.old_value = $(state_id).val();
9   - this.city_parent_div = $(city_id).parent().parent().parent();
10   - this.state_url = state_url;
11   - }
12   -
13   -
14   - SelectFieldChoices.prototype.getCurrentStateElement = function() {
15   - return $(this.state_id);
16   - };
17   -
18   -
19   - SelectFieldChoices.prototype.replaceWith = function(html) {
20   - var parent_div = this.getCurrentStateElement().parent();
21   - parent_div.html(html);
22   - };
23   -
24   -
25   - SelectFieldChoices.prototype.generateSelect = function(state_list) {
26   - var select_element, option;
27   -
28   - select_element = new SelectElement();
29   - select_element.setAttr("name", "profile_data[state]");
30   - select_element.setAttr("id", "state_field");
31   - select_element.setAttr("class", "type-select valid");
32   -
33   - state_list.forEach(function(state) {
34   - option = SelectElement.generateOption(state, state);
35   - select_element.addOption(option);
36   - });
37   -
38   - return select_element.getSelect();
39   - };
40   -
41   -
42   - SelectFieldChoices.prototype.replaceStateWithSelectElement = function() {
43   - var klass = this;
44   -
45   - $.get(this.state_url, function(response) {
46   - var select_html;
47   -
48   - if (response.length > 0) {
49   - select_html = klass.generateSelect(response);
50   - klass.replaceWith(select_html);
51   -
52   - if (klass.old_value.length !== 0 && response.include(klass.old_value)) {
53   - klass.getCurrentStateElement().val(klass.old_value);
54   - }
55   - }
56   - });
57   - };
58   -
59   -
60   - SelectFieldChoices.prototype.replaceStateWithInputElement = function() {
61   - this.replaceWith(this.input_html);
62   - };
63   -
64   -
65   - SelectFieldChoices.prototype.hideCity = function() {
66   - this.city_parent_div.addClass("mpog_hidden_field");
67   - };
68   -
69   -
70   - SelectFieldChoices.prototype.showCity = function() {
71   - this.city_parent_div.removeClass("mpog_hidden_field");
72   - };
73   -
74   -
75   - SelectFieldChoices.prototype.actualFieldIsInput = function() {
76   - return this.getCurrentStateElement().attr("type") === "text";
77   - };
78   -
79   -
80   - return SelectFieldChoices;
81   -});
public/static/governmental_powers.txt
... ... @@ -1,4 +0,0 @@
1   -Executivo
2   -Legislativo
3   -Judiciário
4   -Não se aplica
public/static/governmental_sphere.txt
... ... @@ -1,4 +0,0 @@
1   -Federal
2   -Estadual
3   -Distrital
4   -Municipal
public/static/juridical_nature.txt
... ... @@ -1,8 +0,0 @@
1   -Administração Direta
2   -Autarquia
3   -Empresa Pública
4   -Fundação
5   -Orgão Autônomo
6   -Sociedade
7   -Sociedade Civil
8   -Sociedade de Economia Mista
public/style.css
... ... @@ -1,26 +0,0 @@
1   -#complete_registration {
2   - padding: 5px;
3   - width: 100%;
4   - background-color: #fff;
5   -}
6   -
7   -#complete_registration a {
8   - text-decoration: none;
9   -}
10   -
11   -#complete_registration a:hover {
12   - font-weight: bold;
13   -}
14   -
15   -#complete_registration_percentage {
16   - width: 100%;
17   - height: 20px;
18   - background: #fff;
19   - border: solid 1px #000;
20   -}
21   -
22   -.highlight-error {
23   - outline: none;
24   - border-color: #FF0000;
25   - box-shadow: 0 0 10px #FF0000;
26   -}
public/vendor/jquery.js
... ... @@ -1,3 +0,0 @@
1   -modulejs.define('jquery', function() {
2   - return jQuery;
3   -});
public/vendor/jquery.maskedinput.min.js
... ... @@ -1,7 +0,0 @@
1   -/*
2   - Masked Input plugin for jQuery
3   - Copyright (c) 2007-2013 Josh Bush (digitalbush.com)
4   - Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license)
5   - Version: 1.3.1
6   -*/
7   -(function(e){function t(){var e=document.createElement("input"),t="onpaste";return e.setAttribute(t,""),"function"==typeof e[t]?"paste":"input"}var n,a=t()+".mask",r=navigator.userAgent,i=/iphone/i.test(r),o=/android/i.test(r);e.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},dataName:"rawMaskFn",placeholder:"_"},e.fn.extend({caret:function(e,t){var n;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof e?(t="number"==typeof t?t:e,this.each(function(){this.setSelectionRange?this.setSelectionRange(e,t):this.createTextRange&&(n=this.createTextRange(),n.collapse(!0),n.moveEnd("character",t),n.moveStart("character",e),n.select())})):(this[0].setSelectionRange?(e=this[0].selectionStart,t=this[0].selectionEnd):document.selection&&document.selection.createRange&&(n=document.selection.createRange(),e=0-n.duplicate().moveStart("character",-1e5),t=e+n.text.length),{begin:e,end:t})},unmask:function(){return this.trigger("unmask")},mask:function(t,r){var c,l,s,u,f,h;return!t&&this.length>0?(c=e(this[0]),c.data(e.mask.dataName)()):(r=e.extend({placeholder:e.mask.placeholder,completed:null},r),l=e.mask.definitions,s=[],u=h=t.length,f=null,e.each(t.split(""),function(e,t){"?"==t?(h--,u=e):l[t]?(s.push(RegExp(l[t])),null===f&&(f=s.length-1)):s.push(null)}),this.trigger("unmask").each(function(){function c(e){for(;h>++e&&!s[e];);return e}function d(e){for(;--e>=0&&!s[e];);return e}function m(e,t){var n,a;if(!(0>e)){for(n=e,a=c(t);h>n;n++)if(s[n]){if(!(h>a&&s[n].test(R[a])))break;R[n]=R[a],R[a]=r.placeholder,a=c(a)}b(),x.caret(Math.max(f,e))}}function p(e){var t,n,a,i;for(t=e,n=r.placeholder;h>t;t++)if(s[t]){if(a=c(t),i=R[t],R[t]=n,!(h>a&&s[a].test(i)))break;n=i}}function g(e){var t,n,a,r=e.which;8===r||46===r||i&&127===r?(t=x.caret(),n=t.begin,a=t.end,0===a-n&&(n=46!==r?d(n):a=c(n-1),a=46===r?c(a):a),k(n,a),m(n,a-1),e.preventDefault()):27==r&&(x.val(S),x.caret(0,y()),e.preventDefault())}function v(t){var n,a,i,l=t.which,u=x.caret();t.ctrlKey||t.altKey||t.metaKey||32>l||l&&(0!==u.end-u.begin&&(k(u.begin,u.end),m(u.begin,u.end-1)),n=c(u.begin-1),h>n&&(a=String.fromCharCode(l),s[n].test(a)&&(p(n),R[n]=a,b(),i=c(n),o?setTimeout(e.proxy(e.fn.caret,x,i),0):x.caret(i),r.completed&&i>=h&&r.completed.call(x))),t.preventDefault())}function k(e,t){var n;for(n=e;t>n&&h>n;n++)s[n]&&(R[n]=r.placeholder)}function b(){x.val(R.join(""))}function y(e){var t,n,a=x.val(),i=-1;for(t=0,pos=0;h>t;t++)if(s[t]){for(R[t]=r.placeholder;pos++<a.length;)if(n=a.charAt(pos-1),s[t].test(n)){R[t]=n,i=t;break}if(pos>a.length)break}else R[t]===a.charAt(pos)&&t!==u&&(pos++,i=t);return e?b():u>i+1?(x.val(""),k(0,h)):(b(),x.val(x.val().substring(0,i+1))),u?t:f}var x=e(this),R=e.map(t.split(""),function(e){return"?"!=e?l[e]?r.placeholder:e:void 0}),S=x.val();x.data(e.mask.dataName,function(){return e.map(R,function(e,t){return s[t]&&e!=r.placeholder?e:null}).join("")}),x.attr("readonly")||x.one("unmask",function(){x.unbind(".mask").removeData(e.mask.dataName)}).bind("focus.mask",function(){clearTimeout(n);var e;S=x.val(),e=y(),n=setTimeout(function(){b(),e==t.length?x.caret(0,e):x.caret(e)},10)}).bind("blur.mask",function(){y(),x.val()!=S&&x.change()}).bind("keydown.mask",g).bind("keypress.mask",v).bind(a,function(){setTimeout(function(){var e=y(!0);x.caret(e),r.completed&&e==x.val().length&&r.completed.call(x)},0)}),y()}))}})})(jQuery);
8 0 \ No newline at end of file
public/vendor/modulejs-1.5.0.min.js
... ... @@ -1,2 +0,0 @@
1   -/* modulejs 1.5.0 - http://larsjung.de/modulejs/ */
2   -!function(n){this.modulejs=n()}(function(){"use strict";function n(n){return function(r){return l.toString.call(r)==="[object "+n+"]"}}function r(n){return n===new Object(n)}function t(n,r){return l.hasOwnProperty.call(n,r)}function e(n,r,e){if(p&&n.forEach===p)n.forEach(r,e);else if(n.length===+n.length)for(var i=0,o=n.length;o>i;i+=1)r.call(e,n[i],i,n);else for(var u in n)t(n,u)&&r.call(e,n[u],u,n)}function i(n,r){for(var t=0,e=n.length;e>t;t+=1)if(n[t]===r)return!0;return!1}function o(n){var r={},i=[];return e(n,function(n){t(r,n)||(i.push(n),r[n]=1)}),i}function u(n,r,t){if(n){var e=new Error("[modulejs-"+r+"] "+t);throw e.code=r,e}}function c(n,r,a){if(u(!h(n),31,'id must be a string "'+n+'"'),!r&&t(b,n))return b[n];var f=y[n];u(!f,32,'id not defined "'+n+'"'),a=(a||[]).slice(0),a.push(n);var s=[];if(e(f.deps,function(n){u(i(a,n),33,"circular dependencies: "+a+" & "+n),r?(s=s.concat(c(n,r,a)),s.push(n)):s.push(c(n,r,a))}),r)return o(s);var d=f.fn.apply(void 0,s);return b[n]=d,d}function a(n,t,e){void 0===e&&(e=t,t=[]),u(!h(n),11,'id must be a string "'+n+'"'),u(y[n],12,'id already defined "'+n+'"'),u(!g(t),13,'dependencies for "'+n+'" must be an array "'+t+'"'),u(!r(e)&&!v(e),14,'arg for "'+n+'" must be object or function "'+e+'"'),y[n]={id:n,deps:t,fn:v(e)?e:function(){return e}}}function f(n){return c(n)}function s(){var n={};return e(y,function(r,e){n[e]={deps:r.deps.slice(0),reqs:c(e,!0),init:t(b,e)}}),e(y,function(r,t){var o=[];e(y,function(r,e){i(n[e].reqs,t)&&o.push(e)}),n[t].reqd=o}),n}function d(n){var r="\n";return e(s(),function(t,e){var i=n?t.reqd:t.reqs;r+=(t.init?"* ":" ")+e+" -> [ "+i.join(", ")+" ]\n"}),r}var l=Object.prototype,p=Array.prototype.forEach,h=n("String"),v=n("Function"),g=Array.isArray||n("Array"),y={},b={};return{define:a,require:f,state:s,log:d,_private:{isString:h,isFunction:v,isArray:g,isObject:r,has:t,each:e,contains:i,uniq:o,err:u,definitions:y,instances:b,resolve:c}}});
3 0 \ No newline at end of file
public/views/complete-registration.js
... ... @@ -1,60 +0,0 @@
1   -modulejs.define('CompleteRegistration', ['jquery', 'NoosferoRoot'], function($, NoosferoRoot) {
2   - 'use strict';
3   -
4   -
5   - var AJAX_URL = {
6   - hide_registration_incomplete_percentage:
7   - NoosferoRoot.urlWithSubDirectory("/plugin/gov_user/hide_registration_incomplete_percentage")
8   - };
9   -
10   -
11   - function hide_incomplete_percentage(evt) {
12   - evt.preventDefault();
13   -
14   - jQuery.get(AJAX_URL.hide_registration_incomplete_percentage, {hide:true}, function(response){
15   - if( response === true ) {
16   - jQuery("#complete_registration").fadeOut();
17   - }
18   - });
19   - }
20   -
21   -
22   - function show_complete_progressbar() {
23   - var percentage = jQuery("#complete_registration_message span").html();
24   - var canvas_tag = document.getElementById("complete_registration_percentage");
25   -
26   - if( canvas_tag !== null ) {
27   - var context = canvas_tag.getContext("2d");
28   -
29   - percentage = canvas_tag.width*(percentage/100.0);
30   -
31   - context.beginPath();
32   - context.rect(0, 0, percentage, canvas_tag.height);
33   - context.fillStyle = '#00FF00';
34   - context.fill();
35   - }
36   - }
37   -
38   -
39   - function repositioning_bar_percentage() {
40   - var complete_message = $("#complete_registration").remove();
41   -
42   - $(".profile-info-options").before(complete_message);
43   - }
44   -
45   -
46   - return {
47   - isCurrentPage: function() {
48   - return $("#complete_registration").length === 1;
49   - },
50   -
51   -
52   - init: function() {
53   - repositioning_bar_percentage();
54   -
55   - jQuery(".hide-incomplete-percentage").click(hide_incomplete_percentage);
56   -
57   - show_complete_progressbar();
58   - }
59   - }
60   -});
public/views/control-panel.js
... ... @@ -1,32 +0,0 @@
1   -modulejs.define('ControlPanel', ['jquery'], function($) {
2   - 'use strict';
3   -
4   - function add_institution_on_control_panel(control_panel) {
5   - /*var institution_link = $(".control-panel-instituton-link").remove();
6   -
7   - if( institution_link.size() > 0 ) {
8   - control_panel.prepend(institution_link);
9   - }*/
10   - }
11   -
12   -
13   - function add_itens_on_controla_panel() {
14   - var control_panel = $(".control-panel");
15   -
16   - if( control_panel.size() > 0 ) {
17   - add_institution_on_control_panel(control_panel);
18   - }
19   - }
20   -
21   -
22   - return {
23   - isCurrentPage: function() {
24   - return $("#profile-editor-index").length === 1;
25   - },
26   -
27   -
28   - init: function() {
29   - add_itens_on_controla_panel();
30   - }
31   - }
32   -});
public/views/create-institution.js
... ... @@ -1,406 +0,0 @@
1   -modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'], function($, NoosferoRoot, SelectElement) {
2   - 'use strict';
3   -
4   - var AJAX_URL = {
5   - create_institution_modal:
6   - NoosferoRoot.urlWithSubDirectory("/plugin/gov_user/create_institution"),
7   - new_institution:
8   - NoosferoRoot.urlWithSubDirectory("/plugin/gov_user/new_institution"),
9   - institution_already_exists:
10   - NoosferoRoot.urlWithSubDirectory("/plugin/gov_user/institution_already_exists"),
11   - get_institutions:
12   - NoosferoRoot.urlWithSubDirectory("/plugin/gov_user/get_institutions"),
13   - auto_complete_city:
14   - NoosferoRoot.urlWithSubDirectory("/account/search_cities")
15   - };
16   -
17   -
18   - function open_create_institution_modal(evt) {
19   - evt.preventDefault();
20   -
21   - $.get(AJAX_URL.create_institution_modal, function(response){
22   - $("#institution_dialog").html(response);
23   -
24   - set_form_count_custom_data();
25   - set_events();
26   -
27   - $("#institution_dialog").dialog({
28   - modal: true,
29   - width: 500,
30   - height: 530,
31   - position: 'center',
32   - close: function() {
33   - $("#institution_dialog").html("");
34   - $('#institution_empty_ajax_message').switchClass("show-field", "hide-field");
35   - }
36   - });
37   - });
38   - }
39   -
40   -
41   - function show_public_institutions_fields() {
42   - $(".public-institutions-fields").show();
43   - }
44   -
45   -
46   - function show_private_institutions_fields() {
47   - $(".public-institutions-fields").hide();
48   - $("#institutions_governmental_power option").selected(0);
49   - $("#institutions_governmental_sphere option").selected(0);
50   - }
51   -
52   -
53   - function get_comunity_post_data() {
54   - return {
55   - name : $("#community_name").val(),
56   - country : $("#community_country").val(),
57   - state : $("#community_state").val(),
58   - city : $("#community_city").val()
59   - };
60   - }
61   -
62   -
63   - function get_institution_post_data() {
64   - return {
65   - cnpj: $("#institutions_cnpj").val(),
66   - type: $("input[name='institutions[type]']:checked").val(),
67   - acronym : $("#institutions_acronym").val(),
68   - governmental_power: $("#institutions_governmental_power").selected().val(),
69   - governmental_sphere: $("#institutions_governmental_sphere").selected().val(),
70   - juridical_nature: $("#institutions_juridical_nature").selected().val(),
71   - corporate_name: $("#institutions_corporate_name").val()
72   - };
73   - }
74   -
75   -
76   - function get_post_data() {
77   - var post_data = {};
78   -
79   - post_data.community = get_comunity_post_data();
80   - post_data.institutions = get_institution_post_data();
81   -
82   - return post_data;
83   - }
84   -
85   -
86   - function success_ajax_response(response) {
87   - close_loading();
88   -
89   - if(response.success){
90   - var institution_name = response.institution_data.name;
91   - var institution_id = response.institution_data.id;
92   -
93   - $("#institution_dialog").html("<div class='errorExplanation'><h2>"+response.message+"</h2></div>");
94   - $("#create_institution_errors").switchClass("show-field", "hide-field");
95   -
96   - $(".institution_container").append(get_clone_institution_data(institution_id));
97   - add_selected_institution_to_list(institution_id, institution_name);
98   -
99   - $(".remove-institution").click(remove_institution);
100   - } else {
101   - var errors = create_error_list(response);
102   - $("#create_institution_errors").switchClass("hide-field", "show-field").html("<h2>"+response.message+"</h2>"+errors);
103   -
104   - show_errors_in_each_field(response.errors);
105   - }
106   - }
107   -
108   - function create_error_list(response){
109   - var errors = "<ul>";
110   - var field_name;
111   -
112   - for(var error_key in response.errors) {
113   - field_name = adjust_error_key(error_key);
114   -
115   - if(response.errors[error_key].length > 0){
116   - errors += "<li><b>"+field_name+"</b>: "+response.errors[error_key]+"</li>";
117   - }
118   - }
119   -
120   - errors += "</ul>";
121   - return errors;
122   - }
123   -
124   -
125   - function show_errors_in_each_field(errors) {
126   - var error_keys = Object.keys(errors);
127   -
128   - // (field)|(field)|...
129   - var verify_error = new RegExp("(\\[" + error_keys.join("\\])|(\\[") + "\\])" );
130   -
131   - var fields_with_errors = $("#institution_dialog .formfield input").filter(function(index, field) {
132   - $(field).removeClass("highlight-error");
133   - return verify_error.test(field.getAttribute("name"));
134   - });
135   -
136   - var selects_with_errors = $("#institution_dialog .formfield select").filter(function(index, field) {
137   - $(field).removeClass("highlight-error");
138   - return verify_error.test(field.getAttribute("name"));
139   - });
140   -
141   - fields_with_errors.addClass("highlight-error");
142   - selects_with_errors.addClass("highlight-error");
143   - }
144   -
145   -
146   - function adjust_error_key(error_key) {
147   - var text = error_key.replace(/_/, " ");
148   - text = text.charAt(0).toUpperCase() + text.slice(1);
149   -
150   - return text;
151   - }
152   -
153   -
154   - function save_institution(evt) {
155   - evt.preventDefault();
156   -
157   - open_loading($("#loading_message").val());
158   - $.ajax({
159   - url: AJAX_URL.new_institution,
160   - data : get_post_data(),
161   - type: "POST",
162   - success: success_ajax_response,
163   - error: function() {
164   - close_loading();
165   - var error_message = $("#institution_error_message").val();
166   - $("#create_institution_errors").switchClass("hide-field", "show-field").html("<h2>"+error_message+"</h2>");
167   - }
168   - });
169   - }
170   -
171   - function cancel_institution(evt){
172   - evt.preventDefault();
173   - $('#institution_dialog').dialog('close');
174   - }
175   -
176   -
177   - function institution_already_exists(){
178   - if( this.value.length >= 3 ) {
179   - $.get(AJAX_URL.institution_already_exists, {name:this.value}, function(response){
180   - if( response === true ) {
181   - $("#already_exists_text").switchClass("hide-field", "show-field");
182   - } else {
183   - $("#already_exists_text").switchClass("show-field", "hide-field");
184   - }
185   - });
186   - }
187   - }
188   -
189   -
190   - function get_clone_institution_data(value) {
191   - var user_institutions = $(".user_institutions").first().clone();
192   - user_institutions.val(value);
193   -
194   - return user_institutions;
195   - }
196   -
197   -
198   - function institution_autocomplete() {
199   - $("#input_institution").autocomplete({
200   - source : function(request, response){
201   - $.ajax({
202   - type: "GET",
203   - url: AJAX_URL.get_institutions,
204   - data: {query: request.term},
205   - success: function(result){
206   - response(result);
207   -
208   - if( result.length === 0 ) {
209   - $('#institution_empty_ajax_message').switchClass("hide-field", "show-field");
210   - } else {
211   - $('#institution_empty_ajax_message').switchClass("show-field", "hide-field");
212   - }
213   - },
214   - error: function(ajax, stat, errorThrown) {
215   - console.log('Link not found : ' + errorThrown);
216   - }
217   - });
218   - },
219   -
220   - minLength: 2,
221   -
222   - select : function (event, selected) {
223   - $("#institution_selected").val(selected.item.id).attr("data-name", selected.item.label);
224   - }
225   - });
226   - }
227   -
228   -
229   - function add_selected_institution_to_list(id, name) {
230   - var selected_institution = "<li data-institution='"+id+"'>"+name;
231   - selected_institution += "<a href='#' class='button without-text icon-remove remove-institution'></a></li>";
232   -
233   - $(".institutions_added").append(selected_institution);
234   - }
235   -
236   -
237   - function add_new_institution(evt) {
238   - evt.preventDefault();
239   - var selected = $("#institution_selected");
240   - var institution_already_added = $(".institutions_added li[data-institution='"+selected.val()+"']").length;
241   -
242   - if(selected.val().length > 0 && institution_already_added === 0) {
243   - //field that send the institutions to the server
244   - $(".institution_container").append(get_clone_institution_data(selected.val()));
245   -
246   - // Visualy add the selected institution to the list
247   - add_selected_institution_to_list(selected.val(), selected.attr("data-name"));
248   -
249   - // clean the institution flag
250   - selected.val("").attr("data-name", "");
251   - $("#input_institution").val("");
252   -
253   - $(".remove-institution").click(remove_institution);
254   - }
255   - }
256   -
257   -
258   - function remove_institution(evt) {
259   - evt.preventDefault();
260   - var code = $(this).parent().attr("data-institution");
261   -
262   - $(".user_institutions[value="+code+"]").remove();
263   - $(this).parent().remove();
264   - }
265   -
266   -
267   - function add_mask_to_form_items() {
268   - if ($.mask) {
269   - $("#institutions_cnpj").mask("99.999.999/9999-99");
270   - }
271   - }
272   -
273   -
274   - function show_hide_cnpj_city(country) {
275   - var cnpj = $("#institutions_cnpj").parent().parent();
276   - var city = $("#community_city").parent().parent();
277   - var state = $("#community_state").parent().parent();
278   - var inst_type = $("input[name='institutions[type]']:checked").val();
279   - institution_type_actions(inst_type);
280   -
281   - if( country === "-1" ) $("#community_country").val("BR");
282   -
283   - if( country !== "BR" ) {
284   - cnpj.hide();
285   - city.hide();
286   - state.hide();
287   - } else {
288   - cnpj.show();
289   - city.show();
290   - state.show();
291   - }
292   - }
293   -
294   - function institution_type_actions(type) {
295   - var country = $("#community_country").val();
296   - if( type === "PublicInstitution" && country == "BR") {
297   - show_public_institutions_fields();
298   - } else {
299   - show_private_institutions_fields();
300   - }
301   - }
302   -
303   -
304   - function set_form_count_custom_data() {
305   - var divisor_option = SelectElement.generateOption("-1", "--------------------------------");
306   - var default_option = SelectElement.generateOption("BR", "Brazil");
307   -
308   -
309   - var inst_type = $("input[name='institutions[type]']:checked").val();
310   - var country = $("#community_country").val();
311   -
312   - institution_type_actions(inst_type);
313   - show_hide_cnpj_city(country);
314   -
315   - if( $('#community_country').find("option[value='']").length === 1 ) {
316   - $('#community_country').find("option[value='']").remove();
317   - $('#community_country').prepend(divisor_option);
318   - $('#community_country').prepend(default_option);
319   -
320   - if($("#edit_institution_page").val() === "false") {
321   - $('#community_country').val("BR");
322   - show_hide_cnpj_city($('#community_country').val());
323   - }
324   - }
325   - }
326   -
327   - function autoCompleteCity() {
328   - var country_selected = $('#community_country').val();
329   -
330   - if(country_selected == "BR") {
331   - $('#community_city').autocomplete({
332   - source : function(request, response){
333   - $.ajax({
334   - type: "GET",
335   - url: AJAX_URL.auto_complete_city,
336   - data: {city_name: request.term, state_name: $("#community_state").val()},
337   - success: function(result){
338   - response(result);
339   -
340   - // There are two autocompletes in this page, the last one is modal
341   - // autocomplete just put it above the modal
342   - $(".ui-autocomplete").last().css("z-index", 1000);
343   - },
344   - error: function(ajax, stat, errorThrown) {
345   - console.log('Link not found : ' + errorThrown);
346   - }
347   - });
348   - },
349   -
350   - minLength: 3
351   - });
352   - } else {
353   - if ($('#community_city').data('autocomplete')) {
354   - $('#community_city').autocomplete("destroy");
355   - $('#community_city').removeData('autocomplete');
356   - }
357   - }
358   - }
359   -
360   - function set_events() {
361   - $("#create_institution_link").click(open_create_institution_modal);
362   -
363   - $("input[name='institutions[type]']").click(function(){
364   - institution_type_actions(this.value);
365   - });
366   -
367   - $('#save_institution_button').click(save_institution);
368   - $('#cancel_institution_button').click(cancel_institution);
369   -
370   - $("#community_name").keyup(institution_already_exists);
371   -
372   - $("#add_new_institution").click(add_new_institution);
373   -
374   - $(".remove-institution").click(remove_institution);
375   -
376   - $("#community_country").change(function(){
377   - show_hide_cnpj_city(this.value);
378   - });
379   -
380   - add_mask_to_form_items();
381   -
382   - institution_autocomplete();
383   -
384   - autoCompleteCity();
385   - $('#community_country').change(function(){
386   - autoCompleteCity();
387   - });
388   - }
389   -
390   -
391   - return {
392   - isCurrentPage: function() {
393   - return $("#institution_form").length === 1;
394   - },
395   -
396   -
397   - init: function() {
398   - set_form_count_custom_data();
399   - set_events();
400   - },
401   -
402   - institution_autocomplete: function(){
403   - institution_autocomplete();
404   - }
405   - };
406   -});
public/views/gov-user-comments-extra-fields.js
... ... @@ -1,26 +0,0 @@
1   -modulejs.define("GovUserCommentsExtraFields", ['jquery','CreateInstitution'], function($,CreateInstitution) {
2   -
3   - function set_events() {
4   - CreateInstitution.institution_autocomplete();
5   - }
6   -
7   -
8   - function prepend_to_additional_information() {
9   - var institution_comments = $("#input_institution_comments").remove();
10   -
11   - $(".comments-software-extra-fields").prepend(institution_comments);
12   - }
13   -
14   -
15   - return {
16   - isCurrentPage: function() {
17   - return $(".star-rate-form").length === 1;
18   - },
19   -
20   - init: function() {
21   - prepend_to_additional_information();
22   - set_events();
23   - }
24   - }
25   -
26   -})
public/views/new-community.js
... ... @@ -1,28 +0,0 @@
1   -modulejs.define("NewCommunity", ['jquery'], function($) {
2   -
3   - function replace_mandatory_message() {
4   - $(".required-field").first()
5   - .replaceWith("<span class='required-field'> Os campos em destaque<label class='pseudoformlabel'> (*)</label> são obrigatórios. </span>");
6   - }
7   -
8   - function remove_image_builder_text() {
9   - $("label:contains('Image builder')").hide();
10   - }
11   -
12   - function hide_organization_template_fields(){
13   - $('#template-options').hide();
14   - }
15   -
16   - return {
17   -
18   - isCurrentPage: function() {
19   - return true;
20   - },
21   -
22   - init: function() {
23   - replace_mandatory_message();
24   - remove_image_builder_text();
25   - hide_organization_template_fields();
26   - }
27   - }
28   -})
public/views/user-edit-profile.js
... ... @@ -1,216 +0,0 @@
1   -modulejs.define('UserEditProfile', ['jquery', 'SelectElement', 'SelectFieldChoices', 'CreateInstitution'], function($, SelectElement, SelectFieldChoices, CreateInstitution) {
2   - 'use strict';
3   -
4   - function set_form_count_custom_data() {
5   - var divisor_option = SelectElement.generateOption("-1", "--------------------------------");
6   - var default_option = SelectElement.generateOption("BR", "Brazil");
7   -
8   - $('#profile_data_country').find("option[value='']").remove();
9   - $('#profile_data_country').prepend(divisor_option);
10   - $('#profile_data_country').prepend(default_option);
11   - $('#profile_data_country').val("BR");
12   - }
13   -
14   -
15   - function set_initial_form_custom_data(selectFieldChoices) {
16   - set_form_count_custom_data();
17   -
18   - $("#password-balloon").html($("#user_password_menssage").val());
19   - $("#profile_data_email").parent().append($("#email_public_message").remove());
20   -
21   - if( $("#state_field").length !== 0 ) selectFieldChoices.replaceStateWithSelectElement();
22   - }
23   -
24   -
25   - function show_state_if_country_is_brazil() {
26   - var selectFieldChoices = new SelectFieldChoices("#state_field", "#city_field", "/plugin/gov_user/get_brazil_states");
27   - set_initial_form_custom_data(selectFieldChoices);
28   -
29   - $("#profile_data_country").change(function(){
30   - if( this.value === "-1" ) $(this).val("BR");
31   -
32   - if( this.value === "BR" && selectFieldChoices.actualFieldIsInput() ) {
33   - selectFieldChoices.replaceStateWithSelectElement();
34   - selectFieldChoices.showCity();
35   - } else if( this.value !== "BR" && !selectFieldChoices.actualFieldIsInput() ) {
36   - selectFieldChoices.replaceStateWithInputElement();
37   - selectFieldChoices.hideCity();
38   - }
39   - });
40   - }
41   -
42   -
43   - function show_or_hide_phone_mask() {
44   - if($("#profile_data_country").val() === "BR") {
45   - if( (typeof $("#profile_data_cell_phone").data("rawMaskFn") === 'undefined') ) {
46   - // $("#profile_data_cell_phone").mask("(99) 9999?9-9999");
47   - // $("#profile_data_comercial_phone").mask("(99) 9999?9-9999");
48   - // $("#profile_data_contact_phone").mask("(99) 9999?9-9999");
49   - }
50   - } else {
51   - // $("#profile_data_cell_phone").unmask();
52   - // $("#profile_data_comercial_phone").unmask();
53   - // $("#profile_data_contact_phone").unmask();
54   - }
55   - }
56   -
57   -
58   - function fix_phone_mask_format(id) {
59   - $(id).blur(function() {
60   - var last = $(this).val().substr( $(this).val().indexOf("-") + 1 );
61   -
62   - if( last.length === 3 ) {
63   - var move = $(this).val().substr( $(this).val().indexOf("-") - 1, 1 );
64   - var lastfour = move + last;
65   - var first = $(this).val().substr( 0, 9 );
66   -
67   - $(this).val( first + '-' + lastfour );
68   - }
69   - });
70   - }
71   -
72   -
73   - function show_plugin_error_message(field_selector, hidden_message_id ) {
74   - var field = $(field_selector);
75   -
76   - field.removeClass("validated").addClass("invalid");
77   -
78   - if(!$("." + hidden_message_id)[0]) {
79   - var message = $("#" + hidden_message_id).val();
80   - field.parent().append("<div class='" + hidden_message_id + " errorExplanation'>"+message+"</span>");
81   - } else {
82   - $("." + hidden_message_id).show();
83   - }
84   - }
85   -
86   -
87   - function hide_plugin_error_message(field_selector, hidden_message_id) {
88   - $(field_selector).removeClass("invalid").addClass("validated");
89   - $("." + hidden_message_id).hide();
90   - }
91   -
92   -
93   - function add_blur_fields(field_selector, hidden_message_id, validation_function, allow_blank) {
94   - $(field_selector).blur(function(){
95   - $(this).attr("class", "");
96   -
97   - if( validation_function(this.value, !!allow_blank) ) {
98   - show_plugin_error_message(field_selector, hidden_message_id);
99   - } else {
100   - hide_plugin_error_message(field_selector, hidden_message_id);
101   - }
102   - });
103   - }
104   -
105   -
106   - function invalid_email_validation(value, allow_blank) {
107   - if( allow_blank && value.trim().length === 0 ) {
108   - return false;
109   - }
110   -
111   - var correct_format_regex = new RegExp(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/);
112   -
113   - return !correct_format_regex.test(value);
114   - }
115   -
116   -
117   - function invalid_site_validation(value) {
118   - var correct_format_regex = new RegExp(/(^|)(http[s]{0,1})\:\/\/(\w+[.])\w+/g);
119   -
120   - return !correct_format_regex.test(value);
121   - }
122   -
123   -
124   - function get_privacy_selector_parent_div(field_id, actual) {
125   - if( actual === undefined ) actual = $(field_id);
126   -
127   - if( actual.is("form") || actual.length === 0 ) return null; // Not allow recursion over form
128   -
129   - if( actual.hasClass("field-with-privacy-selector") ) {
130   - return actual;
131   - } else {
132   - return get_privacy_selector_parent_div(field_id, actual.parent());
133   - }
134   - }
135   -
136   -
137   - function try_to_remove(list, field) {
138   - try {
139   - list.push(field.remove());
140   - } catch(e) {
141   - console.log("Cound not remove field");
142   - }
143   - }
144   -
145   -
146   - function get_edit_fields_in_insertion_order() {
147   - var containers = [];
148   -
149   - try_to_remove(containers, get_privacy_selector_parent_div("#city_field"));
150   - try_to_remove(containers, get_privacy_selector_parent_div("#state_field"));
151   - try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_country"));
152   - try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_birth_date"));
153   - try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_organization_website"));
154   - try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_personal_website"));
155   - try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_comercial_phone"));
156   - try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_contact_phone"));
157   - try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_cell_phone"));
158   - try_to_remove(containers, $("#select_institution"));
159   - try_to_remove(containers, $("#user_secondary_email").parent().parent());
160   - try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_email"));
161   - try_to_remove(containers, get_privacy_selector_parent_div("#profile_data_name"));
162   - try_to_remove(containers, $(".pseudoformlabel").parent().parent());
163   - try_to_remove(containers, $("h2")[0]);
164   -
165   - return containers;
166   - }
167   -
168   -
169   - function change_edit_fields_order() {
170   - var form = $("#profile-data");
171   -
172   - if( form.length !== 0 ) {
173   - var containers = get_edit_fields_in_insertion_order();
174   -
175   - containers.forEach(function(container){
176   - form.prepend(container);
177   - });
178   - }
179   - }
180   -
181   -
182   - function set_fields_validations() {
183   - $("#profile_data_country").blur(show_or_hide_phone_mask);
184   -
185   - // $("#profile_data_birth_date").mask("99/99/9999");
186   -
187   - fix_phone_mask_format("#profile_data_cell_phone");
188   - fix_phone_mask_format("#profile_data_comercial_phone");
189   - fix_phone_mask_format("#profile_data_contact_phone");
190   -
191   - add_blur_fields("#profile_data_email", "email_error", invalid_email_validation);
192   - add_blur_fields("#user_secondary_email", "email_error", invalid_email_validation, true);
193   - add_blur_fields("#profile_data_personal_website", "site_error", invalid_site_validation);
194   - add_blur_fields("#profile_data_organization_website", "site_error", invalid_site_validation);
195   - }
196   -
197   -
198   - return {
199   - isCurrentPage: function() {
200   - return $('#profile_data_email').length === 1;
201   - },
202   -
203   -
204   - init: function() {
205   - change_edit_fields_order(); // To change the fields order, it MUST be the first function executed
206   -
207   - show_state_if_country_is_brazil();
208   -
209   - show_or_hide_phone_mask();
210   -
211   - set_fields_validations();
212   -
213   - CreateInstitution.init();
214   - }
215   - }
216   -});
src/gov_user/.gitignore 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +*.swp
  2 +
... ...
src/gov_user/controllers/gov_user_plugin_controller.rb 0 → 100644
... ... @@ -0,0 +1,251 @@
  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 + @governmental_sphere = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}
  19 + @governmental_power = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}
  20 + @juridical_nature = [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}
  21 + @state_options = [[_('Select a state'), '-1']] | @state_list.collect {|state| [state.name, state.name]}
  22 +
  23 + params[:community] ||= {}
  24 + params[:institutions] ||= {}
  25 +
  26 + if request.xhr?
  27 + render :layout=>false
  28 + else
  29 + redirect_to "/"
  30 + end
  31 + end
  32 +
  33 + def split_http_referer http_referer
  34 + split_list = []
  35 + split_list = http_referer.split("/")
  36 + @url_token = split_list.last
  37 + return @url_token
  38 + end
  39 +
  40 + def create_institution_admin
  41 + @show_sisp_field = environment.admins.include?(current_user.person)
  42 + @state_list = get_state_list()
  43 + @governmental_sphere = [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}
  44 + @governmental_power = [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}
  45 + @juridical_nature = [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}
  46 + @state_options = [[_('Select a state'), '-1']] | @state_list.collect {|state| [state.name, state.name]}
  47 +
  48 + @url_token = split_http_referer request.original_url()
  49 +
  50 + params[:community] ||= {}
  51 + params[:institutions] ||= {}
  52 +
  53 + end
  54 +
  55 + def new_institution
  56 + redirect_to "/" if params[:community].blank? || params[:institutions].blank?
  57 +
  58 + response_message = {}
  59 +
  60 + institution_template = Community["institution"]
  61 + add_template_in_params institution_template
  62 +
  63 + @institutions = private_create_institution
  64 + add_environment_admins_to_institution @institutions
  65 +
  66 + response_message = save_institution @institutions
  67 +
  68 + if request.xhr? #User create institution
  69 + render :json => response_message.to_json
  70 + else #Admin create institution
  71 + session[:notice] = response_message[:message] # consume the notice
  72 +
  73 + redirect_depending_on_institution_creation response_message
  74 + end
  75 + end
  76 +
  77 + def institution_already_exists
  78 + redirect_to "/" if !request.xhr? || params[:name].blank?
  79 +
  80 + already_exists = !Community.where(:name=>params[:name]).empty?
  81 +
  82 + render :json=>already_exists.to_json
  83 + end
  84 +
  85 + def get_institutions
  86 + redirect_to "/" if !request.xhr? || params[:query].blank?
  87 +
  88 + list = Institution.search_institution(params[:query]).map{ |institution|
  89 + {:value=>institution.name, :id=>institution.id}
  90 + }
  91 +
  92 + render :json => list.to_json
  93 + end
  94 +
  95 + def get_brazil_states
  96 + redirect_to "/" unless request.xhr?
  97 +
  98 + state_list = get_state_list()
  99 + render :json=>state_list.collect {|state| state.name }.to_json
  100 + end
  101 +
  102 + def get_field_data
  103 + condition = !request.xhr? || params[:query].nil? || params[:field].nil?
  104 + return render :json=>{} if condition
  105 +
  106 + model = get_model_by_params_field
  107 +
  108 + data = model.where("name ILIKE ?", "%#{params[:query]}%").select("id, name")
  109 + .collect { |db|
  110 + {:id=>db.id, :label=>db.name}
  111 + }
  112 +
  113 + other = [model.select("id, name").last].collect { |db|
  114 + {:id=>db.id, :label=>db.name}
  115 + }
  116 +
  117 + # Always has other in the list
  118 + data |= other
  119 +
  120 + render :json=> data
  121 + end
  122 +
  123 + protected
  124 +
  125 + def get_model_by_params_field
  126 + case params[:field]
  127 + when "software_language"
  128 + return ProgrammingLanguage
  129 + else
  130 + return DatabaseDescription
  131 + end
  132 + end
  133 +
  134 + def get_state_list
  135 + NationalRegion.find(
  136 + :all,
  137 + :conditions=>["national_region_type_id = ?", 2],
  138 + :order=>"name"
  139 + )
  140 + end
  141 +
  142 + def set_institution_type
  143 + institution_params = params[:institutions].except(:governmental_power,
  144 + :governmental_sphere,
  145 + :juridical_nature
  146 + )
  147 + if params[:institutions][:type] == "PublicInstitution"
  148 + PublicInstitution::new institution_params
  149 + else
  150 + PrivateInstitution::new institution_params
  151 + end
  152 + end
  153 +
  154 + def set_public_institution_fields institution
  155 + inst_fields = params[:institutions]
  156 +
  157 + begin
  158 + gov_power = GovernmentalPower.find inst_fields[:governmental_power]
  159 + gov_sphere = GovernmentalSphere.find inst_fields[:governmental_sphere]
  160 + jur_nature = JuridicalNature.find inst_fields[:juridical_nature]
  161 +
  162 + institution.juridical_nature = jur_nature
  163 + institution.governmental_power = gov_power
  164 + institution.governmental_sphere = gov_sphere
  165 + rescue
  166 + institution.errors.add(
  167 + :governmental_fields,
  168 + _("Could not find Governmental Power or Governmental Sphere")
  169 + )
  170 + end
  171 + end
  172 +
  173 + def private_create_institution
  174 + community = Community.new(params[:community])
  175 + community.environment = environment
  176 + institution = set_institution_type
  177 +
  178 + institution.name = community[:name]
  179 + institution.community = community
  180 +
  181 + if institution.type == "PublicInstitution"
  182 + set_public_institution_fields institution
  183 + end
  184 +
  185 + institution.date_modification = DateTime.now
  186 + institution.save
  187 + institution
  188 + end
  189 +
  190 + def add_template_in_params institution_template
  191 + com_fields = params[:community]
  192 + if !institution_template.blank? && institution_template.is_template
  193 + com_fields[:template_id]= institution_template.id unless com_fields.blank?
  194 + end
  195 + end
  196 +
  197 + def add_environment_admins_to_institution institution
  198 + edit_page = params[:edit_institution_page] == false
  199 + if environment.admins.include?(current_user.person) && edit_page
  200 + environment.admins.each do |adm|
  201 + institution.community.add_admin(adm)
  202 + end
  203 + end
  204 + end
  205 +
  206 + def save_institution institution
  207 + inst_errors = institution.errors.messages
  208 + com_errors = institution.community.errors.messages
  209 +
  210 + set_errors institution
  211 +
  212 + if inst_errors.empty? && com_errors.empty? && institution.valid? && institution.save
  213 + { :success => true,
  214 + :message => _("Institution successful created!"),
  215 + :institution_data => {:name=>institution.name, :id=>institution.id}
  216 + }
  217 + else
  218 + { :success => false,
  219 + :message => _("Institution could not be created!"),
  220 + :errors => inst_errors.merge(com_errors)
  221 + }
  222 + end
  223 + end
  224 +
  225 + def redirect_depending_on_institution_creation response_message
  226 + if response_message[:success]
  227 + redirect_to :controller => "/admin_panel", :action => "index"
  228 + else
  229 + flash[:errors] = response_message[:errors]
  230 +
  231 + redirect_to :controller => "gov_user_plugin", :action => "create_institution_admin", :params => params
  232 + end
  233 + end
  234 +
  235 + def set_errors institution
  236 + institution.valid? if institution
  237 + institution.community.valid? if institution.community
  238 +
  239 + flash[:error_community_name] = institution.community.errors.include?(:name) ? "highlight-error" : ""
  240 + flash[:error_community_country] = institution.errors.include?(:country) ? "highlight-error" : ""
  241 + flash[:error_community_state] = institution.errors.include?(:state) ? "highlight-error" : ""
  242 + flash[:error_community_city] = institution.errors.include?(:city) ? "highlight-error" : ""
  243 + flash[:error_institution_corporate_name] = institution.errors.include?(:corporate_name) ? "highlight-error" : ""
  244 + flash[:error_institution_cnpj] = institution.errors.include?(:cnpj) ? "highlight-error" : ""
  245 + flash[:error_institution_governmental_sphere] = institution.errors.include?(:governmental_sphere) ? "highlight-error" : ""
  246 + flash[:error_institution_governmental_power] = institution.errors.include?(:governmental_power) ? "highlight-error" : ""
  247 + flash[:error_institution_juridical_nature] = institution.errors.include?(:juridical_nature) ? "highlight-error" : ""
  248 + flash[:error_institution_sisp] = institution.errors.include?(:sisp) ? "highlight-error" : ""
  249 + end
  250 +
  251 +end
... ...
src/gov_user/controllers/gov_user_plugin_myprofile_controller.rb 0 → 100644
... ... @@ -0,0 +1,50 @@
  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(
  10 + :all,
  11 + :conditions => { :national_region_type_id => 2 },
  12 + :order => 'name'
  13 + )
  14 + @institution = @profile.institution
  15 + update_institution if request.post?
  16 + end
  17 +
  18 + private
  19 +
  20 + def update_institution
  21 + @institution.community.update_attributes(params[:community])
  22 + @institution.update_attributes(params[:institutions].except(:governmental_power, :governmental_sphere, :juridical_nature))
  23 + if @institution.type == "PublicInstitution"
  24 + begin
  25 + governmental_updates
  26 + rescue
  27 + @institution.errors.add(:governmental_fields,
  28 + _("Could not find Governmental Power or Governmental Sphere"))
  29 + end
  30 + end
  31 + if @institution.valid?
  32 + redirect_to :controller => 'profile_editor', :action => 'index', :profile => profile.identifier
  33 + else
  34 + flash[:errors] = @institution.errors.full_messages
  35 + end
  36 + end
  37 +
  38 + def governmental_updates
  39 + gov_power = GovernmentalPower.find params[:institutions][:governmental_power]
  40 + gov_sphere = GovernmentalSphere.find params[:institutions][:governmental_sphere]
  41 + jur_nature = JuridicalNature.find params[:institutions][:juridical_nature]
  42 +
  43 + @institution.juridical_nature = jur_nature
  44 + @institution.governmental_power = gov_power
  45 + @institution.governmental_sphere = gov_sphere
  46 + @institution.save
  47 + end
  48 +
  49 +
  50 +end
... ...
src/gov_user/db/migrate/20140528193816_add_extra_fields_to_user.rb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +class AddExtraFieldsToUser < ActiveRecord::Migration
  2 + def self.up
  3 + change_table :users do |t|
  4 + t.string :secondary_email
  5 + t.references :institution
  6 + t.string :role
  7 + end
  8 + end
  9 +
  10 + def self.down
  11 + change_table :users do |t|
  12 + t.remove :secondary_email
  13 + t.remove_references :institution
  14 + t.remove :role
  15 + end
  16 + end
  17 +end
... ...
src/gov_user/db/migrate/20140528193835_create_institutions_table.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +class CreateInstitutionsTable < ActiveRecord::Migration
  2 + def self.up
  3 + create_table :institutions do |t|
  4 + t.string :name
  5 +
  6 + t.timestamps
  7 + end
  8 + end
  9 +
  10 + def self.down
  11 + drop_table :institutions
  12 + end
  13 +end
... ...
src/gov_user/db/migrate/20140617125143_add_new_fields_institution.rb 0 → 100644
... ... @@ -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
... ...
src/gov_user/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
... ...
src/gov_user/db/migrate/20140617132451_create_governmental_powers.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class CreateGovernmentalPowers < ActiveRecord::Migration
  2 + def change
  3 + create_table :governmental_powers do |t|
  4 + t.string :name
  5 +
  6 + t.timestamps
  7 + end
  8 + end
  9 +end
... ...
src/gov_user/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
... ...
src/gov_user/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
... ...
src/gov_user/db/migrate/20140812143218_remove_field_role_from_user.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +class RemoveFieldRoleFromUser < ActiveRecord::Migration
  2 + def up
  3 + change_table :users do |t|
  4 + t.remove :role
  5 + end
  6 + end
  7 +
  8 + def down
  9 + change_table :users do |t|
  10 + t.string :role
  11 + end
  12 + end
  13 +end
... ...
src/gov_user/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
... ...
src/gov_user/db/migrate/20140814131606_create_juridical_natures_table.rb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +class CreateJuridicalNaturesTable < ActiveRecord::Migration
  2 + def up
  3 + create_table :juridical_natures do |t|
  4 + t.string :name
  5 + end
  6 + end
  7 +
  8 + def down
  9 + drop_table :juridical_natures
  10 + end
  11 +end
... ...
src/gov_user/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
... ...
src/gov_user/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
... ...
src/gov_user/db/migrate/20140818195821_remove_institution_from_user.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class RemoveInstitutionFromUser < ActiveRecord::Migration
  2 + def up
  3 + remove_column :users, :institution_id
  4 + end
  5 +
  6 + def down
  7 + add_column :users, :institution_id
  8 + end
  9 +end
... ...
src/gov_user/db/migrate/20140818200738_create_institution_user_relation_table.rb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +class CreateInstitutionUserRelationTable < ActiveRecord::Migration
  2 + def up
  3 + create_table :institutions_users do |t|
  4 + t.belongs_to :user
  5 + t.belongs_to :institution
  6 + end
  7 + end
  8 +
  9 + def down
  10 + drop_table :institutions_users
  11 + end
  12 +end
... ...
src/gov_user/db/migrate/20141103183013_add_corporate_name_to_institution.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class AddCorporateNameToInstitution < ActiveRecord::Migration
  2 + def up
  3 + add_column :institutions, :corporate_name, :string
  4 + end
  5 +
  6 + def down
  7 + remove_column :institutions, :corporate_name
  8 + end
  9 +end
... ...
src/gov_user/db/migrate/20150910135510_add_siorg_code_to_institution.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class AddSiorgCodeToInstitution < ActiveRecord::Migration
  2 + def up
  3 + add_column :institutions, :siorg_code, :integer
  4 + end
  5 +
  6 + def down
  7 + remove_column :institutions, :siorg_code
  8 + end
  9 +end
... ...
src/gov_user/db/migrate/20150910203559_add_institution_to_organization_rating.rb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +class AddInstitutionToOrganizationRating < ActiveRecord::Migration
  2 + def up
  3 + change_table :organization_ratings do |t|
  4 + t.belongs_to :institution
  5 + end
  6 + end
  7 +
  8 + def down
  9 + remove_column :organization_ratings, :institution_id
  10 + end
  11 +end
0 12 \ No newline at end of file
... ...
src/gov_user/db/seeds.rb 0 → 100644
... ... @@ -0,0 +1,19 @@
  1 +# encoding: UTF-8
  2 +powers = ["Executivo", "Legislativo", "Judiciário", "Não se Aplica"]
  3 +spheres = ["Federal", "Estadual", "Distrital", "Municipal"]
  4 +jur_natures = ["Administração Direta", "Autarquia", "Empresa Pública", "Fundação",
  5 + "Orgão Autônomo", "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
... ...
src/gov_user/features/institution_registration.feature 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +Feature: Institution Field
  2 + As a user
  3 + I want to sign up resgistring my institution
  4 + So others users can use it
  5 +
  6 + Background:
  7 + Given "GovUserPlugin" plugin is enabled
  8 + And I am logged in as mpog_admin
  9 + And I go to /admin/plugins
  10 + And I check "GovUserPlugin"
  11 + And I press "Save changes"
  12 + And Institutions has initial default values on database
  13 + And I am logged in as mpog_admin
  14 +
  15 + @selenium
  16 + Scenario: Show new institution fields when clicked in create new institution
  17 + Given I follow "Edit Profile"
  18 + When I follow "Create new institution"
  19 + And I should see "New Institution"
  20 + And I should see "Public Institution"
  21 + And I should see "Private Institution"
  22 + And I should see "Corporate Name"
  23 + And I should see "Name"
  24 + And I should see "State"
  25 + And I should see "City"
  26 + And I should see "Country"
  27 + And I should see "CNPJ"
  28 + And I should see "Acronym"
  29 + And I choose "Public Institution"
  30 + Then I should see "Governmental Sphere:"
  31 + And I should see "Governmental Power:"
  32 + And I should see "Juridical Nature:"
... ...
src/gov_user/features/steps_definitions/gov_user_steps.rb 0 → 100644
... ... @@ -0,0 +1,90 @@
  1 +Given /^Institutions has initial default values on database$/ do
  2 + GovernmentalPower.create(:name => "Executivo")
  3 + GovernmentalPower.create(:name => "Legislativo")
  4 + GovernmentalPower.create(:name => "Judiciario")
  5 +
  6 + GovernmentalSphere.create(:name => "Federal")
  7 +
  8 + JuridicalNature.create(:name => "Autarquia")
  9 + JuridicalNature.create(:name => "Administracao Direta")
  10 + JuridicalNature.create(:name => "Empresa Publica")
  11 + JuridicalNature.create(:name => "Fundacao")
  12 + JuridicalNature.create(:name => "Orgao Autonomo")
  13 + JuridicalNature.create(:name => "Sociedade")
  14 + JuridicalNature.create(:name => "Sociedade Civil")
  15 + JuridicalNature.create(:name => "Sociedade de Economia Mista")
  16 +
  17 + national_region = NationalRegion.new
  18 + national_region.name = "Distrito Federal"
  19 + national_region.national_region_code = '35'
  20 + national_region.national_region_type_id = NationalRegionType::STATE
  21 + national_region.save
  22 +end
  23 +
  24 +Given /^I type in "([^"]*)" in autocomplete list "([^"]*)" and I choose "([^"]*)"$/ do |typed, input_field_selector, should_select|
  25 +# Wait the page javascript load
  26 +sleep 1
  27 +# Basicaly it, search for the input field, type something, wait for ajax end select an item
  28 +page.driver.browser.execute_script %Q{
  29 + var search_query = "#{input_field_selector}.ui-autocomplete-input";
  30 + var input = jQuery(search_query).first();
  31 +
  32 + input.trigger('click');
  33 + input.val('#{typed}');
  34 + input.trigger('keydown');
  35 +
  36 + window.setTimeout(function(){
  37 + search_query = ".ui-menu-item a:contains('#{should_select}')";
  38 + var typed = jQuery(search_query).first();
  39 +
  40 + typed.trigger('mouseenter').trigger('click');
  41 + console.log(jQuery('#license_info_id'));
  42 + }, 1000);
  43 + }
  44 + sleep 1
  45 +end
  46 +
  47 +Given /^the following public institutions?$/ do |table|
  48 + # table is a Cucumber::Ast::Table
  49 + table.hashes.each do |item|
  50 + community = Community.new
  51 + community.name = item[:name]
  52 + community.country = item[:country]
  53 + community.state = item[:state]
  54 + community.city = item[:city]
  55 + community.save!
  56 +
  57 + governmental_power = GovernmentalPower.where(:name => item[:governmental_power]).first
  58 + governmental_sphere = GovernmentalSphere.where(:name => item[:governmental_sphere]).first
  59 +
  60 + juridical_nature = JuridicalNature.create(:name => item[:juridical_nature])
  61 +
  62 + institution = PublicInstitution.new(:name => item[:name], :type => "PublicInstitution", :acronym => item[:acronym], :cnpj => item[:cnpj], :juridical_nature => juridical_nature, :governmental_power => governmental_power, :governmental_sphere => governmental_sphere)
  63 + institution.community = community
  64 + institution.corporate_name = item[:corporate_name]
  65 + institution.save!
  66 + end
  67 +end
  68 +
  69 +Given /^I sleep for (\d+) seconds$/ do |time|
  70 + sleep time.to_i
  71 +end
  72 +
  73 +Given /^I am logged in as mpog_admin$/ do
  74 + visit('/account/logout')
  75 +
  76 + user = User.new(:login => 'admin_user', :password => '123456', :password_confirmation => '123456', :email => 'admin_user@example.com')
  77 + person = Person.new :name=>"Mpog Admin", :identifier=>"mpog-admin"
  78 + user.person = person
  79 + user.save!
  80 +
  81 + user.activate
  82 + e = Environment.default
  83 + e.add_admin(user.person)
  84 +
  85 + visit('/account/login')
  86 + fill_in("Username", :with => user.login)
  87 + fill_in("Password", :with => '123456')
  88 + click_button("Log in")
  89 +end
  90 +
... ...
src/gov_user/features/user_profile_edition.feature 0 → 100644
... ... @@ -0,0 +1,77 @@
  1 +Feature: Institution Field
  2 + As a user
  3 + I want to update my update my user data
  4 + So I can maintain my personal data updated
  5 +
  6 + Background:
  7 + Given "GovUserPlugin" plugin is enabled
  8 + And the following users
  9 + | login | name |
  10 + | joao | Joao Silva |
  11 + And I am logged in as admin
  12 + And I go to /admin/plugins
  13 + And I check "GovUserPlugin"
  14 + And I press "Save changes"
  15 + And feature "skip_new_user_email_confirmation" is enabled on environment
  16 + And I go to /admin/features/manage_fields
  17 + And I check "person_fields_country_active"
  18 + And I check "person_fields_state_active"
  19 + And I check "person_fields_city_active"
  20 + And I press "Save changes"
  21 + And Institutions has initial default values on database
  22 + And the following public institutions
  23 + | name | acronym | country | state | city | cnpj | juridical_nature | governmental_power | governmental_sphere | corporate_name |
  24 + | Ministerio das Cidades | MC | BR | DF | Gama | 58.745.189/0001-21 | Autarquia | Executivo | Federal | Ministerio das Cidades |
  25 + | Governo do DF | GDF | BR | DF | Taguatinga | 12.645.166/0001-44 | Autarquia | Legislativo | Federal | Governo do DF |
  26 + | Ministerio do Planejamento | MP | BR | DF | Brasilia | 41.769.591/0001-43 | Autarquia | Judiciario | Federal | Ministerio do Planejamento |
  27 +
  28 + Scenario: Go to control panel when clicked on 'Complete your profile' link
  29 + Given I am logged in as "joao"
  30 + And I am on joao's control panel
  31 + When I follow "Complete your profile"
  32 + Then I should see "Profile settings for "
  33 + And I should see "Personal information"
  34 +
  35 + @selenium
  36 + Scenario: Verify text information to use governmental e-mail
  37 + Given I am logged in as "joao"
  38 + And I am on joao's control panel
  39 + When I follow "Edit Profile"
  40 + Then I should see "If you work in a public agency use your government e-Mail"
  41 +
  42 + @selenium
  43 + Scenario: Add more then one instituion on profile editor
  44 + Given I am logged in as "joao"
  45 + And I am on joao's control panel
  46 + When I follow "Edit Profile"
  47 + And I follow "Add new institution"
  48 + And I type in "Minis" in autocomplete list "#input_institution" and I choose "Ministerio do Planejamento"
  49 + And I follow "Add new institution"
  50 + And I type in "Gover" in autocomplete list "#input_institution" and I choose "Governo do DF"
  51 + And I follow "Add new institution"
  52 + Then I should see "Ministerio do Planejamento" within ".institutions_added"
  53 + And I should see "Governo do DF" within ".institutions_added"
  54 +
  55 + @selenium
  56 + Scenario: Verify if field 'city' is shown when Brazil is selected
  57 + Given I am logged in as "joao"
  58 + And I am on joao's control panel
  59 + When I follow "Edit Profile"
  60 + Then I should see "City"
  61 +
  62 + @selenium
  63 + Scenario: Verify if field 'city' does not appear when Brazil is not selected as country
  64 + Given I am logged in as "joao"
  65 + And I am on joao's control panel
  66 + When I follow "Edit Profile"
  67 + And I select "United States" from "profile_data_country"
  68 + Then I should not see "City" within ".type-text"
  69 +
  70 + @selenium
  71 + Scenario: Show message of institution not found
  72 + Given I am logged in as "joao"
  73 + And I am on joao's control panel
  74 + When I follow "Edit Profile"
  75 + And I fill in "input_institution" with "Some Nonexistent Institution"
  76 + And I sleep for 1 seconds
  77 + Then I should see "No institution found"
... ...
src/gov_user/lib/ext/communities_block.rb 0 → 100644
... ... @@ -0,0 +1,45 @@
  1 +require_dependency 'communities_block'
  2 +
  3 +class CommunitiesBlock
  4 +
  5 + def profile_list
  6 + result = get_visible_profiles
  7 + result.slice(0..get_limit-1)
  8 + end
  9 +
  10 + def profile_count
  11 + profile_list.count
  12 + end
  13 +
  14 + private
  15 +
  16 + def get_visible_profiles
  17 + visible_profiles = profiles.visible.includes(
  18 + [:image,:domains,:preferred_domain,:environment]
  19 + )
  20 +
  21 + delete_communities = []
  22 + valid_communities_string = Community.get_valid_communities_string
  23 + Community.all.each{|community| delete_communities << community.id unless eval(valid_communities_string)}
  24 +
  25 + visible_profiles = visible_profiles.where(["profiles.id NOT IN (?)", delete_communities]) unless delete_communities.empty?
  26 +
  27 + if !prioritize_profiles_with_image
  28 + return visible_profiles.all(
  29 + :limit => get_limit,
  30 + :order => 'profiles.updated_at DESC'
  31 + ).sort_by {rand}
  32 + elsif profiles.visible.with_image.count >= get_limit
  33 + return visible_profiles.with_image.all(
  34 + :limit => get_limit * 5,
  35 + :order => 'profiles.updated_at DESC'
  36 + ).sort_by {rand}
  37 + else
  38 + visible_profiles = visible_profiles.with_image.sort_by {rand} +
  39 + visible_profiles.without_image.all(
  40 + :limit => get_limit * 5, :order => 'profiles.updated_at DESC'
  41 + ).sort_by {rand}
  42 + return visible_profiles
  43 + end
  44 + end
  45 +end
... ...
src/gov_user/lib/ext/community.rb 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +require_dependency 'community'
  2 +
  3 +class Community
  4 + has_one :institution, :dependent=>:destroy
  5 +
  6 + def institution?
  7 + return !institution.nil?
  8 + end
  9 +
  10 + def remove_of_community_search_institution?
  11 + return institution?
  12 + end
  13 +
  14 + def self.get_valid_communities_string
  15 + remove_of_communities_methods = Community.instance_methods.select{|m| m =~ /remove_of_community_search/}
  16 + valid_communities_string = "!("
  17 + remove_of_communities_methods.each do |method|
  18 + valid_communities_string += "community.send('#{method}') || "
  19 + end
  20 + valid_communities_string = valid_communities_string[0..-5]
  21 + valid_communities_string += ")"
  22 +
  23 + valid_communities_string
  24 + end
  25 +end
... ...
src/gov_user/lib/ext/organization_rating.rb 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +require_dependency "organization_rating"
  2 +
  3 +OrganizationRating.class_eval do
  4 +
  5 + belongs_to :institution
  6 +
  7 + attr_accessible :institution, :institution_id
  8 +
  9 + validate :verify_institution
  10 +
  11 + private
  12 +
  13 + def verify_institution
  14 + if self.institution != nil
  15 + institution = Institution.find_by_id self.institution.id
  16 + self.errors.add :institution, _("not found") unless institution
  17 + end
  18 + end
  19 +
  20 +end
... ...
src/gov_user/lib/ext/person.rb 0 → 100644
... ... @@ -0,0 +1,35 @@
  1 +# encoding: utf-8
  2 +
  3 +require_dependency 'person'
  4 +
  5 +class Person
  6 +
  7 + settings_items :percentage_incomplete, :type => :string, :default => ""
  8 +
  9 + attr_accessible :percentage_incomplete
  10 +
  11 + delegate :login, :to => :user, :prefix => true
  12 +
  13 + def institution?
  14 + false
  15 + end
  16 +
  17 + def secondary_email
  18 + self.user.secondary_email unless self.user.nil?
  19 + end
  20 +
  21 + def secondary_email= value
  22 + self.user.secondary_email = value unless self.user.nil?
  23 + end
  24 +
  25 + def institutions
  26 + institutions = []
  27 + unless self.user.institutions.nil?
  28 + self.user.institutions.each do |institution|
  29 + institutions << institution.name
  30 + end
  31 + end
  32 + institutions
  33 + end
  34 +
  35 +end
... ...
src/gov_user/lib/ext/search_controller.rb 0 → 100644
... ... @@ -0,0 +1,42 @@
  1 +require_dependency 'search_controller'
  2 +
  3 +class SearchController
  4 +
  5 + def communities
  6 + delete_communities = []
  7 + valid_communities_string = Community.get_valid_communities_string
  8 + Community.all.each{|community| delete_communities << community.id unless eval(valid_communities_string)}
  9 +
  10 + @scope = visible_profiles(Community)
  11 + @scope = @scope.where(["id NOT IN (?)", delete_communities]) unless delete_communities.empty?
  12 +
  13 + full_text_search
  14 + end
  15 +
  16 + def institutions
  17 + @titles[:institutions] = _("Institution Catalog")
  18 + results = filter_communities_list{|community| community.institution?}
  19 + results = results.paginate(:per_page => 24, :page => params[:page])
  20 + @searches[@asset] = {:results => results}
  21 + @search = results
  22 + end
  23 +
  24 + def filter_communities_list
  25 + unfiltered_list = visible_profiles(Community)
  26 +
  27 + unless params[:query].nil?
  28 + unfiltered_list = unfiltered_list.select do |com|
  29 + com.name.downcase =~ /#{params[:query].downcase}/
  30 + end
  31 + end
  32 +
  33 + communities_list = []
  34 + unfiltered_list.each do |profile|
  35 + if profile.class == Community && !profile.is_template? && yield(profile)
  36 + communities_list << profile
  37 + end
  38 + end
  39 +
  40 + communities_list
  41 + end
  42 +end
... ...
src/gov_user/lib/ext/search_helper.rb 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +require_dependency 'search_helper'
  2 +
  3 +module SearchHelper
  4 +
  5 + COMMON_PROFILE_LIST_BLOCK ||= []
  6 + COMMON_PROFILE_LIST_BLOCK << :institutions
  7 +
  8 +end
... ...
src/gov_user/lib/ext/user.rb 0 → 100644
... ... @@ -0,0 +1,60 @@
  1 +require_dependency 'user'
  2 +
  3 +class User
  4 +
  5 + GOV_SUFFIX = /^.*@[gov.br|jus.br|leg.br|mp.br]+$/
  6 +
  7 + has_and_belongs_to_many :institutions
  8 +
  9 + validate :email_different_secondary?, :email_has_already_been_used?,
  10 + :secondary_email_format
  11 +
  12 + scope :primary_or_secondary_email_already_used?, lambda { |email|
  13 + where("email=? OR secondary_email=?", email, email)
  14 + }
  15 +
  16 + def email_different_secondary?
  17 + self.errors.add(
  18 + :base,
  19 + _("Email must be different from secondary email.")
  20 + ) if self.email == self.secondary_email
  21 + end
  22 +
  23 + def email_has_already_been_used?
  24 + user_already_saved = User.find(:first,
  25 + :conditions => ["email = ?", self.email])
  26 +
  27 + if user_already_saved.nil?
  28 + primary_email_hasnt_been_used =
  29 + User.primary_or_secondary_email_already_used?(self.email).empty?
  30 +
  31 + if !self.secondary_email.nil? and self.secondary_email.empty?
  32 + self.secondary_email = nil
  33 + end
  34 +
  35 + secondary_email_hasnt_been_used =
  36 + User.primary_or_secondary_email_already_used?(self.secondary_email).
  37 + empty?
  38 +
  39 + if !primary_email_hasnt_been_used or !secondary_email_hasnt_been_used
  40 + self.errors.add(:base, _("E-mail or secondary e-mail already taken."))
  41 + end
  42 + end
  43 + end
  44 +
  45 + def secondary_email_format
  46 + if !self.secondary_email.nil? and self.secondary_email.length > 0
  47 + test = /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/
  48 +
  49 + unless test.match(self.secondary_email)
  50 + self.errors.add(:base, _("Invalid secondary email format."))
  51 + end
  52 + end
  53 + end
  54 +
  55 + private
  56 +
  57 + def valid_format?(value, string_format)
  58 + !value.nil? && value.length > 0 && !string_format.match(value).nil?
  59 + end
  60 +end
... ...
src/gov_user/lib/gov_user_plugin.rb 0 → 100644
... ... @@ -0,0 +1,332 @@
  1 +class GovUserPlugin < Noosfero::Plugin
  2 + include ActionView::Helpers::TagHelper
  3 + include ActionView::Helpers::FormTagHelper
  4 + include ActionView::Helpers::FormOptionsHelper
  5 + include ActionView::Helpers::JavaScriptHelper
  6 + include ActionView::Helpers::AssetTagHelper
  7 + include FormsHelper
  8 + include ActionView::Helpers
  9 + include ActionDispatch::Routing
  10 + include Rails.application.routes.url_helpers
  11 +
  12 + def self.plugin_name
  13 + "GovUserPlugin"
  14 + end
  15 +
  16 + def self.plugin_description
  17 + _("Add features related to Brazilian government.")
  18 + end
  19 +
  20 + def stylesheet?
  21 + true
  22 + end
  23 +
  24 + # Hotspot to insert html without an especific hotspot on view.
  25 + def body_beginning
  26 + return if context.session[:user].nil? or context.session[:hide_incomplete_percentage] == true
  27 +
  28 + person = context.environment.people.where(:user_id=>context.session[:user]).first
  29 +
  30 + if context.profile && context.profile.person? and !person.nil?
  31 + @person = person
  32 + @percentege = calc_percentage_registration(person)
  33 +
  34 + if @percentege >= 0 and @percentege < 100
  35 + expanded_template('incomplete_registration.html.erb')
  36 + end
  37 + end
  38 + end
  39 +
  40 + def profile_editor_transaction_extras
  41 + single_hash_transactions = { :user => 'user',
  42 + :instituton => 'instituton'
  43 + }
  44 +
  45 + single_hash_transactions.each do |model, transaction|
  46 + call_model_transaction(model, transaction)
  47 + end
  48 + end
  49 +
  50 + def profile_editor_controller_filters
  51 + block = proc do
  52 + if request.post? && params[:institution]
  53 + is_admin = environment.admins.include?(current_user.person)
  54 +
  55 + unless is_admin
  56 + institution = profile.user.institutions
  57 +
  58 + if !params[:institution].blank? && params[:institution].class == Hash && !params[:institution][:sisp].nil?
  59 + if params[:institution][:sisp] != institution.sisp
  60 + params[:institution][:sisp] = institution.sisp
  61 + end
  62 + end
  63 + end
  64 + end
  65 + end
  66 +
  67 + [{
  68 + :type => 'before_filter',
  69 + :method_name => 'validate_institution_sisp_field_access',
  70 + :options => { :only => :edit },
  71 + :block => block
  72 + }]
  73 + end
  74 +
  75 + def profile_tabs
  76 + if context.profile.community?
  77 + return profile_tabs_institution if context.profile.institution?
  78 + end
  79 + end
  80 +
  81 + def control_panel_buttons
  82 + if context.profile.institution?
  83 + return institution_info_button
  84 + end
  85 + end
  86 +
  87 + def self.extra_blocks
  88 + {
  89 + InstitutionsBlock => { :type => [Environment, Person] }
  90 + }
  91 + end
  92 +
  93 + def custom_user_registration_attributes(user)
  94 + return if context.params[:user][:institution_ids].nil?
  95 + context.params[:user][:institution_ids].delete('')
  96 +
  97 + update_user_institutions(user)
  98 +
  99 + user.institutions.each do |institution|
  100 + community = institution.community
  101 + community.add_member user.person
  102 + end
  103 + end
  104 +
  105 + def profile_editor_extras
  106 + profile = context.profile
  107 +
  108 + if profile.person?
  109 + expanded_template('person_editor_extras.html.erb')
  110 + end
  111 + end
  112 +
  113 +
  114 + def calc_percentage_registration(person)
  115 + required_list = profile_required_list
  116 + empty_fields = profile_required_empty_list person
  117 + count = required_list[:person_fields].count +
  118 + required_list[:user_fields].count
  119 + percentege = 100 - ((empty_fields.count * 100) / count)
  120 + person.percentage_incomplete = percentege
  121 + person.save(validate: false)
  122 + percentege
  123 + end
  124 +
  125 + def stylesheet?
  126 + true
  127 + end
  128 +
  129 + def admin_panel_links
  130 + [
  131 + {
  132 + :title => _('Create Institution'),
  133 + :url => {
  134 + :controller => 'gov_user_plugin',
  135 + :action => 'create_institution_admin'
  136 + }
  137 + }
  138 + ]
  139 + end
  140 +
  141 +
  142 + def js_files
  143 + %w(
  144 + vendor/modulejs-1.5.0.min.js
  145 + vendor/jquery.js
  146 + lib/noosfero-root.js
  147 + lib/select-element.js
  148 + lib/select-field-choices.js
  149 + views/complete-registration.js
  150 + views/control-panel.js
  151 + views/create-institution.js
  152 + views/new-community.js
  153 + views/user-edit-profile.js
  154 + views/gov-user-comments-extra-fields.js
  155 + initializer.js
  156 + app.js
  157 + )
  158 + end
  159 +
  160 + def admin_panel_links
  161 + [
  162 + {
  163 + :title => _('Create Institution'),
  164 + :url => {
  165 + :controller => 'gov_user_plugin',
  166 + :action => 'create_institution_admin'
  167 + }
  168 + }
  169 + ]
  170 + end
  171 +
  172 + protected
  173 +
  174 + def profile_required_list
  175 + fields = {}
  176 + fields[:person_fields] = %w(cell_phone
  177 + contact_phone
  178 + comercial_phone
  179 + country
  180 + city
  181 + state
  182 + organization_website
  183 + image
  184 + identifier
  185 + name)
  186 +
  187 + fields[:user_fields] = %w(secondary_email email)
  188 + fields
  189 + end
  190 +
  191 + def profile_required_empty_list(person)
  192 + empty_fields = []
  193 + required_list = profile_required_list
  194 +
  195 + required_list[:person_fields].each do |field|
  196 + empty_fields << field.sub('_',' ') if person.send(field).blank?
  197 + end
  198 + required_list[:user_fields].each do |field|
  199 + empty_fields << field.sub('_',' ') if person.user.send(field).blank?
  200 + end
  201 + empty_fields
  202 + end
  203 +
  204 +
  205 + protected
  206 +
  207 + def user_transaction
  208 + user_editor_institution_actions
  209 +
  210 + User.transaction do
  211 + context.profile.user.update_attributes!(context.params[:user])
  212 + end
  213 + end
  214 +
  215 + def institution_transaction
  216 + institution.date_modification = DateTime.now
  217 + institution.save
  218 + institution_models = %w(governmental_power governmental_sphere
  219 + juridical_nature)
  220 +
  221 + institution_models.each do |model|
  222 + call_institution_transaction(model)
  223 + end
  224 +
  225 + if context.params.has_key?(:institution)
  226 + Institution.transaction do
  227 + context.profile.
  228 + institution.
  229 + update_attributes!(context.params[:institution])
  230 + end
  231 + end
  232 + end
  233 +
  234 + def organization_ratings_plugin_comments_extra_fields
  235 + Proc::new do render :file => 'ratings_extra_field' end
  236 + end
  237 +
  238 + def organization_ratings_plugin_extra_fields_show_data user_rating
  239 + gov_user_self = self
  240 +
  241 + Proc::new {
  242 + if logged_in?
  243 + is_admin = environment.admins.include?(current_user.person)
  244 + is_admin ||= user_rating.organization.admins.include?(current_user.person)
  245 +
  246 + if is_admin and gov_user_self.context.profile.software?
  247 + render :file => 'organization_ratings_extra_fields_show_institution',
  248 + :locals => {:user_rating => user_rating}
  249 + end
  250 + end
  251 + }
  252 + end
  253 +
  254 + private
  255 +
  256 + def call_model_transaction(model,name)
  257 + send(name + '_transaction') if context.params.key?(model.to_sym)
  258 + end
  259 +
  260 + def call_institution_transaction(model)
  261 + context.profile.institution.send(model + '_id = ',
  262 + context.params[model.to_sym])
  263 + context.profile.institution.save!
  264 + end
  265 +
  266 + # Add and remove the user from it's institutions communities
  267 + def user_editor_institution_actions
  268 + user = context.profile.user
  269 +
  270 + old_communities = []
  271 + context.profile.user.institutions.each do |institution|
  272 + old_communities << institution.community
  273 + end
  274 +
  275 + new_communities = []
  276 + unless context.params[:user][:institution_ids].nil?
  277 + context.params[:user][:institution_ids].delete('')
  278 +
  279 + context.params[:user][:institution_ids].each do |id|
  280 + new_communities << Institution.find(id).community
  281 + end
  282 + end
  283 +
  284 + manage_user_institutions(user, old_communities, new_communities)
  285 + end
  286 +
  287 + def institution_info_button
  288 + {
  289 + :title => _('Institution Info'),
  290 + :icon => 'edit-profile-group control-panel-instituton-link',
  291 + :url => {
  292 + :controller => 'gov_user_plugin_myprofile',
  293 + :action => 'edit_institution'
  294 + }
  295 + }
  296 + end
  297 +
  298 + def manage_user_institutions(user, old_communities, new_communities)
  299 + leave_communities = (old_communities - new_communities)
  300 + enter_communities = (new_communities - old_communities)
  301 +
  302 + leave_communities.each do |community|
  303 + community.remove_member(user.person)
  304 + user.institutions.delete(community.institution)
  305 + end
  306 +
  307 + enter_communities.each do |community|
  308 + community.add_member(user.person)
  309 + user.institutions << community.institution
  310 + end
  311 + end
  312 +
  313 + def profile_tabs_institution
  314 + { :title => _('Institution'),
  315 + :id => 'intitution-fields',
  316 + :content => Proc::new do render :partial => 'profile/institution_tab' end,
  317 + :start => true
  318 + }
  319 + end
  320 +
  321 + def update_user_institutions(user)
  322 + context.params[:user][:institution_ids].each do |institution_id|
  323 + institution = Institution.find institution_id
  324 + user.institutions << institution
  325 +
  326 + if institution.community.admins.blank?
  327 + institution.community.add_admin(user.person)
  328 + end
  329 + end
  330 + user.save unless user.institution_ids.empty?
  331 + end
  332 +end
... ...
src/gov_user/lib/governmental_power.rb 0 → 100644
... ... @@ -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
... ...
src/gov_user/lib/governmental_sphere.rb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +class GovernmentalSphere < ActiveRecord::Base
  2 + attr_accessible :name
  3 +
  4 + validates :name, :presence=>true, :uniqueness=>true
  5 +
  6 + has_many :institutions
  7 +end
... ...
src/gov_user/lib/institution.rb 0 → 100644
... ... @@ -0,0 +1,107 @@
  1 +class Institution < ActiveRecord::Base
  2 + has_many :comments
  3 +
  4 + SEARCH_FILTERS = {
  5 + :order => %w[],
  6 + :display => %w[compact]
  7 + }
  8 +
  9 + def self.default_search_display
  10 + 'compact'
  11 + end
  12 +
  13 + belongs_to :governmental_power
  14 + belongs_to :governmental_sphere
  15 + belongs_to :juridical_nature
  16 +
  17 + has_and_belongs_to_many :users
  18 +
  19 + attr_accessible :name, :acronym, :unit_code, :parent_code, :unit_type,
  20 + :sub_juridical_nature, :normalization_level,
  21 + :version, :cnpj, :type, :governmental_power,
  22 + :governmental_sphere, :sisp, :juridical_nature,
  23 + :corporate_name, :siorg_code, :community
  24 +
  25 + validates :name, :presence=>true, :uniqueness=>true
  26 +
  27 + before_save :verify_institution_type
  28 +
  29 + belongs_to :community
  30 +
  31 + scope :search_institution, lambda{ |value|
  32 + where("name ilike ? OR acronym ilike ?", "%#{value}%", "%#{value}%" )
  33 + }
  34 +
  35 + validate :validate_country, :validate_state, :validate_city,
  36 + :verify_institution_type, :validate_format_cnpj
  37 +
  38 +
  39 + protected
  40 +
  41 + def verify_institution_type
  42 + valid_institutions_type = ["PublicInstitution", "PrivateInstitution"]
  43 +
  44 + unless valid_institutions_type.include? self.type
  45 + self.errors.add(
  46 + :type,
  47 + _("invalid, only public and private institutions are allowed.")
  48 + )
  49 +
  50 + return false
  51 + end
  52 +
  53 + return true
  54 + end
  55 +
  56 + def validate_country
  57 + unless self.community.blank?
  58 + if self.community.country.blank? && self.errors[:country].blank?
  59 + self.errors.add(:country, _("can't be blank"))
  60 + return false
  61 + end
  62 + end
  63 +
  64 + return true
  65 + end
  66 +
  67 + def validate_state
  68 + unless self.community.blank?
  69 + if self.community.country == "BR" &&
  70 + (self.community.state.blank? || self.community.state == "-1") &&
  71 + self.errors[:state].blank?
  72 +
  73 + self.errors.add(:state, _("can't be blank"))
  74 + return false
  75 + end
  76 + end
  77 +
  78 + return true
  79 + end
  80 +
  81 + def validate_city
  82 + unless self.community.blank?
  83 + if self.community.country == "BR" && self.community.city.blank? &&
  84 + self.errors[:city].blank?
  85 +
  86 + self.errors.add(:city, _("can't be blank"))
  87 + return false
  88 + end
  89 + end
  90 +
  91 + return true
  92 + end
  93 +
  94 + def validate_format_cnpj
  95 + return true if self.community.blank? && self.community.country != "BR"
  96 + return true if self.cnpj.blank?
  97 +
  98 + format = /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/
  99 +
  100 + if !self.cnpj.blank? && format.match(self.cnpj)
  101 + return true
  102 + else
  103 + self.errors.add(:cnpj, _("invalid format"))
  104 + return false
  105 + end
  106 + end
  107 +end
... ...
src/gov_user/lib/institutions_block.rb 0 → 100644
... ... @@ -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
... ...
src/gov_user/lib/institutions_users.rb 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +class InstitutionUser < ActiveRecord::Base
  2 + belongs_to :user
  3 + belongs_to :institution
  4 +end
... ...
src/gov_user/lib/juridical_nature.rb 0 → 100644
... ... @@ -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
... ...
src/gov_user/lib/private_institution.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +class PrivateInstitution < Institution
  2 +end
... ...
src/gov_user/lib/public_institution.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  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_format_of(
  9 + :cnpj,
  10 + :with => /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/,
  11 + :allow_nil => true, :allow_blank => true
  12 + )
  13 +end
... ...