diff --git a/app/controllers/admin/property_hires_controller.rb b/app/controllers/admin/property_hires_controller.rb index 4d17a86..8fbd0ee 100644 --- a/app/controllers/admin/property_hires_controller.rb +++ b/app/controllers/admin/property_hires_controller.rb @@ -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 = [] diff --git a/app/controllers/property_hires_controller.rb b/app/controllers/property_hires_controller.rb index 80f726b..b2bffdc 100644 --- a/app/controllers/property_hires_controller.rb +++ b/app/controllers/property_hires_controller.rb @@ -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 += "
".html_safe + end + p_hire_params["note_for_hire"] = note_texts + p_hire_params.delete("notes_selector") + end + return p_hire_params end end diff --git a/app/models/property.rb b/app/models/property.rb index 42e9232..56b5fe7 100644 --- a/app/models/property.rb +++ b/app/models/property.rb @@ -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 diff --git a/app/views/admin/property_hires/_form.html.erb b/app/views/admin/property_hires/_form.html.erb index 9db8708..f0e41f8 100644 --- a/app/views/admin/property_hires/_form.html.erb +++ b/app/views/admin/property_hires/_form.html.erb @@ -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; + } <% content_for :page_specific_css do %> <%= stylesheet_link_tag "lib/main-forms" %> @@ -324,6 +338,80 @@ <% end %> +
+
+ <% field_name = "enable_notes_selector" %> + +
+ +
+
+
+ <% field_name = "notes_selector" %> + +
+
+ <% @property[field_name].each do |index,sub_hash| %> +
+ +
+
+ + +
+
+
+
+ <% @site_in_use_locales.each_with_index do |locale, i| %> +
" id="select_choice_name_index<%=index%>_<%=locale.to_s%>"> + "> +
+ <% end %> +
+
+ <% @site_in_use_locales.each_with_index do |locale, i| %> + " href="#select_choice_name_index<%=index%>_<%=locale.to_s%>" data-toggle="tab"><%= t(locale.to_s) %> + <% end %> +
+
+
+
+
+ + <% @property["#{field_name}"]["#{index}"]["value"].values.first.each_with_index do |v,val_index|%> +
+ +
+
+ <% @site_in_use_locales.each_with_index do |locale, i| %> +
" id="select_choice_value_index<%=index.to_s%>_<%=locale.to_s%>_<%=val_index%>"> + "> +
+ <% end %> +
+ +
+
+ <% end %> +
+ <%=t("property_hire.add_choice")%> +
+
+ <% end %> +
+ <%=t(:add)%> +
@@ -378,6 +466,13 @@ <%= link_to t('cancel'), admin_property_hires_path, :class=>"btn" %> diff --git a/app/views/admin/property_hires/show_booking_details.html.erb b/app/views/admin/property_hires/show_booking_details.html.erb index edf5ac0..5c8fa03 100644 --- a/app/views/admin/property_hires/show_booking_details.html.erb +++ b/app/views/admin/property_hires/show_booking_details.html.erb @@ -34,7 +34,7 @@ <%= t("property_hire.note_for_hire") %> - <%= @booking.note_for_hire %> + <%= @booking.note_for_hire.html_safe %> <% 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| %> diff --git a/app/views/property_hires/hire.html.erb b/app/views/property_hires/hire.html.erb index 215ee1b..4eba779 100644 --- a/app/views/property_hires/hire.html.erb +++ b/app/views/property_hires/hire.html.erb @@ -118,12 +118,36 @@ <%= f.text_field :reason_for_hire, :class => "form-control", :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %> -
- <%= f.label :note_for_hire, t("property_hire.note_for_hire"), :class => "col-sm-2 control-label" %> -
- <%= f.text_area :note_for_hire, :class => "form-control" %> -
-
+ <% 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"] %> +
+ <%= f.label "notes_selector[#{index}]", name, :class => "col-sm-2 control-label" %> +
+ <% values.each_with_index do |v,i| %> + + <% end %> + <% if type == "checkbox" && (values.count > 1) %> + <%= t("property_hire.checkbox_hint") %> + <% end %> +
+
+ <% end %> + <% else %> +
+ <%= f.label :note_for_hire, t("property_hire.note_for_hire"), :class => "col-sm-2 control-label" %> +
+ <%= f.text_area :note_for_hire, :class => "form-control" %> +
+
+ <% 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) %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 5dda987..bcdf309 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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' diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 396b4a9..203604f 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -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: '租借模組:編輯成功'