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 | 77 | content_tag('div', |
78 | 78 | radio_button(:article, :published, false) + |
79 | 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 | 93 | (article.profile.community? ? content_tag('div', |
82 | 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 | 95 | token_input_field_tag(:q, 'search-article-privacy-exceptions', {:action => 'search_article_privacy_exceptions'}, |
84 | 96 | {:focus => false, :hint_text => _('Type in a search term for a user'), :pre_populate => tokenized_children})) : |
85 | - '')) | |
97 | + ''), :style => 'padding-left: 15px;') | |
86 | 98 | end |
87 | 99 | |
88 | 100 | def prepare_to_token_input(array) | ... | ... |
app/models/article.rb
... | ... | @@ -2,7 +2,7 @@ require 'hpricot' |
2 | 2 | |
3 | 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 | 7 | acts_as_having_image |
8 | 8 | |
... | ... | @@ -498,7 +498,7 @@ class Article < ActiveRecord::Base |
498 | 498 | def display_unpublished_article_to?(user) |
499 | 499 | user == author || allow_view_private_content?(user) || user == profile || |
500 | 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 | 502 | end |
503 | 503 | |
504 | 504 | def display_to?(user = nil) |
... | ... | @@ -656,6 +656,8 @@ class Article < ActiveRecord::Base |
656 | 656 | can_display_versions? && display_versions |
657 | 657 | end |
658 | 658 | |
659 | + settings_items :visibility_mode, :type => :integer, :default => 0 | |
660 | + | |
659 | 661 | def get_version(version_number = nil) |
660 | 662 | version_number ? versions.find(:first, :order => 'version', :offset => version_number - 1) : versions.earliest |
661 | 663 | end | ... | ... |
public/javascripts/article.js
... | ... | @@ -167,18 +167,38 @@ jQuery(function($) { |
167 | 167 | }); |
168 | 168 | |
169 | 169 | function show_hide_token_input() { |
170 | - if($("#article_published_false").attr('checked')) | |
170 | + if($("#article_visibility_mode_0").attr('checked')) | |
171 | 171 | $("#text-input-search-exception-users").parent("div").css('display', 'block'); |
172 | 172 | else |
173 | 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 | 183 | if( $("#token-input-search-article-privacy-exceptions").length == 1 ) { |
184 | + show_hide_visibility_modes(); | |
177 | 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 | 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 | }); | ... | ... |