Commit d3bbe4673935f46c8af6680d5f2cd607906ed3e8

Authored by Daniela Feitosa
2 parents f1d7454d d75a5073
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

Merge softwarepublico/gov_user

Showing 87 changed files with 4782 additions and 0 deletions   Show diff stats
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
... ...
src/gov_user/po/gov_user.pot 0 → 100644
... ... @@ -0,0 +1,356 @@
  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 ""
... ...
src/gov_user/po/pt/gov_user.po 0 → 100644
... ... @@ -0,0 +1,370 @@
  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."
... ...
src/gov_user/public/app.js 0 → 100644
... ... @@ -0,0 +1,11 @@
  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 +})();
... ...
src/gov_user/public/initializer.js 0 → 100644
... ... @@ -0,0 +1,33 @@
  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 +})();
... ...
src/gov_user/public/lib/noosfero-root.js 0 → 100644
... ... @@ -0,0 +1,13 @@
  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 +});
... ...
src/gov_user/public/lib/select-element.js 0 → 100644
... ... @@ -0,0 +1,35 @@
  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 +});
... ...
src/gov_user/public/lib/select-field-choices.js 0 → 100644
... ... @@ -0,0 +1,81 @@
  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 +});
... ...
src/gov_user/public/static/governmental_powers.txt 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +Executivo
  2 +Legislativo
  3 +Judiciário
  4 +Não se aplica
... ...
src/gov_user/public/static/governmental_sphere.txt 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +Federal
  2 +Estadual
  3 +Distrital
  4 +Municipal
... ...
src/gov_user/public/static/juridical_nature.txt 0 → 100644
... ... @@ -0,0 +1,8 @@
  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
... ...
src/gov_user/public/style.css 0 → 100644
... ... @@ -0,0 +1,26 @@
  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 +}
... ...
src/gov_user/public/vendor/jquery.js 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +modulejs.define('jquery', function() {
  2 + return jQuery;
  3 +});
... ...
src/gov_user/public/vendor/jquery.maskedinput.min.js 0 → 100644
... ... @@ -0,0 +1,7 @@
  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);
0 8 \ No newline at end of file
... ...
src/gov_user/public/vendor/modulejs-1.5.0.min.js 0 → 100644
... ... @@ -0,0 +1,2 @@
  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}}});
0 3 \ No newline at end of file
... ...
src/gov_user/public/views/complete-registration.js 0 → 100644
... ... @@ -0,0 +1,60 @@
  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 +});
... ...
src/gov_user/public/views/control-panel.js 0 → 100644
... ... @@ -0,0 +1,32 @@
  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 +});
... ...
src/gov_user/public/views/create-institution.js 0 → 100644
... ... @@ -0,0 +1,406 @@
  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 +});
... ...
src/gov_user/public/views/gov-user-comments-extra-fields.js 0 → 100644
... ... @@ -0,0 +1,26 @@
  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 +})
... ...
src/gov_user/public/views/new-community.js 0 → 100644
... ... @@ -0,0 +1,28 @@
  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 +})
... ...
src/gov_user/public/views/user-edit-profile.js 0 → 100644
... ... @@ -0,0 +1,216 @@
  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/test/functional/gov_user_plugin_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,236 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/institution_test_helper'
  3 +require File.dirname(__FILE__) + '/../../controllers/gov_user_plugin_controller'
  4 +
  5 +class GovUserPluginController; def rescue_action(e) raise e end; end
  6 +class GovUserPluginControllerTest < ActionController::TestCase
  7 +
  8 +
  9 + def setup
  10 + @admin = create_user("adminuser").person
  11 + @admin.stubs(:has_permission?).returns("true")
  12 + @controller.stubs(:current_user).returns(@admin.user)
  13 +
  14 + @environment = Environment.default
  15 + @environment.enabled_plugins = ['SoftwareCommunitiesPlugin']
  16 + @environment.add_admin(@admin)
  17 + @environment.save
  18 +
  19 + @gov_power = GovernmentalPower.create(:name=>"Some Gov Power")
  20 + @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
  21 + @juridical_nature = JuridicalNature.create(:name => "Autarquia")
  22 + @response = ActionController::TestResponse.new
  23 +
  24 + @institution_list = []
  25 + @institution_list << InstitutionTestHelper.create_public_institution(
  26 + "Ministerio Publico da Uniao",
  27 + "MPU",
  28 + "BR",
  29 + "DF",
  30 + "Gama",
  31 + @juridical_nature,
  32 + @gov_power,
  33 + @gov_sphere,
  34 + "12.345.678/9012-45"
  35 + )
  36 + @institution_list << InstitutionTestHelper.create_public_institution(
  37 + "Tribunal Regional da Uniao",
  38 + "TRU",
  39 + "BR",
  40 + "DF",
  41 + "Brasilia",
  42 + @juridical_nature,
  43 + @gov_power,
  44 + @gov_sphere,
  45 + "12.345.678/9012-90"
  46 + )
  47 +
  48 + end
  49 +
  50 + should "Search for institution with acronym" do
  51 + xhr :get, :get_institutions, :query=>"TRU"
  52 +
  53 + json_response = ActiveSupport::JSON.decode(@response.body)
  54 +
  55 + assert_equal "Tribunal Regional da Uniao", json_response[0]["value"]
  56 + end
  57 +
  58 + should "Search for institution with name" do
  59 + xhr :get, :get_institutions, :query=>"Minis"
  60 +
  61 + json_response = ActiveSupport::JSON.decode(@response.body)
  62 +
  63 + assert_equal "Ministerio Publico da Uniao", json_response[0]["value"]
  64 + end
  65 +
  66 + should "search with name or acronym and return a list with institutions" do
  67 + xhr :get, :get_institutions, :query=>"uni"
  68 +
  69 + json_response = ActiveSupport::JSON.decode(@response.body)
  70 +
  71 + assert_equal "Ministerio Publico da Uniao", json_response[0]["value"]
  72 + assert_equal "Tribunal Regional da Uniao", json_response[1]["value"]
  73 + end
  74 +
  75 + should "method create_institution return the html for modal" do
  76 + @controller.stubs(:current_user).returns(@admin.user)
  77 + xhr :get, :create_institution
  78 + assert_template 'create_institution'
  79 + end
  80 +
  81 + should "create new institution with ajax without acronym" do
  82 + @controller.stubs(:verify_recaptcha).returns(true)
  83 +
  84 + fields = InstitutionTestHelper.generate_form_fields(
  85 + "foo bar",
  86 + "BR",
  87 + "DF",
  88 + "Brasilia",
  89 + "12.234.567/8900-10",
  90 + "PublicInstitution"
  91 + )
  92 + fields[:institutions][:governmental_power] = @gov_power.id
  93 + fields[:institutions][:governmental_sphere] = @gov_sphere.id
  94 + fields[:institutions][:juridical_nature] = @juridical_nature.id
  95 +
  96 + xhr :get, :new_institution, fields
  97 +
  98 + json_response = ActiveSupport::JSON.decode(@response.body)
  99 +
  100 + assert json_response["success"]
  101 + end
  102 +
  103 + should "create a institution without cnpj" do
  104 + @controller.stubs(:verify_recaptcha).returns(true)
  105 +
  106 + fields = InstitutionTestHelper.generate_form_fields(
  107 + "Some Private Institution",
  108 + "BR",
  109 + "DF",
  110 + "Brasilia",
  111 + "",
  112 + "PrivateInstitution"
  113 + )
  114 + fields[:institutions][:acronym] = "SPI"
  115 +
  116 + xhr :get, :new_institution, fields
  117 +
  118 + json_response = ActiveSupport::JSON.decode(@response.body)
  119 +
  120 + assert json_response["success"]
  121 + end
  122 +
  123 + should "verify if institution name already exists" do
  124 + xhr :get, :institution_already_exists, :name=>"Ministerio Publico da Uniao"
  125 + assert_equal "true", @response.body
  126 +
  127 + xhr :get, :institution_already_exists, :name=>"Another name here"
  128 + assert_equal "false", @response.body
  129 + end
  130 +
  131 + should "hide registration incomplete message" do
  132 + xhr :get, :hide_registration_incomplete_percentage, :hide=>true
  133 + assert_equal "true", @response.body
  134 + end
  135 +
  136 + should "not hide registration incomplete message" do
  137 + xhr :get, :hide_registration_incomplete_percentage, :hide=>false
  138 + assert_equal "false", @response.body
  139 + end
  140 +
  141 + should "Create new institution with method post" do
  142 + @controller.stubs(:verify_recaptcha).returns(true)
  143 +
  144 + fields = InstitutionTestHelper.generate_form_fields(
  145 + "Some Private Institution",
  146 + "BR",
  147 + "DF",
  148 + "Brasilia",
  149 + "12.345.567/8900-10",
  150 + "PrivateInstitution"
  151 + )
  152 + fields[:institutions][:acronym] = "SPI"
  153 +
  154 + post :new_institution, fields
  155 +
  156 + assert_redirected_to(controller: "admin_panel", action: "index")
  157 + end
  158 +
  159 + should "not create new institution with method post without cnpj" do
  160 + @controller.stubs(:verify_recaptcha).returns(true)
  161 +
  162 + fields = InstitutionTestHelper.generate_form_fields(
  163 + "Some Private Institution",
  164 + "BR",
  165 + "DF",
  166 + "Brasilia",
  167 + "56.366.790/0001-88",
  168 + "PrivateInstitution"
  169 + )
  170 +
  171 + post :new_institution, fields
  172 +
  173 + assert_redirected_to(controller: "admin_panel", action: "index")
  174 + end
  175 +
  176 + should "Create foreign institution without city, state and cnpj by post" do
  177 + @controller.stubs(:verify_recaptcha).returns(true)
  178 +
  179 + fields = InstitutionTestHelper.generate_form_fields(
  180 + "Foreign institution",
  181 + "AZ",
  182 + "",
  183 + "",
  184 + "",
  185 + "PrivateInstitution"
  186 + )
  187 + fields[:institutions][:acronym] = "FI"
  188 +
  189 + post :new_institution, fields
  190 +
  191 + assert_redirected_to(controller: "admin_panel", action: "index")
  192 + end
  193 +
  194 + should "Create foreign institution without city, state and cnpj by ajax" do
  195 + @controller.stubs(:verify_recaptcha).returns(true)
  196 +
  197 + fields = InstitutionTestHelper.generate_form_fields(
  198 + "Foreign institution",
  199 + "AZ",
  200 + "",
  201 + "",
  202 + "",
  203 + "PrivateInstitution"
  204 + )
  205 + fields[:institutions][:acronym] = "FI"
  206 +
  207 + xhr :post, :new_institution, fields
  208 +
  209 + json_response = ActiveSupport::JSON.decode(@response.body)
  210 +
  211 + assert json_response["success"]
  212 + end
  213 +
  214 + should "add environment admins to institution when created via admin panel" do
  215 + @controller.stubs(:verify_recaptcha).returns(true)
  216 + admin2 = create_user("another_admin").person
  217 + admin2.stubs(:has_permission?).returns("true")
  218 + @environment.add_admin(admin2)
  219 + @environment.save
  220 +
  221 + fields = InstitutionTestHelper.generate_form_fields(
  222 + "Private Institution",
  223 + "BR",
  224 + "DF",
  225 + "Brasilia",
  226 + "12.323.557/8900-10",
  227 + "PrivateInstitution"
  228 + )
  229 + fields[:institutions][:acronym] = "PI"
  230 + fields[:edit_institution_page] = false
  231 + post :new_institution, fields
  232 +
  233 + assert(Institution.last.community.admins.include?(admin2) )
  234 + end
  235 +
  236 +end
