From eb500e0765ec7e19102bdd8c509d6e6d83c30bf2 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 10 Aug 2016 18:32:45 +0800 Subject: [PATCH] some new changes for booking, changed wordings and validation of dates plus other stuff --- .../admin/bus_bookings_controller.rb | 10 ++++ app/models/bus.rb | 6 +- app/views/admin/bus_bookings/_form.html.erb | 22 ++++++- app/views/admin/bus_bookings/index.html.erb | 8 ++- app/views/admin/bus_bookings/show.html.erb | 59 ++++++++++++++++++- config/locales/en.yml | 6 +- config/locales/zh_tw.yml | 6 +- config/routes.rb | 1 + 8 files changed, 106 insertions(+), 12 deletions(-) diff --git a/app/controllers/admin/bus_bookings_controller.rb b/app/controllers/admin/bus_bookings_controller.rb index 62742f4..74f3dbc 100644 --- a/app/controllers/admin/bus_bookings_controller.rb +++ b/app/controllers/admin/bus_bookings_controller.rb @@ -80,6 +80,16 @@ class Admin::BusBookingsController < OrbitMemberAppController redirect_to admin_bus_bookings_path end + def deletebookings + bookings = Booking.find(params[:bookings]) rescue nil + if !bookings.nil? + bookings.each do |booking| + booking.destroy + end + end + render :json => {"succes" => true}.to_json + end + private def bus_params diff --git a/app/models/bus.rb b/app/models/bus.rb index 678b8a5..3a508bc 100644 --- a/app/models/bus.rb +++ b/app/models/bus.rb @@ -13,11 +13,15 @@ class Bus def can_reserve? - self.reservation_end_time > Time.now && self.bookings.count < 21 + self.reservation_end_time > Time.now && self.bookings.count <= self.capacity end def posted_by User.find(self.created_by).name rescue "" end + def already_reserved?(user) + self.bookings.where(:user_id => user.id.to_s).count == 1 + end + end \ No newline at end of file diff --git a/app/views/admin/bus_bookings/_form.html.erb b/app/views/admin/bus_bookings/_form.html.erb index c975558..a4599a9 100644 --- a/app/views/admin/bus_bookings/_form.html.erb +++ b/app/views/admin/bus_bookings/_form.html.erb @@ -7,7 +7,6 @@ <%= javascript_include_tag "lib/bootstrap-fileupload" %> <%= javascript_include_tag "lib/bootstrap-datetimepicker" %> <%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %> - <%= javascript_include_tag "lib/file-type" %> <% end %>
@@ -35,6 +34,7 @@
<%= f.datetime_picker :reservation_end_time, :no_label => true, :new_record => @bus.new_record? %> +
Reservation end time cannot be later than departure time.
@@ -96,4 +96,22 @@ <%= f.hidden_field :created_by, :value => current_user.id %> <%= f.submit t('submit'), class: 'btn btn-primary' %> <%= link_to t('cancel'), admin_bus_bookings_path, :class=>"btn" %> - \ No newline at end of file + + + + + + diff --git a/app/views/admin/bus_bookings/index.html.erb b/app/views/admin/bus_bookings/index.html.erb index f05e8ed..609393b 100644 --- a/app/views/admin/bus_bookings/index.html.erb +++ b/app/views/admin/bus_bookings/index.html.erb @@ -23,8 +23,12 @@ <%= t("bus_booking.duplicate") %> <%= t("bus_booking.delete_route") %> <% end %> - <% if bus.can_reserve? %> - <%= t("bus_booking.reserve") %> + <% if bus.already_reserved?(current_user) %> + <%= t("bus_booking.manage") %> + <% else %> + <% if bus.can_reserve? %> + <%= t("bus_booking.reserve") %> + <% end %> <% end %> <%= bus.posted_by %> diff --git a/app/views/admin/bus_bookings/show.html.erb b/app/views/admin/bus_bookings/show.html.erb index bdbc3ac..611e3ef 100644 --- a/app/views/admin/bus_bookings/show.html.erb +++ b/app/views/admin/bus_bookings/show.html.erb @@ -2,6 +2,7 @@

<%= t("bus_booking.booking_details_for") %> <%= @bus.bus_route %>

+ @@ -9,8 +10,9 @@ - <% @bus.bookings.each do |booking| %> + <% @bus.bookings.desc(:created_at).each do |booking| %> + @@ -20,5 +22,56 @@ <% end %>
All <%= t("bus_booking.registered_date") %> <%= t("bus_booking.email") %> <%= t("bus_booking.name") %><%= t("bus_booking.dorm_number") %>
<%= booking.created_at.strftime("%Y/%m/%d") %> <%= booking.email %> <%= booking.name %>
- " class="btn btn-info pull-right"><%= t("bus_booking.export") %> - \ No newline at end of file +
+ + " class="btn btn-info"><%= t("bus_booking.export") %> +
+ + \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 2f18e26..ce5a501 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -12,7 +12,7 @@ en: delete_route: Delete Route bus_schedule: Bus Schedule reserve_now: Reserve - details: Reserve Details + details: Reservation Details reserved: Reserved name: Name email: Email @@ -24,4 +24,6 @@ en: registered_date: Registered Date posted_by: Posted By cancel_reservation: Cancel Reservation - duplicate: Duplicate \ No newline at end of file + duplicate: Duplicate + delete: Delete + manage: Manage Reservation \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index ab4b1b0..94080e5 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -12,7 +12,7 @@ zh_tw: delete_route: Delete Route bus_schedule: Bus Schedule reserve_now: Reserved - details: Reserve Details + details: Reservation Details reserved: Reserved name: Name email: Email @@ -24,4 +24,6 @@ zh_tw: registered_date: Registered Date posted_by: Posted By cancel_reservation: Cancel Reservation - duplicate: Duplicate \ No newline at end of file + duplicate: Duplicate + delete: Delete + manage: Manage Reservation \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 2f32ced..11ec84a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,7 @@ Rails.application.routes.draw do scope "(:locale)", locale: Regexp.new(locales.join("|")) do namespace :admin do post "bus_bookings/bookbus" => "bus_bookings#bookbus" + post "bus_bookings/deletebookings" => "bus_bookings#deletebookings" resources :bus_bookings do get "reserve" get "export"