Commit 40be915c2dd4c08647c890457f16ca566bce3701

Authored by Francisco Marcelo de Araújo Lima Júnior
1 parent 6e3050fd

add enable/disable blocks feature

app/controllers/admin/environment_design_controller.rb
1 class EnvironmentDesignController < BoxOrganizerController 1 class EnvironmentDesignController < BoxOrganizerController
2 - 2 +
3 protect 'edit_environment_design', :environment 3 protect 'edit_environment_design', :environment
4 4
  5 + def filtered_available_blocks(blocks=nil)
  6 + filtered_available_blocks = []
  7 + blocks.each { |block| filtered_available_blocks << block if @environment.enabled_blocks.include?(block.name) }
  8 + filtered_available_blocks
  9 + end
  10 +
5 def available_blocks 11 def available_blocks
6 # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from 12 # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from
7 # the Noosfero core soon, see ActionItem3045 13 # the Noosfero core soon, see ActionItem3045
app/controllers/admin/features_controller.rb
1 class FeaturesController < AdminController 1 class FeaturesController < AdminController
  2 +
2 protect 'edit_environment_features', :environment 3 protect 'edit_environment_features', :environment
3 - 4 +
4 def index 5 def index
5 @features = Environment.available_features.sort_by{|k,v|v} 6 @features = Environment.available_features.sort_by{|k,v|v}
6 end 7 end
7 8
  9 + def manage_blocks
  10 + @blocks = [ ArticleBlock,
  11 + TagsBlock,
  12 + RecentDocumentsBlock,
  13 + ProfileInfoBlock,
  14 + LinkListBlock,
  15 + MyNetworkBlock,
  16 + FeedReaderBlock,
  17 + ProfileImageBlock,
  18 + LocationBlock,
  19 + SlideshowBlock,
  20 + ProfileSearchBlock,
  21 + HighlightsBlock,
  22 + FriendsBlock,
  23 + FavoriteEnterprisesBlock,
  24 + CommunitiesBlock,
  25 + EnterprisesBlock,
  26 + MembersBlock,
  27 + DisabledEnterpriseMessageBlock,
  28 + ProductCategoriesBlock,
  29 + FeaturedProductsBlock,
  30 + FansBlock,
  31 + ProductsBlock ]
  32 +
  33 + @blocks += plugins.dispatch(:extra_blocks)
  34 + @blocks.sort_by! { |block| block.name }
  35 + end
  36 +
8 post_only :update 37 post_only :update
9 def update 38 def update
10 if @environment.update_attributes(params[:environment]) 39 if @environment.update_attributes(params[:environment])
@@ -15,6 +44,16 @@ class FeaturesController &lt; AdminController @@ -15,6 +44,16 @@ class FeaturesController &lt; AdminController
15 end 44 end
16 end 45 end
17 46
  47 + post_only :update_blocks
  48 + def update_blocks
  49 + if @environment.update_attributes(params[:environment])
  50 + session[:notice] = _('Blocks updated successfully.')
  51 + redirect_to :action => 'manage_blocks'
  52 + else
  53 + render :action => 'manage_blocks'
  54 + end
  55 + end
  56 +
18 def manage_fields 57 def manage_fields
19 @person_fields = Person.fields 58 @person_fields = Person.fields
20 @enterprise_fields = Enterprise.fields 59 @enterprise_fields = Enterprise.fields
app/controllers/box_organizer_controller.rb
@@ -68,8 +68,8 @@ class BoxOrganizerController &lt; ApplicationController @@ -68,8 +68,8 @@ class BoxOrganizerController &lt; ApplicationController
68 raise ArgumentError.new("Type %s is not allowed. Go away." % type) 68 raise ArgumentError.new("Type %s is not allowed. Go away." % type)
69 end 69 end
70 else 70 else
71 - @center_block_types = (Box.acceptable_center_blocks & available_blocks) + plugins.dispatch(:extra_blocks, :type => boxes_holder.class, :position => 1)  
72 - @side_block_types = (Box.acceptable_side_blocks & available_blocks) + plugins.dispatch(:extra_blocks, :type => boxes_holder.class, :position => [2,3]) 71 + @center_block_types = filtered_available_blocks((Box.acceptable_center_blocks & available_blocks) + plugins.dispatch(:extra_blocks, :type => boxes_holder.class, :position => 1))
  72 + @side_block_types = filtered_available_blocks((Box.acceptable_side_blocks & available_blocks) + plugins.dispatch(:extra_blocks, :type => boxes_holder.class, :position => [2,3]))
73 @boxes = boxes_holder.boxes.with_position 73 @boxes = boxes_holder.boxes.with_position
74 render :action => 'add_block', :layout => false 74 render :action => 'add_block', :layout => false
75 end 75 end
app/controllers/my_profile/profile_design_controller.rb
@@ -3,7 +3,13 @@ class ProfileDesignController &lt; BoxOrganizerController @@ -3,7 +3,13 @@ class ProfileDesignController &lt; BoxOrganizerController
3 needs_profile 3 needs_profile
4 4
5 protect 'edit_profile_design', :profile 5 protect 'edit_profile_design', :profile
6 - 6 +
  7 + def filtered_available_blocks(blocks=nil)
  8 + filtered_available_blocks = []
  9 + blocks.each { |block| filtered_available_blocks << block if @environment.enabled_blocks.include?(block.name) }
  10 + filtered_available_blocks
  11 + end
  12 +