... ...
src/gov_user/test/functional/gov_user_plugin_myprofile_controller.rb 0 → 100644
... ... @@ -0,0 +1,105 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/institution_test_helper'
  3 +require(
  4 +File.dirname(__FILE__) +
  5 +'/../../controllers/gov_user_plugin_myprofile_controller'
  6 +)
  7 +
  8 +class GovUserPluginMyprofileController; def rescue_action(e) raise e end;
  9 +end
  10 +
  11 +class GovUserPluginMyprofileControllerTest < ActionController::TestCase
  12 + def setup
  13 + @controller = GovUserPluginMyprofileController.new
  14 + @request = ActionController::TestRequest.new
  15 + @response = ActionController::TestResponse.new
  16 + @person = create_user('person').person
  17 + @offer = create_user('Angela Silva')
  18 + @offer_1 = create_user('Ana de Souza')
  19 + @offer_2 = create_user('Angelo Roberto')
  20 +
  21 + login_as(@person.user_login)
  22 + @environment = Environment.default
  23 + @environment.enable_plugin('GovUserPlugin')
  24 + @environment.save!
  25 + end
  26 + should "user edit its community institution" do
  27 + govPower = GovernmentalPower.create(:name=>"Some Gov Power")
  28 + govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
  29 + juridical_nature = JuridicalNature.create(:name => "Autarquia")
  30 +
  31 + institution = InstitutionTestHelper.create_public_institution(
  32 + "Ministerio Publico da Uniao",
  33 + "MPU",
  34 + "BR",
  35 + "DF",
  36 + "Gama",
  37 + juridical_nature,
  38 + govPower,
  39 + govSphere,
  40 + "12.345.678/9012-45"
  41 + )
  42 +
  43 + identifier = institution.community.identifier
  44 +
  45 + fields = InstitutionTestHelper.generate_form_fields(
  46 + "institution new name",
  47 + "BR",
  48 + "DF",
  49 + "Gama",
  50 + "12.345.678/9012-45",
  51 + "PrivateInstitution"
  52 + )
  53 +
  54 + post(
  55 + :edit_institution,
  56 + :profile=>institution.community.identifier,
  57 + :community=>fields[:community],
  58 + :institutions=>fields[:institutions]
  59 + )
  60 +
  61 + institution = Community[identifier].institution
  62 + assert_not_equal "Ministerio Publico da Uniao", institution.community.name
  63 + end
  64 +
  65 + should "not user edit its community institution with wrong values" do
  66 + govPower = GovernmentalPower.create(:name=>"Some Gov Power")
  67 + govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
  68 + juridical_nature = JuridicalNature.create(:name => "Autarquia")
  69 +
  70 + institution = InstitutionTestHelper.create_public_institution(
  71 + "Ministerio Publico da Uniao",
  72 + "MPU",
  73 + "BR",
  74 + "DF",
  75 + "Gama",
  76 + juridical_nature,
  77 + govPower,
  78 + govSphere,
  79 + "12.345.678/9012-45"
  80 + )
  81 +
  82 + identifier = institution.community.identifier
  83 +
  84 + fields = InstitutionTestHelper.generate_form_fields(
  85 + "",
  86 + "BR",
  87 + "DF",
  88 + "Gama",
  89 + "6465465465",
  90 + "PrivateInstitution"
  91 + )
  92 +
  93 + post(
  94 + :edit_institution,
  95 + :profile=>institution.community.identifier,
  96 + :community=>fields[:community],
  97 + :institutions=>fields[:institutions]
  98 + )
  99 +
  100 + institution = Community[identifier].institution
  101 + assert_equal "Ministerio Publico da Uniao", institution.community.name
  102 + assert_equal "12.345.678/9012-45", institution.cnpj
  103 + end
  104 +
  105 +end
