沒登入也可以看到日曆,沒有開放預約時,管理者仍可以在前臺預約

This commit is contained in:
邱博亞 2023-08-26 11:16:56 +08:00
parent c3eb6f7ac8
commit 864358bd69
6 changed files with 29 additions and 21 deletions

View File

@ -30,22 +30,26 @@ class PropertyHiresController < ApplicationController
data = properties.collect do |property| data = properties.collect do |property|
actions = [] actions = []
url_to_show = "#{url}/#{property.to_param}" url_to_show = "#{url}/#{property.to_param}"
if property.can_be_hired if property.can_be_hired_frontend
hire_url = url_to_show + "?method=hire" hire_url = url_to_show + "?method=hire"
actions << { actions << {
"text" => t("property_hire.hire"), "text" => t("property_hire.hire"),
"btn-class" => "btn-primary", "btn-class" => "btn-primary",
"link" => hire_url "link" => hire_url
} }
unless property.disable_view_calendar_page end
actions << { unless property.disable_view_calendar_page
"text" => t("property_hire.view_calendar"), actions << {
"btn-class" => "btn-info", "text" => t("property_hire.view_calendar"),
"link" => url_to_show + "?method=view_calendar" "btn-class" => "btn-info",
} "link" => url_to_show + "?method=view_calendar"
end }
if property.disable_content_page end
if property.disable_content_page
if hire_url
url_to_show = hire_url url_to_show = hire_url
elsif !property.disable_view_calendar_page
url_to_show += "?method=view_calendar"
end end
end end
{ {
@ -157,19 +161,19 @@ class PropertyHiresController < ApplicationController
end end
actions = [] actions = []
url_to_show = OrbitHelper.url_to_show(property.to_param) url_to_show = OrbitHelper.url_to_show(property.to_param)
if property.can_be_hired if property.can_be_hired_frontend
actions << { actions << {
"text" => t("property_hire.hire"), "text" => t("property_hire.hire"),
"btn-class" => "btn-primary", "btn-class" => "btn-primary",
"link" => url_to_show + "?method=hire" "link" => url_to_show + "?method=hire"
} }
unless property.disable_view_calendar_page end
actions << { unless property.disable_view_calendar_page
"text" => t("property_hire.view_calendar"), actions << {
"btn-class" => "btn-info", "text" => t("property_hire.view_calendar"),
"link" => url_to_show + "?method=view_calendar" "btn-class" => "btn-info",
} "link" => url_to_show + "?method=view_calendar"
end }
end end
{ {
"data" => data, "data" => data,

View File

@ -561,4 +561,8 @@ class Property
self.enable_fields_sort ? self.custom_field_names : self.default_field_names self.enable_fields_sort ? self.custom_field_names : self.default_field_names
end end
end end
def can_be_hired_frontend
user = OrbitHelper.current_user
self.can_be_hired || (user && (user.is_admin? || property.owners.include?(user.member_profile_id)))
end
end end

View File

@ -327,7 +327,7 @@ ul.list-unstyled li {
width: 100%; width: 100%;
} }
</style> </style>
<% if !property.can_be_hired %> <% if !property.can_be_hired_frontend %>
<script type="text/javascript"> <script type="text/javascript">
alert("This property is unavailable for hire."); alert("This property is unavailable for hire.");
window.location.href = "<%= "/" + I18n.locale.to_s + url %>"; window.location.href = "<%= "/" + I18n.locale.to_s + url %>";

View File

@ -171,7 +171,7 @@
margin-left: 0; margin-left: 0;
} }
</style> </style>
<% if !property.can_be_hired %> <% if !property.can_be_hired_frontend %>
<script type="text/javascript"> <script type="text/javascript">
alert("This property is unavailable for hire."); alert("This property is unavailable for hire.");
window.location.href = "<%= "/" + I18n.locale.to_s + url %>"; window.location.href = "<%= "/" + I18n.locale.to_s + url %>";

View File

@ -10,7 +10,7 @@
url = data["page"] url = data["page"]
current_user = data["current_user"] current_user = data["current_user"]
%> %>
<% if !property.can_be_hired %> <% if !property.can_be_hired_frontend %>
<script type="text/javascript"> <script type="text/javascript">
alert("This property is unavailable for hire."); alert("This property is unavailable for hire.");
window.location.href = "<%= "/" + I18n.locale.to_s + url %>"; window.location.href = "<%= "/" + I18n.locale.to_s + url %>";

View File

@ -7,7 +7,7 @@
property = data["property"] property = data["property"]
url = data["url"] url = data["url"]
%> %>
<% if !property.can_be_hired %> <% if property.disable_view_calendar_page %>
<script type="text/javascript"> <script type="text/javascript">
alert("This property is unavailable for hire."); alert("This property is unavailable for hire.");
window.location.href = "<%= "/" + I18n.locale.to_s + url %>"; window.location.href = "<%= "/" + I18n.locale.to_s + url %>";