event :add_and_drop_items, :prepare_to_validate, on: :save do
adds = Env.params["add_item"]
drops = Env.params["drop_item"]
Array.wrap(adds).each { |i| add_item i } if adds
Array.wrap(drops).each { |i| drop_item i } if drops
end
event :insert_item_event, :prepare_to_validate,
on: :save, when: proc { Env.params["insert_item"] } do
index = Env.params["item_index"] || 0
insert_item index.to_i, Env.params["insert_item"]
end
format :html do
view :editor do |args|
_render_hidden_content_field + raw(_render(part_view, args))
# .merge(pointer_item_class: 'form-control')))
end
def part_view
(c = card.rule(:input)) ? c.gsub(/[\[\]]/, "") : :list
end
view :list do |args|
args ||= {}
items = args[:item_list] || card.item_names(context: :raw)
items = [""] if items.empty?
rendered_items = items.map do |item|
_render_list_item args.merge(pointer_item: item)
end.join "\n"
extra_css_class = args[:extra_css_class] || "pointer-list-ul"
<<-HTML
#{rendered_items}
#{add_item_button}
HTML
end
def options_card_name
(oc = card.options_rule_card) ? oc.cardname.url_key : ":all"
end
def add_item_button
wrap_with :span, class: "input-group" do
button_tag class: "pointer-item-add" do
glyphicon("plus") + " add another"
end
end
end
view :list_item do |args|
<<-HTML
HTML
end
view :checkbox do |_args|
options = card.option_names.map do |option_name|
checked = card.item_names.include?(option_name)
id = "pointer-checkbox-#{option_name.to_name.key}"
<<-HTML