... ...
src/gov_user/test/functional/profile_editor_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,112 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/institution_test_helper'
  3 +require(
  4 +File.dirname(__FILE__) +
  5 +'/../../../../app/controllers/my_profile/profile_editor_controller'
  6 +)
  7 +
  8 +class ProfileEditorController; def rescue_action(e) raise e end; end
  9 +
  10 +class ProfileEditorControllerTest < ActionController::TestCase
  11 +
  12 + def setup
  13 + @controller = ProfileEditorController.new
  14 + @request = ActionController::TestRequest.new
  15 + @response = ActionController::TestResponse.new
  16 + @profile = create_user('default_user').person
  17 +
  18 + Environment.default.affiliate(
  19 + @profile,
  20 + [Environment::Roles.admin(Environment.default.id)] +
  21 + Profile::Roles.all_roles(Environment.default.id)
  22 + )
  23 +
  24 + @environment = Environment.default
  25 + @environment.enabled_plugins = ['GovUserPlugin']
  26 + admin = create_user("adminuser").person
  27 + admin.stubs(:has_permission?).returns("true")
  28 + login_as('adminuser')
  29 + @environment.add_admin(admin)
  30 + @environment.save
  31 +
  32 + @govPower = GovernmentalPower.create(:name=>"Some Gov Power")
  33 + @govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
  34 + @juridical_nature = JuridicalNature.create(:name => "Autarquia")
  35 +
  36 + @institution_list = []
  37 + @institution_list << InstitutionTestHelper.create_public_institution(
  38 + "Ministerio Publico da Uniao",
  39 + "MPU",
  40 + "BR",
  41 + "DF",
  42 + "Gama",
  43 + @juridical_nature,
  44 + @govPower,
  45 + @govSphere,
  46 + "12.345.678/9012-45"
  47 + )
  48 +
  49 + @institution_list << InstitutionTestHelper.create_public_institution(
  50 + "Tribunal Regional da Uniao",
  51 + "TRU",
  52 + "BR",
  53 + "DF",
  54 + "Brasilia",
  55 + @juridical_nature,
  56 + @govPower,
  57 + @govSphere,
  58 + "12.345.678/9012-90"
  59 + )
  60 + end
  61 +
  62 + should "add new institution for user into edit profile" do
  63 + user = create_basic_user
  64 +
  65 + params_user = Hash.new
  66 + params_user[:institution_ids] = []
  67 +
  68 + @institution_list.each do |institution|
  69 + params_user[:institution_ids] << institution.id
  70 + end
  71 +
  72 + post :edit, :profile => User.last.person.identifier, :user => params_user
  73 +
  74 + assert_equal @institution_list.count, User.last.institutions.count
  75 + end
  76 +
  77 + should "remove institutions for user into edit profile" do
  78 + user = create_basic_user
  79 +
  80 + @institution_list.each do |institution|
  81 + user.institutions << institution
  82 + end
  83 + user.save!
  84 +
  85 + params_user = Hash.new
  86 + params_user[:institution_ids] = []
  87 +
  88 + assert_equal @institution_list.count, User.last.institutions.count
  89 +
  90 + post :edit, :profile => User.last.person.identifier, :user => params_user
  91 +
  92 + assert_equal 0, User.last.institutions.count
  93 + end
  94 +
  95 + protected
  96 +
  97 + def create_basic_user
  98 + user = fast_create(User)
  99 + user.person = fast_create(Person)
  100 + user.person.user = user
  101 + user.save!
  102 + user.person.save!
  103 + user
  104 + end
  105 +
  106 + def create_community name
  107 + community = fast_create(Community)
  108 + community.name = name
  109 + community.save
  110 + community
  111 + end
  112 +end
... ...
src/gov_user/test/functional/search_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,57 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +require(
  4 +File.dirname(__FILE__) +
  5 +'/../../../../app/controllers/public/search_controller'
  6 +)
  7 +
  8 +class SearchController; def rescue_action(e) raise e end; end
  9 +
  10 +class SearchControllerTest < ActionController::TestCase
  11 + include PluginTestHelper
  12 +
  13 + def setup
  14 + @environment = Environment.default
  15 + @environment.enabled_plugins = ['SoftwareCommunitiesPlugin']
  16 + @environment.save
  17 +
  18 + @controller = SearchController.new
  19 + @request = ActionController::TestRequest.new
  20 + @request.stubs(:ssl?).returns(:false)
  21 + @response = ActionController::TestResponse.new
  22 + end
  23 +
  24 + should "communities searches don't have institution" do
  25 + community = create_community("New Community")
  26 + institution = create_private_institution(
  27 + "New Private Institution",
  28 + "NPI" ,
  29 + "Brazil",
  30 + "DF",
  31 + "Gama",
  32 + "66.544.314/0001-63"
  33 + )
  34 +
  35 + get :communities, :query => "New"
  36 +
  37 + assert_includes assigns(:searches)[:communities][:results], community
  38 + assert_not_includes assigns(:searches)[:communities][:results], institution.community
  39 + end
  40 +
  41 + should "institutions_search don't have community" do
  42 + community = create_community("New Community")
  43 + institution = create_private_institution(
  44 + "New Private Institution",
  45 + "NPI" ,
  46 + "Brazil",
  47 + "DF",
  48 + "Gama",
  49 + "66.544.314/0001-63"
  50 + )
  51 +
  52 + get :institutions, :query => "New"
  53 +
  54 + assert_includes assigns(:searches)[:institutions][:results], institution.community
  55 + assert_not_includes assigns(:searches)[:institutions][:results], community
  56 + end
  57 +end
... ...
src/gov_user/test/helpers/institution_test_helper.rb 0 → 100644
... ... @@ -0,0 +1,59 @@
  1 +module InstitutionTestHelper
  2 +
  3 + def self.generate_form_fields name, country, state, city, cnpj, type
  4 + fields = {
  5 + :community => {
  6 + :name => name,
  7 + :country => country,
  8 + :state => state,
  9 + :city => city
  10 + },
  11 + :institutions => {
  12 + :cnpj=> cnpj,
  13 + :type => type,
  14 + :acronym => "",
  15 + :governmental_power => "",
  16 + :governmental_sphere => "",
  17 + :juridical_nature => "",
  18 + :corporate_name => "coporate default"
  19 + }
  20 + }
  21 + fields
  22 + end
  23 +
  24 + def self.create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s, cnpj
  25 + institution = PublicInstitution.new
  26 + institution.community = institution_community(name, country, state, city)
  27 + institution.name = name
  28 + institution.juridical_nature = juridical_nature
  29 + institution.acronym = acronym
  30 + institution.governmental_power = gov_p
  31 + institution.governmental_sphere = gov_s
  32 + institution.cnpj = cnpj
  33 + institution.corporate_name = "corporate default"
  34 + institution.save
  35 + institution
  36 + end
  37 +
  38 + def self.create_private_institution name, acronym, country, state, city, cnpj
  39 + institution = PrivateInstitution.new
  40 + institution.community = institution_community(name, country, state, city)
  41 + institution.name = name
  42 + institution.acronym = acronym
  43 + institution.cnpj = cnpj
  44 + institution.corporate_name = "corporate default"
  45 + institution.save
  46 +
  47 + institution
  48 + end
  49 +
  50 + def self.institution_community name, country, state, city
  51 + institution_community = Community::new
  52 + institution_community.name = name
  53 + institution_community.country = country
  54 + institution_community.state = state
  55 + institution_community.city = city
  56 + institution_community.save
  57 + institution_community
  58 + end
  59 +end
