property_hire/app/views/property_hires/_notes_selector.html.erb

50 lines
1.8 KiB
Plaintext
Raw Permalink Normal View History

2023-04-22 07:39:05 +00:00
<%
hire = (defined?(hire) ? hire : nil)
if hire
notes_selector_value = hire.note_for_hire.split('<br>').map{|s| s.split(':', 2)}.to_h
use_default = false
else
use_default = true
end
%>
2021-09-19 07:56:01 +00:00
<% property.notes_selector.each do |index,sub_hash| %>
<% name = sub_hash["name"][I18n.locale.to_s] %>
<% name = sub_hash["name"].values.select{|v| v.present?}.first.to_s if name.blank? %>
<% values = sub_hash["value"][I18n.locale.to_s] %>
<% values = sub_hash["value"].values.select{|v| v.present?}.first.to_s if values.blank? %>
<% type = sub_hash["type"] %>
<div class="form-group">
<%= f.label "notes_selector[#{index}]", name, :class => "col-sm-#{label_col} control-label" %>
<div class="col-sm-<%=input_col%>">
2023-04-22 07:39:05 +00:00
<%
if use_default
if type == "radio"
selected_indices = [0]
else
selected_indices = []
end
else
selected_indices = []
sub_hash["name"].each do |l, k|
if notes_selector_value.has_key?(k)
sub_hash["value"][l].each_with_index do |v, i|
if notes_selector_value[k].match(/(^|,)#{::Regexp.escape(v)}(,|$)/)
selected_indices << i
end
end
end
end
end
%>
2021-09-19 07:56:01 +00:00
<% values.each_with_index do |v,i| %>
<label class="checkbox-inline">
2023-04-22 07:39:05 +00:00
<input type="<%=type%>" name="p_hire[notes_selector][<%=index.to_s%>][]" value="<%=i%>" <%= (selected_indices.include?(i)) ? "checked=\"checked\"" : "" %>>
2021-09-19 07:56:01 +00:00
<%=v%>
</label>
<% end %>
<% if type == "checkbox" && (values.count > 1) %>
<small class="help-block"><%= t("property_hire.checkbox_hint") %></small>
<% end %>
</div>
</div>
<% end %>