Add hire success page.

Add display custom fields in calendar event title.
Add need hire before setting.
This commit is contained in:
BoHung Chiu 2021-10-22 22:09:10 +08:00
parent 958bade200
commit 3691a14c64
15 changed files with 162 additions and 67 deletions

View File

@ -112,6 +112,7 @@ function setData(l, type, ol) {
_title_translations: ["title_translations_" +l, fields+"["+l+"][title_translations]"],
_to_delete: ["to_delete_" +l, fields+"["+l+"][to_delete]"],
_to_require: ["to_require_" +l, fields+"["+l+"][to_require]"],
_display_in_reason_for_hire: ["display_in_reason_for_hire_" +l, fields+"["+l+"][display_in_reason_for_hire]"],
};
return data;
}

View File

@ -681,7 +681,7 @@ var AgendaView = function(calendar){
dateFormat = getDateString(s,short_date,is_chinese) + ' - ' + getDateString(e,short_date,is_chinese);
e_t.find("td:first").text(dateFormat);
e_t.find("td.event_time").text((event.allDay ? "All Day" : (getDateString(s, "h:m b")+"~"+getDateString(e, "h:m b"))));
e_t.find("div.event").text(event.title).css("color",event.color);
e_t.find("div.event").html(event.title).css("color",event.color);
e_t.find("td.Borrower").text(hiring_person_name);
return e_t;
}

View File

@ -93,6 +93,16 @@ class Admin::PropertyHiresController < OrbitAdminController
@attribute_field = PHireField.add_p_hire_field(property, a.last, a.last[:id], field_status)
@attribute = property
end
if property.need_change_tmp_reason
Thread.new do
p_hire_field_ids = property.p_hire_fields.where(:display_in_reason_for_hire=>true).pluck(:id)
property.p_hires.each do |p_hire|
p_hire.tmp_reason_for_hire = p_hire.p_hire_field_values.where(:p_hire_field_id.in=>p_hire_field_ids).map{|v| v.get_value_by_locale(I18n.locale.to_s)}.join(" ")
p_hire.save
end
property.update(:need_change_tmp_reason => false)
end
end
flash.now[:notice] = "Updated Fields"
property.p_hire_fields.each{|t| t.destroy if t["to_delete"] == true}
else
@ -149,6 +159,8 @@ class Admin::PropertyHiresController < OrbitAdminController
phire.passed = false
end
phire.save
email = [hire.hiring_person_email].select{|e| e.present?}
Admin::PropertyHiresHelper::HireMethod.send_mail('p_hire',email,phire.property.id,nil,hire.id,(current_user.id rescue nil))
if params[:ref] == "index"
if params[:page]
redirect_to admin_property_hire_path(phire.property, :page => params[:page])

View File

@ -163,7 +163,13 @@ class PropertyHiresController < ApplicationController
"current_user" => OrbitHelper.current_user
}
end
def hire_success
params = OrbitHelper.params
@property = Property.where(:uid => params[:uid]).first rescue nil
page = OrbitHelper.page rescue Page.where(:page_id => params[:page_id]).first
back_url = (page.url + (params[:slug].present? ? "/#{params[:slug]}" : "") rescue "#")
{"back_url"=>back_url}
end
def make_booking
booking_p = booking_params
time_setting_id = booking_p[:time]
@ -224,7 +230,7 @@ class PropertyHiresController < ApplicationController
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
redirect_to index_page + "?method=hire_success"
else
session["hire-save-msg"] = data["msg"]
if property.nil?

View File

