changes made to property hire

This commit is contained in:
rulingcom 2024-09-04 21:03:02 +08:00
parent aa19dd1416
commit 420ce3b065
7 changed files with 181 additions and 41 deletions

View File

@ -114,6 +114,9 @@ class Admin::PropertyHiresController < OrbitAdminController
flash.now[:notice] = "Updated Fields" flash.now[:notice] = "Updated Fields"
property.p_hire_fields.each{|t| t.destroy if t["to_delete"] == true} property.p_hire_fields.each{|t| t.destroy if t["to_delete"] == true}
else else
if @property_params["special_unavailable_dates"].nil?
@property_params["special_unavailable_dates"] = []
end
property.update_attributes(@property_params) property.update_attributes(@property_params)
email = property.get_owner_emails email = property.get_owner_emails
Admin::PropertyHiresHelper::HireMethod.send_mail('edit',email,property.id,nil,nil,current_user.id) Admin::PropertyHiresHelper::HireMethod.send_mail('edit',email,property.id,nil,nil,current_user.id)

View File

@ -2,7 +2,7 @@ class PropertyHiresController < ApplicationController
include Admin::PropertyHiresHelper include Admin::PropertyHiresHelper
FrontendMethods = ["hire", "view_calendar", "hire_success"] FrontendMethods = ["hire", "view_calendar", "hire_success"]
def index def index
properties = Property.filter_by_categories.sort_order properties = Property.can_display.filter_by_categories.sort_order
url = "/#{I18n.locale}#{OrbitHelper.page.get_url}" url = "/#{I18n.locale}#{OrbitHelper.page.get_url}"
data = index_data(properties, url) data = index_data(properties, url)
headers = [ headers = [
@ -33,11 +33,13 @@ class PropertyHiresController < ApplicationController
end end
def index_data(properties, url) def index_data(properties, url)
ma = ModuleApp.find_by_key("property_hire")
is_user_manager = (OrbitHelper.current_user.is_admin? || OrbitHelper.current_user.is_manager?(ma) || OrbitHelper.current_user.is_sub_manager?(ma))
data = properties.collect do |property| data = properties.collect do |property|
actions = [] actions = []
url_to_show = "#{url}/#{property.to_param}?method=hire" url_to_show = "#{url}/#{property.to_param}?method=hire"
hire_url = nil hire_url = nil
if property.can_be_hired_frontend && property.can_reserve if (property.can_be_hired_frontend && property.can_reserve) || is_user_manager
hire_url = url_to_show hire_url = url_to_show
actions << { actions << {
"text" => t("property_hire.hire"), "text" => t("property_hire.hire"),
@ -45,7 +47,7 @@ class PropertyHiresController < ApplicationController
"link" => hire_url "link" => hire_url
} }
end end
if !property.disable_view_calendar_page && property.can_be_show_frontend && property.can_reserve if (!property.disable_view_calendar_page && property.can_be_show_frontend && property.can_reserve) || is_user_manager
actions << { actions << {
"text" => t("property_hire.view_calendar"), "text" => t("property_hire.view_calendar"),
"btn-class" => "btn-info", "btn-class" => "btn-info",
@ -331,10 +333,13 @@ class PropertyHiresController < ApplicationController
end end
allow_no_logins_user = PropertyHireSetting.first.allow_no_logins_user allow_no_logins_user = PropertyHireSetting.first.allow_no_logins_user
all_day_settings = property.all_day_settings.map{|d,settings| [d,settings.map{|s| [s.id.to_s,s.title]}]}.to_h all_day_settings = property.all_day_settings.map{|d,settings| [d,settings.map{|s| [s.id.to_s,s.title]}]}.to_h
ma = ModuleApp.find_by_key("property_hire")
is_user_manager = (OrbitHelper.current_user.is_admin? || OrbitHelper.current_user.is_manager?(ma) || OrbitHelper.current_user.is_sub_manager?(ma))
{ {
"hire" => hire, "hire" => hire,
"property" => property, "property" => property,
"page" => page.url, "page" => page.url,
"is_user_manager" => is_user_manager,
"current_user" => OrbitHelper.current_user, "current_user" => OrbitHelper.current_user,
"allow_no_logins_user" => allow_no_logins_user, "allow_no_logins_user" => allow_no_logins_user,
"carousel_display_style" => "width: #{property.carousel_image_width};", "carousel_display_style" => "width: #{property.carousel_image_width};",
@ -352,7 +357,7 @@ class PropertyHiresController < ApplicationController
def get_bookings def get_bookings
events =[] events =[]
allevents = [] allevents = []
property = Property.find(params[:property_id]) rescue nil property = @property = Property.find(params[:property_id]) rescue nil
unless property.nil? unless property.nil?
if params[:start].present? && params[:end].present? if params[:start].present? && params[:end].present?
sdt = Time.at(params[:start].to_i) sdt = Time.at(params[:start].to_i)
@ -362,9 +367,10 @@ class PropertyHiresController < ApplicationController
events = events.map{|e| e.as_json} events = events.map{|e| e.as_json}
allevents = events.inject(re, :<<) allevents = events.inject(re, :<<)
allevents = allevents.sort_by{|e| e[:start]} allevents = allevents.sort_by{|e| e[:start]}
Rails.logger.info allevents
@need_check_events = allevents.map{|e| [e[:date],e[:s_id]]} @need_check_events = allevents.map{|e| [e[:date],e[:s_id]]}
@special_unavailable_dates = property.special_unavailable_dates.map{|dt| Date.parse(dt)} @special_unavailable_dates = property.special_unavailable_dates.map{|dt| Date.parse(dt)}
ma = ModuleApp.find_by_key("property_hire")
is_user_manager = (OrbitHelper.current_user.is_admin? || OrbitHelper.current_user.is_manager?(ma) || OrbitHelper.current_user.is_sub_manager?(ma))
if property.set_availability && params[:display_hire_event] == "true" if property.set_availability && params[:display_hire_event] == "true"
check_setting = property.set_unavailibility && (property.property_day_settings.where(:enable=>false).count != 0) check_setting = property.set_unavailibility && (property.property_day_settings.where(:enable=>false).count != 0)
@ -380,14 +386,19 @@ class PropertyHiresController < ApplicationController
all_day_settings = property.all_day_settings.map{|d,settings| [d,settings.map{|s| [s.start_time,s.end_time,s.id.to_s,s.title,s.reservation_limit,s.enable]}]}.to_h all_day_settings = property.all_day_settings.map{|d,settings| [d,settings.map{|s| [s.start_time,s.end_time,s.id.to_s,s.title,s.reservation_limit,s.enable]}]}.to_h
if all_day_settings.count != 0 if all_day_settings.count != 0
time_now = Time.zone.now time_now = Time.zone.now
if is_user_manager
get_start_time = property.p_open_start_time
get_end_time = property.p_open_end_time
else
get_start_time = [sdt,time_now].max get_start_time = [sdt,time_now].max
get_end_time = edt get_end_time = edt
end
if property.set_unavailibility if property.set_unavailibility
if property.can_hire_before_months != 0 if property.can_hire_before_months != 0
get_end_time = [time_now + (property.can_hire_before_months).send("month"),edt].min get_end_time = [time_now + (property.can_hire_before_months).send("month"),edt].min
end end
end end
if property.can_reserve if property.can_reserve || is_user_manager
allevents += generate_all_reserve_buttons(get_start_time,get_end_time,all_day_settings,check_setting) allevents += generate_all_reserve_buttons(get_start_time,get_end_time,all_day_settings,check_setting)
end end
@ -417,15 +428,57 @@ class PropertyHiresController < ApplicationController
if @special_unavailable_dates.include?(date) if @special_unavailable_dates.include?(date)
available = false available = false
end end
if DateTime.now >= @property.start_date && DateTime.now <= @property.end_date
if @property.hours_restriction > 0 && @is_user_manager === false
check = false
sd = nil
ed = nil
case @property.hours_restriction_duration
when "week"
weeknumber = date.strftime("%U").to_i
if @weeknumber != weeknumber
sd = date - date.wday
ed = date + (6 - date.wday)
@weeknumber = weeknumber
check = true
end
when "month"
if @monthnumber != date.month
sd = Date.new(date.year, date.month, 1)
ed = sd.next_month.prev_day
@monthnumber = date.month
check = true
end
end
if check === true
@user_total_hired_hours = @property.get_user_total_user_hired_hours(OrbitHelper.current_user.id.to_s, sd, ed)
end
if @user_total_hired_hours >= @property.hours_restriction
available = false
end
end
end
if available
if DateTime.now >= @property.start_date && DateTime.now <= @property.end_date
available = date > (DateTime.now + (@property.need_hire_before).send(@property.need_hire_before_unit))
end
end
if @check_setting && allow_times.select{|a| !a[5]}.count != 0 if @check_setting && allow_times.select{|a| !a[5]}.count != 0
available = (date > @check_end_date rescue false) || (date < @check_start_date rescue false) available = (date > @check_end_date rescue false) || (date < @check_start_date rescue false)
if available
available = @property.weekdays.include?(date.wday.to_s) ? false : true
end
unless available unless available
allow_times = allow_times.select do |allow_time| allow_times = allow_times.select do |allow_time|
if allow_time[5] if allow_time[5]
true true
elsif (allow_time[0] > @check_end_time || allow_time[1] < @check_start_time) elsif (allow_time[0] > @check_end_time || allow_time[1] < @check_start_time)
true true
else elsif
false false
end end
end end
@ -453,6 +506,10 @@ class PropertyHiresController < ApplicationController
@all_day_settings = all_day_settings @all_day_settings = all_day_settings
@startt = startt @startt = startt
@endt = endt @endt = endt
@weeknumber = 0
@monthnumber = 0
ma = ModuleApp.find_by_key("property_hire")
@is_user_manager = (OrbitHelper.current_user.is_admin? || OrbitHelper.current_user.is_manager?(ma) || OrbitHelper.current_user.is_sub_manager?(ma))
def generate_events(start_wday,end_wday,type=0,start_validate=false) def generate_events(start_wday,end_wday,type=0,start_validate=false)
if type == 0 if type == 0
(start_wday..end_wday).each_with_index do |wday,i| (start_wday..end_wday).each_with_index do |wday,i|

View File

@ -41,7 +41,7 @@ module Admin::PropertyHiresHelper
return {"success" => false, "msg" => I18n.t("property_hire.starting_time_cannot_be_greater_than_ending_time")} return {"success" => false, "msg" => I18n.t("property_hire.starting_time_cannot_be_greater_than_ending_time")}
end end
end end
available_flag = property.is_available_for_hire?(stime, etime, interval, recurring_end_date, time_setting_id) available_flag = property.is_available_for_hire?(stime, etime, interval, recurring_end_date, time_setting_id, OrbitHelper.current_user.member_profile)
if available_flag == 1 if available_flag == 1
if property.not_yet_hired?(stime, etime, interval, recurring_end_date,params[:phire_id], time_setting_id) if property.not_yet_hired?(stime, etime, interval, recurring_end_date,params[:phire_id], time_setting_id)
data = {"success" => true} data = {"success" => true}

View File

@ -31,6 +31,8 @@ class Property
field :p_hire_end_time, type: DateTime field :p_hire_end_time, type: DateTime
field :p_open_start_time, type: DateTime field :p_open_start_time, type: DateTime
field :p_open_end_time, type: DateTime field :p_open_end_time, type: DateTime
field :p_display_start_time, type: DateTime
field :p_display_end_time, type: DateTime
field :recurring_enable, type: Boolean, :default => false field :recurring_enable, type: Boolean, :default => false
mount_uploader :image, ImageUploader mount_uploader :image, ImageUploader
@ -46,6 +48,8 @@ class Property
field :special_unavailable_dates_title, type: Array, default: [] field :special_unavailable_dates_title, type: Array, default: []
field :start_date, type: DateTime field :start_date, type: DateTime
field :end_date, type: DateTime field :end_date, type: DateTime
field :hours_restriction, type: Integer, default: 0
field :hours_restriction_duration, type: String
field :description, :localize => true field :description, :localize => true
field :unavailibility_note, :localize => true field :unavailibility_note, :localize => true
field :hiring_person_email, type: Hash, default: {"enable"=>"1","required"=>"true"} field :hiring_person_email, type: Hash, default: {"enable"=>"1","required"=>"true"}
@ -86,7 +90,7 @@ class Property
has_many :property_links, :autosave => true, :dependent => :destroy has_many :property_links, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :property_links, :allow_destroy => true accepts_nested_attributes_for :property_links, :allow_destroy => true
scope :sort_order, ->{order_by([:created_at,:desc],[:order_position,:asc])} 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})} scope :can_display, ->{any_of({:p_display_start_time.lt=>Time.now, :p_display_end_time.gt=>Time.now},{:p_display_start_time.lt=>Time.now, :p_display_end_time=>nil},{:p_display_start_time=>nil, :p_display_end_time=>nil})}
WEEKDAYS = [ WEEKDAYS = [
"Sunday", "Sunday",
"Monday", "Monday",
@ -288,6 +292,9 @@ class Property
default_msg = "This property is unavaliable to reserved 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}) message += I18n.t("property_hire.unavailable_hint2",{:month=>property.can_hire_before_months,:default=>default_msg})
end end
if property.hours_restriction > 0
message += "<br />" + I18n.t("property_hire.hours_restriction_message", {:no_of_hours => property.hours_restriction, :duration => I18n.t("property_hire._#{property.hours_restriction_duration}") })
end
end end
return message.html_safe return message.html_safe
end end
@ -299,8 +306,22 @@ class Property
MemberProfile.find(self.owners) rescue [] MemberProfile.find(self.owners) rescue []
end end
def is_available_for_hire?(stime, etime, interval = nil, recurring_end_date = nil, time_setting_id = nil) def get_user_total_user_hired_hours(member_profile_id, start_time, end_time)
hires = self.p_hires.where(:hiring_person_id => member_profile_id, :start_time.gte => start_time, :end_time.lte => end_time)
total_hours = 0.0
hires.each do |hire|
diff = hire.end_time - hire.start_time
total_hours += diff * 24.0
end
return total_hours
end
def is_available_for_hire?(stime, etime, interval = nil, recurring_end_date = nil, time_setting_id = nil, member_profile)
available = 0 available = 0
ma = ModuleApp.find_by_key("property_hire")
user = member_profile.user
is_user_manager = (user.is_admin? || user.is_manager?(ma) || user.is_sub_manager?(ma))
return 1 if is_user_manager == true
return 1 if self.set_unavailibility == false return 1 if self.set_unavailibility == false
return 1 if self.weekdays.empty? && self.can_hire_before_months == 0 return 1 if self.weekdays.empty? && self.can_hire_before_months == 0
time_now = Time.now.to_datetime time_now = Time.now.to_datetime
@ -317,6 +338,24 @@ class Property
return 0 return 0
end end
end end
if DateTime.now > self.start_date && DateTime.now < self.end_date
if self.hours_restriction > 0 && !user.nil?
sd = nil
edd = nil
case self.hours_restriction_duration
when "week"
sd = stime - stime.wday
edd = stime + (6 - stime.wday)
when "month"
sd = Date.new(stime.year, stime.month, 1)
edd = sd.next_month.prev_day
end
if self.get_user_total_user_hired_hours(member_profile.id.to_s, sd, edd) >= self.hours_restriction
return 0
end
end
end
startt = self.start_date.nil? ? stime : self.start_date startt = self.start_date.nil? ? stime : self.start_date
endt = self.end_date.nil? ? etime : self.end_date endt = self.end_date.nil? ? etime : self.end_date
available = 1 if (startt > stime && endt > etime) available = 1 if (startt > stime && endt > etime)

View File

@ -125,15 +125,33 @@
<%= f.text_field :other_location %> <%= f.text_field :other_location %>
</div> </div>
</div> </div>
<%
=begin%>
<div class="control-group"> <div class="control-group">
<%= f.label :property_number, t("property_hire.property_number"), :class => "control-label muted" %> <%= f.label :property_number, t("property_hire.property_number"), :class => "control-label muted" %>
<div class="controls"> <div class="controls">
<%= f.text_field :property_number %> <%= f.text_field :property_number %>
</div> </div>
</div> </div>
<%
=end%>
<div class="control-group">
<%= f.label :p_display_start_time, t("property_hire.p_display_start_time"), :class => "control-label muted" %>
<div class="controls">
<%= f.datetime_picker :p_display_start_time, :picker_type => "date", :no_label => true, :new_record => @property.new_record?, :data=>{"picker-type" => "range", "range" => "start"}, :format => "yyyy/MM/dd hh:mm" %>
</div>
</div>
<div class="control-group">
<%= f.label :p_display_end_time, t("property_hire.p_display_end_time"), :class => "control-label muted" %>
<div class="controls">
<%= f.datetime_picker :p_display_end_time, :picker_type => "date", :no_label => true, :new_record => @property.new_record?, :data=>{"picker-type" => "range", "range" => "end"}, :format => "yyyy/MM/dd hh:mm" %>
</div>
</div>
<div class="control-group"> <div class="control-group">
<%= f.label :p_hire_start_time, t("property_hire.p_hire_start_time"), :class => "control-label muted" %> <%= f.label :p_hire_start_time, t("property_hire.p_hire_start_time"), :class => "control-label muted" %>
<div class="controls"> <div class="controls">
<div class="muted"><%= t("property_hire.time_period_note") %></div>
<%= f.datetime_picker :p_hire_start_time, :picker_type => "date", :no_label => true, :new_record => @property.new_record?, :data=>{"picker-type" => "range", "range" => "start"}, :format => "yyyy/MM/dd hh:mm" %> <%= f.datetime_picker :p_hire_start_time, :picker_type => "date", :no_label => true, :new_record => @property.new_record?, :data=>{"picker-type" => "range", "range" => "start"}, :format => "yyyy/MM/dd hh:mm" %>
</div> </div>
</div> </div>
@ -153,6 +171,7 @@
<div class="control-group"> <div class="control-group">
<%= f.label :p_open_start_time, t("property_hire.p_open_start_time"), :class => "control-label muted" %> <%= f.label :p_open_start_time, t("property_hire.p_open_start_time"), :class => "control-label muted" %>
<div class="controls"> <div class="controls">
<div class="muted"><%= t("property_hire.available_time_note") %></div>
<%= f.datetime_picker :p_open_start_time, :picker_type => "date", :no_label => true, :new_record => @property.new_record?, :data=>{"picker-type" => "range", "range" => "start"}, :format => "yyyy/MM/dd" %> <%= f.datetime_picker :p_open_start_time, :picker_type => "date", :no_label => true, :new_record => @property.new_record?, :data=>{"picker-type" => "range", "range" => "start"}, :format => "yyyy/MM/dd" %>
</div> </div>
</div> </div>
@ -163,12 +182,16 @@
</div> </div>
</div> </div>
</div> </div>
<%
=begin%>
<div class="control-group"> <div class="control-group">
<%= f.label :purchase_date, t("property_hire.purchase_date"), :class => "control-label muted" %> <%= f.label :purchase_date, t("property_hire.purchase_date"), :class => "control-label muted" %>
<div class="controls"> <div class="controls">
<%= f.datetime_picker :purchase_date, :no_label => true, :new_record => @property.new_record?, :picker_type => "date", :format => "yyyy/MM/dd" %> <%= f.datetime_picker :purchase_date, :no_label => true, :new_record => @property.new_record?, :picker_type => "date", :format => "yyyy/MM/dd" %>
</div> </div>
</div> </div>
<%
=end%>
<div class="control-group"> <div class="control-group">
<%= f.label :owners, t("property_hire.owners"), :class => "control-label muted" %> <%= f.label :owners, t("property_hire.owners"), :class => "control-label muted" %>
<div class="controls"> <div class="controls">
@ -199,12 +222,16 @@
<%= f.text_field :owner_phone %> <%= f.text_field :owner_phone %>
</div> </div>
</div> </div>
<%
=begin%>
<div class="control-group"> <div class="control-group">
<%= f.label :price, t("property_hire.price"), :class => "control-label muted" %> <%= f.label :price, t("property_hire.price"), :class => "control-label muted" %>
<div class="controls"> <div class="controls">
<%= f.text_field :price %> <%= f.text_field :price %>
</div> </div>
</div> </div>
<%
=end%>
</div> </div>
<!-- page_setting --> <!-- page_setting -->
<div class="tab-pane fade" id="page_setting"> <div class="tab-pane fade" id="page_setting">
@ -378,20 +405,13 @@
<% else %> <% else %>
<div id="set_unavailibility_div" style="display: none;"> <div id="set_unavailibility_div" style="display: none;">
<% end %> <% end %>
<div class="control-group"> <div class="control-group">
<%= f.label :can_hire_before_months, t("property_hire.how_many_months_ago_can_be_hired"), :class => "control-label muted" %> <%= f.label :can_hire_before_months, t("property_hire.how_many_months_ago_can_be_hired"), :class => "control-label muted" %>
<div class="controls"> <div class="controls">
<%= 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) %> <%= 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> </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"> <div class="control-group">
<label class="control-label muted"><%=t("property_hire.weekdays").html_safe%></label> <label class="control-label muted"><%=t("property_hire.weekdays").html_safe%></label>
<div class="controls"> <div class="controls">
@ -432,6 +452,22 @@
<button class="primary" id="add_special_unavailable_date">Add</button> <button class="primary" id="add_special_unavailable_date">Add</button>
</div> </div>
</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.hours_restriction") %></label>
<div class="controls">
<% units = ['week', 'month'] %>
<%= f.number_field :hours_restriction, :min=>0, :max=>24 %>
<%= f.select :hours_restriction_duration, options_for_select(units.map{|unit| [t("property_hire._#{unit}"), unit]},f.object.need_hire_before_unit) %>
</div>
</div>
<div class="control-group"> <div class="control-group">
<%= f.label :start_date, t("property_hire.start_date"), :class => "control-label muted" %> <%= f.label :start_date, t("property_hire.start_date"), :class => "control-label muted" %>
<div class="controls"> <div class="controls">
@ -836,6 +872,11 @@
}) })
var setting_count = <%=setting_count%>; var setting_count = <%=setting_count%>;
var default_time_settings = <%= PropertyHireSetting.first.default_time_settings.map{|s| s.attributes.except("_id","created_at","updated_at")}.to_s.gsub("=>",": ").html_safe rescue "[]" %> var default_time_settings = <%= PropertyHireSetting.first.default_time_settings.map{|s| s.attributes.except("_id","created_at","updated_at")}.to_s.gsub("=>",": ").html_safe rescue "[]" %>
<% property_day_setting = f.object.property_day_settings.new(:id=>nil) %>
<%= f.fields_for :property_day_settings,property_day_setting,:child_index => "new_index" do |f| %>
var template_html = "<%= escape_javascript(render(:partial=>"time_form",:locals=>{:f=>f})) %>";
console.log(template_html);
<%end%>
$(".apply_default_time_settings").click(function(){ $(".apply_default_time_settings").click(function(){
var target = $($(this).data("target")); var target = $($(this).data("target"));
var key = $(this).data("count"); var key = $(this).data("count");
@ -844,22 +885,21 @@
var old_key = new RegExp("new_key", "g"); var old_key = new RegExp("new_key", "g");
var new_day = day; var new_day = day;
var old_day = new RegExp("new_day", "g"); var old_day = new RegExp("new_day", "g");
var new_key = key;
target.empty(); target.empty();
default_time_settings.forEach(function(setting){ default_time_settings.forEach(function(setting){
var old_index = new RegExp("new_index", "g"); var old_index = new RegExp("new_index", "g");
var new_index = setting_count; var new_index = setting_count;
var new_key = key;
setting_count += 1; setting_count += 1;
<% property_day_setting = f.object.property_day_settings.new(:id=>nil) %>
<%= f.fields_for :property_day_settings,property_day_setting,:child_index => "new_index" do |f| %>
var template_html = "<%= escape_javascript(render(:partial=>"time_form",:locals=>{:f=>f})) %>";
<%end%>
var tmp = $(template_html.replace(old_index,new_index).replace(old_key,new_key).replace(old_day,new_day)); var tmp = $(template_html.replace(old_index,new_index).replace(old_key,new_key).replace(old_day,new_day));
Object.keys(setting).forEach(function(k){ Object.keys(setting).forEach(function(k){
if(k != "day" && k != "key"){
if(tmp.find("[name*='["+k+"]'").length != 0){ if(tmp.find("[name*='["+k+"]'").length != 0){
tmp.find("[name*='["+k+"]']").val(setting[k]); tmp.find("[name*='["+k+"]']").val(setting[k]);
console.log([k,setting[k]]) console.log([k,setting[k]])
} }
}
}); });
target.append(tmp); target.append(tmp);
key += 1; key += 1;

View File

@ -33,8 +33,8 @@
<%= f.datetime_picker :end_time, :picker_type => "time", :no_label => true, :new_record => (@property.new_record? rescue true) %> <%= f.datetime_picker :end_time, :picker_type => "time", :no_label => true, :new_record => (@property.new_record? rescue true) %>
</div> </div>
</div> </div>
<%= f.hidden_field :key, :value => key %> <%= f.hidden_field :key, :value => key, :data => {"type" => "key"} %>
<%= f.hidden_field :day, :value => day %> <%= f.hidden_field :day, :value => day, :data => {"type" => "day"} %>
<div class="control-group"> <div class="control-group">
<%= f.label "reservation_limit_#{key}_#{day}", t("property_hire.reservation_limit"), :class => "control-label muted" %> <%= f.label "reservation_limit_#{key}_#{day}", t("property_hire.reservation_limit"), :class => "control-label muted" %>
<div class="controls"> <div class="controls">

View File

@ -8,6 +8,7 @@
data = action_data data = action_data
hire = data["hire"] hire = data["hire"]
property = data["property"] property = data["property"]
is_user_manager = data["is_user_manager"]
url = data["page"] url = data["page"]
current_user = data["current_user"] current_user = data["current_user"]
allow_no_logins_user = data["allow_no_logins_user"] allow_no_logins_user = data["allow_no_logins_user"]
@ -451,9 +452,9 @@
</script> </script>
<% end %> <% end %>
<div class="col-lg-<%=right_col%>"> <div class="col-lg-<%=right_col%>">
<% if property.can_reserve === true %> <% if property.can_reserve === true || is_user_manager %>
<%= form_for hire, :url => "/xhr/property_hires/make_booking", html: { class: "form-horizontal", id: "hire_form" } do |f| %> <%= form_for hire, :url => "/xhr/property_hires/make_booking", html: { class: "form-horizontal", id: "hire_form" } do |f| %>
<% if property.set_availability %> <% if property.set_availability || is_user_manager %>
<div class="form-group"> <div class="form-group">
<%= f.label :date, "*"+t("property_hire.date"), :class => "col-sm-#{label_col} control-label" %> <%= f.label :date, "*"+t("property_hire.date"), :class => "col-sm-#{label_col} control-label" %>
<div class="col-sm-<%=input_col%>" id="date_target_block"> <div class="col-sm-<%=input_col%>" id="date_target_block">