Module: PyrRules::EventsHelper

Defined in:
app/helpers/pyr_rules/events_helper.rb

Instance Method Summary collapse

Instance Method Details

#_render_action_leaf(action_name, stack) ⇒ Object



87
88
89
90
91
92
93
94
# File 'app/helpers/pyr_rules/events_helper.rb', line 87

def _render_action_leaf(action_name, stack)
	name = "#{stack.join('::')}_#{action_name}"
	 :div, id: name, style:"margin-left:30px;padding:5px;" do
		 :input, name: name, type: "checkbox" do
			"<span style='margin-left:10px;'>#{action_name.to_s}</span>".html_safe
		end
	end
end

#_render_and_recurse(key, children, stack) ⇒ Object



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
82
83
84
85
# File 'app/helpers/pyr_rules/events_helper.rb', line 54

def _render_and_recurse(key,children,stack)
	return "" if key.blank?	# escape - don't render context variables
	body = ""
	if key == :actions				# render each action as a leaf
		children.each do |action|
			body += _render_action_leaf(action, stack)
		end
	elsif key == :context
		body =  :div, class: "collapse-group", style:"block:inline;margin-left:30px;padding:5px;" do
			 :div, id:"#{stack.join('_')}_context", class: "collapse", style: "block:inline;padding:5px;min-height:30px;" do
				context = children.collect{|k,v| "<b>#{k}</b> (<i>#{v}</i>)"}.join("<br/>")
				inner_body = "<a class='btn btn-mini' data-toggle='collapse' data-target='##{stack.join('_')}_context'>context</a>".html_safe
				inner_body += "<div class='collapse-group'>#{context}</div>".html_safe
				inner_body += "<div style='clear:both;'></div>".html_safe
			end
		end
	else
		stack.push key
		body +=  :div, class: "collapse-group", style: "margin-left:30px;position:relative;" do
					 :div, id:"#{stack.join('_')}", class: "collapse", style: "padding:5px;min-height:30px;" do
						inner_body = "<a class='btn btn-mini' data-toggle='collapse' data-target='##{stack.join('_')}'>+</a><span style='font-weight:bold;'>#{key.to_s.titleize}</span>"
						children.each do |child_key, grandkids|
							#inner_body += "&nbsp;" * stack.size
							inner_body += _render_and_recurse(child_key, grandkids, stack) + "\n"
						end
						inner_body.html_safe
					end
				end
		stack.pop
	end
	body.html_safe
end

#render_tree(events_tree) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'app/helpers/pyr_rules/events_helper.rb', line 42

def render_tree(events_tree)
	stack = []
	 :div, id: "events_tree" do
		body = ""
		events_tree.each do |event_type, sub_events|
			body += _render_and_recurse(event_type, sub_events, stack) + "\n"
		end
		body.html_safe
	end
end