parent
d1b61401cb
commit
92b3b91138
|
@ -221,6 +221,13 @@ class PropertyHiresController < ApplicationController
|
||||||
params[:phire_id] = booking_p[:id]
|
params[:phire_id] = booking_p[:id]
|
||||||
end
|
end
|
||||||
data = check_for_availability(start_time,end_time,booking_p[:property_id], booking_p[:recurring_interval], booking_p[:recurring_end_date], time_setting_id)
|
data = check_for_availability(start_time,end_time,booking_p[:property_id], booking_p[:recurring_interval], booking_p[:recurring_end_date], time_setting_id)
|
||||||
|
if data["success"] == true
|
||||||
|
error_messages = property.check_require_fields(booking_p)
|
||||||
|
if error_messages.present?
|
||||||
|
data["msg"] = error_messages
|
||||||
|
data["success"] = false
|
||||||
|
end
|
||||||
|
end
|
||||||
if data["success"] == true
|
if data["success"] == true
|
||||||
hire = nil
|
hire = nil
|
||||||
if params[:phire_id]
|
if params[:phire_id]
|
||||||
|
@ -240,6 +247,7 @@ class PropertyHiresController < ApplicationController
|
||||||
end
|
end
|
||||||
redirect_to index_page + "?method=hire_success"
|
redirect_to index_page + "?method=hire_success"
|
||||||
else
|
else
|
||||||
|
session[:hire_data] = booking_p
|
||||||
session["hire-save-msg"] = data["msg"]
|
session["hire-save-msg"] = data["msg"]
|
||||||
if property.nil?
|
if property.nil?
|
||||||
redirect_to index_page
|
redirect_to index_page
|
||||||
|
|
|
@ -20,7 +20,7 @@ module Admin::PHireFieldHelper
|
||||||
@member = member
|
@member = member
|
||||||
@attribute_value = @member.get_value_from_field_id(id,p_hire)
|
@attribute_value = @member.get_value_from_field_id(id,p_hire)
|
||||||
@attribute_type = attribute_type
|
@attribute_type = attribute_type
|
||||||
@new_attribute = @attribute_value.nil?
|
@new_attribute = @attribute_value.nil? || @attribute_value.new_record?
|
||||||
@attribute_value = @attribute_value || p_hire.p_hire_field_values.build(p_hire_field_id: id)
|
@attribute_value = @attribute_value || p_hire.p_hire_field_values.build(p_hire_field_id: id)
|
||||||
@prefiled_value = value || @attribute_value.value rescue nil
|
@prefiled_value = value || @attribute_value.value rescue nil
|
||||||
return instance_eval("render_#{markup}") rescue ""
|
return instance_eval("render_#{markup}") rescue ""
|
||||||
|
|
|
@ -371,7 +371,8 @@ class Property
|
||||||
else
|
else
|
||||||
d_step = 0
|
d_step = 0
|
||||||
end
|
end
|
||||||
bookings = bookings.any_of([{:start_time.gte => etime},{:end_time.gte => etime}])
|
not_in_ids = bookings.any_of([{:end_time.lt=>stime},{:start_time.gt=>etime}]).pluck(:id)
|
||||||
|
bookings = bookings.where(:id.nin=>not_in_ids)
|
||||||
if time_setting_id
|
if time_setting_id
|
||||||
recurring_bookings = recurring_bookings.where(:property_day_setting_id=>time_setting_id)
|
recurring_bookings = recurring_bookings.where(:property_day_setting_id=>time_setting_id)
|
||||||
bookings = recurring_bookings.where(:property_day_setting_id=>time_setting_id)
|
bookings = recurring_bookings.where(:property_day_setting_id=>time_setting_id)
|
||||||
|
@ -465,7 +466,45 @@ class Property
|
||||||
end
|
end
|
||||||
return available
|
return available
|
||||||
end
|
end
|
||||||
|
def check_require_fields(booking_p)
|
||||||
|
fields_name = self.get_all_fields
|
||||||
|
has_p_hire_fields = self.p_hire_fields.count != 0
|
||||||
|
p_hire_fields = {}
|
||||||
|
if has_p_hire_fields
|
||||||
|
p_hire_fields = self.p_hire_fields.map{|rf| [rf.id.to_s,rf]}.to_h
|
||||||
|
end
|
||||||
|
error_messages = ""
|
||||||
|
form_index = 0
|
||||||
|
cross_lang_types = ['select','date','radio_button','checkbox']
|
||||||
|
unfilled_text = I18n.t('property_hire.unfilled')
|
||||||
|
available_locales = I18n.available_locales
|
||||||
|
available_locales_trans = available_locales.map{|l| [l, I18n.t(l)]}.to_h
|
||||||
|
fields_name.each do |field_name|
|
||||||
|
if has_p_hire_fields && field_name.include?("p_hire_fields")
|
||||||
|
rf = p_hire_fields[field_name.sub("p_hire_fields.",'')]
|
||||||
|
if rf.markup != 'hint_text' && rf.to_require
|
||||||
|
v = booking_p["p_hire_field_values_attributes"][form_index.to_s]['value']
|
||||||
|
if cross_lang_types.include?(rf.markup) || rf.get_data["cross_lang"] == "true"
|
||||||
|
if v.blank?
|
||||||
|
error_messages += "#{rf.title}: #{unfilled_text}\n"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
available_locales.each do |l|
|
||||||
|
if (v[l].blank? rescue true)
|
||||||
|
error_messages += "#{rf.title}(#{available_locales_trans[l]}): #{unfilled_text}\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
form_index = form_index +1
|
||||||
|
else
|
||||||
|
if self.send(field_name)["required"] == "true" && booking_p[field_name].blank?
|
||||||
|
error_messages += "#{self.custom_text(field_name,"name")}: #{unfilled_text}\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
error_messages
|
||||||
|
end
|
||||||
def self.time_iterate(start_time, end_time, step, &block)
|
def self.time_iterate(start_time, end_time, step, &block)
|
||||||
times = []
|
times = []
|
||||||
if block_given?
|
if block_given?
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
<script src="https://polyfill.io/v3/polyfill.min.js?features=Intl.DateTimeFormat,Intl.DateTimeFormat.~locale.en,Intl.NumberFormat.~locale.en"></script>
|
<script src="https://polyfill.io/v3/polyfill.min.js?features=Intl.DateTimeFormat,Intl.DateTimeFormat.~locale.en,Intl.NumberFormat.~locale.en"></script>
|
||||||
<script type="text/javascript" src="/assets/property_hire_fullcalendar.min.js"></script>
|
<script type="text/javascript" src="/assets/property_hire_fullcalendar.min.js"></script>
|
||||||
<script type="text/javascript" src="/assets/property_hire_calendar_frontend.js"></script>
|
<script type="text/javascript" src="/assets/property_hire_calendar_frontend.js"></script>
|
||||||
|
<%= javascript_include_tag "basic/jquery.nanoscroller.js" %>
|
||||||
<%
|
<%
|
||||||
data = action_data
|
data = action_data
|
||||||
hire = data["hire"]
|
hire = data["hire"]
|
||||||
|
@ -257,8 +258,8 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
<% if session["hire-save-msg"].present? %>
|
<% if session["hire-save-msg"].present? %>
|
||||||
<div id="property-unavaialable-alert" class="alert alert-danger" role="alert"><b>Sorry! </b><span> <%= session["hire-save-msg"] %></span></div>
|
<div id="property-unavaialable-alert" class="alert alert-danger" role="alert"><b>Sorry! </b><br><span> <%= session["hire-save-msg"].gsub("\n",'<br>').html_safe %></span></div>
|
||||||
<script type="text/javascript">alert("<%= session["hire-save-msg"] %>")</script>
|
<script type="text/javascript">alert("<%= escape_javascript(session["hire-save-msg"]) %>")</script>
|
||||||
<% session.delete("hire-save-msg") %>
|
<% session.delete("hire-save-msg") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</article>
|
</article>
|
||||||
|
@ -304,7 +305,7 @@
|
||||||
<div style="display: grid;">
|
<div style="display: grid;">
|
||||||
<span id="hidden_date" class="pull-left" style="margin-right: 1em;"></span>
|
<span id="hidden_date" class="pull-left" style="margin-right: 1em;"></span>
|
||||||
<%= fields_for :timepicker do |f|%>
|
<%= fields_for :timepicker do |f|%>
|
||||||
<%= f.time_picker :timepicker, :no_label => true, :new_record => hire.new_record? && !recover,:format=>"HH:mm", :class => "pull-left", :data=>{"picker-type" => "range", "range" => "end", "fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %>
|
<%= f.time_picker :timepicker, :no_label => true, :new_record => hire.new_record? && !recover,:format=>"HH:mm", :class => "pull-left", :data=>{"picker-type" => "range", "range" => "end"} %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<div class="pull-left btn-group" style="margin-top: 0.5em;">
|
<div class="pull-left btn-group" style="margin-top: 0.5em;">
|
||||||
<button id="confirm_date" class="btn btn-primary btn-sm" style="margin-right: 0.5em;" onclick="set_datetimepicker()"><%=t("property_hire.confirm")%></button>
|
<button id="confirm_date" class="btn btn-primary btn-sm" style="margin-right: 0.5em;" onclick="set_datetimepicker()"><%=t("property_hire.confirm")%></button>
|
||||||
|
@ -474,7 +475,7 @@
|
||||||
<%= f.label :start_time, "*"+t("property_hire.start_time"), :class => "col-sm-#{label_col} control-label" %>
|
<%= f.label :start_time, "*"+t("property_hire.start_time"), :class => "col-sm-#{label_col} control-label" %>
|
||||||
<% if property.calendar_type == 0 %>
|
<% if property.calendar_type == 0 %>
|
||||||
<div class="col-sm-<%=input_col%>">
|
<div class="col-sm-<%=input_col%>">
|
||||||
<%= f.datetime_picker :start_time, :no_label => true, :new_record => hire.new_record? && !recover,:class => "pull-left", :data=>{"picker-type" => "range", "range" => "start", "fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %>
|
<%= f.datetime_picker :start_time, :no_label => true, :new_record => hire.new_record? && !recover,:class => "pull-left", :data=>{"picker-type" => "range", "range" => "start","fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %>
|
||||||
<button type="button" id="pick_start_date" onclick="change_pick(this)" class="btn btn-primary btn-sm pull-left" style="margin-left: 1em;"><%=t("property_hire.pick_from_calendar")%></button>
|
<button type="button" id="pick_start_date" onclick="change_pick(this)" class="btn btn-primary btn-sm pull-left" style="margin-left: 1em;"><%=t("property_hire.pick_from_calendar")%></button>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -482,7 +483,7 @@
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<%= f.label :end_time, "*"+t("property_hire.end_time"), :class => "col-sm-#{label_col} control-label" %>
|
<%= f.label :end_time, "*"+t("property_hire.end_time"), :class => "col-sm-#{label_col} control-label" %>
|
||||||
<div class="col-sm-<%=input_col%>">
|
<div class="col-sm-<%=input_col%>">
|
||||||
<%= f.datetime_picker :end_time, :no_label => true, :new_record => hire.new_record? && !recover,:class => "pull-left", :data=>{"picker-type" => "range", "range" => "end", "fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %>
|
<%= f.datetime_picker :end_time, :no_label => true, :new_record => hire.new_record? && !recover,:class => "pull-left", :data=>{"picker-type" => "range", "range" => "end","fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %>
|
||||||
<button type="button" id="pick_end_date" onclick="change_pick(this)" class="btn btn-primary btn-sm pull-left" style="margin-left: 1em;"><%=t("property_hire.pick_from_calendar")%></button>
|
<button type="button" id="pick_end_date" onclick="change_pick(this)" class="btn btn-primary btn-sm pull-left" style="margin-left: 1em;"><%=t("property_hire.pick_from_calendar")%></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -498,7 +499,7 @@
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<%= f.label :recurring_interval, t("property_hire.recurring_interval"), :class => "col-sm-#{label_col} control-label" %>
|
<%= f.label :recurring_interval, t("property_hire.recurring_interval"), :class => "col-sm-#{label_col} control-label" %>
|
||||||
<div class="col-sm-1">
|
<div class="col-sm-1">
|
||||||
<%= f.select :recurring_interval, PHire::INTERVALS.collect{|int| [t("property_hire.recurring_interval_types.#{int}"), int] }, {:prompt => t('property_hire.select_interval')}, {:data => {"fv-validation" => "requiredifrecurring;" , "fv-messages" => "Cannot be empty;"}} %>
|
<%= f.select :recurring_interval, PHire::INTERVALS.collect{|int| [t("property_hire.recurring_interval_types.#{int}"), int] }, {:prompt => t('property_hire.select_interval'),:data=>{"fv-validation"=> "requiredifrecurring;", "fv-messages"=> "Cannot be empty;"}} %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -583,9 +584,9 @@
|
||||||
<div class="col-sm-<%=input_col%>">
|
<div class="col-sm-<%=input_col%>">
|
||||||
<% placeholder = property.custom_text(field_name,"placeholder") %>
|
<% placeholder = property.custom_text(field_name,"placeholder") %>
|
||||||
<% if custom_field_type[field_name] %>
|
<% if custom_field_type[field_name] %>
|
||||||
<%= f.send(custom_field_type[field_name], field_name , {:class => "form-control", :placeholder => placeholder, :value => default_values[field_name], :data => (required ? {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} : nil)}) %>
|
<%= f.send(custom_field_type[field_name], field_name , {:class => "form-control", :placeholder => placeholder, :value => default_values[field_name], :required=>(required ? 'required' : nil)}) %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= f.text_field field_name, :class => "form-control", :placeholder => placeholder, :value => default_values[field_name], :data => (required ? {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} : nil) %>
|
<%= f.text_field field_name, :class => "form-control", :placeholder => placeholder, :value => default_values[field_name], :required=>(required ? 'required' : nil) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -608,6 +609,7 @@
|
||||||
<% if f.object.id.present? %>
|
<% if f.object.id.present? %>
|
||||||
<%= f.hidden_field :id %>
|
<%= f.hidden_field :id %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<div class="nano"><div class="content"></div></div>
|
||||||
<%= f.submit t("property_hire.save"), :class => "btn btn-primary" %>
|
<%= f.submit t("property_hire.save"), :class => "btn btn-primary" %>
|
||||||
<%= f.hidden_field :property_id, :value => property.id %>
|
<%= f.hidden_field :property_id, :value => property.id %>
|
||||||
<input type="hidden" name="url" value="<%= url %>" />
|
<input type="hidden" name="url" value="<%= url %>" />
|
||||||
|
@ -755,7 +757,9 @@
|
||||||
$("#unavailable-schedule").on("click",function(){
|
$("#unavailable-schedule").on("click",function(){
|
||||||
|
|
||||||
})
|
})
|
||||||
|
if( document.createElement('canvas').getContext == undefined ){ //html5 not supported
|
||||||
|
$('[required]:not([readonly])').attr({"data-fv-validation": "required;", "data-fv-messages": "Cannot be empty;"});
|
||||||
|
}
|
||||||
var hireForm = new FormValidator($("#hire_form"));
|
var hireForm = new FormValidator($("#hire_form"));
|
||||||
hireForm.validate_functions.checkForDates = function(value,element){
|
hireForm.validate_functions.checkForDates = function(value,element){
|
||||||
return value == "1";
|
return value == "1";
|
||||||
|
@ -767,7 +771,6 @@
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#p_hire_recurring").on("click",function(){
|
$("#p_hire_recurring").on("click",function(){
|
||||||
$("#dates_validated").val("0");
|
$("#dates_validated").val("0");
|
||||||
$("#property-avaialable-alert").hide();
|
$("#property-avaialable-alert").hide();
|
||||||
|
|
|
@ -5,6 +5,7 @@ en:
|
||||||
restful_actions:
|
restful_actions:
|
||||||
fields_display_order: "Fields display order"
|
fields_display_order: "Fields display order"
|
||||||
property_hire:
|
property_hire:
|
||||||
|
unfilled: Unfilled
|
||||||
hire_time: Reservation time
|
hire_time: Reservation time
|
||||||
back_to_hire_page: "Back to Reserve Page"
|
back_to_hire_page: "Back to Reserve Page"
|
||||||
apply_default_time_settings: Apply default time settings
|
apply_default_time_settings: Apply default time settings
|
||||||
|
|
|
@ -5,6 +5,7 @@ zh_tw:
|
||||||
restful_actions:
|
restful_actions:
|
||||||
fields_display_order: "欄位顯示順序"
|
fields_display_order: "欄位顯示順序"
|
||||||
property_hire:
|
property_hire:
|
||||||
|
unfilled: 未填寫
|
||||||
hire_time: 預約時間
|
hire_time: 預約時間
|
||||||
back_to_hire_page: "回到預約頁面"
|
back_to_hire_page: "回到預約頁面"
|
||||||
apply_default_time_settings: 套用預設時段設定
|
apply_default_time_settings: 套用預設時段設定
|
||||||
|
|
Loading…
Reference in New Issue