Commit eb7194d94f8fbd16efc8b11f95f3e4646f0757bc
1 parent
40be915c
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
invert logic
Showing
5 changed files
with
27 additions
and
7 deletions
Show diff stats
app/controllers/admin/environment_design_controller.rb
... | ... | @@ -4,7 +4,7 @@ class EnvironmentDesignController < BoxOrganizerController |
4 | 4 | |
5 | 5 | def filtered_available_blocks(blocks=nil) |
6 | 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 | 8 | filtered_available_blocks |
9 | 9 | end |
10 | 10 | ... | ... |
app/controllers/admin/features_controller.rb
... | ... | @@ -46,6 +46,7 @@ class FeaturesController < AdminController |
46 | 46 | |
47 | 47 | post_only :update_blocks |
48 | 48 | def update_blocks |
49 | + params[:environment].delete(:available_blocks) | |
49 | 50 | if @environment.update_attributes(params[:environment]) |
50 | 51 | session[:notice] = _('Blocks updated successfully.') |
51 | 52 | redirect_to :action => 'manage_blocks' | ... | ... |
app/controllers/my_profile/profile_design_controller.rb
... | ... | @@ -6,7 +6,7 @@ class ProfileDesignController < BoxOrganizerController |
6 | 6 | |
7 | 7 | def filtered_available_blocks(blocks=nil) |
8 | 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 | 10 | filtered_available_blocks |
11 | 11 | end |
12 | 12 | ... | ... |
app/models/environment.rb
... | ... | @@ -3,7 +3,7 @@ |
3 | 3 | # domains. |
4 | 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 | 8 | has_many :users |
9 | 9 | |
... | ... | @@ -289,7 +289,7 @@ class Environment < ActiveRecord::Base |
289 | 289 | |
290 | 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 | 294 | settings_items :search_hints, :type => Hash, :default => {} |
295 | 295 | |
... | ... | @@ -339,8 +339,8 @@ class Environment < ActiveRecord::Base |
339 | 339 | enabled_plugins.include?(plugin.to_s) |
340 | 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 | 344 | end |
345 | 345 | |
346 | 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 | 24 | <%= _(block.description) %> |
25 | 25 | </td> |
26 | 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 | 31 | </td> |
29 | 32 | </tr> |
30 | 33 | <% end %> |
... | ... | @@ -42,6 +45,22 @@ |
42 | 45 | // --> |
43 | 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 | 64 | <div> |
46 | 65 | <% button_bar do %> |
47 | 66 | <%= submit_button('save', _('Save changes'), :id=>"save_blocks") %> | ... | ... |