diff --git a/app/controllers/property_hires_controller.rb b/app/controllers/property_hires_controller.rb index a606650..013d3ab 100644 --- a/app/controllers/property_hires_controller.rb +++ b/app/controllers/property_hires_controller.rb @@ -221,6 +221,13 @@ class PropertyHiresController < ApplicationController params[:phire_id] = booking_p[:id] 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) + 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 hire = nil if params[:phire_id] @@ -240,6 +247,7 @@ class PropertyHiresController < ApplicationController end redirect_to index_page + "?method=hire_success" else + session[:hire_data] = booking_p session["hire-save-msg"] = data["msg"] if property.nil? redirect_to index_page diff --git a/app/helpers/admin/p_hire_field_helper.rb b/app/helpers/admin/p_hire_field_helper.rb index c1cc29a..33360b8 100644 --- a/app/helpers/admin/p_hire_field_helper.rb +++ b/app/helpers/admin/p_hire_field_helper.rb @@ -20,7 +20,7 @@ module Admin::PHireFieldHelper @member = member @attribute_value = @member.get_value_from_field_id(id,p_hire) @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) @prefiled_value = value || @attribute_value.value rescue nil return instance_eval("render_#{markup}") rescue "" diff --git a/app/models/property.rb b/app/models/property.rb index 1bfd21c..5eb2a10 100644 --- a/app/models/property.rb +++ b/app/models/property.rb @@ -371,7 +371,8 @@ class Property else d_step = 0 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 recurring_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 return available 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) times = [] if block_given? diff --git a/app/views/property_hires/hire.html.erb b/app/views/property_hires/hire.html.erb index 76837b2..cafbdb0 100644 --- a/app/views/property_hires/hire.html.erb +++ b/app/views/property_hires/hire.html.erb @@ -3,6 +3,7 @@ +<%= javascript_include_tag "basic/jquery.nanoscroller.js" %> <% data = action_data hire = data["hire"] @@ -257,8 +258,8 @@ <% end %> <% if session["hire-save-msg"].present? %> - - + + <% session.delete("hire-save-msg") %> <% end %> @@ -304,7 +305,7 @@
<%= 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 %>
@@ -474,7 +475,7 @@ <%= f.label :start_time, "*"+t("property_hire.start_time"), :class => "col-sm-#{label_col} control-label" %> <% if property.calendar_type == 0 %>
- <%= 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;"} %>
<% end %> @@ -482,7 +483,7 @@
<%= f.label :end_time, "*"+t("property_hire.end_time"), :class => "col-sm-#{label_col} control-label" %>
- <%= 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;"} %>
@@ -498,7 +499,7 @@
<%= f.label :recurring_interval, t("property_hire.recurring_interval"), :class => "col-sm-#{label_col} control-label" %>
- <%= 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;"}} %>
@@ -583,9 +584,9 @@
<% placeholder = property.custom_text(field_name,"placeholder") %> <% 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 %> - <%= 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 %>
@@ -608,6 +609,7 @@ <% if f.object.id.present? %> <%= f.hidden_field :id %> <% end %> +
<%= f.submit t("property_hire.save"), :class => "btn btn-primary" %> <%= f.hidden_field :property_id, :value => property.id %> @@ -755,7 +757,9 @@ $("#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")); hireForm.validate_functions.checkForDates = function(value,element){ return value == "1"; @@ -767,7 +771,6 @@ return true; } } - $("#p_hire_recurring").on("click",function(){ $("#dates_validated").val("0"); $("#property-avaialable-alert").hide(); diff --git a/config/locales/en.yml b/config/locales/en.yml index 573c62b..a007944 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -5,6 +5,7 @@ en: restful_actions: fields_display_order: "Fields display order" property_hire: + unfilled: Unfilled hire_time: Reservation time back_to_hire_page: "Back to Reserve Page" apply_default_time_settings: Apply default time settings diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index a263d12..dffc589 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -5,6 +5,7 @@ zh_tw: restful_actions: fields_display_order: "欄位顯示順序" property_hire: + unfilled: 未填寫 hire_time: 預約時間 back_to_hire_page: "回到預約頁面" apply_default_time_settings: 套用預設時段設定