Sha256: 65e485d256eb6e1209762602c2a54765949317c728064a1d86807921a7904110
Contents?: true
Size: 1.31 KB
Versions: 4
Compression:
Stored size: 1.31 KB
Contents
class ViewableListPresenter < BaseListPresenter def initialize(list, context, list_key, max) super(list, context) @max = max @list_key = list_key end def edit_links(method_name = nil) return unless h.cms_edit_mode? h.content_tag(: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.content_tag(:li, h.cms_js_element('cms-sortable-id', m.unique_key.id)) do m.edit_link(name) end) end h.concat h.content_tag(:li, add_link) end end 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 def sortable(options = {}) if h.cms_edit_mode? h.cms_js_element('cms-sortable', { url: h.main_app.edit_viewable_url(format: :js) }, options) else options end end def sortable_html(options = {}) sortable(options).to_a.map{ |a| %{#{a.first}=#{a.last}} }.join(' ') end def ul_sortable_tag(options = {}) h.content_tag :ul, sortable(options) do yield end end private def add_path h.main_app.new_viewable_url list_key: @list_key, max: @max end end
Version data entries
4 entries across 4 versions & 1 rubygems