@ -41,7 +41,7 @@ module Admin::PropertyHiresHelper
end
end
available_flag = property.is_available_for_hire?(stime, etime, interval, recurring_end_date, time_setting_id)
if available_flag
if available_flag == 1
if property.not_yet_hired?(stime, etime, interval, recurring_end_date,params[:phire_id], time_setting_id)
data = {"success" => true}
else
@ -52,14 +52,16 @@ module Admin::PropertyHiresHelper
else
I18n.with_locale(params[:locale]) do
msg = I18n.t("property_hire.property_is_unavailable_during_this_time")
if available_flag.nil?
if available_flag == 2 ## need hire after
if recurring_end_date.present?
stime = [stime,recurring_end_date].max
end
can_hire_date = stime - (property.can_hire_before_months).month
puts "can_hire_date #{can_hire_date}"
msg += ("<br>" + I18n.t("property_hire.please_hire_after_date",{:date=>"{#{can_hire_date.utc.to_json.gsub('"','')}}"}))
else
elsif available_flag == 3 ## need hire before
default_msg = "This property must be reserved #{property.need_hire_before} #{property.need_hire_before_unit}s in advance."
msg += I18n.t("property_hire.unavailable_hint3",{:month=>property.need_hire_before,:unit=>I18n.t("property_hire._#{property.need_hire_before_unit}",:default=>property.need_hire_before_unit),:default=>default_msg})
elsif available_flag == 0
msg += ("<br>" + property.render_unavailable_message)
end
data = {"success" => false, "msg" => msg}

View File

@ -11,6 +11,7 @@ class PHire
field :hiring_person_id
field :hiring_person_name
field :reason_for_hire
field :tmp_reason_for_hire, type: String, default: "" # store reason text from custom fields
field :note_for_hire
field :property_day_setting_id
field :passed, type: Boolean, default: false
@ -51,7 +52,7 @@ class PHire
end
{
:id => self.id.to_s,
:title => self.reason_for_hire,
:title => (self.reason_for_hire.to_s + " "+ self.tmp_reason_for_hire.to_s).html_safe,
:hiring_person_id => self.hiring_person_id,
:hiring_person_name => self.hiring_person_name,
:note => self.note_for_hire || "",

View File

@ -4,7 +4,7 @@ class PHireField
include Mongoid::Attributes::Dynamic
include ::AttributeFieldsHelper
include ::Admin::PHireFieldHelper
field :display_in_reason_for_hire, type: Boolean, default: false
field :key, type: String
field :af_count
field :title, type: String, localize: true
@ -44,6 +44,9 @@ class PHireField
end
end
end
if self.display_in_reason_for_hire_changed? && self.property
self.property.update(:need_change_tmp_reason=>true)
end
end
def markup_value
get_data["option_list"]

View File

@ -6,6 +6,9 @@ class Property
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 :need_change_tmp_reason, type: Boolean, default: false
field :need_hire_before, type: Integer, default: 0 #0代表沒有限制
field :need_hire_before_unit, type: String, default: "day" #month, day, hour, minute
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
@ -235,11 +238,18 @@ class Property
message += hint1
end
end
if property.need_hire_before != 0
if message != ""
message += "<br>"
end
default_msg = "This property must be reserved #{property.need_hire_before} #{property.need_hire_before_unit}s in advance."
message += I18n.t("property_hire.unavailable_hint3",{:month=>property.need_hire_before,:unit=>I18n.t("property_hire._#{property.need_hire_before_unit}",:default=>property.need_hire_before_unit),:default=>default_msg})
end
if property.can_hire_before_months != 0
if message != ""
message += "<br>"
end
default_msg = "This property is unavaliable to hire before #{property.can_hire_before_months} month ago."
default_msg = "This property is unavaliable to reserved before #{property.can_hire_before_months} month ago."
message += I18n.t("property_hire.unavailable_hint2",{:month=>property.can_hire_before_months,:default=>default_msg})
end
end
@ -254,30 +264,35 @@ class Property
end
def is_available_for_hire?(stime, etime, interval = nil, recurring_end_date = nil, time_setting_id = nil)
available = false
return true if self.set_unavailibility == false
return true if self.weekdays.empty? && self.can_hire_before_months == 0
available = 0
return 1 if self.set_unavailibility == false
return 1 if self.weekdays.empty? && self.can_hire_before_months == 0
time_now = Time.now.to_datetime
if self.can_hire_before_months != 0
return nil if (((stime - Time.now.to_datetime) * 1.day) > (self.can_hire_before_months).month)
available = true
return 2 if ((stime - (self.can_hire_before_months).month) > time_now)
available = 1
end
if self.need_hire_before != 0
return 3 if (time_now + (self.need_hire_before).send(self.need_hire_before_unit) > stime)
available = 1
end
startt = self.start_date.nil? ? stime : self.start_date
endt = self.end_date.nil? ? etime : self.end_date
available = true if (startt > stime && endt > etime)
available = true if (endt < stime)
available = 1 if (startt > stime && endt > etime)
available = 1 if (endt < stime)
weekdays = self.weekdays.collect{|w| w.to_i}
if !startt.nil?
if !available
if available == 0
common_dates = (startt..endt) & (stime..etime)
available = true if common_dates.nil?
if !available
available = 1 if common_dates.nil?
if available == 0
time_weekdays = []
Property.time_iterate(common_dates.min, common_dates.max, 1.day) do |t|
time_weekdays << t.wday
end
time_weekdays.uniq!
weekdays = weekdays & time_weekdays
available = true if weekdays.blank?
available = 1 if weekdays.blank?
startt = DateTime.parse(stime.strftime("%Y-%m-%d " + (self.start_time.blank? ? "00:00" : self.start_time) + Time.zone.to_s))
endt = DateTime.parse(etime.strftime("%Y-%m-%d " + (self.end_time.blank? ? "23:59" : self.end_time) + Time.zone.to_s))
common_dates = (startt..endt) & (stime..etime)
@ -300,10 +315,10 @@ class Property
new_etime = date_time
new_stime = stime + (new_etime - etime)
available = self.is_available_for_hire?(new_stime, new_etime, nil, nil)
break if !available
break if available != 1
end
else
available = false
available = 0
end
end
end

View File

@ -35,6 +35,17 @@
</label>
</div>
</div>
<div class="control-group">
<label class="control-label muted" for=""><%= t('property_hire.display_in_reason_for_hire') %></label>
<div class="controls">
<label class="radio inline">
<%= radio_button("#{@field_name}[p_hire_fields][#{@af_counter}]", "display_in_reason_for_hire", "true",:checked => (attribute_field.display_in_reason_for_hire == true ? true : false), :data=>{:type=>"search_true"}) %><%= t(:yes_)%>
</label>
<label class="radio inline">
<%= radio_button("#{@field_name}[p_hire_fields][#{@af_counter}]", "display_in_reason_for_hire", "false",:checked => (attribute_field.display_in_reason_for_hire == false ? true : false), :data=>{:type=>"search_false"}) %><%= t(:no_)%>
</label>
</div>
</div>
<div class="control-group">
<label class="control-label muted" for=""><%= t(:type)%></label>
<div class="controls">

View File

@ -348,6 +348,14 @@
<%= f.select :can_hire_before_months, options_for_select([[t("property_hire.no_limit"),0]] + (1..12).to_a.map{|month| [t("property_hire.month", month: month), month]},f.object.can_hire_before_months) %>
</div>
</div>
<div class="control-group">
<%= f.label :need_hire_before, t("property_hire.need_hire_before"), :class => "control-label muted" %>
<div class="controls">
<% units = ['month', 'day', 'hour', 'minute'] %>
<%= f.number_field :need_hire_before, :min=>0 %>
<%= f.select :need_hire_before_unit, options_for_select(units.map{|unit| [t("property_hire._#{unit}"), unit]},f.object.need_hire_before_unit) %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%=t("property_hire.weekdays").html_safe%></label>
<div class="controls">

View File

@ -48,6 +48,17 @@
</label>
</div>
</div>
<div class="control-group">
<label class="control-label muted" for=""><%= t('property_hire.display_in_reason_for_hire') %></label>
<div class="controls">
<label class="radio inline">
<input type="radio" data-type="search_true" id="${_display_in_reason_for_hire[0]+'_true'}" name="${_display_in_reason_for_hire[1]}" value="true"> <%= t(:yes_)%>
</label>
<label class="radio inline">
<input type="radio" data-type="search_false" id="${_display_in_reason_for_hire[0]+'_false'}" name="${_display_in_reason_for_hire[1]}" value="false" checked=""> <%= t(:no_)%>
</label>
</div>
</div>
<div class="control-group">
<label class="control-label muted" for=""><%= t(:type)%></label>
<div class="controls">

View File

@ -425,7 +425,7 @@
scrollTo(target_offset.left - window_width / 2, target_offset.top - window_height / 2);
}else{
if(window.check_message !== ""){
alert(window.check_message.replace(/<br>/g,"\n"));
alert(window.check_message.replace(/(<|&lt;)br(>|&gt;)/g,"\n"));
}else{
alert('<%=t("property_hire.unavailability")%>');
}

View File

@ -0,0 +1,8 @@
<%
data = action_data
back_url = data["back_url"]
%>
<h4><%=t("property_hire.the_reservation_was_successfully_sent")%></h4>
<div>
<a href="<%=back_url%>" class="btn btn-warning"><%=t("property_hire.go_to_infos_page")%></a>
</div>

View File

@ -5,6 +5,14 @@ en:
restful_actions:
fields_display_order: "Fields display order"
property_hire:
the_reservation_was_successfully_sent: "The reservation was successfully sent!Please see email to get more information"
go_to_infos_page: Go to infos page
display_in_reason_for_hire: "Display in reason for hire"
need_hire_before: "How late does the user need to hire?"
_month: Month
_day: Day
_hour: Hour
_minute: Minute
sort_number: Sort Number
enable_fields_sort: Enable fields sort
fields_display_order: "Fields display order"
@ -19,9 +27,9 @@ en:
display: Display
not_display: Not display
page_setting: Page Setting
display_calendar_default: "Display calendar in hire page?(default)"
display_calendar: "Display calendar in hire page?"
allow_no_logins_user: "Allow no logins user to hire property."
display_calendar_default: "Display calendar in reserved page?(default)"
display_calendar: "Display calendar in reservation page?"
allow_no_logins_user: "Allow no logins user to reserve property."
please_select_time: "Please select Time!"
date: "Date"
time: "Time"
@ -55,9 +63,9 @@ en:
order: Order
custom_fields_setting: Custom fields Setting
custom_fields: Custom fields
please_hire_after_date: "Please hire after %{date}!"
please_hire_after_date: "Please reserve after %{date}!"
property_is_unavailable_during_this_time: "Property is unavailable during this time."
property_is_already_hired_during_this_time: "Property is already hired during this time."
property_is_already_hired_during_this_time: "Property is already reserved during this time."
starting_time_cannot_be_greater_than_ending_time: "Starting time cannot be greater than ending time."
please_select_recurring_interval: "Please select recurring interval!"
confirm: Confirm
@ -77,10 +85,10 @@ en:
notes_selector: Note field selector
enable_notes_selector: Enable Note field selector
editor: Editor
email_p_hire_success: Hire Success
email_p_hire_success: Reserve Success
email_edit_success: 'Property Hire Module:Edit Success'
email_delete_success: 'Property Hire Module:Delete Success'
email_p_hire_content: Hire Success
email_p_hire_content: Reserve Success
email_edit_content: 'Property Hire Module:Edit Success'
email_delete_content: 'Property Hire Module:Delete Success'
edit: Edit
@ -111,7 +119,7 @@ en:
property_usage: Subtitle
note: Note
property_number: Property Number
can_be_hired: Available for hire
can_be_hired: Available for reservation
purchase_date: Purchase Date
owners: Owners
other_owner: Other Owner
@ -129,13 +137,13 @@ en:
description: Unavailability Description
unavailibility_note: Unavailability Note
property_location: Property Location
available_for_hire: Available for hire
hire: Hire
available_for_hire: Available for reservation
hire: Reserve
view_calendar: Calendar
image: Property Image
actions: Actions
start_time: Hire Start Time
end_time: Hire End Time
start_time: Reserve Start Time
end_time: Reserve End Time
hiring_person_email: Hiring Person Email
hiring_person_number: Hiring Person Number
hiring_person_name: Hiring Person

View File

@ -5,10 +5,18 @@ zh_tw:
restful_actions:
fields_display_order: "欄位顯示順序"
property_hire:
the_reservation_was_successfully_sent: "預約成功送出請查看Email確認預約資訊!"
go_to_infos_page: 前往資訊頁面
display_in_reason_for_hire: "顯示於使用用途"
need_hire_before: "需提早多久借用"
_month: 個月
_day:
_hour: 個小時
_minute: 分鐘
sort_number: 排序數
enable_fields_sort: 啟用欄位排序
fields_display_order: "欄位顯示順序"
this_property_is_available: "<b>可借用</b>"
this_property_is_available: "<b>可預約</b>"
recaptcha:
recaptcha: 驗證碼
errors:
@ -21,7 +29,7 @@ zh_tw:
page_setting: 頁面設定
display_calendar_default: "是否顯示行事曆在租借頁面(預設值)"
display_calendar: "是否顯示行事曆在租借頁面"
allow_no_logins_user: "允許未登入使用者借用"
allow_no_logins_user: "允許未登入使用者預約"
please_select_time: "請選擇時段!"
date: "日期"
time: "時段"
@ -30,7 +38,7 @@ zh_tw:
reserve: 預約本日
files_links: "檔案與連結"
disable_content_page: 關閉內容頁
disable_view_calendar_page: '關閉"查詢目前借用狀況"頁面'
disable_view_calendar_page: '關閉"查詢目前預約狀況"頁面'
display_img: 內容頁顯示封面圖片
carousel_image: 輪播圖片
carousel_image_title: 輪播圖片(在show頁面底部顯示)
@ -55,10 +63,10 @@ zh_tw:
order: 排序
custom_fields_setting: 客製化欄位設定
custom_fields: 客製預約欄位
recurring_end_date_must_exceed_time: "週期結束時間需超過借用結束時間%{time}!"
recurring_end_date_must_exceed_time: "週期結束時間需超過預約結束時間%{time}!"
1_week: "一週"
1_month: "一個月"
values_are_not_ok: "借用開始時間和結束時間不可為空"
values_are_not_ok: "預約開始時間和結束時間不可為空"
dot: " 、 "
from: " 從 "
to: " 到 "
@ -68,8 +76,9 @@ zh_tw:
from_now_on: "從現在起"
every: 每個
time1_to_time2: "%{time1}到%{time2}之間"
unavailable_hint1: "此地點或設備%{str1}%{str2}%{week_str}%{str3}為不可借用。"
unavailable_hint2: "此地點或設備在%{month}個月之前不可借用。"
unavailable_hint1: "此地點或設備%{str1}%{str2}%{week_str}%{str3}為不可預約。"
unavailable_hint2: "此地點或設備在%{month}個月之前不可預約。"
unavailable_hint3: "此地點或設備須提前%{month}%{unit}預約。"
Sunday: 週日
Monday: 週一
Tuesday: 週二
@ -77,12 +86,12 @@ zh_tw:
Thursday: 週四
Friday: 週五
Saturday: 週六
please_hire_after_date: "請在%{date}之後再借用!"
property_is_unavailable_during_this_time: "該時段不可借用。"
property_is_already_hired_during_this_time: "該時段已被借用,請再選擇其他時段!"
starting_time_cannot_be_greater_than_ending_time: "借用開始時間不能超過借用結束時間!"
please_select_recurring_interval: "請選擇借用週期!"
please_select_recurring_interval_and_recurring_end_time: "請選擇借用週期和週期結束時間"
please_hire_after_date: "請在%{date}之後再預約!"
property_is_unavailable_during_this_time: "該時段不可預約。"
property_is_already_hired_during_this_time: "該時段已被預約,請再選擇其他時段!"
starting_time_cannot_be_greater_than_ending_time: "預約開始時間不能超過預約結束時間!"
please_select_recurring_interval: "請選擇預約週期!"
please_select_recurring_interval_and_recurring_end_time: "請選擇預約週期和週期結束時間"
confirm: 確認
cancel: 取消
pick_from_calendar: 從日曆上選擇
@ -100,10 +109,10 @@ zh_tw:
notes_selector: 備註選項
enable_notes_selector: 啟用備註選項
editor: 編輯者
email_p_hire_success: 借用成功
email_p_hire_success: 預約成功
email_edit_success: '租借模組:編輯成功'
email_delete_success: '租借模組:刪除成功'
email_p_hire_content: 借用成功
email_p_hire_content: 預約成功
email_edit_content: '租借模組:編輯成功'
email_delete_content: '租借模組:刪除成功'
edit: 編輯
@ -111,8 +120,8 @@ zh_tw:
auto_send_email_set: 自動發信設定
email_title: 主旨
email_content: 內文
recurring: 週期性借用
recurring_interval: 借用週期
recurring: 週期性預約
recurring_interval: 預約週期
recurring_interval_types:
month:
week:
@ -127,16 +136,16 @@ zh_tw:
property_count: Property Count
edit_location: Edit Location
add_location: Add Location
unavailability: 不可借用
unavailability: 不可預約
unavailable_time: 不開放時段
available_time: 開放時段
title: 名稱
select_interval: 選則週期
check_availibility: 檢查是否可借用
check_availibility: 檢查是否可預約
property_usage: 副標題
note: 說明
property_number: 編號
can_be_hired: 可供借用
can_be_hired: 可供預約
purchase_date: Purchase Date
owners: 管理人
other_owner: 其他管理人
@ -150,28 +159,28 @@ zh_tw:
description: Unavailability Description
unavailibility_note: Unavailability Note
property_location: Property Location
available_for_hire: 可供借用
hire: 線上借用
view_calendar: 查詢目前借用狀況
available_for_hire: 可供預約
hire: 線上預約
view_calendar: 查詢目前預約狀況
image: Property Image
actions: 操作
limit_start_time: 限制開始時間
limit_end_time: 限制結束時間
start_time: 借用開始時間
end_time: 借用結束時間
hiring_person_email: 借用人電子信箱
hiring_person_number: 借用人聯絡電話
hiring_person_name: 借用人姓名
start_time: 預約開始時間
end_time: 預約結束時間
hiring_person_email: 預約人電子信箱
hiring_person_number: 預約人聯絡電話
hiring_person_name: 預約人姓名
reason_for_hire: 使用用途
note_for_hire: 備註
period: Period
passed: 借用允許
passed: 允許預約
'yes':
'no':
wait_for_permit: 等待授權
Unavailibility_Schedule: 不提供借用時間
Unavailibility_Schedule: 不提供預約時段
required: 必填
organization: 借用單位
organization: 預約單位
person_in_charge: 單位負責人
tel_of_person_in_charge: 負責人聯絡電話
department: 服務單位