Fix bug.
This commit is contained in:
parent
0660a12bff
commit
336c940457
|
@ -254,7 +254,24 @@ class Admin::PropertyHiresController < OrbitAdminController
|
||||||
params.require(:property_location).permit!
|
params.require(:property_location).permit!
|
||||||
end
|
end
|
||||||
def phire_params
|
def phire_params
|
||||||
params.require(:p_hire).permit!
|
p_hire_params = params.require(:p_hire).permit!
|
||||||
|
property = (@phire ? @phire.property : Property.find(params[:p_hire][:property_id]) rescue nil)
|
||||||
|
if(property.enable_notes_selector rescue false)
|
||||||
|
note_texts = ""
|
||||||
|
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?
|
||||||
|
value_text = p_hire_params["notes_selector"][index.to_s].to_a.map{|i| values[i.to_i]}.join(",") rescue ""
|
||||||
|
value_text = I18n.t("property_hire.none") if value_text.blank?
|
||||||
|
note_texts += (name + ":"+value_text)
|
||||||
|
note_texts += "<br>".html_safe
|
||||||
|
end
|
||||||
|
p_hire_params["note_for_hire"] = note_texts
|
||||||
|
p_hire_params.delete("notes_selector")
|
||||||
|
end
|
||||||
|
return p_hire_params
|
||||||
end
|
end
|
||||||
def property_params
|
def property_params
|
||||||
prop = params.require(:property).permit!
|
prop = params.require(:property).permit!
|
||||||
|
|
|
@ -711,7 +711,7 @@ ul.list-unstyled li {
|
||||||
<% custom_field_inputs = {} %>
|
<% custom_field_inputs = {} %>
|
||||||
<% custom_field_type = {"note_for_hire"=>"text_area"} %>
|
<% custom_field_type = {"note_for_hire"=>"text_area"} %>
|
||||||
<% if(property.enable_notes_selector rescue false) %>
|
<% if(property.enable_notes_selector rescue false) %>
|
||||||
<% custom_field_inputs["note_for_hire"] = render(:partial=>"note_for_hire",:locals=>{:f=>f,:property=>property}) %>
|
<% custom_field_inputs["note_for_hire"] = render(:partial=>"property_hires/notes_selector",:locals=>{:f=>f,:property=>property,:label_col=>label_col,:input_col=>input_col,:hire=>hire}) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% fields_name = property.get_all_fields %>
|
<% fields_name = property.get_all_fields %>
|
||||||
<% has_p_hire_fields = property.p_hire_fields_enabled.count != 0
|
<% has_p_hire_fields = property.p_hire_fields_enabled.count != 0
|
||||||
|
|
|
@ -1,3 +1,12 @@
|
||||||
|
<%
|
||||||
|
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| %>
|
<% property.notes_selector.each do |index,sub_hash| %>
|
||||||
<% name = sub_hash["name"][I18n.locale.to_s] %>
|
<% name = sub_hash["name"][I18n.locale.to_s] %>
|
||||||
<% name = sub_hash["name"].values.select{|v| v.present?}.first.to_s if name.blank? %>
|
<% name = sub_hash["name"].values.select{|v| v.present?}.first.to_s if name.blank? %>
|
||||||
|
@ -7,9 +16,29 @@
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<%= f.label "notes_selector[#{index}]", name, :class => "col-sm-#{label_col} control-label" %>
|
<%= f.label "notes_selector[#{index}]", name, :class => "col-sm-#{label_col} control-label" %>
|
||||||
<div class="col-sm-<%=input_col%>">
|
<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| %>
|
<% values.each_with_index do |v,i| %>
|
||||||
<label class="checkbox-inline">
|
<label class="checkbox-inline">
|
||||||
<input type="<%=type%>" name="p_hire[notes_selector][<%=index.to_s%>][]" value="<%=i%>" <%= (type=="radio" && i == 0) ? "checked=\"checked\"" : "" %>>
|
<input type="<%=type%>" name="p_hire[notes_selector][<%=index.to_s%>][]" value="<%=i%>" <%= (selected_indices.include?(i)) ? "checked=\"checked\"" : "" %>>
|
||||||
<%=v%>
|
<%=v%>
|
||||||
</label>
|
</label>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -555,7 +555,7 @@
|
||||||
<% custom_field_inputs = {} %>
|
<% custom_field_inputs = {} %>
|
||||||
<% custom_field_type = {"note_for_hire"=>"text_area"} %>
|
<% custom_field_type = {"note_for_hire"=>"text_area"} %>
|
||||||
<% if(property.enable_notes_selector rescue false) %>
|
<% if(property.enable_notes_selector rescue false) %>
|
||||||
<% custom_field_inputs["note_for_hire"] = render(:partial=>"note_for_hire",:locals=>{:f=>f,:property=>property}) %>
|
<% custom_field_inputs["note_for_hire"] = render(:partial=>"property_hires/notes_selector",:locals=>{:f=>f,:property=>property,:label_col=>label_col,:input_col=>input_col,:hire=>nil}) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% fields_name = property.get_all_fields %>
|
<% fields_name = property.get_all_fields %>
|
||||||
<% has_p_hire_fields = property.p_hire_fields_enabled.count != 0
|
<% has_p_hire_fields = property.p_hire_fields_enabled.count != 0
|
||||||
|
|
Loading…
Reference in New Issue