diff --git a/app/assets/javascripts/property_hire_calendar_frontend.js b/app/assets/javascripts/property_hire_calendar_frontend.js
index ede39cb..a7771d6 100644
--- a/app/assets/javascripts/property_hire_calendar_frontend.js
+++ b/app/assets/javascripts/property_hire_calendar_frontend.js
@@ -104,8 +104,7 @@ window.getDateString = function(date, format,is_chinese) {
}
return formattedDate;
};
-var Calendar = function(dom,property_id,currentView,display_hire_event){
-
+var Calendar = function(dom, property_id, valid_range, currentView, display_hire_event){
var c = this;
display_hire_event = (display_hire_event == undefined ? true : display_hire_event);
this.title = $("#current_title");
@@ -136,6 +135,7 @@ var Calendar = function(dom,property_id,currentView,display_hire_event){
editable: false,
selectable: true,
width: "100%",
+ validRange: valid_range,
events: function(args, success_callback, fail_callback) {
var start = args.start;
var end = args.end;
@@ -276,6 +276,10 @@ var Calendar = function(dom,property_id,currentView,display_hire_event){
if(c.currentView == "agenda"){toggleViews("agenda");loadeventsonviewchange = true;}
};
+ this.destroy = function () {
+ c.calendar_dom.fullCalendar("destroy");
+ }
+
this.renderEvent = function(eventStick){
if(eventStick.recurring === true)
c.calendar_dom.calendar.refetchEvents();
diff --git a/app/controllers/admin/property_hires_controller.rb b/app/controllers/admin/property_hires_controller.rb
index 901c9b5..7e96b3d 100644
--- a/app/controllers/admin/property_hires_controller.rb
+++ b/app/controllers/admin/property_hires_controller.rb
@@ -248,7 +248,7 @@ class Admin::PropertyHiresController < OrbitAdminController
def custom_fields
@field_name = 'property'
uid = params[:id].split("-").last
- @attribute = Property.find_by(:uid=>uid)
+ @attribute = Property.find_by(:uid=>uid)
@attribute_type = 'property'
@class = 'properties'
end
@@ -262,7 +262,7 @@ class Admin::PropertyHiresController < OrbitAdminController
params.require(:property_location).permit!
end
def phire_params
- p_hire_params = params.require(:p_hire).permit!
+ p_hire_params = params.require(:p_hire).permit!
property = (@phire ? @phire.property : Property.find(params[:p_hire][:property_id]) rescue nil)
if(property.enable_notes_selector rescue false)
note_texts = ""
@@ -274,7 +274,7 @@ class Admin::PropertyHiresController < OrbitAdminController
value_text = p_hire_params["notes_selector"][index.to_s].to_a.map{|i| values[i.to_i]}.join(",") rescue ""
value_text = I18n.t("property_hire.none") if value_text.blank?
note_texts += (name + ":"+value_text)
- note_texts += "
".html_safe
+ note_texts += "
".html_safe
end
p_hire_params["note_for_hire"] = note_texts
p_hire_params.delete("notes_selector")
@@ -319,4 +319,4 @@ class Admin::PropertyHiresController < OrbitAdminController
@email_set << email_set
end
end
-end
\ No newline at end of file
+end
diff --git a/app/controllers/property_hires_controller.rb b/app/controllers/property_hires_controller.rb
index 7c31282..4664840 100644
--- a/app/controllers/property_hires_controller.rb
+++ b/app/controllers/property_hires_controller.rb
@@ -22,39 +22,44 @@ class PropertyHiresController < ApplicationController
{
"properties" => data,
"headers" => headers,
+ "extras" => {
+ "first_property_id" => data.first["id"]
+ },
+ "manage_booking_btn" => (OrbitHelper.current_user.nil? ? false : true),
+ "manage_booking" => t("property_hire.manage_booking"),
+ "manage_booking_url" => "/" + OrbitHelper.get_site_locale.to_s + "/admin/property_hires/my_bookings",
"total_pages" => (properties.total_pages rescue 1)
}
end
def index_data(properties, url)
data = properties.collect do |property|
- actions = []
- url_to_show = "#{url}/#{property.to_param}"
+ actions = []
+ url_to_show = "#{url}/#{property.to_param}?method=hire"
hire_url = nil
- if property.can_be_hired_frontend
- hire_url = url_to_show + "?method=hire"
+ if property.can_be_hired_frontend && property.can_reserve
+ hire_url = url_to_show
actions << {
"text" => t("property_hire.hire"),
"btn-class" => "btn-primary",
"link" => hire_url
}
end
- if !property.disable_view_calendar_page && property.can_be_show_frontend
+ if !property.disable_view_calendar_page && property.can_be_show_frontend && property.can_reserve
actions << {
"text" => t("property_hire.view_calendar"),
"btn-class" => "btn-info",
- "link" => url_to_show + "?method=view_calendar"
+ "link" => url_to_show
}
end
if property.disable_content_page
if hire_url
url_to_show = hire_url
- elsif !property.disable_view_calendar_page && property.can_be_show_frontend
- url_to_show += "?method=view_calendar"
end
end
{
"title" => property.title,
+ "id" => property.id.to_s,
"image" => (property.image.url.blank? ? '" style="display: none;' : property.image.url),
"image-thumb" => (property.image.thumb.url.blank? ? '" style="display: none;' : property.image.thumb.url),
"url_to_show" => url_to_show,
@@ -65,7 +70,7 @@ class PropertyHiresController < ApplicationController
end
def widget
- properties = Property.filter_by_widget_categories.sort_order
+ properties = Property.filter_by_widget_categories.sort_order.can_display
url = OrbitHelper.get_current_widget.get_read_more_page_url
data = index_data(properties, url)
headers = [
@@ -114,7 +119,7 @@ class PropertyHiresController < ApplicationController
"header" => t("property_hire.property_number"),
"value" => property.property_number
}
- end
+ end
data << {
"header" => t("property_hire.can_be_hired"),
"value" => (property.can_be_hired ? "Yes" : "No")
@@ -159,7 +164,7 @@ class PropertyHiresController < ApplicationController
"header" => t("property_hire.location"),
"value" => property.get_location_name
}
- end
+ end
actions = []
url_to_show = OrbitHelper.url_to_show(property.to_param)
if property.can_be_hired_frontend
@@ -185,7 +190,7 @@ class PropertyHiresController < ApplicationController
"back_url" => page.url
}
}
-
+
end
def view_calendar
@@ -357,8 +362,11 @@ class PropertyHiresController < ApplicationController
events = events.map{|e| e.as_json}
allevents = events.inject(re, :<<)
allevents = allevents.sort_by{|e| e[:start]}
+ Rails.logger.info allevents
@need_check_events = allevents.map{|e| [e[:date],e[:s_id]]}
- if property.set_availability && params[:display_hire_event]
+ @special_unavailable_dates = property.special_unavailable_dates.map{|dt| Date.parse(dt)}
+
+ if property.set_availability && params[:display_hire_event] == "true"
check_setting = property.set_unavailibility && (property.property_day_settings.where(:enable=>false).count != 0)
@check_start_time = property.start_time.blank? ? "00:00" : property.start_time
@check_end_time = property.end_time.blank? ? "24:00" : property.end_time
@@ -379,9 +387,15 @@ class PropertyHiresController < ApplicationController
get_end_time = [time_now + (property.can_hire_before_months).send("month"),edt].min
end
end
- allevents += generate_all_reserve_buttons(get_start_time,get_end_time,all_day_settings,check_setting)
+ if property.can_reserve
+ allevents += generate_all_reserve_buttons(get_start_time,get_end_time,all_day_settings,check_setting)
+ end
+
end
end
+ if @special_unavailable_dates.count > 0
+ allevents += special_unavailable_dates_labels(property)
+ end
end
end
respond_to do |format|
@@ -389,8 +403,20 @@ class PropertyHiresController < ApplicationController
format.json { render json: allevents.to_json }
end
end
+
+ def special_unavailable_dates_labels(property)
+ events = []
+ @special_unavailable_dates.each_with_index do |dt, idx|
+ events << {:title=>property.special_unavailable_dates_title[idx][OrbitHelper.get_site_locale], :start=>dt.to_s, :end => (dt + 1.day).to_s, :allDay => true, :color => "#d33535", :classNames=>["special_unavailable_btn"], :note => ""}
+ end
+ events
+ end
+
def reserve_calendar_event(date,title,allow_times)
available = true
+ if @special_unavailable_dates.include?(date)
+ available = false
+ end
if @check_setting && allow_times.select{|a| !a[5]}.count != 0
available = (date > @check_end_date rescue false) || (date < @check_start_date rescue false)
unless available
@@ -420,7 +446,7 @@ class PropertyHiresController < ApplicationController
endt = endt.in_time_zone(Time.zone)
start_wday = startt.wday
start_date = startt.to_date
- @start_date = start_date
+ @start_date = start_date
end_date = endt.to_date
@end_date = end_date
@first_check_time = startt.strftime("%H:%M")
@@ -481,7 +507,7 @@ class PropertyHiresController < ApplicationController
end
else
@all_day_settings.each do |wday_str,settings|
- tmp_date = @start_date + wday_str.to_i.send("day")
+ tmp_date = @start_date + wday_str.to_i.send("day")
i = @need_check_events.index{|e| e[0] > tmp_date}
if i.nil?
if @need_check_events.length != 0 && @need_check_events[-1][0] <= tmp_date
@@ -535,7 +561,7 @@ class PropertyHiresController < ApplicationController
private
def booking_params
- p_hire_params = params.require(:p_hire).permit!
+ p_hire_params = params.require(:p_hire).permit!
property = Property.find(params[:p_hire][:property_id]) rescue Property.last
if(property.enable_notes_selector rescue false)
note_texts = ""
@@ -547,7 +573,7 @@ class PropertyHiresController < ApplicationController
value_text = p_hire_params["notes_selector"][index.to_s].to_a.map{|i| values[i.to_i]}.join(",") rescue ""
value_text = I18n.t("property_hire.none") if value_text.blank?
note_texts += (name + ":"+value_text)
- note_texts += "
".html_safe
+ note_texts += "
".html_safe
end
p_hire_params["note_for_hire"] = note_texts
p_hire_params.delete("notes_selector")
@@ -556,8 +582,3 @@ class PropertyHiresController < ApplicationController
end
end
-
-
-
-
-
diff --git a/app/models/p_hire.rb b/app/models/p_hire.rb
index e5f2130..f82ee6b 100644
--- a/app/models/p_hire.rb
+++ b/app/models/p_hire.rb
@@ -53,9 +53,11 @@ class PHire
if options[:recurring]
recurring = options[:recurring]
end
+ title = startt.strftime("%H:%M") + " ~ " + endt.strftime("%H:%M") + " " + self.hiring_person_name
{
:id => self.id.to_s,
- :title => (self.reason_for_hire.to_s + " "+ self.tmp_reason_for_hire.to_s).html_safe,
+ # :title => (self.reason_for_hire.to_s + " "+ self.tmp_reason_for_hire.to_s).html_safe,
+ :title => title,
:hiring_person_id => self.hiring_person_id,
:hiring_person_name => self.hiring_person_name,
:note => self.note_for_hire || "",
@@ -189,4 +191,4 @@ class PHire
end while (start_time += step_interval) <= recurring_end_date
end
-end
\ No newline at end of file
+end
diff --git a/app/models/property.rb b/app/models/property.rb
index c397c11..5d77347 100644
--- a/app/models/property.rb
+++ b/app/models/property.rb
@@ -26,8 +26,13 @@ class Property
field :owner_phone
field :price
field :other_location
-
- mount_uploader :image, ImageUploader
+ field :p_hire_start_time, type: DateTime
+ field :p_hire_end_time, type: DateTime
+ field :p_open_start_time, type: DateTime
+ field :p_open_end_time, type: DateTime
+ field :recurring_enable, type: Boolean, :default => false
+
+ mount_uploader :image, ImageUploader
# unavailibility fields
field :can_hire_before_months, type: Integer, default: 0
@@ -36,6 +41,8 @@ class Property
field :start_time
field :end_time
field :weekdays, type: Array, default: []
+ field :special_unavailable_dates, type: Array, default: []
+ field :special_unavailable_dates_title, type: Array, default: []
field :start_date, type: DateTime
field :end_date, type: DateTime
field :description, :localize => true
@@ -77,7 +84,8 @@ class Property
accepts_nested_attributes_for :property_files, :allow_destroy => true
has_many :property_links, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :property_links, :allow_destroy => true
- scope :sort_order, ->{order_by([:order_position,:asc],[:created_at,:desc])}
+ scope :sort_order, ->{order_by([:created_at,:desc],[:order_position,:asc])}
+ scope :can_display, ->{any_of({:p_hire_start_time.lt=>Time.now, :p_hire_end_time.gt=>Time.now},{:p_hire_start_time.lt=>Time.now, :p_hire_end_time=>nil},{:p_hire_start_time=>nil, :p_hire_end_time=>nil})}
WEEKDAYS = [
"Sunday",
"Monday",
@@ -133,6 +141,13 @@ class Property
after_save do
self.change_day_setting_status
end
+
+ def can_reserve
+ start_time = self.p_hire_start_time || Time.now
+ end_time = self.p_hire_end_time || Time.now
+ return Time.now >= start_time && end_time >= Time.now
+ end
+
def p_hire_fields_enabled
self.p_hire_fields.where(disabled: false)
end
@@ -255,6 +270,9 @@ class Property
message += hint1
end
end
+ if property.special_unavailable_dates.count > 1
+ message += " And on " + property.special_unavailable_dates.join(", ")
+ end
if property.need_hire_before != 0
if message != ""
message += "
"
@@ -291,6 +309,13 @@ class Property
if self.need_hire_before != 0
return 3 if (time_now + (self.need_hire_before).send(self.need_hire_before_unit) > stime)
end
+ self.special_unavailable_dates.each do |dt|
+ unavailable_date = Date.parse(dt)
+ cd = (stime..etime) & (unavailable_date..unavailable_date)
+ if !cd.nil?
+ return 0
+ end
+ end
startt = self.start_date.nil? ? stime : self.start_date
endt = self.end_date.nil? ? etime : self.end_date
available = 1 if (startt > stime && endt > etime)
@@ -475,7 +500,7 @@ class Property
else
b_datas = []
end
- end
+ end
break if available == false
end
end
@@ -665,7 +690,7 @@ class Property
tmp_relations_fields << k
else
org_k = k.to_s
- result = other_has_many_class.map do |k|
+ result = other_has_many_class.map do |k|
belongs_to_class = k.classify.constantize.relations.select{|kk,v| v.macro == :belongs_to}.keys
has_many_class = k.classify.constantize.relations.select{|kk,v| v.macro.to_s.start_with?('has') }.keys
if (belongs_to_class - tmp_singularize_relations_fields - [org_k]).count == 0
@@ -810,4 +835,4 @@ class Property
return new_object, clone_target
end
end
-end
\ No newline at end of file
+end
diff --git a/app/views/admin/property_hires/_form.html.erb b/app/views/admin/property_hires/_form.html.erb
index 2ccea8d..8fc3e55 100644
--- a/app/views/admin/property_hires/_form.html.erb
+++ b/app/views/admin/property_hires/_form.html.erb
@@ -132,9 +132,35 @@