From 703c5322ca4e78ddc6a5a275935000fccc305515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Sat, 24 Aug 2024 11:00:08 +0800 Subject: [PATCH] Add owner_email_rule. --- app/controllers/admin/property_hires_controller.rb | 4 ++-- app/controllers/property_hires_controller.rb | 2 +- app/helpers/admin/property_hires_helper.rb | 1 + app/models/property.rb | 13 +++++++++++++ app/views/admin/property_hires/_form.html.erb | 6 ++++++ config/locales/en.yml | 7 ++++++- config/locales/zh_tw.yml | 7 ++++++- 7 files changed, 35 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/property_hires_controller.rb b/app/controllers/admin/property_hires_controller.rb index 7e96b3d..b10232b 100644 --- a/app/controllers/admin/property_hires_controller.rb +++ b/app/controllers/admin/property_hires_controller.rb @@ -80,7 +80,7 @@ class Admin::PropertyHiresController < OrbitAdminController def destroy property = Property.find(params[:id]) rescue nil - email = MemberProfile.where(:id.in=>property.owners.to_a).collect{|v| v.email} + email = property.get_owner_emails Admin::PropertyHiresHelper::HireMethod.send_mail('delete',email,property.id,nil,nil,current_user.id) property.destroy if !property.nil? if params[:page] @@ -115,7 +115,7 @@ class Admin::PropertyHiresController < OrbitAdminController property.p_hire_fields.each{|t| t.destroy if t["to_delete"] == true} else property.update_attributes(@property_params) - email = MemberProfile.where(:id.in=>property.owners.to_a).collect{|v| v.email} + email = property.get_owner_emails Admin::PropertyHiresHelper::HireMethod.send_mail('edit',email,property.id,nil,nil,current_user.id) end redirect_to params[:referer_url] diff --git a/app/controllers/property_hires_controller.rb b/app/controllers/property_hires_controller.rb index 4664840..33cdc82 100644 --- a/app/controllers/property_hires_controller.rb +++ b/app/controllers/property_hires_controller.rb @@ -285,7 +285,7 @@ class PropertyHiresController < ApplicationController hire.passed = true if PropertyHireSetting.auto_approve_enabled? hire.save if !property.nil? && !is_admin_page - email = MemberProfile.where(:id.in=>property.owners).collect{|v| v.email} + email = property.get_owner_emails email << hire.hiring_person_email email = email.select{|e| e.present?} Admin::PropertyHiresHelper::HireMethod.send_mail('p_hire',email,property.id,nil,hire.id,(current_user.id rescue nil)) diff --git a/app/helpers/admin/property_hires_helper.rb b/app/helpers/admin/property_hires_helper.rb index b761d51..23df175 100644 --- a/app/helpers/admin/property_hires_helper.rb +++ b/app/helpers/admin/property_hires_helper.rb @@ -134,6 +134,7 @@ module Admin::PropertyHiresHelper a.html_safe end def self.send_mail(field_name,email,property_id,send_date=nil,hire_id=nil,user_id=nil) + return if email.blank? property = Property.where(id: property_id).first if !property.nil? email_set = property.hire_email_sets.select{|v| v.field_name == field_name} diff --git a/app/models/property.rb b/app/models/property.rb index 5d77347..9fd410e 100644 --- a/app/models/property.rb +++ b/app/models/property.rb @@ -23,6 +23,7 @@ class Property field :owners, type: Array, :default => [] field :other_owner field :owner_email + field :owner_email_rule, type: Integer, default: 0 # 0 => owners, 1 => owner_email, 2 => owners + owner_email field :owner_phone field :price field :other_location @@ -835,4 +836,16 @@ class Property return new_object, clone_target end end + def get_owner_emails + emails = [] + case self.owner_email_rule + when 0 + emails = MemberProfile.where(:id.in=> self.owners.to_a).pluck(:email) + when 1 + emails = [self.owner_email] + when 2 + emails = MemberProfile.where(:id.in=> self.owners.to_a).pluck(:email) + [self.owner_email] + end + emails.select{|email| email.present?} + end end diff --git a/app/views/admin/property_hires/_form.html.erb b/app/views/admin/property_hires/_form.html.erb index 8fc3e55..166f506 100644 --- a/app/views/admin/property_hires/_form.html.erb +++ b/app/views/admin/property_hires/_form.html.erb @@ -187,6 +187,12 @@ <%= f.text_field :owner_email %> +
+ <%= f.label :owner_email_rule, t("property_hire.owner_email_rule"), :class => "control-label muted" %> +
+ <%= f.select :owner_email_rule, options_for_select([0,1,2].map{|i| [t("property_hire.owner_email_rules.#{i}"), i]}, f.object.owner_email_rule) %> +
+
<%= f.label :owner_phone, t("property_hire.owner_phone"), :class => "control-label muted" %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index f7ea1e7..a62c4fa 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -132,6 +132,7 @@ en: owners: Owners other_owner: Other Owner owner_email: Owner Email + owner_email_rule: Owner Email Rule owner_phone: Owner Phone price: Price set_unavailibility: Set Unavailability @@ -181,4 +182,8 @@ en: contact_person_department: Contact person department special_unavailable_date: Special Unavailable Date manage_booking: Manage Bookings - recurring_enable: Enable Recurring \ No newline at end of file + recurring_enable: Enable Recurring + owner_email_rules: + '0': 'Only Owners' + '1': 'Only Owner Email' + '2': 'Owners and Owner Email' \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 6b81433..8d8b2d6 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -158,6 +158,7 @@ zh_tw: owners: 管理人 other_owner: 其他管理人 owner_email: 管理人Email + owner_email_rule: 管理人Email規則 owner_phone: 管理人聯絡電話 price: Price set_unavailibility: 設定不開放時段 @@ -203,4 +204,8 @@ zh_tw: contact_person_department: 聯絡人服務單位 special_unavailable_date: 特定不開放預約⽇ manage_booking: 管理我的預約 - recurring_enable: 啟用週期性預約 \ No newline at end of file + recurring_enable: 啟用週期性預約 + owner_email_rules: + '0': '僅管理人' + '1': '僅管理人Email' + '2': '管理人+管理人Email' \ No newline at end of file