Add notes selector.
This commit is contained in:
parent
262eaa36b9
commit
5d14e25578
|
@ -182,7 +182,9 @@ class Admin::PropertyHiresController < OrbitAdminController
|
|||
def property_params
|
||||
prop = params.require(:property).permit!
|
||||
prop.delete(:property_location) if prop[:property_location] == "other"
|
||||
prop
|
||||
notes_selector = prop["notes_selector"]
|
||||
prop["notes_selector"] = (0 ... notes_selector.keys.count).to_a.map{|k| k.to_s}.zip(notes_selector.values).to_h
|
||||
return prop
|
||||
end
|
||||
def create_set (save_flag)
|
||||
@email_set = []
|
||||
|
|
|
@ -222,7 +222,24 @@ class PropertyHiresController < ApplicationController
|
|||
private
|
||||
|
||||
def booking_params
|
||||
params.require(:p_hire).permit!
|
||||
p_hire_params = params.require(:p_hire).permit!
|
||||
property = Property.find(params[:property_id]) rescue Property.last
|
||||
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(",")
|
||||
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
|
||||
|
|
|
@ -39,6 +39,8 @@ class Property
|
|||
field :mobile_phone_of_contact_person
|
||||
field :contact_person_Email
|
||||
field :contact_person_department
|
||||
field :enable_notes_selector , type: Boolean, default: false
|
||||
field :notes_selector ,type: Hash, default: {}
|
||||
belongs_to :property_location
|
||||
has_many :p_hires
|
||||
has_many :hire_email_sets, :autosave => true, :dependent => :destroy, :inverse_of => :property
|
||||
|
|
|
@ -13,6 +13,20 @@
|
|||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.label_left{
|
||||
float: left;
|
||||
margin-right: 0.5em;
|
||||
}
|
||||
.select_field_block{
|
||||
border: 0.2em solid #666;
|
||||
padding: 1em;
|
||||
}
|
||||
.remove_btn:hover{
|
||||
font-size: 1.3em;
|
||||
}
|
||||
.remove_btn{
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
<% content_for :page_specific_css do %>
|
||||
<%= stylesheet_link_tag "lib/main-forms" %>
|
||||
|
@ -324,6 +338,80 @@
|
|||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<hr style="border-color: black; ">
|
||||
<div class="control-group">
|
||||
<% field_name = "enable_notes_selector" %>
|
||||
<label class="control-label muted"><%= t("property_hire.#{field_name}") %></label>
|
||||
<div class="controls">
|
||||
<label for="act_enabled_name" class="checkbox inline">
|
||||
<%= hidden_field_tag "property[#{field_name}]", "0" %>
|
||||
<%= f.check_box_tag "property[#{field_name}]", "1" , (@property[field_name] rescue false) %>
|
||||
Enable
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group" id="selector_block">
|
||||
<% field_name = "notes_selector" %>
|
||||
<label class="control-label muted"><%= t("property_hire.#{field_name}") %></label>
|
||||
<div class="controls">
|
||||
<div id="select_choice_block">
|
||||
<% @property[field_name].each do |index,sub_hash| %>
|
||||
<div id="select_choice<%=index.to_s%>" class="select_field_block">
|
||||
<span class="remove_btn">❌</span>
|
||||
<div class="field_name_block">
|
||||
<div>
|
||||
<label for="select_choice_type_index<%=index.to_s%>" class="label_left"><%=t("property_hire.field_type")%>:</label>
|
||||
<select name="<%="property[#{field_name}][#{index}][type]"%>">
|
||||
<option value="radio" <%=(@property["#{field_name}"]["#{index}"]["type"] == "radio") ? 'selected="selected"' : ''%>><%=t("property_hire.radio")%></option>
|
||||
<option value="checkbox" <%=(@property["#{field_name}"]["#{index}"]["type"] == "checkbox") ? 'selected="selected"' : ''%>><%=t("property_hire.checkbox")%></option>
|
||||
</select>
|
||||
</div>
|
||||
<div><label for="select_choice_name_index<%=index.to_s%>" class="label_left"><%=t("property_hire.field_name")%>:</label>
|
||||
<div class="input-append">
|
||||
<div class="tab-content">
|
||||
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||
<div class="tab-pane fade <%= ( i == 0 ) ? "active in" : '' %>" id="select_choice_name_index<%=index%>_<%=locale.to_s%>">
|
||||
<input type="text" value="<%=sub_hash['name'][locale.to_s] rescue ''%>" name="<%="property[#{field_name}][#{index}][name][#{locale}]"%>">
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="btn-group" data-toggle="buttons-radio">
|
||||
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||
<a class="btn <%= ( i == 0 ) ? "active" : '' %>" href="#select_choice_name_index<%=index%>_<%=locale.to_s%>" data-toggle="tab"><%= t(locale.to_s) %></a>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field_value_block">
|
||||
<label><%=t("property_hire.field_value")%></label>
|
||||
<% @property["#{field_name}"]["#{index}"]["value"].values.first.each_with_index do |v,val_index|%>
|
||||
<div class="value_choice">
|
||||
<span class="remove_btn">❌</span>
|
||||
<div class="input-append">
|
||||
<div class="tab-content">
|
||||
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||
<div class="tab-pane fade <%= ( i == 0 ) ? "active in" : '' %>" id="select_choice_value_index<%=index.to_s%>_<%=locale.to_s%>_<%=val_index%>">
|
||||
<input type="text" name="property[notes_selector][<%=index.to_s%>][value][<%=locale.to_s%>][]" value="<%=@property["#{field_name}"][index.to_s]["value"][locale.to_s][val_index]%>">
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="btn-group" data-toggle="buttons-radio">
|
||||
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||
<a class="btn <%= ( i == 0 ) ? "active" : '' %>" href="#select_choice_value_index<%=index.to_s%>_<%=locale.to_s%>_<%=val_index%>" data-toggle="tab"><%= t(locale.to_s) %></a>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<div style="clear: both;"></div>
|
||||
<a class="btn btn-primary add_choice" data-index="<%=index.to_s%>"><%=t("property_hire.add_choice")%></a>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<a id="add_note_select_field" class="btn btn-primary"><%=t(:add)%></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -378,6 +466,13 @@
|
|||
<%= link_to t('cancel'), admin_property_hires_path, :class=>"btn" %>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
if($("[type=checkbox][name='property[enable_notes_selector]']:checked").length == 0){
|
||||
$("#selector_block").css("display","none");
|
||||
}else{
|
||||
$("#selector_block").css("display","");
|
||||
}
|
||||
})
|
||||
$("#property_set_unavailibility").on("click",function(){
|
||||
if($(this).is(":checked")){
|
||||
$("#set_unavailibility_div").show();
|
||||
|
@ -393,6 +488,121 @@
|
|||
$("#other-location-div").hide();
|
||||
}
|
||||
})
|
||||
$("#add_note_select_field").on("click",function(){
|
||||
var index = ($("#select_choice_block").find(">div").length == 0) ? 0 : (Number($("#select_choice_block").find(">div").eq(-1).attr("id").split("select_choice").last()) + 1);
|
||||
$("#select_choice_block").append('<div id="select_choice'+String(index)+'" class="select_field_block"><span class="remove_btn">❌</span>'+
|
||||
'<div class="field_name_block">'+
|
||||
'<div>'+
|
||||
'<label for="select_choice_type_index'+String(index)+'" class="label_left"><%=t("property_hire.field_type")%>:</label>'+
|
||||
'<select name="property[notes_selector]['+String(index)+'][type]">'+
|
||||
'<option value="radio"><%=t("property_hire.radio")%></option>'+
|
||||
'<option value="checkbox"><%=t("property_hire.checkbox")%></option>'+
|
||||
'</select>'+
|
||||
'</div>'+
|
||||
'<div><label for="select_choice_name_index'+String(index)+'" class="label_left"><%=t("property_hire.field_name")%>:</label>'+
|
||||
'<div class="input-append" id="select_choice_name_index'+String(index)+'">'+
|
||||
'<div class="tab-content">'+
|
||||
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||
'<div class="tab-pane fade <%= ( i == 0 ) ? "active in" : '' %>" id="select_choice_name_index'+String(index)+'_<%=locale.to_s%>">'+
|
||||
'<input type="text" name="property[notes_selector]['+String(index)+'][name][<%=locale.to_s%>]">'+
|
||||
'</div>'+
|
||||
<% end %>
|
||||
'</div>'+
|
||||
'<div class="btn-group" data-toggle="buttons-radio">'+
|
||||
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||
'<a class="btn <%= ( i == 0 ) ? "active" : '' %>" href="#select_choice_name_index'+String(index)+'_<%=locale.to_s%>" data-toggle="tab"><%= t(locale.to_s) %></a>'+
|
||||
<% end %>
|
||||
'</div>'+
|
||||
'</div>'+
|
||||
'</div>'+
|
||||
'</div>'+
|
||||
'<div class="field_value_block">'+
|
||||
'<label><%=t("property_hire.field_value")%></label>'+
|
||||
'<div class="value_choice">'+
|
||||
'<span class="remove_btn">❌</span>'+
|
||||
'<div class="input-append">'+
|
||||
'<div class="tab-content">'+
|
||||
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||
'<div class="tab-pane fade <%= ( i == 0 ) ? "active in" : '' %>" id="select_choice_value_index'+String(index)+'_<%=locale.to_s%>_0">'+
|
||||
'<input type="text" name="property[notes_selector]['+String(index)+'][value][<%=locale.to_s%>][]">'+
|
||||
'</div>'+
|
||||
<% end %>
|
||||
'</div>'+
|
||||
'<div class="btn-group" data-toggle="buttons-radio">'+
|
||||
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||
'<a class="btn <%= ( i == 0 ) ? "active" : '' %>" href="#select_choice_value_index'+String(index)+'_<%=locale.to_s%>_0" data-toggle="tab"><%= t(locale.to_s) %></a>'+
|
||||
<% end %>
|
||||
'</div>'+
|
||||
'</div>'+
|
||||
'</div>'+
|
||||
'<div style="clear: both;"></div>'+
|
||||
'<a class="btn btn-primary add_choice" data-index="'+String(index)+'"><%=t("property_hire.add_choice")%></a>'+
|
||||
'</div>'+
|
||||
'</div>');
|
||||
$(".add_choice").off("click").on("click",function(){
|
||||
var index = $(this).attr("data-index");
|
||||
var val_index = $(this).siblings(".value_choice").length;
|
||||
var $last_item = $(this).siblings(".value_choice").eq(-1);
|
||||
if(val_index == 0){
|
||||
$last_item = $(this).siblings("label").eq(-1);
|
||||
}
|
||||
$last_item.after('<div class="value_choice"><span class="remove_btn">❌</span><div class="input-append">'+
|
||||
'<div class="tab-content">'+
|
||||
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||
'<div class="tab-pane fade <%= ( i == 0 ) ? "active in" : '' %>" id="select_choice_value_index'+String(index)+'_<%=locale.to_s%>_'+String(val_index)+'">'+
|
||||
'<input type="text" name="property[notes_selector]['+String(index)+'][value][<%=locale.to_s%>][]">'+
|
||||
'</div>'+
|
||||
<% end %>
|
||||
'</div>'+
|
||||
'<div class="btn-group" data-toggle="buttons-radio">'+
|
||||
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||
'<a class="btn <%= ( i == 0 ) ? "active" : '' %>" href="#select_choice_value_index'+String(index)+'_<%=locale.to_s%>_'+String(val_index)+'" data-toggle="tab"><%= t(locale.to_s) %></a>'+
|
||||
<% end %>
|
||||
'</div>'+
|
||||
'</div></div>');
|
||||
$(".remove_btn").off("click").on("click",function(){
|
||||
$(this).parent().remove();
|
||||
})
|
||||
})
|
||||
$(".remove_btn").off("click").on("click",function(){
|
||||
$(this).parent().remove();
|
||||
})
|
||||
})
|
||||
$(".add_choice").off("click").on("click",function(){
|
||||
var index = $(this).attr("data-index");
|
||||
var val_index = $(this).siblings(".value_choice").length;
|
||||
var $last_item = $(this).siblings(".value_choice").eq(-1);
|
||||
if(val_index == 0){
|
||||
$last_item = $(this).siblings("label").eq(-1);
|
||||
}
|
||||
$last_item.after('<div class="value_choice"><span class="remove_btn">❌</span><div class="input-append">'+
|
||||
'<div class="tab-content">'+
|
||||
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||
'<div class="tab-pane fade <%= ( i == 0 ) ? "active in" : '' %>" id="select_choice_value_index'+String(index)+'_<%=locale.to_s%>_'+String(val_index)+'">'+
|
||||
'<input type="text" name="property[notes_selector]['+String(index)+'][value][<%=locale.to_s%>][]">'+
|
||||
'</div>'+
|
||||
<% end %>
|
||||
'</div>'+
|
||||
'<div class="btn-group" data-toggle="buttons-radio">'+
|
||||
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||
'<a class="btn <%= ( i == 0 ) ? "active" : '' %>" href="#select_choice_value_index'+String(index)+'_<%=locale.to_s%>_'+String(val_index)+'" data-toggle="tab"><%= t(locale.to_s) %></a>'+
|
||||
<% end %>
|
||||
'</div>'+
|
||||
'</div></div>');
|
||||
$(".remove_btn").off("click").on("click",function(){
|
||||
$(this).parent().remove();
|
||||
})
|
||||
});
|
||||
$(".remove_btn").off("click").on("click",function(){
|
||||
$(this).parent().remove();
|
||||
})
|
||||
$("[type=checkbox][name='property[enable_notes_selector]']").click(function(){
|
||||
if(!$(this).prop("checked")){
|
||||
$("#selector_block").css("display","none");
|
||||
}else{
|
||||
$("#selector_block").css("display","");
|
||||
}
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td><%= t("property_hire.note_for_hire") %></td>
|
||||
<td><%= @booking.note_for_hire %></td>
|
||||
<td><%= @booking.note_for_hire.html_safe %></td>
|
||||
</tr>
|
||||
<% fields_name = ["organization" ,"person_in_charge" , "tel_of_person_in_charge" , "department" , "contact_person" , "tel_of_contact_person" , "mobile_phone_of_contact_person" , "contact_person_Email" , "contact_person_department"] %>
|
||||
<% fields_name.each do |field_name| %>
|
||||
|
|
|
@ -118,12 +118,36 @@
|
|||
<%= f.text_field :reason_for_hire, :class => "form-control", :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<%= f.label :note_for_hire, t("property_hire.note_for_hire"), :class => "col-sm-2 control-label" %>
|
||||
<div class="col-sm-5">
|
||||
<%= f.text_area :note_for_hire, :class => "form-control" %>
|
||||
</div>
|
||||
</div>
|
||||
<% if(property.enable_notes_selector rescue false) %>
|
||||
<% 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-2 control-label" %>
|
||||
<div class="col-sm-5">
|
||||
<% values.each_with_index do |v,i| %>
|
||||
<label class="checkbox-inline">
|
||||
<input type="<%=type%>" name="p_hire[notes_selector][<%=index.to_s%>][]" value="<%=i%>" <%= (type=="radio" && i == 0) ? "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 %>
|
||||
<% else %>
|
||||
<div class="form-group">
|
||||
<%= f.label :note_for_hire, t("property_hire.note_for_hire"), :class => "col-sm-2 control-label" %>
|
||||
<div class="col-sm-5">
|
||||
<%= f.text_area :note_for_hire, :class => "form-control" %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% fields_name = ["organization" ,"person_in_charge" , "tel_of_person_in_charge" , "department" , "contact_person" , "tel_of_contact_person" , "mobile_phone_of_contact_person" , "contact_person_Email" , "contact_person_department"] %>
|
||||
<% fields_name.each do |field_name| %>
|
||||
<% if(property[field_name]["enable"] == "1" rescue false) %>
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
en:
|
||||
property_hire:
|
||||
none: None
|
||||
checkbox_hint: You Can Select Mulitple Places
|
||||
add_choice: Add choice
|
||||
radio: Radio
|
||||
checkbox: Checkbox
|
||||
field_name: Field name
|
||||
field_value: Field choices
|
||||
field_type: Field type
|
||||
notes_selector: Note field selector
|
||||
enable_notes_selector: Enable Note field selector
|
||||
editor: Editor
|
||||
email_p_hire_success: Hire Success
|
||||
email_edit_success: 'Property Hire Module:Edit Success'
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
zh_tw:
|
||||
property_hire:
|
||||
none: 無
|
||||
checkbox_hint: 可重複勾選
|
||||
add_choice: 新增選項
|
||||
radio: 單選
|
||||
checkbox: 多選
|
||||
field_name: 欄位名稱
|
||||
field_value: 欄位選項
|
||||
field_type: 欄位類型
|
||||
notes_selector: 備註選項
|
||||
enable_notes_selector: 啟用備註選項
|
||||
editor: 編輯者
|
||||
email_p_hire_success: 借用成功
|
||||
email_edit_success: '租借模組:編輯成功'
|
||||
|
|
Loading…
Reference in New Issue