From 6f3333a85724a0047ed942b4210e31df7130a823 Mon Sep 17 00:00:00 2001 From: bohung Date: Thu, 2 Jul 2020 22:56:03 +0800 Subject: [PATCH] Fix some important bugs.Add extra fields(can set enabled) to hire page. --- .../admin/property_hires_controller.rb | 7 ++- app/controllers/property_hires_controller.rb | 6 +-- app/models/p_hire.rb | 10 +++- app/models/property.rb | 10 +++- app/views/admin/property_hires/_form.html.erb | 25 ++++++++- .../property_hires/manage_locations.html.erb | 8 ++- .../show_booking_details.html.erb | 9 ++++ app/views/email/p_hire_email.html.erb | 11 ++-- app/views/property_hires/hire.html.erb | 32 ++++++++--- config/locales/en.yml | 13 ++++- config/locales/zh_tw.yml | 53 +++++++++++-------- 11 files changed, 140 insertions(+), 44 deletions(-) diff --git a/app/controllers/admin/property_hires_controller.rb b/app/controllers/admin/property_hires_controller.rb index 1c512bb..4d17a86 100644 --- a/app/controllers/admin/property_hires_controller.rb +++ b/app/controllers/admin/property_hires_controller.rb @@ -6,8 +6,7 @@ class Admin::PropertyHiresController < OrbitAdminController @filter_fields = filter_fields(@categories, @tags) @table_fields = ["property_hire.title", :category, "property_hire.location", "property_hire.available_for_hire"] - @properties = Property.where(:title.ne => "") - .order_by(sort) + @properties = Property.order_by(sort) .with_categories(filters("category")) .with_tags(filters("tag")) @@ -60,9 +59,9 @@ class Admin::PropertyHiresController < OrbitAdminController email = User.all.select{|v| v.is_admin? && v.user_name != 'rulingcom'}.collect{|v| v.member_profile.email} if email.length == 0 Admin::PropertyHiresHelper::HireMethod.send_mail('edit',email,property.id,nil,nil,current_user.id) if params[:page] - redirect_to admin_property_hires_path(:page => params[:page]) + redirect_to admin_property_hires_path(:page => params[:page],:locale => params[:locale]) else - redirect_to admin_property_hires_path + redirect_to admin_property_hires_path(:locale => params[:locale]) end end diff --git a/app/controllers/property_hires_controller.rb b/app/controllers/property_hires_controller.rb index 68acab8..80f726b 100644 --- a/app/controllers/property_hires_controller.rb +++ b/app/controllers/property_hires_controller.rb @@ -18,8 +18,8 @@ class PropertyHiresController < ApplicationController end { "title" => property.title, - "image" => property.image.url, - "image-thumb" => property.image.thumb.url, + "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" => OrbitHelper.url_to_show(property.to_param), "location" => property.get_location_name, "actions" => actions @@ -30,7 +30,7 @@ class PropertyHiresController < ApplicationController "column" => t("property_hire.title") }, { - "column" => t("property_hire.image") + "column" => "" }, { "column" => t("property_hire.location") diff --git a/app/models/p_hire.rb b/app/models/p_hire.rb index 5e2336e..8c8e311 100644 --- a/app/models/p_hire.rb +++ b/app/models/p_hire.rb @@ -16,7 +16,15 @@ class PHire field :recurring, type: Boolean, :default => false field :recurring_end_date, type: DateTime field :recurring_interval - + field :organization + field :person_in_charge + field :tel_of_person_in_charge + field :department + field :contact_person + field :tel_of_contact_person + field :mobile_phone_of_contact_person + field :contact_person_Email + field :contact_person_department belongs_to :property def as_json(options = {}) diff --git a/app/models/property.rb b/app/models/property.rb index 393ed16..42e9232 100644 --- a/app/models/property.rb +++ b/app/models/property.rb @@ -30,7 +30,15 @@ class Property field :end_date, type: DateTime field :description, :localize => true field :unavailibility_note, :localize => true - + field :organization + field :person_in_charge + field :tel_of_person_in_charge + field :department + field :contact_person + field :tel_of_contact_person + field :mobile_phone_of_contact_person + field :contact_person_Email + field :contact_person_department belongs_to :property_location has_many :p_hires has_many :hire_email_sets, :autosave => true, :dependent => :destroy, :inverse_of => :property diff --git a/app/views/admin/property_hires/_form.html.erb b/app/views/admin/property_hires/_form.html.erb index b70bcbf..9db8708 100644 --- a/app/views/admin/property_hires/_form.html.erb +++ b/app/views/admin/property_hires/_form.html.erb @@ -38,6 +38,7 @@
  • <%= t(:image) %>
  • <%= t('property_hire.unavailability')%>
  • <%= t('property_hire.auto_send_email_set') %>
  • +
  • <%= t('property_hire.settings') %>
  • @@ -291,7 +292,7 @@ <% end %> <% end %> <% @site_in_use_locales.each do |locale| %> - <%= f.fields_for :unavailibility_note do |f| %> + <%= f.fields_for :unavailibility_note_translations do |f| %>
    @@ -302,6 +303,28 @@ <% end %>
    +
    + <% fields_name = ["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"] %> + <% fields_name.each do |field_name| %> +
    + +
    + +
    +
    + + <%= f.fields_for field_name do |sub_f|%> + + + <% end %> +
    +
    + <% end %> +
    diff --git a/app/views/admin/property_hires/manage_locations.html.erb b/app/views/admin/property_hires/manage_locations.html.erb index 158fa1c..5fd15f7 100644 --- a/app/views/admin/property_hires/manage_locations.html.erb +++ b/app/views/admin/property_hires/manage_locations.html.erb @@ -61,7 +61,7 @@
    <%= content_tag(:div, paginate(@locations), class: "pagination pagination-centered") %>
    - <%= link_to t(:add), add_location_admin_property_hires_path, :class => "btn btn-primary", :data => {"toggle" => "modal", "target" => "#location-modal"} %> + <%= link_to t(:add), add_location_admin_property_hires_path, :id=>'create_new_location', :class => "btn btn-primary", :data => {"toggle" => "modal", "target" => "#location-modal"} %>
    @@ -72,4 +72,10 @@ $("#edit-location-btn").on("click",function(){ $("#edit-location-modal form").submit(); }) + $("#create_new_location").on("click",function(){ + var url = $(this).attr("href"); + $.get(url).done(function(data){ + $("#location-modal .modal-body").html(data); + }) + }) \ No newline at end of file diff --git a/app/views/admin/property_hires/show_booking_details.html.erb b/app/views/admin/property_hires/show_booking_details.html.erb index 4aecfd4..edf5ac0 100644 --- a/app/views/admin/property_hires/show_booking_details.html.erb +++ b/app/views/admin/property_hires/show_booking_details.html.erb @@ -36,6 +36,15 @@ <%= t("property_hire.note_for_hire") %> <%= @booking.note_for_hire %> + <% fields_name = ["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"] %> + <% fields_name.each do |field_name| %> + <% if(@booking.property[field_name]["enable"] == "1" rescue false) %> + + <%= t("property_hire.#{field_name}") %> + <%= @booking[field_name].to_s %> + + <% end %> + <% end %> <%= t("property_hire.passed") %> diff --git a/app/views/email/p_hire_email.html.erb b/app/views/email/p_hire_email.html.erb index e486a83..0e4932a 100644 --- a/app/views/email/p_hire_email.html.erb +++ b/app/views/email/p_hire_email.html.erb @@ -1,4 +1,5 @@ -<% email_set = Property.where(id: @data['property_id']).first.hire_email_sets.select{|v| v.field_name == 'p_hire'} %> +<% property = Property.where(id: @data['property_id']).first%> +<% email_set = property.hire_email_sets.select{|v| v.field_name == 'p_hire'} %> <% if email_set.length != 0 %> <% if !(email_set[0].content.nil?) %> <%= email_set[0].content[@data['locale']].html_safe %> @@ -8,7 +9,7 @@ <% end %>
    <% I18n.with_locale(@data['locale']) do %> -

    <%= Property.where(id: @data['property_id']).first.title rescue nil %>

    +

    <%= property.title rescue nil %>

    <% if !@data['hire_id'].nil? %> <% hire = PHire.where(id: @data['hire_id']).first %> @@ -19,7 +20,11 @@ - <% ['hiring_person_name','hiring_person_email','start_time','end_time','recurring','recurring_interval','recurring_end_date','passed','reason_for_hire','note_for_hire'].each do |k| %> + <% extra_fields_name = ["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"] %> + <% keys = ['hiring_person_name','hiring_person_email','start_time','end_time','recurring','recurring_interval','recurring_end_date','passed','reason_for_hire','note_for_hire'] %> + <% used_extra_fields_name = extra_fields_name.select{|field_name| (property[field_name]["enable"] == "1" rescue false) } %> + <% keys.concat( used_extra_fields_name ) %> + <% keys.each do |k| %> <% v = hire.send(k) %> <% if !v.nil? && !(k.include?('recurring') && hire.recurring != true)%> diff --git a/app/views/property_hires/hire.html.erb b/app/views/property_hires/hire.html.erb index 035e4c3..215ee1b 100644 --- a/app/views/property_hires/hire.html.erb +++ b/app/views/property_hires/hire.html.erb @@ -28,13 +28,13 @@ <% end %> <%= form_for hire, :url => "/xhr/property_hires/make_booking", html: { class: "form-horizontal" } do |f| %>
    - <%= f.label :start_time, t("property_hire.start_time"), :class => "col-sm-2 control-label" %> + <%= f.label :start_time, "*"+t("property_hire.start_time"), :class => "col-sm-2 control-label" %>
    <%= f.datetime_picker :start_time, :no_label => true, :new_record => hire.new_record?, :data=>{"picker-type" => "range", "range" => "start", "fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %>
    - <%= f.label :end_time, t("property_hire.end_time"), :class => "col-sm-2 control-label" %> + <%= f.label :end_time, "*"+t("property_hire.end_time"), :class => "col-sm-2 control-label" %>
    <%= f.datetime_picker :end_time, :no_label => true, :new_record => hire.new_record?, :data=>{"picker-type" => "range", "range" => "end", "fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %>
    @@ -55,7 +55,7 @@
    - <%= f.label :recurring_end_date, t("property_hire.recurring_end_date"), :class => "col-sm-2 control-label" %> + <%= f.label :recurring_end_date, "*"+t("property_hire.recurring_end_date"), :class => "col-sm-2 control-label" %>
    <%= f.datetime_picker :recurring_end_date, :no_label => true, :new_record => hire.new_record?, :data=>{"fv-validation" => "requiredifrecurring;", "fv-messages" => "Cannot be empty;"} %>
    @@ -70,7 +70,7 @@
    <% if property.set_unavailibility %>
    - Unavailibility Schedule + <%= t("property_hire.Unavailibility_Schedule") %>
    This property is unavaliable <%= !property.start_date.nil? ? " from " + property.start_date.strftime("%Y-%m-%d") : "" %> <%= !property.end_date.nil? ? " to " + property.end_date.strftime("%Y-%m-%d") : "" %> every <% property.weekdays.each_with_index do |d,i| %> @@ -94,26 +94,26 @@
    - <%= f.label :hiring_person_email, t("property_hire.hiring_person_email"), :class => "col-sm-2 control-label" %> + <%= f.label :hiring_person_email, "*"+t("property_hire.hiring_person_email"), :class => "col-sm-2 control-label" %>
    <%= f.text_field :hiring_person_email, :class => "form-control", :value => current_user.member_profile.email, :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %>
    - <%= f.label :hiring_person_number, t("property_hire.hiring_person_number"), :class => "col-sm-2 control-label" %> + <%= f.label :hiring_person_number, "*"+t("property_hire.hiring_person_number"), :class => "col-sm-2 control-label" %>
    <%= f.text_field :hiring_person_number, :class => "form-control", :value => current_user.member_profile.mobile_no, :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %>
    - <%= f.label :hiring_person_name, t("property_hire.hiring_person_name"), :class => "col-sm-2 control-label" %> + <%= f.label :hiring_person_name, "*"+t("property_hire.hiring_person_name"), :class => "col-sm-2 control-label" %>
    <%= f.text_field :hiring_person_name, :class => "form-control", :value => (current_user.name rescue ""), :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %> <%= f.hidden_field :hiring_person_id, :value => (current_user.member_profile.id.to_s rescue "") %>
    - <%= f.label :reason_for_hire, t("property_hire.reason_for_hire"), :class => "col-sm-2 control-label" %> + <%= f.label :reason_for_hire, "*"+t("property_hire.reason_for_hire"), :class => "col-sm-2 control-label" %>
    <%= f.text_field :reason_for_hire, :class => "form-control", :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %>
    @@ -124,6 +124,22 @@ <%= f.text_area :note_for_hire, :class => "form-control" %>
    + <% fields_name = ["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"] %> + <% fields_name.each do |field_name| %> + <% if(property[field_name]["enable"] == "1" rescue false) %> + <% required = (property[field_name]["required"] == "true" rescue false) %> +
    + <%= f.label field_name, (required ? "*" : "") + t("property_hire.#{field_name}"), :class => "col-sm-2 control-label" %> +
    + <% if required %> + <%= f.text_field field_name, :class => "form-control", :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %> + <% else %> + <%= f.text_field field_name, :class => "form-control" %> + <% end %> +
    +
    + <% end %> + <% end %>
    <%= f.submit t("property_hire.save"), :class => "btn btn-primary" %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 6b8b034..5dda987 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -67,4 +67,15 @@ en: 'no': 'No' wait_for_permit: 'Wait for permit' select_interval: Select interval - check_availibility: Check Availibility \ No newline at end of file + check_availibility: Check Availibility + Unavailibility_Schedule: Unavailibility Schedule + required: Required + organization: Organization + person_in_charge: Person in charge + tel_of_person_in_charge: Tel. of person in charge + department: Department + contact_person: Contact person + tel_of_contact_person: Tel. of contact person + mobile_phone_of_contact_person: Mobile phone of contact person + contact_person_Email: Contact person Email + contact_person_department: Contact person department \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 03060dd..396b4a9 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -1,10 +1,10 @@ zh_tw: property_hire: editor: 編輯者 - email_p_hire_success: 租借成功 + email_p_hire_success: 借用成功 email_edit_success: '租借模組:編輯成功' email_delete_success: '租借模組:刪除成功' - email_p_hire_content: 租借成功 + email_p_hire_content: 借用成功 email_edit_content: '租借模組:編輯成功' email_delete_content: '租借模組:刪除成功' edit: 編輯 @@ -12,26 +12,26 @@ zh_tw: auto_send_email_set: 自動發信設定 email_title: 主旨 email_content: 內文 - recurring: 週期性租借 - recurring_interval: 租借週期 + recurring: 週期性借用 + recurring_interval: 借用週期 recurring_interval_types: month: 月 week: 周 recurring_end_date: 週期結束時間 save: Save my_bookings: My Bookings - settings: Settings - property_hire: 租借管理 + settings: 設定 + property_hire: 借用管理 manage_locations: Manage Locations - location: Location + location: 位置 auto_approve: Auto approve property_count: Property Count edit_location: Edit Location add_location: Add Location - unavailability: Unavailability + unavailability: 不可借用 title: 名稱 select_interval: 選則週期 - check_availibility: 檢查是否可租借 + check_availibility: 檢查是否可借用 property_usage: 用途 note: 說明 property_number: 編號 @@ -42,9 +42,9 @@ zh_tw: owner_email: 管理人Email owner_phone: 管理人聯絡電話 price: Price - set_unavailibility: 設定為不可租借 - start_time: 租借開始時間 - end_time: 租借結束時間 + set_unavailibility: 設定為不可借用 + start_time: 借用開始時間 + end_time: 借用結束時間 weekdays: Weekdays start_date: From Date end_date: To Date @@ -55,16 +55,27 @@ zh_tw: hire: 線上借用 view_calendar: 查詢目前借用狀況 image: Property Image - actions: Actions - start_time: 租借開始時間 - end_time: 租借結束時間 - hiring_person_email: 租借人電子信箱 - hiring_person_number: 租借人聯絡電話 - hiring_person_name: 租借人姓名 - reason_for_hire: 租借原因 + actions: 操作 + start_time: 借用開始時間 + end_time: 借用結束時間 + hiring_person_email: 借用人電子信箱 + hiring_person_number: 借用人聯絡電話 + hiring_person_name: 借用人姓名 + reason_for_hire: 使用用途 note_for_hire: 備註 period: Period - passed: 租借允許 + passed: 借用允許 'yes': 是 'no': 否 - wait_for_permit: 等待授權 \ No newline at end of file + wait_for_permit: 等待授權 + Unavailibility_Schedule: 不提供借用時間 + required: 必填 + organization: 借用單位 + person_in_charge: 單位負責人 + tel_of_person_in_charge: 負責人聯絡電話 + department: 服務單位 + contact_person: 聯絡人 + tel_of_contact_person: 聯絡人聯絡電話 + mobile_phone_of_contact_person: 聯絡人行動電話 + contact_person_Email: 聯絡Email + contact_person_department: 聯絡人服務單位 \ No newline at end of file