0 60 \ No newline at end of file
... ...
src/gov_user/test/helpers/plugin_test_helper.rb 0 → 100644
... ... @@ -0,0 +1,77 @@
  1 +require File.dirname(__FILE__) + '/../helpers/institution_test_helper'
  2 +
  3 +module PluginTestHelper
  4 +
  5 + def create_person name, email, password, password_confirmation, secondary_email, state="state", city="city"
  6 + user = create_user(
  7 + name.to_slug,
  8 + email,
  9 + password,
  10 + password_confirmation,
  11 + secondary_email
  12 + )
  13 + person = Person::new
  14 +
  15 + user.person = person
  16 + person.user = user
  17 +
  18 + person.name = name
  19 + person.identifier = name.to_slug
  20 + person.state = state
  21 + person.city = city
  22 +
  23 + user.save
  24 + person.save
  25 +
  26 + person
  27 + end
  28 +
  29 + def create_user login, email, password, password_confirmation, secondary_email
  30 + user = User.new
  31 +
  32 + user.login = login
  33 + user.email = email
  34 + user.password = password
  35 + user.password_confirmation = password_confirmation
  36 + user.secondary_email = secondary_email
  37 +
  38 + user
  39 + end
  40 +
  41 + def create_public_institution *params
  42 + InstitutionTestHelper.create_public_institution *params
  43 + end
  44 +
  45 + def create_community name
  46 + community = fast_create(Community)
  47 + community.name = name
  48 + community.save
  49 + community
  50 + end
  51 +
  52 +
  53 + def create_private_institution name, acronym, country, state, city, cnpj
  54 + InstitutionTestHelper.create_private_institution(
  55 + name,
  56 + acronym,
  57 + country,
  58 + state,
  59 + city,
  60 + cnpj
  61 + )
  62 + end
  63 +
  64 + def create_public_institution *params
  65 + InstitutionTestHelper.create_public_institution *params
  66 + end
  67 +
  68 + def create_community_institution name, country, state, city
  69 + community = fast_create(Community)
  70 + community.name = name
  71 + community.country = country
  72 + community.state = state
  73 + community.city = city
  74 + community.save
  75 + community
  76 + end
  77 +end
... ...
src/gov_user/test/unit/gov_user_person_test.rb 0 → 100644
... ... @@ -0,0 +1,58 @@
  1 +# encoding: utf-8
  2 +
  3 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  4 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  5 +
  6 +class SoftwareCommunitiesPluginPersonTest < ActiveSupport::TestCase
  7 + include PluginTestHelper
  8 +
  9 + def setup
  10 + @plugin = GovUserPlugin.new
  11 +
  12 + @user = fast_create(User)
  13 + @person = create_person(
  14 + "My Name",
  15 + "user@email.com",
  16 + "123456",
  17 + "123456",
  18 + "user2@email.com",
  19 + "Any State",
  20 + "Some City"
  21 + )
  22 + end
  23 +
  24 + def teardown
  25 + @plugin = nil
  26 + end
  27 +
  28 + should 'be a noosfero plugin' do
  29 + assert_kind_of Noosfero::Plugin, @plugin
  30 + end
  31 +
  32 + should 'save person with a valid full name' do
  33 + p = Person::new :name=>"S1mpl3 0f N4m3", :identifier=>"simple-name"
  34 + p.user = fast_create(:user)
  35 +
  36 + assert_equal true, p.save
  37 + end
  38 +
  39 + should 'save person with a valid full name with accents' do
  40 + name = 'Jônatàs dâ Sîlvã Jösé'
  41 + identifier = "jonatas-jose-da-silva"
  42 + p = Person::new :name=>name, :identifier=>identifier
  43 + p.user = fast_create(:user)
  44 +
  45 + assert_equal true, p.save
  46 + end
  47 +
  48 + should 'not save person whose name has not capital letter' do
  49 + p = Person::new :name=>"simple name"
  50 + assert !p.save, _("Name Should begin with a capital letter and no special characters")
  51 + end
  52 +
  53 + should 'not save person whose name has special characters' do
  54 + p = Person::new :name=>"Simple N@me"
  55 +
  56 + assert !p.save , _("Name Should begin with a capital letter and no special characters")
  57 + end
  58 +end
... ...
src/gov_user/test/unit/governmental_power_test.rb 0 → 100644
... ... @@ -0,0 +1,33 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/institution_test_helper'
  3 +
  4 +class GovernmentalPowerTest < ActiveSupport::TestCase
  5 +
  6 + def setup
  7 + @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
  8 + @juridical_nature = JuridicalNature.create(:name => "Autarquia")
  9 + end
  10 +
  11 + def teardown
  12 + Institution.destroy_all
  13 + end
  14 +
  15 + should "get public institutions" do
  16 + inst_name = "Ministerio Publico da Uniao"
  17 + inst_cnpj = "12.345.678/9012-45"
  18 + gov_power = GovernmentalPower.create(:name=>"Some gov power")
  19 + InstitutionTestHelper.create_public_institution(
  20 + inst_name,
  21 + "MPU",
  22 + "BR",
  23 + "DF",
  24 + "Gama",
  25 + @juridical_nature,
  26 + gov_power,
  27 + @gov_sphere,
  28 + inst_cnpj
  29 + )
  30 +
  31 + assert_equal gov_power.public_institutions.count, PublicInstitution.count
  32 + end
  33 +end
0 34 \ No newline at end of file
... ...
src/gov_user/test/unit/institution_test.rb 0 → 100644
... ... @@ -0,0 +1,63 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +
  4 +class InstitutionTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
  6 + def setup
  7 + @gov_power = GovernmentalPower.create(:name=>"Some Gov Power")
  8 + @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
  9 + @juridical_nature = JuridicalNature.create(:name => "Autarquia")
  10 +
  11 + @institution = create_public_institution(
  12 + "Ministerio Publico da Uniao",
  13 + "MPU",
  14 + "BR",
  15 + "DF",
  16 + "Gama",
  17 + @juridical_nature,
  18 + @gov_power,
  19 + @gov_sphere,
  20 + "11.222.333/4444-55"
  21 + )
  22 + end
  23 +
  24 + def teardown
  25 + GovernmentalPower.destroy_all
  26 + GovernmentalSphere.destroy_all
  27 + JuridicalNature.destroy_all
  28 + @institution = nil
  29 + end
  30 + should "not save institutions without name" do
  31 + @institution.name = nil
  32 + assert_equal false, @institution.save
  33 + assert_equal true, @institution.errors.full_messages.include?("Name can't be blank")
  34 + end
  35 +
  36 + should "not save if institution has invalid type" do
  37 + invalid_msg = "Type invalid, only public and private institutions are allowed."
  38 + @institution.type = "Other type"
  39 + assert_equal false, @institution.save
  40 + assert_equal true, @institution.errors.full_messages.include?(invalid_msg)
  41 + end
  42 +
  43 + should "not save without country" do
  44 + @institution.community.country = nil
  45 + assert_equal false, @institution.save
  46 + assert_equal true, @institution.errors.full_messages.include?("Country can't be blank")
  47 + end
  48 +
  49 + should "not save without state" do
  50 + @institution.community.state = nil
  51 +
  52 + assert_equal false, @institution.save
  53 + assert_equal true, @institution.errors.full_messages.include?("State can't be blank")
  54 + end
  55 +
  56 + should "not save without city" do
  57 + @institution.community.city = nil
  58 + @institution.community.state = "DF"
  59 +
  60 + assert_equal false, @institution.save
  61 + assert_equal true, @institution.errors.full_messages.include?("City can't be blank")
  62 + end
  63 +end
