diff --git a/app/assets/javascripts/property_hire/property-field-forms.js b/app/assets/javascripts/property_hire/property-field-forms.js
index 2efd0f0..04ba72d 100644
--- a/app/assets/javascripts/property_hire/property-field-forms.js
+++ b/app/assets/javascripts/property_hire/property-field-forms.js
@@ -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;
}
diff --git a/app/assets/javascripts/property_hire_calendar_frontend.js b/app/assets/javascripts/property_hire_calendar_frontend.js
index 78a82c8..e35f869 100644
--- a/app/assets/javascripts/property_hire_calendar_frontend.js
+++ b/app/assets/javascripts/property_hire_calendar_frontend.js
@@ -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;
}
diff --git a/app/controllers/admin/property_hires_controller.rb b/app/controllers/admin/property_hires_controller.rb
index 15f759a..cc8fb79 100644
--- a/app/controllers/admin/property_hires_controller.rb
+++ b/app/controllers/admin/property_hires_controller.rb
@@ -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])
diff --git a/app/controllers/property_hires_controller.rb b/app/controllers/property_hires_controller.rb
index 5bd762d..b4c4181 100644
--- a/app/controllers/property_hires_controller.rb
+++ b/app/controllers/property_hires_controller.rb
@@ -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?
diff --git a/app/helpers/admin/property_hires_helper.rb b/app/helpers/admin/property_hires_helper.rb
index 375589a..3542e43 100644
--- a/app/helpers/admin/property_hires_helper.rb
+++ b/app/helpers/admin/property_hires_helper.rb
@@ -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 += ("
" + 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 += ("
" + property.render_unavailable_message)
end
data = {"success" => false, "msg" => msg}
diff --git a/app/models/p_hire.rb b/app/models/p_hire.rb
index 2e52ea6..a744a48 100644
--- a/app/models/p_hire.rb
+++ b/app/models/p_hire.rb
@@ -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 || "",
diff --git a/app/models/p_hire_field.rb b/app/models/p_hire_field.rb
index 060e8fb..17c8785 100644
--- a/app/models/p_hire_field.rb
+++ b/app/models/p_hire_field.rb
@@ -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"]
diff --git a/app/models/property.rb b/app/models/property.rb
index 1117b48..a4f4935 100644
--- a/app/models/property.rb
+++ b/app/models/property.rb
@@ -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 += "
"
+ 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 += "
"
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
diff --git a/app/views/admin/property_hires/_attribute_field.html.erb b/app/views/admin/property_hires/_attribute_field.html.erb
index 663e94f..06bce30 100644
--- a/app/views/admin/property_hires/_attribute_field.html.erb
+++ b/app/views/admin/property_hires/_attribute_field.html.erb
@@ -35,6 +35,17 @@
+