Commit eb7194d94f8fbd16efc8b11f95f3e4646f0757bc

Authored by Francisco Marcelo de Araújo Lima Júnior
1 parent 40be915c

invert logic

app/controllers/admin/environment_design_controller.rb
@@ -4,7 +4,7 @@ class EnvironmentDesignController < BoxOrganizerController @@ -4,7 +4,7 @@ class EnvironmentDesignController < BoxOrganizerController
4 4
5 def filtered_available_blocks(blocks=nil) 5 def filtered_available_blocks(blocks=nil)
6 filtered_available_blocks = [] 6 filtered_available_blocks = []
7 - blocks.each { |block| filtered_available_blocks << block if @environment.enabled_blocks.include?(block.name) } 7 + blocks.each { |block| filtered_available_blocks << block unless @environment.disabled_blocks.include?(block.name) }
8 filtered_available_blocks 8 filtered_available_blocks
9 end 9 end
10 10
app/controllers/admin/features_controller.rb
@@ -46,6 +46,7 @@ class FeaturesController &lt; AdminController @@ -46,6 +46,7 @@ class FeaturesController &lt; AdminController
46 46
47 post_only :update_blocks 47 post_only :update_blocks
48 def update_blocks 48 def update_blocks
  49 + params[:environment].delete(:available_blocks)
49 if @environment.update_attributes(params[:environment]) 50 if @environment.update_attributes(params[:environment])
50 session[:notice] = _('Blocks updated successfully.') 51 session[:notice] = _('Blocks updated successfully.')
51 redirect_to :action => 'manage_blocks' 52 redirect_to :action => 'manage_blocks'
app/controllers/my_profile/profile_design_controller.rb
@@ -6,7 +6,7 @@ class ProfileDesignController &lt; BoxOrganizerController @@ -6,7 +6,7 @@ class ProfileDesignController &lt; BoxOrganizerController
6 6
7 def filtered_available_blocks(blocks=nil) 7 def filtered_available_blocks(blocks=nil)
8 filtered_available_blocks = [] 8 filtered_available_blocks = []
9 - blocks.each { |block| filtered_available_blocks << block if @environment.enabled_blocks.include?(block.name) } 9 + blocks.each { |block| filtered_available_blocks << block unless @environment.disabled_blocks.include?(block.name) }
10 filtered_available_blocks 10 filtered_available_blocks
11 end 11 end
12 12
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, :enabled_blocks, :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, :disabled_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,7 +289,7 @@ class Environment &lt; ActiveRecord::Base @@ -289,7 +289,7 @@ 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 => [] 292 + settings_items :disabled_blocks, :type => Array, :default => []
293 293
294 settings_items :search_hints, :type => Hash, :default => {} 294 settings_items :search_hints, :type => Hash, :default => {}
295 295
@@ -339,8 +339,8 @@ class Environment &lt; ActiveRecord::Base @@ -339,8 +339,8 @@ class Environment &lt; ActiveRecord::Base
339 enabled_plugins.include?(plugin.to_s) 339 enabled_plugins.include?(plugin.to_s)
340 end 340 end
341 341
342 - def block_enabled?(block)  
343 - enabled_blocks.include?(block.to_s) 342 + def block_disabled?(block)
  343 + disabled_blocks.include?(block.to_s)
344 end 344 end
345 345
346 # 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
app/views/features/manage_blocks.html.erb
@@ -24,7 +24,10 @@ @@ -24,7 +24,10 @@
24 <%= _(block.description) %> 24 <%= _(block.description) %>
25 </td> 25 </td>
26 <td align="center"> 26 <td align="center">
27 - <%= check_box_tag "environment[enabled_blocks][]", block, @environment.block_enabled?(block) %> 27 + <%= check_box_tag "environment[available_blocks][]", block, !@environment.block_disabled?(block), :id => "environment_available_blocks_#{block.name}", :onclick => "toogle_hidden_field(this, '#{block.name}');" %>
  28 + <% if @environment.block_disabled?(block) %>
  29 + <%= hidden_field_tag "environment[disabled_blocks][]", block.name %>
  30 + <% end %>
28 </td> 31 </td>
29 </tr> 32 </tr>
30 <% end %> 33 <% end %>
@@ -42,6 +45,22 @@ @@ -42,6 +45,22 @@
42 // --> 45 // -->
43 </script> 46 </script>
44 47
  48 +<script type="text/javascript">
  49 + function toogle_hidden_field(element, block_name) {
  50 +
  51 + var chbx = jQuery(element);
  52 +
  53 + if (element.checked) {
  54 + var hidden = chbx.next().remove();
  55 + }
  56 + else {
  57 + var el = jQuery( "<input>", { id: "environment_disabled_blocks_", name: "environment[disabled_blocks][]", type: "hidden", value: block_name } )
  58 + chbx.after( el );
  59 + }
  60 +
  61 + }
  62 +</script>
  63 +
45 <div> 64 <div>
46 <% button_bar do %> 65 <% button_bar do %>
47 <%= submit_button('save', _('Save changes'), :id=>"save_blocks") %> 66 <%= submit_button('save', _('Save changes'), :id=>"save_blocks") %>