].html_safe
end
def iterate_form
v.form_tag(v.iterate_url, method: :get, class: 'iterate') do
html = ''
if v.iord_features.include?(:search)
html +=
search_term +
search_operator +
search_value
html += ' '
end
html += %Q[]
html += %q[]
html += ' '
html += %Q[]
html += %q[]
html += ' '
html += %Q[]
html += %q[]
html += ' '
html += %Q[]
html += v.submit_tag(v.t('iord.buttons.iterate'), name: '')
html.html_safe
end
end
end
module Iterable
extend ActiveSupport::Concern
include Sort
included do
iord_features << :iterable
helper_method :pos
helper_method :iterate_url
helper_method :collection_count
helper_method :iterate_edition
end
def iterate_edition
if @iterate_edition.nil?
@iterate_edition = params[:edit] == 'true'
collection_url_defaults[:edit] = @iterate_edition
end
return @iterate_edition
end
def pos
if @pos.nil?
@pos = params[:pos]
if @pos
@pos = @pos.to_i
collection_url_defaults[:pos] = @pos
end
end
return @pos
end
def iterate_url(options = {})
if options.present?
if options == true
options = collection_url_defaults
else
options = collection_url_defaults.merge(options)
end
return self.public_send "iterate_#{collection_url_method}".to_sym, options
else
@iterate_url = self.public_send "iterate_#{collection_url_method}".to_sym
end
end
def collection_count
@collection_count ||= create_collection.count
end
def iterate
collection = create_collection
@pos = pos || collection_count
if @pos == -1
@resource = collection.last
@pos = collection_count - 1
elsif @pos < collection_count
@resource = collection.skip(pos).first
else
@resource = nil
@pos = nil
end
collection_url_defaults[:pos] = @pos
if iterate_edition and request.request_method == 'PATCH'
@pos = 0 if @pos.nil?
update_resource
if @resource.save
flash[:notice] = t('iord.flash.update.notice', model: resource_name)
redirect_to params[:go_to]
return
end
end
end
end
end