cirandas.net

ref: master

app/helpers/article_helper.rb


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
module ArticleHelper

  include TokenHelper
  include FormsHelper

  def article_reported_version(article)
    search_path = Rails.root.join('app', 'views', 'shared', 'reported_versions')
    partial_path = File.join('shared', 'reported_versions', 'profile', partial_for_class_in_view_path(article.class, search_path))
    render_to_string(:partial => partial_path, :locals => {:article => article})
  end

  def custom_options_for_article(article, tokenized_children)
    @article = article

    visibility_options(@article, tokenized_children) +
    topic_creation(@article) +
    content_tag('h4', _('Options')) +
    content_tag('div',
      content_tag(
        'div',
        check_box(:article, :archived) +
        content_tag('label', _('Do not allow new content on this article and its children'), :for => 'article_archived_true')
      ) +

      (article.profile.has_members? ?
      content_tag(
        'div',
        check_box(:article, :allow_members_to_edit) +
        content_tag('label', _('Allow all members to edit this article'), :for => 'article_allow_members_to_edit')
      ) :
      '') +

      content_tag(
        'div',
        check_box(:article, :accept_comments) +
        content_tag('label', (article.parent && article.parent.forum? ? _('This topic is opened for replies') : _('I want to receive comments about this article')), :for => 'article_accept_comments')
      ) +

      content_tag(
        'div',
        check_box(:article, :notify_comments) +
        content_tag('label', _('I want to receive a notification of each comment written by e-mail'), :for => 'article_notify_comments') +
        observe_field(:article_accept_comments, :function => "jQuery('#article_notify_comments')[0].disabled = ! jQuery('#article_accept_comments')[0].checked;jQuery('#article_moderate_comments')[0].disabled = ! jQuery('#article_accept_comments')[0].checked")
      ) +

      content_tag(
        'div',
        check_box(:article, :moderate_comments) +
        content_tag('label', _('I want to approve comments on this article'), :for => 'article_moderate_comments')
      ) +

      (article.can_display_hits? ?
      content_tag(
        'div',
        check_box(:article, :display_hits) +
        content_tag('label', _('I want this article to display the number of hits it received'), :for => 'article_display_hits')
      ) : '') +

      (article.can_display_versions? ?
      content_tag(
        'div',
        check_box(:article, :display_versions) +
        content_tag('label', _('I want this article to display a link to older versions'), :for => 'article_display_versions')
      ) : '') +

      (self.respond_to?(:extra_options) ? self.extra_options : "")
    )
  end

  def visibility_options(article, tokenized_children)
    content_tag('h4', _('Visibility')) +
    content_tag('div',
      content_tag('div',
        radio_button(:article, :published, true) +
          content_tag('span', ' '.html_safe, :class => 'access-public-icon') +
          content_tag('label', _('Public'), :for => 'article_published_true') +
          content_tag('span', _('Visible to other people'), :class => 'access-note'),
          :class => 'access-item'
           ) +
      content_tag('div',
        radio_button(:article, :published, false) +
          content_tag('span', ' '.html_safe, :class => 'access-private-icon') +
          content_tag('label', _('Private'), :for => 'article_published_false', :id => "label_private") +
          content_tag('span', _('Limit visibility of this article'), :class => 'access-note'),
          :class => 'access-item'
      ) +
      privacity_exceptions(article, tokenized_children),
      :class => 'access-itens'
    )
  end

  def topic_creation(article)
    return '' unless article.forum?

    content_tag('h4', _('Topic creation')) +
    content_tag( 'small', _('Who will be able to create new topics on this forum?')) +
    slider_field_tag('topic-creation', 'article[topic_creation]', article.profile, article.topic_creation_access, article.topic_creation)
  end

  def privacity_exceptions(article, tokenized_children)
    content_tag('div',
      content_tag('div',
        (
          if article.profile
            add_option_to_followers(article, tokenized_children)
          else
            ''
          end
        )
      ),
      :style => "margin-left:10px"
    )
  end

  def add_option_to_followers(article, tokenized_children)
    label_message = article.profile.organization? ? _('Allow all community members to view this content') : _('Allow all your friends to view this content')

    check_box(
      :article,
      :show_to_followers,
      {:class => "custom_privacy_option"}
    ) +
    content_tag(
      'label',
      label_message,
      :for => 'article_show_to_followers',
      :id => 'label_show_to_followers'
    ) +
    (article.profile.community? ?
      content_tag(
        'div',
        content_tag(
          'label',
          _('Allow only community members entered below to view this content'),
          :id => "text-input-search-exception-users"
        ) +
        token_input_field_tag(
          :q,
          'search-article-privacy-exceptions',
          {:action => 'search_article_privacy_exceptions'},
          {
            :focus => false,
            :hint_text => _('Type in a name of a community member'),
            :pre_populate => tokenized_children
          }
        )
      ) : '')
  end

  def prepare_to_token_input(array)
    array.map { |object| {:id => object.id, :name => object.name} }
  end

  def prepare_to_token_input_by_label(array)
    array.map { |object| {:label => object.name, :value => object.name} }
  end

  def prepare_to_token_input_by_class(array)
    array.map { |object| {:id => "#{object.class.name}_#{object.id || object.name}", :name => "#{object.name} (#{_(object.class.name)})", :class => object.class.name}}
  end

  def cms_label_for_new_children
    _('New article')
  end

  def cms_label_for_edit
    _('Edit')
  end

  def follow_button_text(article)
    if article.event?
      _('Attend')
    else
      _('Follow')
    end
  end

  def unfollow_button_text(article)
    if article.event?
      _('Unattend')
    else
      _('Unfollow')
    end
  end

  def following_button(page, user)
    if !user.blank? and user != page.author
      if page.is_followed_by? user
        button :cancel, unfollow_button_text(page), {controller: :profile, profile: page.profile.identifier, action: :unfollow_article, article_id: page.id}
      else
        button :add, follow_button_text(page), {controller: :profile, profile: page.profile.identifier, action: :follow_article, article_id: page.id}
      end
    end
  end

  def filter_html(html, source)
    if @plugins && source && source.has_macro?
      html = convert_macro(html, source) unless @plugins.enabled_macros.blank?
      #TODO This parse should be done through the macro infra, but since there
      #     are old things that do not support it we are keeping this hot spot.
      html = @plugins.pipeline(:parse_content, html, source).first
    end
    html && html.html_safe
  end

  def article_to_html(article, options = {})
    options.merge!(:page => params[:npage])
    content = article.to_html(options)
    content = content.kind_of?(Proc) ? self.instance_exec(&content).html_safe : content.html_safe
    filter_html(content, article)
  end

end