... ...
src/gov_user/test/unit/institutions_block_test.rb 0 → 100644
... ... @@ -0,0 +1,51 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +
  4 +class InstitutionsBlockTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
  6 + should 'inherit from Block' do
  7 + assert_kind_of Block, InstitutionsBlock.new
  8 + end
  9 +
  10 + should 'declare its default title' do
  11 + InstitutionsBlock.any_instance.stubs(:profile_count).returns(0)
  12 + assert_not_equal Block.new.default_title, InstitutionsBlock.new.default_title
  13 + end
  14 +
  15 + should 'describe itself' do
  16 + assert_not_equal Block.description, InstitutionsBlock.description
  17 + end
  18 +
  19 + should 'give empty footer on unsupported owner type' do
  20 + block = InstitutionsBlock.new
  21 + block.expects(:owner).returns(1)
  22 + assert_equal '', block.footer
  23 + end
  24 +
  25 + should 'list institutions' do
  26 + user = create_person("Jose_Augusto",
  27 + "jose_augusto@email.com",
  28 + "aaaaaaa",
  29 + "aaaaaaa",
  30 + 'jose@secondary.com',
  31 + "DF",
  32 + "Gama"
  33 + )
  34 +
  35 + institution = create_private_institution(
  36 + "inst name",
  37 + "IN",
  38 + "country",
  39 + "state",
  40 + "city",
  41 + "00.111.222/3333-44"
  42 + )
  43 + institution.community.add_member(user)
  44 +
  45 + block = InstitutionsBlock.new
  46 + block.expects(:owner).at_least_once.returns(user)
  47 +
  48 + assert_equivalent [institution.community], block.profiles
  49 + end
  50 +
  51 +end
... ...
src/gov_user/test/unit/juridical_nature_test.rb 0 → 100644
... ... @@ -0,0 +1,23 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +
  4 +class JuridicalNatureTest < ActiveSupport::TestCase
  5 +
  6 + include PluginTestHelper
  7 +
  8 + def setup
  9 + @govPower = GovernmentalPower.create(:name=>"Some Gov Power")
  10 + @govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
  11 + end
  12 +
  13 + def teardown
  14 + Institution.destroy_all
  15 + end
  16 +
  17 + should "get public institutions" do
  18 + juridical_nature = JuridicalNature.create(:name => "Autarquia")
  19 + create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", juridical_nature, @govPower, @govSphere, "22.333.444/5555-66")
  20 + create_public_institution("Tribunal Regional da Uniao", "TRU", "BR", "DF", "Brasilia", juridical_nature, @govPower, @govSphere, "22.333.444/5555-77")
  21 + assert juridical_nature.public_institutions.count == PublicInstitution.count
  22 + end
  23 +end
... ...
src/gov_user/test/unit/organization_rating_test.rb 0 → 100644
... ... @@ -0,0 +1,44 @@
  1 +require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper'
  2 +require File.expand_path(File.dirname(__FILE__)) + '/../helpers/plugin_test_helper'
  3 +
  4 +class OrganizationRatingTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
  6 +
  7 + def setup
  8 + @environment = Environment.default
  9 + @environment.enabled_plugins = ['SoftwareCommunitiesPlugin']
  10 + @environment.save
  11 + end
  12 +
  13 + should "validate institution if there is an institution_id" do
  14 + person = fast_create(Person)
  15 + community = fast_create(Community)
  16 + private_institution = build_private_institution "huehue", "hue", "11.222.333/4444-55"
  17 +
  18 + community_rating = OrganizationRating.new(:person => person, :value => 3, :organization => community, :institution => private_institution)
  19 + assert_equal false, community_rating.valid?
  20 +
  21 + assert_equal true, community_rating.errors[:institution].include?("not found")
  22 +
  23 + private_institution.save
  24 + community_rating.institution = private_institution
  25 +
  26 + assert_equal true, community_rating.valid?
  27 + assert_equal false, community_rating.errors[:institution].include?("not found")
  28 + end
  29 +
  30 + private
  31 +
  32 + def build_private_institution name, corporate_name, cnpj, country="AR"
  33 + community = Community.new :name => name
  34 + community.country = country
  35 +
  36 + institution = PrivateInstitution.new :name=> name
  37 + institution.corporate_name = corporate_name
  38 + institution.cnpj = cnpj
  39 + institution.community = community
  40 +
  41 + institution
  42 + end
  43 +end
  44 +
... ...
src/gov_user/test/unit/person_test.rb 0 → 100644
... ... @@ -0,0 +1,43 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +
  4 +class SoftwareCommunitiesPluginPersonTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
  6 + def setup
  7 + @plugin = GovUserPlugin.new
  8 +
  9 + @user = fast_create(User)
  10 + @person = create_person(
  11 + "My Name",
  12 + "user@email.com",
  13 + "123456",
  14 + "123456",
  15 + "user@secondaryemail.com",
  16 + "Any State",
  17 + "Some City"
  18 + )
  19 + end
  20 +
  21 + should 'calculate the percentege of person incomplete fields' do
  22 + @person.cell_phone = "76888919"
  23 + @person.contact_phone = "987654321"
  24 +
  25 + assert_equal(67, @plugin.calc_percentage_registration(@person))
  26 +
  27 + @person.comercial_phone = "11223344"
  28 + @person.country = "I dont know"
  29 + @person.state = "I dont know"
  30 + @person.city = "I dont know"
  31 + @person.organization_website = "www.whatever.com"
  32 + @person.image = Image::new :uploaded_data=>fixture_file_upload('/files/rails.png', 'image/png')
  33 + @person.save
  34 +
  35 + assert_equal(100, @plugin.calc_percentage_registration(@person))
  36 + end
  37 +
  38 + should 'return true when the email has not gov.br,jus.br,leg.br or mp.br' do
  39 + @user.secondary_email = "test_email@com.br"
  40 + @user.email = "test_email@net.br"
  41 + assert @user.save
  42 + end
  43 +end
... ...
src/gov_user/test/unit/private_institution_test.rb 0 → 100644
... ... @@ -0,0 +1,34 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +
  4 +class PrivateInstitutionTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
  6 + def setup
  7 + @institution = create_private_institution(
  8 + "Simple Private Institution",
  9 + "SPI",
  10 + "BR",
  11 + "DF",
  12 + "Gama",
  13 + "00.000.000/0001-00"
  14 + )
  15 + end
  16 +
  17 + def teardown
  18 + @institution = nil
  19 + Institution.destroy_all
  20 + end
  21 +
  22 + should "save without a cnpj" do
  23 + @institution.cnpj = nil
  24 +
  25 + assert @institution.save
  26 + end
  27 +
  28 + should "save without fantasy name" do
  29 + @institution.acronym = nil
  30 + @institution.community.save
  31 +
  32 + assert @institution.save
  33 + end
  34 +end
... ...
src/gov_user/test/unit/public_institution_test.rb 0 → 100644
... ... @@ -0,0 +1,68 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +
  4 +class PublicInstitutionTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
  6 + def setup
  7 + @gov_power = GovernmentalPower.create(:name=>"Some Gov Power")
  8 + @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
  9 + @juridical_nature = JuridicalNature.create(:name => "Autarquia")
  10 +
  11 + @institution = create_public_institution(
  12 + "Ministerio Publico da Uniao",
  13 + "MPU",
  14 + "BR",
  15 + "DF",
  16 + "Gama",
  17 + @juridical_nature,
  18 + @gov_power,
  19 + @gov_sphere,
  20 + "11.222.333/4444-55"
  21 + )
  22 + end
  23 +
  24 + def teardown
  25 + GovernmentalPower.destroy_all
  26 + GovernmentalSphere.destroy_all
  27 + JuridicalNature.destroy_all
  28 + Institution.destroy_all
  29 + @gov_power = nil
  30 + @gov_sphere = nil
  31 + @juridical_nature = nil
  32 + @institution = nil
  33 + end
  34 +
  35 + should "save without a cnpj" do
  36 + @institution.cnpj = nil
  37 + assert @institution.save
  38 + end
  39 +
  40 + should "save institution without an acronym" do
  41 + @institution.acronym = nil
  42 + assert @institution.save
  43 + end
  44 +
  45 + should "Not save institution without a governmental_power" do
  46 + invalid_msg = "Governmental power can't be blank"
  47 + @institution.governmental_power = nil
  48 +
  49 + assert !@institution.save
  50 + assert @institution.errors.full_messages.include? invalid_msg
  51 + end
  52 +
  53 + should "Not save institution without a governmental_sphere" do
  54 + invalid_msg = "Governmental sphere can't be blank"
  55 + @institution.governmental_sphere = nil
  56 +
  57 + assert !@institution.save
  58 + assert @institution.errors.full_messages.include? invalid_msg
  59 + end
  60 +
  61 + should "not save institution without juridical nature" do
  62 + invalid_msg = "Juridical nature can't be blank"
  63 + @institution.juridical_nature = nil
  64 +
  65 + assert !@institution.save
  66 + assert @institution.errors.full_messages.include? invalid_msg
  67 + end
  68 +end
