diff --git a/app/controllers/admin/admin_panel_controller.rb b/app/controllers/admin/admin_panel_controller.rb
index 59c87a7..4ffcec4 100644
--- a/app/controllers/admin/admin_panel_controller.rb
+++ b/app/controllers/admin/admin_panel_controller.rb
@@ -73,10 +73,20 @@ class AdminPanelController < AdminController
end
def manage_organizations_status
- scope = environment.organizations
@filter = params[:filter] || 'any'
@title = "Organization profiles"
@title = @title+" - "+@filter if @filter != 'any'
+ @type = params[:type] || "any"
+ @types_filter = [['All', 'any'], [_('Community'), 'communities'], [_('Enterprise'), 'enterprises']]
+ @types_filter = @types_filter | @plugins.dispatch_without_flatten(:organization_types_filter_options).flatten(1)
+
+ scope = if @type == "communities"
+ environment.communities
+ elsif @type == "enterprises"
+ environment.enterprises
+ else
+ environment.organizations
+ end
if @filter == 'enabled'
scope = scope.visible
@@ -85,8 +95,12 @@ class AdminPanelController < AdminController
end
scope = scope.order('name ASC')
+ result_plugin = @plugins.dispatch(:filter_manage_organization_scope, scope, @type)
+ scope = result_plugin if !result_plugin.blank?
@q = params[:q]
@collection = find_by_contents(:organizations, environment, scope, @q, {:per_page => 10, :page => params[:npage]})[:results]
+
+ render :layout=>false if request.xhr?
end
end
diff --git a/app/views/admin_panel/manage_organizations_status.html.erb b/app/views/admin_panel/manage_organizations_status.html.erb
index 3a708f1..372a55b 100644
--- a/app/views/admin_panel/manage_organizations_status.html.erb
+++ b/app/views/admin_panel/manage_organizations_status.html.erb
@@ -23,15 +23,22 @@
-
+
-
+
+
<%= _('Member') %> |
<%= _('Actions') %> |
+ <%= _('Type') %>
+
+
+ |
<% @collection.each do |p| %>
@@ -48,22 +55,20 @@
<%= button_without_text :'delete', _('Remove'), {:controller => "profile_editor", :action => 'destroy_profile', :profile => p.identifier, :id => p.id, :return_to => "/admin/admin_panel/manage_organizations_status"}, :method => :post, :confirm => _("Do you want to deactivate this profile ?") %>
+
+ <%= _("#{p.type}") %> |
<% end %>
<% end %>
-<%= pagination_links @collection, {:param_name => 'npage', :page_links => true} %>
+
+ <%= pagination_links @collection, {:param_name => 'npage', :page_links => true} %>
+
<% button_bar do %>
<%= button :back, _('Back'), :controller => 'admin_panel' %>
<% end %>
-
\ No newline at end of file
+<%= javascript_include_tag 'manage-organizations-status' %>
diff --git a/lib/noosfero/plugin.rb b/lib/noosfero/plugin.rb
index 59710f4..3e673ea 100644
--- a/lib/noosfero/plugin.rb
+++ b/lib/noosfero/plugin.rb
@@ -277,6 +277,18 @@ class Noosfero::Plugin
nil
end
+ # -> Filters the types of organizations that are shown on manage organizations
+ # returns a scope filtered by the specified type
+ def filter_manage_organization_scope scope, type
+ nil
+ end
+
+ # -> Add new options for manage organization filters
+ # returns an array of new options
+ # i.e [[_('Type'), 'type'], [_('Type2'), 'type2']]
+ def organization_types_filter_options
+ nil
+ end
# -> Adds content to profile editor info and settings
# returns = lambda block that creates html code or raw rhtml/html.erb
def profile_editor_extras
diff --git a/public/javascripts/manage-organizations-status.js b/public/javascripts/manage-organizations-status.js
new file mode 100644
index 0000000..3368c8f
--- /dev/null
+++ b/public/javascripts/manage-organizations-status.js
@@ -0,0 +1,45 @@
+(function($) {
+ function set_events() {
+ $("#profile_filter_select").change(filter_page_loader);
+ $("#profile_type_select").change(filter_page_loader);
+ }
+
+ function filter_page_loader() {
+ var page_action = '/admin/admin_panel/manage_organizations_status';
+ var filter = $("#profile_filter_select").val();
+ var type = $("#profile_type_select").val();
+
+ $.ajax({
+ url: page_action,
+ type: 'GET',
+ data: {
+ 'filter': filter,
+ 'type': type,
+ 'npage': 1
+ }, success: function(response) {
+ var response_html = $(response);
+ var table_data = response_html.find('#organizations-list tbody').html();
+ var pagination_data = response_html.find('.pagination').html();
+ var title_header = response_html.find('#environment-users-filter-title').html();
+ var has_pagination = response_html.find('.pagination').length === 1;
+
+ $('#environment-users-filter-title').html(title_header);
+ $('#organizations-list').html(table_data);
+
+ if(has_pagination) {
+ $('.pagination').html(pagination_data);
+ } else {
+ $('.pagination').html('');
+ }
+
+ set_events();
+ }
+ });
+ }
+
+
+ $(document).ready(function(){
+ set_events();
+ filter_page_loader();
+ });
+})(jQuery);
diff --git a/test/functional/admin_panel_controller_test.rb b/test/functional/admin_panel_controller_test.rb
index a451e48..b32daaa 100644
--- a/test/functional/admin_panel_controller_test.rb
+++ b/test/functional/admin_panel_controller_test.rb
@@ -17,12 +17,12 @@ class AdminPanelControllerTest < ActionController::TestCase
should 'manage the correct environment' do
current = fast_create(Environment, :name => 'test environment', :is_default => false)
current.domains.create!(:name => 'example.com')
-
+
@request.expects(:host).returns('example.com').at_least_once
get :index
assert_equal current, assigns(:environment)
end
-
+
should 'link to site_info editing page' do
get :index
assert_tag :tag => 'a', :attributes => { :href => '/admin/admin_panel/site_info' }
@@ -411,4 +411,49 @@ class AdminPanelControllerTest < ActionController::TestCase
assert_not_match(/enabled community/, @response.body)
assert_match(/disabled community/, @response.body)
end
+
+ should 'show list only of enterprise' do
+ community = fast_create(Community, :environment_id => Environment.default, :name=>"Community Test")
+ enterprise = fast_create(Enterprise, :environment_id => Environment.default, :name=>"Enterprise Test")
+
+ user = create_user('user')
+
+ Environment.default.add_admin user.person
+ login_as('user')
+
+ get :manage_organizations_status, :type=>"enterprises"
+ assert_match(/Organization profiles/, @response.body)
+ assert_match(/Enterprise Test/, @response.body)
+ assert_not_match(/Community Test/, @response.body)
+ end
+
+ should 'show list only of communities' do
+ community = fast_create(Community, :environment_id => Environment.default, :name=>"Community Test")
+ enterprise = fast_create(Enterprise, :environment_id => Environment.default, :name=>"Enterprise Test")
+
+ user = create_user('user')
+
+ Environment.default.add_admin user.person
+ login_as('user')
+
+ get :manage_organizations_status, :type=>"communities"
+ assert_match(/Organization profiles/, @response.body)
+ assert_not_match(/Enterprise Test/, @response.body)
+ assert_match(/Community Test/, @response.body)
+ end
+
+ should 'show list all organizations' do
+ community = fast_create(Community, :environment_id => Environment.default, :name=>"Community Test")
+ enterprise = fast_create(Enterprise, :environment_id => Environment.default, :name=>"Enterprise Test")
+
+ user = create_user('user')
+
+ Environment.default.add_admin user.person
+ login_as('user')
+
+ get :manage_organizations_status, :type=>"any"
+ assert_match(/Organization profiles/, @response.body)
+ assert_match(/Enterprise Test/, @response.body)
+ assert_match(/Community Test/, @response.body)
+ end
end
--
libgit2 0.21.2