diff --git a/app/assets/images/property_hire/AAAAAA.png b/app/assets/images/property_hire/AAAAAA.png new file mode 100644 index 0000000..772a39b Binary files /dev/null and b/app/assets/images/property_hire/AAAAAA.png differ diff --git a/app/controllers/admin/property_hires_controller.rb b/app/controllers/admin/property_hires_controller.rb index 02d428d..15f759a 100644 --- a/app/controllers/admin/property_hires_controller.rb +++ b/app/controllers/admin/property_hires_controller.rb @@ -12,6 +12,17 @@ class Admin::PropertyHiresController < OrbitAdminController @properties = search_data(@properties,[:title]).page(params[:page]).per(10) end + def fields_display_order + uid = params[:id].split("-").last + @property = Property.find_by(:uid=>uid) + end + def update_fields_display_order + uid = params[:id].split("-").last + @property = Property.find_by(:uid=>uid) + prop = params.require(:property).permit! + @property.update_attributes(prop) + redirect_to params[:referer_url] + end def order @properties = Property.all.sort_order end @@ -84,18 +95,13 @@ class Admin::PropertyHiresController < OrbitAdminController end flash.now[:notice] = "Updated Fields" property.p_hire_fields.each{|t| t.destroy if t["to_delete"] == true} - redirect_to admin_property_hires_path(:locale => params[:locale]) and return else property.update_attributes(@property_params) email = Array(MemberProfile.find(property.owners)).collect{|v| v.email} rescue [] email = User.all.select{|v| v.is_admin? && v.user_name != 'rulingcom'}.collect{|v| v.member_profile.email} if email.length == 0 Admin::PropertyHiresHelper::HireMethod.send_mail('edit',email,property.id,nil,nil,current_user.id) - if params[:page] - redirect_to admin_property_hires_path(:page => params[:page],:locale => params[:locale]) - else - redirect_to admin_property_hires_path(:locale => params[:locale]) - end end + redirect_to params[:referer_url] end def create diff --git a/app/controllers/property_hires_controller.rb b/app/controllers/property_hires_controller.rb index 985ad57..5bd762d 100644 --- a/app/controllers/property_hires_controller.rb +++ b/app/controllers/property_hires_controller.rb @@ -221,7 +221,8 @@ class PropertyHiresController < ApplicationController email = Array(MemberProfile.find(property.owners)).collect{|v| v.email} rescue [] email = User.all.select{|v| v.is_admin? && v.user_name != 'rulingcom'}.collect{|v| v.member_profile.email} if email.length == 0 email << hire.hiring_person_email - Admin::PropertyHiresHelper::HireMethod.send_mail('p_hire',email,property.id,nil,hire.id) + email = email.select{|e| e.present?} + Admin::PropertyHiresHelper::HireMethod.send_mail('p_hire',email,property.id,nil,hire.id,(current_user.id rescue nil)) end redirect_to index_page else diff --git a/app/models/p_hire_field.rb b/app/models/p_hire_field.rb index 6ba34df..060e8fb 100644 --- a/app/models/p_hire_field.rb +++ b/app/models/p_hire_field.rb @@ -27,7 +27,24 @@ class PHireField has_many :p_hire_field_values, autosave: true, dependent: :destroy accepts_nested_attributes_for :p_hire_field_values, :allow_destroy => true before_save :check_option_list - + before_destroy do + @property = self.property + if @property && @property.custom_field_names + @property.custom_field_names.delete("p_hire_fields.#{self.id}") + @property.save + end + end + after_save do + unless self.disabled + @property = self.property + if @property && @property.custom_field_names + if self.new_record? || !(@property.custom_field_names.include?("p_hire_fields.#{self.id}")) + @property.custom_field_names << "p_hire_fields.#{self.id}" + @property.save + end + end + end + end def markup_value get_data["option_list"] end diff --git a/app/models/property.rb b/app/models/property.rb index 544fec0..1117b48 100644 --- a/app/models/property.rb +++ b/app/models/property.rb @@ -4,6 +4,8 @@ class Property include OrbitTag::Taggable include OrbitCategory::Categorizable include Slug + + FIELDSNAME=["hiring_person_email","hiring_person_number","hiring_person_name","reason_for_hire","note_for_hire","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"] field :custom_calendar_type, type: Integer, default: 0 #0=>預設, 1=> 顯示, 2=> 不顯示 field :custom_carousel_image_width, type: String, default: "" field :display_img, :type => Boolean, :default => false @@ -34,7 +36,12 @@ class Property field :start_date, type: DateTime field :end_date, type: DateTime field :description, :localize => true - field :unavailibility_note, :localize => true + field :unavailibility_note, :localize => true + field :hiring_person_email, type: Hash, default: {"enable"=>"1","required"=>"true"} + field :hiring_person_number, type: Hash, default: {"enable"=>"1","required"=>"true"} + field :hiring_person_name, type: Hash, default: {"enable"=>"1","required"=>"true"} + field :reason_for_hire, type: Hash, default: {"enable"=>"1","required"=>"true"} + field :note_for_hire field :organization field :person_in_charge field :tel_of_person_in_charge @@ -46,6 +53,9 @@ class Property field :contact_person_department field :enable_notes_selector , type: Boolean, default: false field :notes_selector ,type: Hash, default: {} + field :enable_fields_sort , type: Boolean, default: false + field :custom_field_names, type: Array + field :default_field_names, type: Array belongs_to :property_location has_many :p_hires has_many :hire_email_sets, :autosave => true, :dependent => :destroy, :inverse_of => :property @@ -73,10 +83,40 @@ class Property "Saturday" ] CAlENDARTYPE = ["default","display","not_display"] + after_initialize do + unless self.new_record? + save_flag = false + @no_validate = true + if self.default_field_names.nil? + self.default_field_names = self.get_all_fields(true) + save_flag = true + end + if self.custom_field_names.nil? + self.custom_field_names = self.get_all_fields(true) + save_flag = true + end + if save_flag + self.save + end + end + end before_create do max_position = self.class.max(:order_position) max_position = -1 if max_position.nil? self.order_position = max_position + 1 + @no_validate = true + self.default_field_names = self.get_all_fields(true) + self.custom_field_names = self.get_all_fields(true) + end + before_save do + unless @no_validate + self.default_field_names = self.get_all_fields(true) + self.class::FIELDSNAME.each do |f| + if((self.send(f)["enable"] == "1" rescue true) && !(self.custom_field_names.include?(f))) + self.custom_field_names << f + end + end + end end after_save do self.change_day_setting_status @@ -123,7 +163,7 @@ class Property def disable_view_calendar_page @@disable_view_calendar_page end - def custom_text(field_name,type,locale=nil) + def custom_text(field_name,type="name",locale=nil) locale = locale || I18n.locale default_text = I18n.with_locale(locale){I18n.t("property_hire.#{field_name}")} if (self.send(field_name)[type][locale.to_s].present? rescue false) @@ -432,11 +472,33 @@ class Property end def get_attribute_values(attribute_type=nil) - @attribute_values = attribute_type.seminar_signup_values rescue nil + @attribute_values = attribute_type.p_hire_field_values rescue nil end def get_value_from_field_id(field_id,attribute_type=nil) values = get_attribute_values(attribute_type) - value = values.detect {|value| value.seminar_signup_field_id == field_id} rescue nil + value = values.detect {|value| value.p_hire_field_id == field_id} rescue nil value ? value : nil end + def get_basic_fields + basic_fields = self.class::FIELDSNAME + basic_fields = basic_fields.select{|f| (self.send(f)["enable"] == "1" rescue true)} + end + def get_all_fields(get_default=false) + @default_field_names = nil if @default_field_names.nil? + if get_default + if @default_field_names.nil? + basic_fields = self.get_basic_fields + custom_fields = [] + self.p_hire_fields.each do |p_hire_field| + unless p_hire_field.disabled + custom_fields << "p_hire_fields.#{p_hire_field.id}" + end + end + @default_field_names = basic_fields + custom_fields + end + return @default_field_names + else + self.enable_fields_sort ? self.custom_field_names : self.default_field_names + end + end end \ No newline at end of file diff --git a/app/views/admin/property_hires/_form.html.erb b/app/views/admin/property_hires/_form.html.erb index 0ec200c..083d917 100644 --- a/app/views/admin/property_hires/_form.html.erb +++ b/app/views/admin/property_hires/_form.html.erb @@ -201,7 +201,7 @@ <% if @property.image.file %> <%= image_tag @property.image %> <% else %> - + <% end %>
@@ -449,7 +449,7 @@
- <% 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 = f.object.class::FIELDSNAME %>
@@ -604,12 +604,12 @@
- <% if params[:page] %> - - <% end %> + <% referer = request.referer rescue nil %> + <% referer = get_referer_url if referer.blank? || request.host != URI.parse(URI.encode(referer)).host %> + <%= hidden_field_tag("property[id]",@property.id) %> <%= f.submit t('submit'), class: 'btn btn-primary' %> - <%= link_to t('cancel'), admin_property_hires_path, :class=>"btn" %> + <%= link_to t('cancel'), referer, :class=>"btn" %>
+ + \ No newline at end of file diff --git a/app/views/admin/property_hires/index.html.erb b/app/views/admin/property_hires/index.html.erb index 84c04fe..7aac958 100644 --- a/app/views/admin/property_hires/index.html.erb +++ b/app/views/admin/property_hires/index.html.erb @@ -16,6 +16,7 @@ diff --git a/app/views/admin/property_hires/order.html.erb b/app/views/admin/property_hires/order.html.erb index e93d807..0c7a520 100644 --- a/app/views/admin/property_hires/order.html.erb +++ b/app/views/admin/property_hires/order.html.erb @@ -5,6 +5,14 @@ .icons-list-2 { cursor: all-scroll; } + .position-text-div { + cursor: text; + margin: -8px; + padding: 8px; + } + .position-text-div:hover { + background: aqua; + }
<%= t("property_hire.please_save") %>
@@ -81,10 +89,10 @@ allRows = table_element.rows; for(i = 1; i < allRows.length; i++){ var thisRow = allRows[i], - text = thisRow.cells[0].textContent.trim(), + text = thisRow.cells[1].textContent.trim(), hash = {}; hash.index = parseInt(text); - text = thisRow.cells[1].innerHTML.trim(); + text = thisRow.cells[2].innerHTML.trim(); if(text != " "){ hash.property = text; } @@ -99,8 +107,8 @@ for(i = 0;i < data.length; i++){ var thisRow = allRows[i + 1], current_value = i + 1; - thisRow.cells[0].innerHTML = "
" + current_value + "
"; - thisRow.cells[1].innerHTML = data[i].property; + thisRow.cells[1].innerHTML = "
" + current_value + "
"; + thisRow.cells[2].innerHTML = data[i].property; } $("#property_order_table div.position-text-div").on("click",makeEditable); } diff --git a/app/views/email/p_hire_email.html.erb b/app/views/email/p_hire_email.html.erb index 4adc40f..6e921f0 100644 --- a/app/views/email/p_hire_email.html.erb +++ b/app/views/email/p_hire_email.html.erb @@ -25,14 +25,40 @@ - <% extra_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"] %> - <% keys = ['hiring_person_name','hiring_person_email','start_time','end_time','recurring','recurring_interval','recurring_end_date','passed','reason_for_hire','note_for_hire'] %> - <% used_extra_fields_name = extra_fields_name.select{|field_name| (property[field_name]["enable"] == "1" rescue false) } %> - <% all_trans = keys.map{|k| t("property_hire.#{k}")} %> - <% all_trans += used_extra_fields_name.map{|k| property.custom_text(k,"name")} %> - <% keys.concat( used_extra_fields_name ) %> + <% + p_hire_fields = property.p_hire_fields.map{|rf| [rf.id.to_s,rf]}.to_h + fields_name = property.get_all_fields + basic_keys = ['hiring_person_name','hiring_person_email','start_time','end_time','recurring','recurring_interval','recurring_end_date','passed'] + fields_name = fields_name - basic_keys + keys = basic_keys + fields_name + keys = keys.select{|field_name| (property[field_name]["enable"] == "1" rescue true) } + p_hire_fields = property.p_hire_fields.map{|rf| [rf.id.to_s,rf]}.to_h + has_p_hire_fields = p_hire_fields.count != 0 + tmp_keys = [] + all_trans = keys.map do |k| + if has_p_hire_fields && k.include?("p_hire_fields") + tmp_keys << k.sub("p_hire_fields.",'') + nil + else + tmp_keys << k + property.custom_text(k,"name") + end + end + %> + <% p_hire_field_values = hire.p_hire_field_values.to_a %> <% keys.each_with_index do |k,i| %> - <% v = hire.send(k) %> + <% if has_p_hire_fields && k.include?("p_hire_fields") + p_hire_field_id = tmp_keys[i] + v = p_hire_field_values.select{|v| v.p_hire_field_id.to_s == p_hire_field_id}.first + field_info = v.get_field_value rescue {} + if field_info["title"].present? && !field_info["value"].nil? + all_trans[i] = field_info["title"] + v = field_info["value"] + end + else + v = hire.send(k) + end + %> <% if !v.nil? && !(k.include?('recurring') && hire.recurring != true)%> <% end %> <% end %> - <% hire.p_hire_field_values.each do |v| %> - <% field_info = v.get_field_value rescue {} %> - <% if field_info["title"].present? && !field_info["value"].nil? %> - - - - - <% end%> - <% end%>
@@ -54,15 +80,6 @@
<%=field_info["title"]%>: <%=field_info["value"]%>
<% end %> diff --git a/app/views/property_hires/_notes_selector.html.erb b/app/views/property_hires/_notes_selector.html.erb new file mode 100644 index 0000000..762e17b --- /dev/null +++ b/app/views/property_hires/_notes_selector.html.erb @@ -0,0 +1,21 @@ +<% 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-#{label_col} control-label" %> +
+ <% values.each_with_index do |v,i| %> + + <% end %> + <% if type == "checkbox" && (values.count > 1) %> + <%= t("property_hire.checkbox_hint") %> + <% end %> +
+
+<% end %> \ No newline at end of file diff --git a/app/views/property_hires/hire.html.erb b/app/views/property_hires/hire.html.erb index b88cead..5532888 100644 --- a/app/views/property_hires/hire.html.erb +++ b/app/views/property_hires/hire.html.erb @@ -543,86 +543,53 @@
-
- <%= f.label :hiring_person_email, "*"+t("property_hire.hiring_person_email"), :class => "col-sm-#{label_col} control-label" %> -
- <%= f.text_field :hiring_person_email, :class => "form-control", :value => (recover ? hire.hiring_person_email : ( current_user.member_profile.email rescue "")), :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %> -
-
-
- <%= f.label :hiring_person_number, "*"+t("property_hire.hiring_person_number"), :class => "col-sm-#{label_col} control-label" %> -
- <%= f.text_field :hiring_person_number, :class => "form-control", :value => (recover ? hire.hiring_person_number : ( current_user.member_profile.mobile_no rescue "")), :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %> -
-
-
- <%= f.label :hiring_person_name, "*"+t("property_hire.hiring_person_name"), :class => "col-sm-#{label_col} control-label" %> -
- <%= f.text_field :hiring_person_name, :class => "form-control", :value => (recover ? hire.hiring_person_name : ( current_user.name rescue "")), :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %> - <%= f.hidden_field :hiring_person_id, :value => (current_user.member_profile.id.to_s rescue "") %> -
-
-
- <%= f.label :reason_for_hire, "*"+t("property_hire.reason_for_hire"), :class => "col-sm-#{label_col} control-label" %> -
- <%= f.text_field :reason_for_hire, :class => "form-control", :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %> -
-
+ <% default_values = {"hiring_person_email" => ( current_user.member_profile.email rescue ""), + "hiring_person_number" => ( current_user.member_profile.mobile_no rescue ""), + "hiring_person_name" => ( current_user.name rescue "") + } %> + <% if recover + default_values = default_values.merge(Property::FIELDSNAME.map{|f| [f,hire.send(f)]}.to_h) + end %> + <%= f.hidden_field :hiring_person_id, :value => (current_user.member_profile.id.to_s rescue "") %> + <% custom_field_inputs = {} %> + <% custom_field_type = {"note_for_hire"=>"text_area"} %> <% 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-#{label_col} 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-#{label_col} control-label" %> -
- <%= f.text_area :note_for_hire, :class => "form-control" %> -
-
+ <% custom_field_inputs["note_for_hire"] = render(:partial=>"note_for_hire",:locals=>{:f=>f,:property=>property}) %> <% 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 = property.get_all_fields %> + <% has_p_hire_fields = property.p_hire_fields.count != 0 + p_hire_fields = {} + if has_p_hire_fields + p_hire_fields = property.p_hire_fields.map{|rf| [rf.id.to_s,rf]}.to_h + end + %> + <% @form_index = 0 %> <% fields_name.each do |field_name| %> - <% if(property[field_name]["enable"] == "1" rescue false) %> - <% required = (property[field_name]["required"] == "true" rescue false) %> -
- <%= f.label field_name, (required ? "*" : "") + property.custom_text(field_name,"name"), :class => "col-sm-#{label_col} control-label" %> -
- <% placeholder = property.custom_text(field_name,"placeholder") %> - <% if required %> - <%= f.text_field field_name, :class => "form-control", :placeholder => placeholder, :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %> - <% else %> - <%= f.text_field field_name, :class => "form-control", :placeholder => placeholder %> - <% end %> -
-
- <% end %> - <% end %> - <% if property.p_hire_fields.count != 0 %> - <% p_hire = PHire.new(:id=>nil) %> - <% @form_index = 0 %> - <% property.p_hire_fields.asc(:_id).each do |rf| %> + <% if has_p_hire_fields && field_name.include?("p_hire_fields") %>
- <%= rf.block_helper(property,@form_index,false,"p_hire",p_hire, rf.to_require,label_col) %> + <% rf = p_hire_fields[field_name.sub("p_hire_fields.",'')] %> + <%= rf.block_helper(property,@form_index,false,"p_hire",hire, rf.to_require,label_col) %>
<% @form_index = @form_index +1 %> + <% else %> + <% if(property[field_name]["enable"] == "1" rescue true) %> + <% required = (property[field_name]["required"] == "true" rescue false) %> + <% if custom_field_inputs[field_name] %> + <%= custom_field_inputs[field_name] %> + <% else %> +
+ <%= f.label field_name, (required ? "*" : "") + property.custom_text(field_name,"name"), :class => "col-sm-#{label_col} control-label" %> +
+ <% placeholder = property.custom_text(field_name,"placeholder") %> + <% if custom_field_type[field_name] %> + <%= f.send(custom_field_type[field_name], field_name , {:class => "form-control", :placeholder => placeholder, :value => default_values[field_name], :data => (required ? {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} : nil)}) %> + <% else %> + <%= f.text_field field_name, :class => "form-control", :placeholder => placeholder, :value => default_values[field_name], :data => (required ? {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} : nil) %> + <% end %> +
+
+ <% end %> + <% end %> <% end %> <% end %> <% if allow_no_logins_user && current_user.nil? %> @@ -637,7 +604,9 @@ <% end %>
- <%= f.hidden_field :id %> + <% if f.object.id.present? %> + <%= f.hidden_field :id %> + <% end %> <%= f.submit t("property_hire.save"), :class => "btn btn-primary" %> <%= f.hidden_field :property_id, :value => property.id %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 977d396..9d37bb4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2,7 +2,12 @@ en: lists: markups: hint_text: Hint Text + restful_actions: + fields_display_order: "Fields display order" property_hire: + sort_number: Sort Number + enable_fields_sort: Enable fields sort + fields_display_order: "Fields display order" this_property_is_available: "Hooray! This property is available." recaptcha: recaptcha: Recaptcha diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index d4956f2..5bd28b0 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -2,7 +2,12 @@ zh_tw: lists: markups: hint_text: 提示文字 + restful_actions: + fields_display_order: "欄位顯示順序" property_hire: + sort_number: 排序數 + enable_fields_sort: 啟用欄位排序 + fields_display_order: "欄位顯示順序" this_property_is_available: "可借用" recaptcha: recaptcha: 驗證碼 @@ -139,8 +144,6 @@ zh_tw: owner_phone: 管理人聯絡電話 price: Price set_unavailibility: 設定不開放時段 - start_time: 可被借用開始時間 - end_time: 可被借用結束時間 weekdays: 每週不開放預約日 start_date: 套用限制開始日期 end_date: 套用限制結束日期 diff --git a/config/routes.rb b/config/routes.rb index b1ec1b8..0bd9ad6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,6 +18,9 @@ Rails.application.routes.draw do get "edit_hire" patch "update_hire" get "custom_fields" + get "fields_display_order" + post "update_fields_display_order" + patch "update_fields_display_order" end collection do get "my_bookings"