cirandas.net

ref: master

app/helpers/folder_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
module FolderHelper

  include ArticleHelper

  def list_contents(configure={})
    configure[:recursive] ||= false
    configure[:list_type] ||= :folder
    contents = configure[:contents]
    contents = contents.order('name ASC') unless contents.is_a? Array
    contents = contents.paginate per_page: 30, page: params[:npage]
    configure[:contents] = contents
    if contents.present?
      render :file => 'shared/content_list', :locals => configure
    else
      content_tag('em', _('(empty folder)'))
    end
  end

  def available_articles(articles, user)
    articles.select {|article| article.display_to?(user)}
  end

  def display_content_icon(content_item)
    content = FilePresenter.for content_item
    content_link = if content.image?
         link_to(
           image_tag(icon_for_article(content, :bigicon)),
           content.url.merge(:view => true)
         )
       else
         link_to('',
          content.url.merge(:view => true),
          :class => icon_for_article(content, :bigicon)
         )
       end
  end

  def icon_for_article(article, size = 'icon')
    article = FilePresenter.for article
    if article.respond_to?(:sized_icon)
      article.sized_icon(size)
    else
      icon = article.respond_to?(:icon_name) ?
              article.icon_name :
              article.class.icon_name(article)
      klasses = "#{size} " + [icon].flatten.map{|name| "#{size}-"+name}.join(' ')
      if article.kind_of?(UploadedFile) || article.kind_of?(FilePresenter)
        klasses += " #{size}-upload-file"
      end
      klasses
    end
  end

  def icon_for_new_article(klass)
    "icon-new icon-new%s" % klass.icon_name
  end

  def custom_options_for_article(article,tokenized_children)
    @article = article

    visibility_options(article,tokenized_children) +
    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')
      ) +
      hidden_field_tag('article[accept_comments]', 0)
    )
  end

  def cms_label_for_new_children
    _('New article')
  end

  def cms_label_for_edit
    _('Edit folder')
  end

end