Class: ViewableListPresenter

Inherits:
BaseListPresenter show all
Defined in:
app/presenters/viewable_list_presenter.rb

Instance Attribute Summary

Attributes inherited from BaseListPresenter

#context, #list

Instance Method Summary collapse

Constructor Details

#initialize(list, context, list_key, max) ⇒ ViewableListPresenter

Returns a new instance of ViewableListPresenter.



2
3
4
5
6
# File 'app/presenters/viewable_list_presenter.rb', line 2

def initialize(list, context, list_key, max)
  super(list, context)
  @max = max
  @list_key = list_key
end

Instance Method Details



22
23
24
25
26
27
28
29
# File 'app/presenters/viewable_list_presenter.rb', line 22

def add_link
  return unless h.cms_edit_mode?
  return unless @max == Float::INFINITY || list.size < @max.to_i

  h.link_to add_path, class: "cms-add", 'data-no-turbolink' => true do
    h.t('cms.add')
  end
end


8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/presenters/viewable_list_presenter.rb', line 8

def edit_links(method_name = nil)
  return unless h.cms_edit_mode?

  h.(:ul, sortable(class: "cms-wrapped-edit")) do
    list.each.with_index(1) do |m, i|
      name = method_name ? m.__send__(method_name) : i
      h.concat(h.(:li, h.cms_data_js('cms-sortable-id', m.unique_key.id)) do
        m.edit_link(name)
      end)
    end
    h.concat h.(:li, add_link)
  end
end

#sortable(options = {}) ⇒ Object



31
32
33
34
35
36
37
# File 'app/presenters/viewable_list_presenter.rb', line 31

def sortable(options = {})
  if h.cms_edit_mode?
    h.cms_data_js('cms-sortable', { url: h.main_app.edit_viewable_url(format: :js) }, options)
  else
    options
  end
end

#sortable_html(options = {}) ⇒ Object



39
40
41
# File 'app/presenters/viewable_list_presenter.rb', line 39

def sortable_html(options = {})
  CMS.options_to_html sortable(options)
end

#ul_sortable_tag(options = {}) ⇒ Object



43
44
45
46
47
# File 'app/presenters/viewable_list_presenter.rb', line 43

def ul_sortable_tag(options = {})
  h. :ul, sortable(options) do
    yield
  end
end