... ...
src/gov_user/test/unit/user_test.rb 0 → 100644
... ... @@ -0,0 +1,99 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +
  4 +class UserTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
  6 +
  7 + should 'not save user whose both email and secondary email are the same' do
  8 + user = fast_create(User)
  9 + user.email = "test@email.com"
  10 + user.secondary_email = "test@email.com"
  11 +
  12 + assert !user.save
  13 + end
  14 +
  15 + should 'not save user whose email and secondary email have been taken' do
  16 + user1 = create_default_user
  17 + user2 = fast_create(User)
  18 +
  19 + user2.email = "primary@email.com"
  20 + user2.secondary_email = "secondary@email.com"
  21 + assert !user2.save
  22 + end
  23 +
  24 + should 'not save user whose email has already been used' do
  25 + user1 = create_default_user
  26 + user2 = fast_create(User)
  27 +
  28 + user2.email = "primary@email.com"
  29 + user2.secondary_email = "noosfero@email.com"
  30 + assert !user2.save
  31 + end
  32 +
  33 + should 'not save user whose email has been taken another in users secondary email' do
  34 + user1 = create_default_user
  35 + user2 = fast_create(User)
  36 +
  37 + user2.login = "another-login"
  38 + user2.email = "secondary@email.com"
  39 + user2.secondary_email = "noosfero@email.com"
  40 + assert !user2.save
  41 + end
  42 +
  43 + should 'not save user whose secondary email has been taken used in another users email' do
  44 + user1 = create_default_user
  45 + user2 = fast_create(User)
  46 +
  47 + user2.login = "another-login"
  48 + user2.email = "noosfero@email.com"
  49 + user2.secondary_email = "primary@email.com"
  50 + assert !user2.save
  51 + end
  52 +
  53 + should 'not save user whose secondary email has already been used in another users secondary email' do
  54 + user1 = create_default_user
  55 + user2 = fast_create(User)
  56 +
  57 + user2.login = "another-login"
  58 + user2.email = "noosfero@email.com"
  59 + user2.secondary_email = "secondary@email.com"
  60 + assert !user2.save
  61 + end
  62 +
  63 + should 'not save user whose secondary email is in the wrong format' do
  64 + user = fast_create(User)
  65 + user.email = "test@email.com"
  66 + user.secondary_email = "notarightformat.com"
  67 +
  68 + assert !user.save
  69 +
  70 + user.secondary_email = "not@arightformatcom"
  71 +
  72 + assert !user.save
  73 + end
  74 +
  75 + should 'save more than one user without secondary email' do
  76 + user = fast_create(User)
  77 + user.email = "test@email.com"
  78 + user.secondary_email = ""
  79 + user.save
  80 +
  81 + user2 = fast_create(User)
  82 + user2.email = "test2@email.com"
  83 + user2.secondary_email = ""
  84 + assert user2.save
  85 + end
  86 +
  87 + private
  88 +
  89 + def create_default_user
  90 + user = fast_create(User)
  91 + user.login = "a-login"
  92 + user.email = "primary@email.com"
  93 + user.secondary_email = "secondary@email.com"
  94 + user.save
  95 +
  96 + return user
  97 + end
  98 +
  99 +end
