Commit 6798e5c190843ac47cbc37b56a063ff6e1afc791
1 parent
09ac1c70
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
improved visibility options for private article
Showing
3 changed files
with
40 additions
and
6 deletions
Show diff stats
app/helpers/article_helper.rb
| @@ -77,12 +77,24 @@ module ArticleHelper | @@ -77,12 +77,24 @@ module ArticleHelper | ||
| 77 | content_tag('div', | 77 | content_tag('div', |
| 78 | radio_button(:article, :published, false) + | 78 | radio_button(:article, :published, false) + |
| 79 | content_tag('label', _('Private'), :for => 'article_published_false', :id => "label_private") | 79 | content_tag('label', _('Private'), :for => 'article_published_false', :id => "label_private") |
| 80 | + ) + visibility_mode_options(article, tokenized_children)) | ||
| 81 | + end | ||
| 82 | + | ||
| 83 | + def visibility_mode_options(article, tokenized_children) | ||
| 84 | + content_tag('div', | ||
| 85 | + | ||
| 86 | + content_tag('div', | ||
| 87 | + radio_button(:article, :visibility_mode, 1) + | ||
| 88 | + content_tag('label', _('For all community members'), :for => 'article_visibility_mode_1', :id => "label_private")) + | ||
| 89 | + content_tag('div', | ||
| 90 | + radio_button(:article, :visibility_mode, 0) + | ||
| 91 | + content_tag('label', _('For community admins or specific users'), :for => 'article_visibility_mode_0', :id => "label_private") | ||
| 80 | ) + | 92 | ) + |
| 81 | (article.profile.community? ? content_tag('div', | 93 | (article.profile.community? ? content_tag('div', |
| 82 | content_tag('label', _('Fill in the search field to add the exception users to see this content'), :id => "text-input-search-exception-users") + | 94 | content_tag('label', _('Fill in the search field to add the exception users to see this content'), :id => "text-input-search-exception-users") + |
| 83 | token_input_field_tag(:q, 'search-article-privacy-exceptions', {:action => 'search_article_privacy_exceptions'}, | 95 | token_input_field_tag(:q, 'search-article-privacy-exceptions', {:action => 'search_article_privacy_exceptions'}, |
| 84 | {:focus => false, :hint_text => _('Type in a search term for a user'), :pre_populate => tokenized_children})) : | 96 | {:focus => false, :hint_text => _('Type in a search term for a user'), :pre_populate => tokenized_children})) : |
| 85 | - '')) | 97 | + ''), :style => 'padding-left: 15px;') |
| 86 | end | 98 | end |
| 87 | 99 | ||
| 88 | def prepare_to_token_input(array) | 100 | def prepare_to_token_input(array) |
app/models/article.rb
| @@ -2,7 +2,7 @@ require 'hpricot' | @@ -2,7 +2,7 @@ require 'hpricot' | ||
| 2 | 2 | ||
| 3 | class Article < ActiveRecord::Base | 3 | class Article < ActiveRecord::Base |
| 4 | 4 | ||
| 5 | - attr_accessible :name, :body, :abstract, :profile, :tag_list, :parent, :allow_members_to_edit, :translation_of_id, :language, :license_id, :parent_id, :display_posts_in_current_language, :category_ids, :posts_per_page, :moderate_comments, :accept_comments, :feed, :published, :source, :highlighted, :notify_comments, :display_hits, :slug, :external_feed_builder, :display_versions, :external_link, :image_builder, :published_at | 5 | + attr_accessible :name, :body, :abstract, :profile, :tag_list, :parent, :allow_members_to_edit, :translation_of_id, :language, :license_id, :parent_id, :display_posts_in_current_language, :category_ids, :posts_per_page, :moderate_comments, :accept_comments, :feed, :published, :source, :highlighted, :notify_comments, :display_hits, :slug, :external_feed_builder, :display_versions, :external_link, :image_builder, :published_at, :visibility_mode |
| 6 | 6 | ||
| 7 | acts_as_having_image | 7 | acts_as_having_image |
| 8 | 8 | ||
| @@ -498,7 +498,7 @@ class Article < ActiveRecord::Base | @@ -498,7 +498,7 @@ class Article < ActiveRecord::Base | ||
| 498 | def display_unpublished_article_to?(user) | 498 | def display_unpublished_article_to?(user) |
| 499 | user == author || allow_view_private_content?(user) || user == profile || | 499 | user == author || allow_view_private_content?(user) || user == profile || |
| 500 | user.is_admin?(profile.environment) || user.is_admin?(profile) || | 500 | user.is_admin?(profile.environment) || user.is_admin?(profile) || |
| 501 | - article_privacy_exceptions.include?(user) | 501 | + article_privacy_exceptions.include?(user) || (visibility_mode == 1 && user.is_member_of?(profile)) |
| 502 | end | 502 | end |
| 503 | 503 | ||
| 504 | def display_to?(user = nil) | 504 | def display_to?(user = nil) |
| @@ -656,6 +656,8 @@ class Article < ActiveRecord::Base | @@ -656,6 +656,8 @@ class Article < ActiveRecord::Base | ||
| 656 | can_display_versions? && display_versions | 656 | can_display_versions? && display_versions |
| 657 | end | 657 | end |
| 658 | 658 | ||
| 659 | + settings_items :visibility_mode, :type => :integer, :default => 0 | ||
| 660 | + | ||
| 659 | def get_version(version_number = nil) | 661 | def get_version(version_number = nil) |
| 660 | version_number ? versions.find(:first, :order => 'version', :offset => version_number - 1) : versions.earliest | 662 | version_number ? versions.find(:first, :order => 'version', :offset => version_number - 1) : versions.earliest |
| 661 | end | 663 | end |
public/javascripts/article.js
| @@ -167,18 +167,38 @@ jQuery(function($) { | @@ -167,18 +167,38 @@ jQuery(function($) { | ||
| 167 | }); | 167 | }); |
| 168 | 168 | ||
| 169 | function show_hide_token_input() { | 169 | function show_hide_token_input() { |
| 170 | - if($("#article_published_false").attr('checked')) | 170 | + if($("#article_visibility_mode_0").attr('checked')) |
| 171 | $("#text-input-search-exception-users").parent("div").css('display', 'block'); | 171 | $("#text-input-search-exception-users").parent("div").css('display', 'block'); |
| 172 | else | 172 | else |
| 173 | $("#text-input-search-exception-users").parent("div").css('display', 'none'); | 173 | $("#text-input-search-exception-users").parent("div").css('display', 'none'); |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | + function show_hide_visibility_modes() { | ||
| 177 | + if ($("#article_published_false").attr('checked')) | ||
| 178 | + $("#article_visibility_mode_1").parent("div").parent("div").css("display", "block"); | ||
| 179 | + else | ||
| 180 | + $("#article_visibility_mode_1").parent("div").parent("div").css("display", "none"); | ||
| 181 | + } | ||
| 182 | + | ||
| 176 | if( $("#token-input-search-article-privacy-exceptions").length == 1 ) { | 183 | if( $("#token-input-search-article-privacy-exceptions").length == 1 ) { |
| 184 | + show_hide_visibility_modes(); | ||
| 177 | show_hide_token_input(); | 185 | show_hide_token_input(); |
| 178 | 186 | ||
| 187 | + $("#article_published_true").click(function() { | ||
| 188 | + show_hide_visibility_modes(); | ||
| 189 | + }); | ||
| 190 | + | ||
| 191 | + $("#article_published_false").click(function() { | ||
| 192 | + show_hide_visibility_modes(); | ||
| 193 | + }); | ||
| 194 | + | ||
| 179 | //Hide / Show the text area | 195 | //Hide / Show the text area |
| 180 | - $("#article_published_false").click(show_hide_token_input); | ||
| 181 | - $("#article_published_true").click(show_hide_token_input); | 196 | + $("#article_visibility_mode_0").click(function() { |
| 197 | + show_hide_token_input(); | ||
| 198 | + }); | ||
| 199 | + $("#article_visibility_mode_1").click(function() { | ||
| 200 | + show_hide_token_input(); | ||
| 201 | + }); | ||
| 182 | } | 202 | } |
| 183 | 203 | ||
| 184 | }); | 204 | }); |