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 %>
@@ -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 %>
- " class="btn btn-info pull-right"><%= t("bus_booking.export") %>
-
\ No newline at end of file
+
+
+
\ 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"