... ...
src/gov_user/views/gov_user_plugin/_institution.html.erb 0 → 100644
... ... @@ -0,0 +1,128 @@
  1 +<h1><%= _('New Institution') %></h1>
  2 +
  3 +<% if environment.enabled?('admin_must_approve_new_communities') %>
  4 + <div class='explanation'>
  5 + <%= _("Note that the creation of communities in this environment is restricted. Your request to create this new community will be sent to %{environment} administrators and will be approved or rejected according to their methods and criteria.") % { :environment => environment.name }%>
  6 + </div>
  7 +<%end %>
  8 +
  9 +<% unless flash[:errors].nil? %>
  10 +<div class="errorExplanation" id="errorExplanation">
  11 + <h2> <%= _("Can`t create new Institution: #{flash[:errors].length} errors") %> </h2>
  12 + <ul>
  13 + <% flash[:errors].each do |key, value| %>
  14 + <% key_name = key.to_s.gsub("_", " ") %>
  15 + <% if value.length > 0 %>
  16 + <li> <%= _("<b>#{key_name.capitalize}</b> #{value.join()}") %> </li>
  17 + <% end %>
  18 + <% end %>
  19 + </ul>
  20 +</div>
  21 +<% end %>
  22 +
  23 +<div id = 'create_institution_errors' class='errorExplanation hide-field'></div>
  24 +
  25 +<div>
  26 + <%= labelled_form_for :community, :url => {:action=>"new_institution"}, :html => { :multipart => true, :id=>"institution_form" } do |f| %>
  27 + <%= required_fields_message %>
  28 + <%= hidden_field_tag "edit_institution_page", false %>
  29 + <%= fields_for :institutions do |inst| %>
  30 + <span class=''>
  31 + <div class='formfield type-radio'>
  32 + <label>
  33 + <%= _("Private Institution") %>
  34 + <%= radio_button_tag("institutions[type]" ,"PrivateInstitution", true)%>
  35 + </label>
  36 +
  37 + <label> <%= _("Public Institution") %>
  38 + <%= radio_button_tag("institutions[type]", "PublicInstitution") %>
  39 + </label>
  40 + </div>
  41 + </span>
  42 +
  43 + <%= required f.text_field(:name, :class => flash[:error_community_name], :value => params[:community][:name]) %>
  44 + <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %>
  45 +
  46 + <span class='optional-field'>
  47 + <div class="formfield type-text">
  48 + <%= inst.label "corporate_name", _("Corporate Name"), :class=>"formlabel" %>
  49 + <%= inst.text_field(:corporate_name, :value => params[:institutions][:corporate_name], :size => 55) %>
  50 + </div>
  51 + </span>
  52 +
  53 + <%= required select_country(_('Country'), 'community', 'country', {:class => "type-select #{flash[:error_community_country]}", :id => "community_country"}) %>
  54 +
  55 + <span class='required-field'>
  56 + <div class="formfield">
  57 + <label for="community_state" class="formlabel"><%= _("State") %></label>
  58 + <%= f.select(:state, @state_options, {:selected => params[:community][:state]}, {:class => flash[:error_community_state]}) %>
  59 + </div>
  60 + </span>
  61 +
  62 + <%= required f.text_field(:city, :class => flash[:error_community_city], :value => params[:community][:city]) %>
  63 +
  64 +
  65 + <div class="formfield type-text">
  66 + <%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %>
  67 + <%= required inst.text_field(:cnpj, :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field", :value => params[:institutions][:cnpj]) %>
  68 + </div>
  69 +
  70 + <span class='optional-field'>
  71 + <div class="formfield type-text">
  72 + <%= hidden_field_tag "acronym_translate", _("Acronym") %>
  73 + <%= hidden_field_tag "fantasy_name_translate", _("Fantasy name") %>
  74 + <%= inst.label("acronym" ,_("Acronym"), :class=>"formlabel") %>
  75 + <%= inst.text_field(:acronym, :value => params[:institutions][:acronym]) %>
  76 + </div>
  77 + </span>
  78 +
  79 + <span class='required-field public-institutions-fields'>
  80 + <div class="formfield type-text">
  81 + <%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %>
  82 + <%= inst.select(:governmental_sphere, @governmental_sphere, :selected=>params[:institutions][:governmental_sphere], :class => flash[:error_institution_governmental_sphere])%>
  83 + </div>
  84 + </span>
  85 +
  86 + <span class='required-field public-institutions-fields'>
  87 + <div class="formfield type-text">
  88 + <%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %>
  89 + <%= inst.select(:governmental_power, @governmental_power, :selected=>params[:institutions][:governmental_sphere], :class => flash[:error_institution_governmental_power])%>
  90 + </div>
  91 + </span>
  92 + <span class='required-field public-institutions-fields'>
  93 + <div class="formfield type-text">
  94 + <%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %>
  95 + <%= inst.select(:juridical_nature, @juridical_nature, :selected=>params[:institutions][:juridical_nature], :class => flash[:error_institution_juridical_nature])%>
  96 + </div>
  97 + </span>
  98 +
  99 + <span class='required-field public-institutions-fields'>
  100 + <div class="formfield type-text">
  101 + <%= _("SISP?") %>
  102 + <% if @show_sisp_field %>
  103 + <%= inst.radio_button(:sisp, true, :class => "#{flash[:error_institution_sisp]}" ) %>
  104 + <%= inst.label :sisp ,_("Yes"), :value => true %>
  105 + <%= inst.radio_button(:sisp, false, :checked=>"checked", :class => "#{flash[:error_institution_sisp]}") %>
  106 + <%= inst.label :sisp ,_("No"), :value => false %>
  107 + <% else %>
  108 + <%= inst.label("sisp", _("No")) %>
  109 + <% end %>
  110 + </div>
  111 + </span>
  112 +
  113 + <% if @url_token == "create_institution_admin" %>
  114 + <%= submit_button :save, _('Save') %>
  115 + <%= button(:cancel, _("Cancel"), {:controller => "admin_panel", :action => 'index'}) %>
  116 + <%else%>
  117 + <div>
  118 + <%= link_to(_('Save'), '#', :id=>'save_institution_button', :class=>'button with-text icon-add') %>
  119 + <%= link_to(_('Cancel'), '#', :id=>"cancel_institution_button", :class=>'button with-text icon-cancel') %>
  120 + </div>
  121 + <%= hidden_field_tag :institution_error_message, _("Could not send the form data to the server") %>
  122 + <%end%>
  123 +
  124 + <% end %>
  125 +
  126 + <% end %>
  127 +</div>
  128 +<%= hidden_field_tag :loading_message, _("Creating institution") %>
... ...
src/gov_user/views/gov_user_plugin/create_institution.html.erb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +<%= render :partial => "institution" %>
... ...
src/gov_user/views/gov_user_plugin/create_institution_admin.html.erb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +<%= render :partial => "institution" %>
... ...
src/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb 0 → 100644
... ... @@ -0,0 +1,114 @@
  1 +<h1><%= _('Edit Institution') %></h1>
  2 +
  3 +<% if environment.enabled?('admin_must_approve_new_communities') %>
  4 + <div class='explanation'>
  5 + <%= _("Note that the creation of communities in this environment is restricted. Your request to create this new community will be sent to %{environment} administrators and will be approved or rejected according to their methods and criteria.") % { :environment => environment.name }%>
  6 + </div>
  7 +<%end %>
  8 +
  9 +<% unless flash[:errors].blank? %>
  10 + <div class="errorExplanation" id="errorExplanation">
  11 + <h2> <%= _("Can`t create new Institution: #{flash[:errors].length} errors") %> </h2>
  12 + <ul>
  13 + <% flash[:errors].each do |error| %>
  14 + <li> <%= error %> </li>
  15 + <% end %>
  16 + </ul>
  17 + </div>
  18 +<% end %>
  19 +
  20 +<div id = 'create_institution_errors' class='errorExplanation hide-field'></div>
  21 +
  22 +<div>
  23 + <%= labelled_form_for :community,:html => { :multipart => true, :id=>"institution_form" } do |f| %>
  24 + <%= hidden_field_tag "edit_institution_page", true %>
  25 + <%= fields_for :institutions do |inst| %>
  26 + <span class=''>
  27 + <div class='formfield type-radio'>
  28 + <label> <%= _("Public Institution") %>
  29 + <%= radio_button_tag("institutions[type]", "PublicInstitution", (@institution.type == "PublicInstitution" ? true : false)) %>
  30 + </label>
  31 +
  32 + <label>
  33 + <%= _("Private Institution") %>
  34 + <%= radio_button_tag("institutions[type]" ,"PrivateInstitution", (@institution.type == "PrivateInstitution" ? true : false))%>
  35 + </label>
  36 + </div>
  37 + </span>
  38 +
  39 + <%= required f.text_field(:name, :value => @institution.community.name) %>
  40 + <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %>
  41 +
  42 + <span class='required-field'>
  43 + <div class="formfield type-text">
  44 + <%= inst.label "corporate_name", _("Corporate Name"), :class=>"formlabel" %>
  45 + <%= required inst.text_field(:corporate_name, :value => @institution.corporate_name) %>
  46 + </div>
  47 + </span>
  48 +
  49 + <%= required select_country(_('Country'), 'community', 'country', {:class => 'type-select', :id => "community_country"}, :selected => @institution.community.country) %>
  50 +
  51 + <span class='required-field'>
  52 + <div class="formfield">
  53 + <label for="community_state" class="formlabel"><%= _("State") %></label>
  54 + <%= f.select(:state, @state_list.collect {|state| [state.name, state.name]}, :selected => @institution.community.state) %>
  55 + </div>
  56 + </span>
  57 +
  58 + <%= required f.text_field(:city, :value => @institution.community.city) %>
  59 +
  60 +
  61 + <span class='optional-field'>
  62 + <div class="formfield type-text">
  63 + <%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %>
  64 + <%= required inst.text_field(:cnpj, :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field", :value => @institution.cnpj) %>
  65 + </div>
  66 + </span>
  67 +
  68 + <span class='optional-field'>
  69 + <div class="formfield type-text">
  70 + <%= hidden_field_tag "acronym_translate", _("Acronym") %>
  71 + <%= hidden_field_tag "fantasy_name_translate", _("Fantasy name") %>
  72 + <%= inst.label("acronym" ,_("Acronym"), :class=>"formlabel") %>
  73 + <%= inst.text_field(:acronym, :value => @institution.acronym) %>
  74 + </div>
  75 + </span>
  76 +
  77 + <span class='required-field public-institutions-fields'>
  78 + <div class="formfield type-text">
  79 + <%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %>
  80 + <%= inst.select(:governmental_sphere, [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}, {:selected=>@institution.governmental_power_id})%>
  81 + </div>
  82 + </span>
  83 +
  84 + <span class='required-field public-institutions-fields'>
  85 + <div class="formfield type-text">
  86 + <%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %>
  87 + <%= inst.select(:governmental_power, [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}, {:selected=> @institution.governmental_sphere_id})%>
  88 + </div>
  89 + </span>
  90 + <span class='required-field public-institutions-fields'>
  91 + <div class="formfield type-text">
  92 + <%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %>
  93 + <%= inst.select(:juridical_nature, [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}, {:selected=> @institution.juridical_nature_id})%>
  94 + </div>
  95 + </span>
  96 +
  97 + <span class='required-field public-institutions-fields'>
  98 + <div class="formfield type-text">
  99 + <%= _("SISP?") %>
  100 + <% if @show_sisp_field %>
  101 + <%= inst.label("sisp" ,_("Yes")) %>
  102 + <%= inst.radio_button(:sisp, true, :checked=>(@institution.sisp ? true : false)) %>
  103 + <%= inst.label("sisp" ,_("No")) %>
  104 + <%= inst.radio_button(:sisp, false, :checked=>(@institution.sisp ? false : true)) %>
  105 + <% else %>
  106 + <%= inst.label("sisp", _("No")) %>
  107 + <% end %>
  108 + </div>
  109 + </span>
  110 +
  111 + <%= submit_button :save, _('Save') %>
  112 + <% end %>
  113 +<% end %>
  114 +
... ...
src/gov_user/views/incomplete_registration.html.erb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +<div id='complete_registration'>
  2 + <div id="complete_registration_message">
  3 + <div><%= _("Complete Profile")+": <span>#{@percentege}</span>%" %></div>
  4 + <canvas id="complete_registration_percentage" width="100%" height="20"></canvas>
  5 + <div>
  6 + <%= link_to _("Complete your profile"), "#{Noosfero.root}/myprofile/#{@person.identifier}/profile_editor/edit" %> |
  7 + <%= link_to _("Hide"), "#", :class=>"hide-incomplete-percentage" %>
  8 + </div>
  9 + </div>
  10 +</div>
  11 +</div>
... ...
src/gov_user/views/organization_ratings_extra_fields_show_institution.html.erb 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +<% if user_rating.institution %>
  2 +<div class="aditional-informations">
  3 + <div class="comments-user-institution">
  4 + <span>Institution :<span> <%= user_rating.institution.name unless user_rating.institution.nil? %>
  5 + </div>
  6 +</div>
  7 +<% end %>
  8 +
... ...
src/gov_user/views/person_editor_extras.html.erb 0 → 100644
... ... @@ -0,0 +1,42 @@
  1 +<div class="formfieldline">
  2 + <%= label_tag "user[secondary_email]", _('Secondary e-mail')+":", :class=>"formlabel" %>
  3 +
  4 + <div class="formfield type-text">
  5 + <%= text_field_tag "user[secondary_email]", context.profile.user.secondary_email %>
  6 + </div>
  7 +</div>
  8 +
  9 +
  10 +<div class="formfieldline" id="select_institution">
  11 + <%= label_tag "user[institution_ids]", _('Institutions'), :class=>"formlabel" %>
  12 +
  13 + <div class="institution_container">
  14 + <%= text_field_tag(:institution, "", :id=>"input_institution") %>
  15 +
  16 + <% context.profile.user.institutions.each do |institution| %>
  17 + <%= hidden_field_tag("user[institution_ids][]", institution.id, :class => 'user_institutions') %>
  18 + <% end %>
  19 + </div>
  20 +
  21 + <%= content_tag(:div, _("No institution found"), :id=>"institution_empty_ajax_message", :class=>"errorExplanation hide-field") %>
  22 + <%= link_to(_("Add new institution"), "#", :class=>'button with-text icon-add', :id => 'add_new_institution') %>
  23 + <%= link_to(_("Create new institution"), "#", :id=>"create_institution_link", :class=>'button with-text icon-add') %>
  24 + <%= content_tag(:div, "", :id=>"institution_dialog") %>
  25 +
  26 + <%= hidden_field_tag("user[institution_ids][]", "", :class => 'user_institutions') %>
  27 + <%= hidden_field_tag("institution_selected", "") %>
  28 +
  29 + <ul class="institutions_added">
  30 + <% context.profile.user.institutions.each do |institution| %>
  31 + <li data-institution="<%= institution.id %>">
  32 + <%= institution.name %>
  33 + <%= link_to("", "#", :class => "button without-text icon-remove remove-institution") %>
  34 + </li>
  35 + <% end %>
  36 + </ul>
  37 +</div>
  38 +
  39 +<%= hidden_field_tag("full_name_error", _("Should begin with a capital letter and no special characters")) %>
  40 +<%= hidden_field_tag("email_error", _("Email should have the following format: name@host.br")) %>
  41 +<%= hidden_field_tag("site_error", _("Site should have a valid format: http://name.hosts")) %>
  42 +<div id="email_public_message"><%= _("If you work in a public agency use your government e-Mail") %> </div>
... ...
src/gov_user/views/profile/_institution_tab.html.erb 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +<table>
  2 + <tr>
  3 + <th colspan='2'><%= _('Institution Information')%></th>
  4 + </tr>
  5 +
  6 + <%= display_mpog_field(_('Type:'), profile.institution, :type, true) %>
  7 + <%= display_mpog_field(_('CNPJ:'), profile.institution, :cnpj, true) %>
  8 + <%= display_mpog_field(_('Last modification:'), profile.institution, :date_modification, true) %>
  9 + <%= display_mpog_field(_('Country:'), profile.institution.community, :country, true) %>
  10 + <%= display_mpog_field(_('State:'), profile.institution.community, :state, true) %>
  11 + <%= display_mpog_field(_('City:'), profile.institution.community, :city, true) %>
  12 + <% if profile.institution.type == "PrivateInstitution"%>
  13 + <%= display_mpog_field(_('Fantasy Name:'), profile.institution, :acronym, true) %>
  14 + <% else %>
  15 + <%= display_mpog_field(_('Acronym:'), profile.institution, :acronym, true) %>
  16 + <%= display_mpog_field(_('Governmental Power:'), profile.institution.governmental_power, :name, true) %>
  17 + <%= display_mpog_field(_('Governmental Sphere:'), profile.institution.governmental_sphere, :name, true) %>
  18 + <%= display_mpog_field(_('Juridical Nature:'), profile.institution.juridical_nature, :name, true) %>
  19 + <%= content_tag('tr', content_tag('td', _("SISP:")) + content_tag('td', profile.institution.sisp ? _("Yes") : _("No"))) %>
  20 + <% end %>
  21 +</table>
... ...
src/gov_user/views/profile/_profile_tab.html.erb 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +<table>
  2 + <%= display_mpog_profile_information %>
  3 +</table>
... ...
src/gov_user/views/ratings_extra_field.html.erb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +<div id="input_institution_comments">
  2 + <%= label_tag "input_institution", _("Organization name or Enterprise name")%>
  3 + <span class="star-tooltip" title="Órgão ou Empresa que você representa e utiliza o software"></span>
  4 + <input type="text" id="input_institution">
  5 +
  6 + <%= content_tag(:div, _("No institution found"),
  7 + :id=>"institution_empty_ajax_message",
  8 + :class=>"errorExplanation hide-field") %>
  9 + <%= hidden_field_tag "organization_rating[institution_id]", "", id: "institution_selected" %>
  10 +</div>
... ...
src/gov_user/views/search/institutions.html.erb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +<%= search_page_title( @titles[@asset], @category ) %>
  2 +
  3 +<%= render :partial => 'search_form', :locals => { :hint => _("Type words about the %s you're looking for") % @asset.to_s.singularize } %>
  4 +
  5 +<%= display_results(@searches, @asset) %>
  6 +<% if params[:display] != 'map' %>
  7 + <%= pagination_links @searches[@asset][:results] %>
  8 +<% end %>
  9 +
  10 +<div style="clear: both"></div>
  11 +
  12 +<% if @asset == :product %>
  13 + <%= javascript_tag do %>
  14 + jQuery('.search-product-price-details').altBeautify();
  15 + <% end %>
  16 +<% end %>
... ...