diff --git a/app/controllers/public/enterprise_registration_controller.rb b/app/controllers/public/enterprise_registration_controller.rb
new file mode 100644
index 0000000..92c2edf
--- /dev/null
+++ b/app/controllers/public/enterprise_registration_controller.rb
@@ -0,0 +1,52 @@
+class EnterpriseRegistrationController < ApplicationController
+
+ # Just go to the first step.
+ #
+ # FIXME: shouldn't this action present some sort of welcome message and point
+ # to the first step explicitly?
+ def index
+ @create_enterprise = CreateEnterprise.new(params[:create_enterprise])
+ @create_enterprise.requestor = current_user.person
+ the_action =
+ if request.post?
+ if @create_enterprise.valid_before_selecting_target?
+ if @create_enterprise.valid?
+ :confirmation
+ else
+ :select_validator
+ end
+ end
+ end
+
+ # default to basic_information
+ the_action ||= :basic_information
+
+ send(the_action)
+ render :action => the_action
+ end
+
+ protected
+
+ # Fill in the form and select your Region.
+ #
+ # Posts back.
+ def basic_information
+ @regions = environment.regions.map {|item| [item.name, item.id]}
+ end
+
+ # present information about validator organizations, and the user one to
+ # validate her brand new enterprise.
+ #
+ # Posts back.
+ def select_validator
+ @validators = @create_enterprise.region.validators
+ end
+
+ # Actually records the enterprise registration request and presents a
+ # confirmation message saying to the user that the enterprise register
+ # request was done.
+ def confirmation
+ @create_enterprise.save!
+ end
+
+end
diff --git a/app/models/create_enterprise.rb b/app/models/create_enterprise.rb
index 6f9a13b..4d467ae 100644
--- a/app/models/create_enterprise.rb
+++ b/app/models/create_enterprise.rb
@@ -34,6 +34,14 @@ class CreateEnterprise < Task
end
end
+ def valid_before_selecting_target?
+ if valid?
+ true
+ else
+ self.errors.size == 1 and self.errors[:target_id]
+ end
+ end
+
# gets the associated region for the enterprise creation
def region(reload = false)
if self.region_id
diff --git a/app/views/enterprise_registration/_hidden_fields.rhtml b/app/views/enterprise_registration/_hidden_fields.rhtml
new file mode 100644
index 0000000..bdf5533
--- /dev/null
+++ b/app/views/enterprise_registration/_hidden_fields.rhtml
@@ -0,0 +1,11 @@
+<%= hidden_field 'create_enterprise', 'identifier' %>
+<%= hidden_field 'create_enterprise', 'name' %>
+<%= hidden_field 'create_enterprise', 'address' %>
+<%= hidden_field 'create_enterprise', 'contact_phone' %>
+<%= hidden_field 'create_enterprise', 'contact_person' %>
+<%= hidden_field 'create_enterprise', 'acronym' %>
+<%= hidden_field 'create_enterprise', 'foundation_year' %>
+<%= hidden_field 'create_enterprise', 'legal_form' %>
+<%= hidden_field 'create_enterprise', 'economic_activity' %>
+<%= hidden_field 'create_enterprise', 'management_information' %>
+<%= hidden_field 'create_enterprise', 'region_id' %>
diff --git a/app/views/enterprise_registration/basic_information.rhtml b/app/views/enterprise_registration/basic_information.rhtml
new file mode 100644
index 0000000..e154fcf
--- /dev/null
+++ b/app/views/enterprise_registration/basic_information.rhtml
@@ -0,0 +1,36 @@
+<%= error_messages_for 'create_enterprise' %>
+
+
<%= _('Register enterprise') %>
+
+ <%= _('How to proceed') %>
+ <%= _('Fill the form and hit the Register button then the enterprise will be submitted for evaluation at the validation entitiy of your choice (within your state), when the enterprise is aproved you will be able to activate its profile') %>
+
+<% labelled_form_for(:create_enterprise, @create_enterprise) do |f| %>
+ <%= f.text_field 'identifier', 'size' => 20 %>
+
+ <%= f.text_field 'name', 'size' => 20 %>
+
+ <%= f.text_field 'address', 'size' => 50 %>
+
+ <%= f.text_field 'contact_phone', 'size' => 20 %>
+
+ <%= f.text_field 'contact_person', 'size' => 20 %>
+
+ <%= f.text_field 'acronym', 'size' => 20 %>
+
+ <%= f.text_field 'foundation_year', 'size' => 20 %>
+
+ <%= f.text_field 'legal_form', 'size' => 20 %>
+
+ <%= f.text_field 'economic_activity', 'size' => 20 %>
+
+ <%= labelled_form_field(_('Management information'), text_editor('create_enterprise', 'management_information')) %>
+
+ <%= f.select('region_id', @regions) %>
+
+
+ <%= submit_tag _('Register') %>
+ <%= link_to _('Cancel'), :action => 'index' %>
+
+
+<% end %>
diff --git a/app/views/enterprise_registration/confirmation.rhtml b/app/views/enterprise_registration/confirmation.rhtml
new file mode 100644
index 0000000..e5424c3
--- /dev/null
+++ b/app/views/enterprise_registration/confirmation.rhtml
@@ -0,0 +1,9 @@
+<%= _('Enterprise Registration completed') %>
+
+
+<%= _("Your enterprise registration request was successfully registered. The validator organization you choose (%s) should get in touch with to start the validation process. As soon as the validators approve (or reject) your request, you will be notified by e-mail.") % @create_enterprise.target.name %>
+
+
+
+<%= link_to _('You can continue to browse this environment.'), :controller => 'home' %>
+
diff --git a/app/views/enterprise_registration/select_validator.rhtml b/app/views/enterprise_registration/select_validator.rhtml
new file mode 100644
index 0000000..a874dc5
--- /dev/null
+++ b/app/views/enterprise_registration/select_validator.rhtml
@@ -0,0 +1,18 @@
+<%= _('Enterprise Registration: Select a validator organization') %>
+
+
+<%= _('Select one organization to validate your enterprise registration request. Check the provided information about their validation methodoly and criteria.') %>
+
+
+<% form_tag do %>
+ <%= render :partial => 'hidden_fields' %>
+
+ <% for validator in @validators %>
+
+ <%= radio_button_tag('create_enterprise[target_id]', validator.id) %>
+ <%= validator.name %>
+
+ <% end %>
+
+ <%= submit_tag _('Confirm') %>
+<% end %>
diff --git a/app/views/layouts/application.rhtml b/app/views/layouts/application.rhtml
index deff76f..c21896c 100644
--- a/app/views/layouts/application.rhtml
+++ b/app/views/layouts/application.rhtml
@@ -3,7 +3,7 @@
<%= javascript_include_tag 'prototype' %>
- <%= javascript_include_tag 'sweetTitles' %>
+ <%# javascript_include_tag 'sweetTitles' %>
<%= javascript_include_tag 'tiny_mce/tiny_mce.js' %>
<%= javascript_include_tag 'scriptaculous' %>
<%= javascript_include_tag 'dragdrop' %>
diff --git a/config/routes.rb b/config/routes.rb
index a0a6e55..ddd11cc 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -22,7 +22,9 @@ ActionController::Routing::Routes.draw do |map|
map.connect 'account/new_password/:code', :controller => 'account', :action => 'new_password'
map.connect 'account/:action', :controller => 'account'
-
+
+ # enterprise registration
+ map.connect 'enterprise_registration/:action', :controller => 'enterprise_registration'
######################################################
## Controllers that are profile-specific (for profile admins )
diff --git a/public/stylesheets/common.css b/public/stylesheets/common.css
index c63f5a3..718bd29 100644
--- a/public/stylesheets/common.css
+++ b/public/stylesheets/common.css
@@ -34,3 +34,29 @@ padding-left: 60px !important ;
color: #dfdfdf !important ;
}
+div.fieldWithErrors {
+ display: inline;
+ background: yellow;
+}
+
+div.fieldWithErrors input {
+ border: 1px solid red;
+ background: #fee;
+}
+
+div#errorExplanation {
+ border: 2px solid #933;
+ background: #fee;
+ padding: 5px;
+}
+
+div#errorExplanation h2 {
+ margin-top: -5px;
+ margin-left: -5px;
+ margin-right: -5px;
+
+ padding: 3px;
+ background: #933;
+ color: white;
+ text-align: center;
+}
diff --git a/script/anhetegua b/script/anhetegua
index e68a452..e17090e 100644
--- a/script/anhetegua
+++ b/script/anhetegua
@@ -9,16 +9,34 @@ def new_category(parent, name, color = nil)
category
end
+def new_region(parent, name, color = nil)
+ region = Environment.default.regions.build(:name => name, :display_color => color, :parent_id => (parent ? parent.id: nil))
+ region.save!
+ region
+end
+
tematicas = new_category(nil, 'Temáticas', 1)
new_category(tematicas, 'Finanças Solidárias')
new_category(tematicas, 'Marco Legal')
new_category(tematicas, 'Software Livre')
-territorios = new_category(nil, 'Territórios', 2)
-new_category(territorios, 'Bahia')
-new_category(territorios, 'Distrito Federal')
-new_category(territorios, 'Rio Grande do Sul')
+territorios = new_region(nil, 'Territórios', 2)
+ba = new_region(territorios, 'Bahia')
+df = new_region(territorios, 'Distrito Federal')
+rs = new_region(territorios, 'Rio Grande do Sul')
cadeias = new_category(nil, 'Cadeias', 3)
new_category(cadeias, 'Algodão')
new_category(cadeias, 'Tecnologia de Informação')
+
+
+# validators
+ba.validators << Organization.create!(:name => "Colivre", :identifier => 'colivre')
+ba.validators << Organization.create!(:name => "Forum Baiano de Economia Solidaraia", :identifier => 'ecosolbahia')
+
+df.validators << Organization.create!(:name => 'Caritas', :identifier => 'caritas')
+df.validators << Organization.create!(:name => 'Forum Brasileiro de Economia Solidaria', :identifier => 'fbes')
+
+rs.validators << Organization.create!(:name => 'Associacao Software Livre.Org', :identifier => 'asl')
+rs.validators << Organization.create!(:name => 'Forum Gaucho de Economia Solidaria', :identifier => 'ecosolrs')
+
diff --git a/test/functional/enterprise_registration_controller_test.rb b/test/functional/enterprise_registration_controller_test.rb
new file mode 100644
index 0000000..10c10e5
--- /dev/null
+++ b/test/functional/enterprise_registration_controller_test.rb
@@ -0,0 +1,82 @@
+require File.dirname(__FILE__) + '/../test_helper'
+require 'enterprise_registration_controller'
+
+# Re-raise errors caught by the controller.
+class EnterpriseRegistrationController; def rescue_action(e) raise e end; end
+
+class EnterpriseRegistrationControllerTest < Test::Unit::TestCase
+
+ fixtures :users
+
+ def setup
+ @controller = EnterpriseRegistrationController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ login_as 'ze'
+ end
+
+ should 'go to the first step on index' do
+ get :index
+ assert_response :success
+ assert_template 'basic_information'
+ end
+
+ should 'prompt for basic information' do
+ get :index
+ %w[ name identifier address contact_phone contact_person
+ acronym foundation_year legal_form economic_activity ].each do |item|
+ assert_tag :tag => 'input', :attributes => { :name => "create_enterprise[#{item}]" }
+ end
+ assert_tag :tag => 'textarea', :attributes => { :name => "create_enterprise[management_information]"}
+ assert_tag :tag => 'select', :attributes => { :name => "create_enterprise[region_id]"}
+ end
+
+ should 'get back to entering basic information if data is invalid' do
+ post :index, :create_enterprise => {}
+ assert_response :success
+ assert_template 'basic_information'
+ end
+
+ should 'prompt for selecting validator' do
+ data = { 'name' => 'My new enterprise', 'identifier' => 'mynew' }
+
+ create_enterprise = CreateEnterprise.new
+ CreateEnterprise.expects(:new).with(data).returns(create_enterprise)
+
+ validator1 = mock()
+ validator1.expects(:id).returns(1)
+ validator1.expects(:name).returns("validator1")
+ validator2 = mock()
+ validator2.expects(:id).returns(2)
+ validator2.expects(:name).returns("validator2")
+ region = mock()
+ region.expects(:validators).returns([validator1, validator2]).at_least_once
+ create_enterprise.expects(:region).returns(region)
+
+ # all data but validator selected
+ create_enterprise.expects(:valid_before_selecting_target?).returns(true)
+ create_enterprise.expects(:valid?).returns(false)
+
+ post :index, :create_enterprise => data
+ assert_template 'select_validator'
+ end
+
+ should 'provide confirmation at the end of the process' do
+ data = { 'name' => 'My new enterprise', 'identifier' => 'mynew' }
+
+ create_enterprise = CreateEnterprise.new
+ CreateEnterprise.expects(:new).with(data).returns(create_enterprise)
+
+ # all including validator selected
+ validator = mock()
+ validator.stubs(:name).returns("lalala")
+ create_enterprise.expects(:valid_before_selecting_target?).returns(true)
+ create_enterprise.expects(:valid?).returns(true) # validator already selected
+ create_enterprise.expects(:save!)
+ create_enterprise.expects(:target).returns(validator)
+
+ post :index, :create_enterprise => data
+ assert_template 'confirmation'
+ end
+
+end
diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb
index 640e823..93237ab 100644
--- a/test/integration/routing_test.rb
+++ b/test/integration/routing_test.rb
@@ -21,6 +21,10 @@ class RoutingTest < ActionController::IntegrationTest
assert_routing('/account', :controller => 'account', :action => 'index')
end
+ def test_enterprise_registration_controller
+ assert_routing('/enterprise_registration', :controller => 'enterprise_registration', :action => 'index')
+ end
+
def test_new_password
assert_routing('/account/new_password/90dfhga7sadgd0as6saas', :controller => 'account', :action => 'new_password', :code => '90dfhga7sadgd0as6saas')
end
diff --git a/test/unit/create_enterprise_test.rb b/test/unit/create_enterprise_test.rb
index fc876b0..ce704d0 100644
--- a/test/unit/create_enterprise_test.rb
+++ b/test/unit/create_enterprise_test.rb
@@ -115,4 +115,29 @@ class CreateEnterpriseTest < Test::Unit::TestCase
end
end
+ should 'validate that eveything is ok but the validator (target)' do
+ Environment.destroy_all
+ environment = Environment.create!(:name => "My environment", :contact_email => 'test@localhost.localdomain', :is_default => true)
+ region = Region.create!(:name => 'My region', :environment_id => environment.id)
+ validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id)
+ region.validators << validator
+ person = User.create!(:login => 'testuser', :password => 'test', :password_confirmation => 'test', :email => 'testuser@localhost.localdomain').person
+ task = CreateEnterprise.new({
+ :name => 'My new enterprise',
+ :identifier => 'mynewenterprise',
+ :address => 'satan street, 666',
+ :contact_phone => '1298372198',
+ :contact_person => 'random joe',
+ :legal_form => 'cooperative',
+ :economic_activity => 'free software',
+ :region_id => region.id,
+ :requestor_id => person.id,
+ })
+
+ assert !task.valid? && task.valid_before_selecting_target?
+
+ task.target = validator
+ assert task.valid?
+ end
+
end
diff --git a/vendor/plugins/update-externals.sh b/vendor/plugins/update-externals.sh
new file mode 100644
index 0000000..f6f1c07
--- /dev/null
+++ b/vendor/plugins/update-externals.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+# this script can be used when using svk, since svk does not support automatic
+# checkout of svn's svn:externals. Then if you use svk, change to
+# vendor/plugins directory and run this script with `sh update-externals.sh`
+
+svk propget svn:externals . | awk '{ if ($1) print "if [ -e " $1 " ]; then svn update " $1 "; else svn co " $2 " " $1 "; fi"}' | sh
--
libgit2 0.21.2