50 lines
1.8 KiB
Plaintext
50 lines
1.8 KiB
Plaintext
<%
|
|
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
|
|
%>
|
|
<% 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%>">
|
|
<%
|
|
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
|
|
%>
|
|
<% values.each_with_index do |v,i| %>
|
|
<label class="checkbox-inline">
|
|
<input type="<%=type%>" name="p_hire[notes_selector][<%=index.to_s%>][]" value="<%=i%>" <%= (selected_indices.include?(i)) ? "checked=\"checked\"" : "" %>>
|
|
<%=v%>
|
|
</label>
|
|
<% end %>
|
|
<% if type == "checkbox" && (values.count > 1) %>
|
|
<small class="help-block"><%= t("property_hire.checkbox_hint") %></small>
|
|
<% end %>
|
|
</div>
|
|
</div>
|
|
<% end %> |