7 def available_blocks 13 def available_blocks
8 blocks = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock, LinkListBlock, MyNetworkBlock, FeedReaderBlock, ProfileImageBlock, LocationBlock, SlideshowBlock, ProfileSearchBlock, HighlightsBlock ] 14 blocks = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock, LinkListBlock, MyNetworkBlock, FeedReaderBlock, ProfileImageBlock, LocationBlock, SlideshowBlock, ProfileSearchBlock, HighlightsBlock ]
9 15
app/models/environment.rb
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 # domains. 3 # domains.
4 class Environment < ActiveRecord::Base 4 class Environment < ActiveRecord::Base
5 5
6 - attr_accessible :name, :is_default, :signup_welcome_text_subject, :signup_welcome_text_body, :terms_of_use, :message_for_disabled_enterprise, :news_amount_by_folder, :default_language, :languages, :description, :organization_approval_method, :enabled_plugins, :enabled_features, :redirection_after_login, :redirection_after_signup, :contact_email, :theme, :reports_lower_bound 6 + attr_accessible :name, :is_default, :signup_welcome_text_subject, :signup_welcome_text_body, :terms_of_use, :message_for_disabled_enterprise, :news_amount_by_folder, :default_language, :languages, :description, :organization_approval_method, :enabled_plugins, :enabled_features, :enabled_blocks, :redirection_after_login, :redirection_after_signup, :contact_email, :theme, :reports_lower_bound
7 7
8 has_many :users 8 has_many :users
9 9
@@ -289,6 +289,8 @@ class Environment &lt; ActiveRecord::Base @@ -289,6 +289,8 @@ class Environment &lt; ActiveRecord::Base
289 289
290 settings_items :enabled_plugins, :type => Array, :default => [] 290 settings_items :enabled_plugins, :type => Array, :default => []
291 291
  292 + settings_items :enabled_blocks, :type => Array, :default => []
  293 +
292 settings_items :search_hints, :type => Hash, :default => {} 294 settings_items :search_hints, :type => Hash, :default => {}
293 295
294 # Set to return http forbidden to host not on the allow origin list bellow 296 # Set to return http forbidden to host not on the allow origin list bellow
@@ -337,6 +339,10 @@ class Environment &lt; ActiveRecord::Base @@ -337,6 +339,10 @@ class Environment &lt; ActiveRecord::Base
337 enabled_plugins.include?(plugin.to_s) 339 enabled_plugins.include?(plugin.to_s)
338 end 340 end
339 341
  342 + def block_enabled?(block)
  343 + enabled_blocks.include?(block.to_s)
  344 + end
  345 +
340 # enables the features identified by <tt>features</tt>, which is expected to 346 # enables the features identified by <tt>features</tt>, which is expected to
341 # be an Enumarable object containing the identifiers of the desired features. 347 # be an Enumarable object containing the identifiers of the desired features.
342 # Passing <tt>nil</tt> is the same as passing an empty Array. 348 # Passing <tt>nil</tt> is the same as passing an empty Array.
app/views/admin_panel/index.html.erb
@@ -11,6 +11,7 @@ @@ -11,6 +11,7 @@
11 <tr><td><%= link_to _('Homepage'), :action => 'set_portal_community' %></td></tr> 11 <tr><td><%= link_to _('Homepage'), :action => 'set_portal_community' %></td></tr>
12 <tr><td><%= link_to _('Licenses'), :controller =>'licenses' %></td></tr> 12 <tr><td><%= link_to _('Licenses'), :controller =>'licenses' %></td></tr>
13 <tr><td><%= link_to _('Trusted sites'), :controller =>'trusted_sites' %></td></tr> 13 <tr><td><%= link_to _('Trusted sites'), :controller =>'trusted_sites' %></td></tr>
  14 + <tr><td><%= link_to _('Blocks'), :controller => 'features', :action => 'manage_blocks' %></td></tr>
14 </table> 15 </table>
15 16
16 <h2><%= _('Profiles') %></h2> 17 <h2><%= _('Profiles') %></h2>
app/views/features/manage_blocks.html.erb 0 → 100644
@@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
  1 +<h1><%= _('System blocks') %></h1>
  2 +
  3 +<h2><%= _('Enable/Disable blocks') %></h2>
  4 +
  5 +<p>
  6 +<%= _('Here you can enable or disable blocks of your environment.') %>
  7 +</p>
  8 +
  9 +<%= labelled_form_for(:environment, :url => {:action => 'update_blocks'}) do |f| %>
  10 +
  11 +<table id='blocks-grid' class="blocks-grid" align="center" style="width: auto">
  12 + <tr>
  13 + <th width="33%"><%= _('Block') %></th>
  14 + <th width="33%"><%= _('Description') %></th>
  15 + <th width="33%"><%= _('Enabled?') %></th>
  16 + </tr>
  17 +
  18 + <% @blocks.each do |block| %>
  19 + <tr>
  20 + <td>
  21 + <%= _(block.name.humanize) %>
  22 + </td>
  23 + <td>
  24 + <%= _(block.description) %>
  25 + </td>
  26 + <td align="center">
  27 + <%= check_box_tag "environment[enabled_blocks][]", block, @environment.block_enabled?(block) %>
  28 + </td>
  29 + </tr>
  30 + <% end %>
  31 +</table>
  32 +
  33 +<script type='text/javascript'>// <!--
  34 + var trs = jQuery('#blocks-grid tr');
  35 +
  36 + var tr, td2;
  37 + for ( var i=2; tr=trs[i]; i++ ) {
  38 + if ( td2 = tr.getElementsByTagName('td')[1] ) {
  39 + td2.getElementsByTagName('input')[1].onclick();
  40 + }
  41 + }
  42 + // -->
  43 +</script>
  44 +
  45 +<div>
  46 + <% button_bar do %>
  47 + <%= submit_button('save', _('Save changes'), :id=>"save_blocks") %>
  48 + <%= button :back, _('Back to admin panel'), :controller => 'admin_panel', :action => 'index' %>
  49 + <% end %>
  50 +</div>
  51 +
  52 +<% end %>