some new changes for booking, changed wordings and validation of dates plus other stuff
This commit is contained in:
parent
95945ed3cb
commit
eb500e0765
|
@ -80,6 +80,16 @@ class Admin::BusBookingsController < OrbitMemberAppController
|
||||||
redirect_to admin_bus_bookings_path
|
redirect_to admin_bus_bookings_path
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def bus_params
|
def bus_params
|
||||||
|
|
|
@ -13,11 +13,15 @@ class Bus
|
||||||
|
|
||||||
|
|
||||||
def can_reserve?
|
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
|
end
|
||||||
|
|
||||||
def posted_by
|
def posted_by
|
||||||
User.find(self.created_by).name rescue ""
|
User.find(self.created_by).name rescue ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def already_reserved?(user)
|
||||||
|
self.bookings.where(:user_id => user.id.to_s).count == 1
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -7,7 +7,6 @@
|
||||||
<%= javascript_include_tag "lib/bootstrap-fileupload" %>
|
<%= javascript_include_tag "lib/bootstrap-fileupload" %>
|
||||||
<%= javascript_include_tag "lib/bootstrap-datetimepicker" %>
|
<%= javascript_include_tag "lib/bootstrap-datetimepicker" %>
|
||||||
<%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %>
|
<%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %>
|
||||||
<%= javascript_include_tag "lib/file-type" %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="input-area">
|
<div class="input-area">
|
||||||
|
@ -35,6 +34,7 @@
|
||||||
<label class="control-label muted"><%= t("bus_booking.reservation_end_time") %></label>
|
<label class="control-label muted"><%= t("bus_booking.reservation_end_time") %></label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<%= f.datetime_picker :reservation_end_time, :no_label => true, :new_record => @bus.new_record? %>
|
<%= f.datetime_picker :reservation_end_time, :no_label => true, :new_record => @bus.new_record? %>
|
||||||
|
<div class='validator_error_class text-error hide'>Reservation end time cannot be later than departure time.</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -97,3 +97,21 @@
|
||||||
<%= f.submit t('submit'), class: 'btn btn-primary' %>
|
<%= f.submit t('submit'), class: 'btn btn-primary' %>
|
||||||
<%= link_to t('cancel'), admin_bus_bookings_path, :class=>"btn" %>
|
<%= link_to t('cancel'), admin_bus_bookings_path, :class=>"btn" %>
|
||||||
</div>
|
</div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(".main-forms").on("submit",function(){
|
||||||
|
$(".validator_error_class").addClass("hide");
|
||||||
|
var d = new Date($("#bus_departure_time").val()),
|
||||||
|
d1 = new Date($("#bus_reservation_end_time").val());
|
||||||
|
|
||||||
|
if((d - d1) > 0){
|
||||||
|
$(this).submit();
|
||||||
|
}else{
|
||||||
|
$(".validator_error_class").removeClass("hide");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,12 @@
|
||||||
<a href="<%= admin_bus_booking_duplicate_path(bus) %>"><%= t("bus_booking.duplicate") %></a>
|
<a href="<%= admin_bus_booking_duplicate_path(bus) %>"><%= t("bus_booking.duplicate") %></a>
|
||||||
<a class="error" href="<%= admin_bus_booking_path(bus) %>" data-method="delete" data-confirm="Are you sure?"><%= t("bus_booking.delete_route") %></a>
|
<a class="error" href="<%= admin_bus_booking_path(bus) %>" data-method="delete" data-confirm="Are you sure?"><%= t("bus_booking.delete_route") %></a>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if bus.can_reserve? %>
|
<% if bus.already_reserved?(current_user) %>
|
||||||
<a href="<%= admin_bus_booking_reserve_path(bus) %>"><%= t("bus_booking.reserve") %></a>
|
<a href="<%= admin_bus_booking_reserve_path(bus) %>"><%= t("bus_booking.manage") %></a>
|
||||||
|
<% else %>
|
||||||
|
<% if bus.can_reserve? %>
|
||||||
|
<a href="<%= admin_bus_booking_reserve_path(bus) %>"><%= t("bus_booking.reserve") %></a>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<td><%= bus.posted_by %></td>
|
<td><%= bus.posted_by %></td>
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
<h2><%= t("bus_booking.booking_details_for") %> <%= @bus.bus_route %></h2>
|
<h2><%= t("bus_booking.booking_details_for") %> <%= @bus.bus_route %></h2>
|
||||||
<table class="table table-striped table-bordered">
|
<table class="table table-striped table-bordered">
|
||||||
<thead>
|
<thead>
|
||||||
|
<th class="span1"><input type="checkbox" id="checkall"> All</th>
|
||||||
<th><%= t("bus_booking.registered_date") %></th>
|
<th><%= t("bus_booking.registered_date") %></th>
|
||||||
<th><%= t("bus_booking.email") %></th>
|
<th><%= t("bus_booking.email") %></th>
|
||||||
<th><%= t("bus_booking.name") %></th>
|
<th><%= t("bus_booking.name") %></th>
|
||||||
|
@ -9,8 +10,9 @@
|
||||||
<th><%= t("bus_booking.dorm_number") %></th>
|
<th><%= t("bus_booking.dorm_number") %></th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @bus.bookings.each do |booking| %>
|
<% @bus.bookings.desc(:created_at).each do |booking| %>
|
||||||
<tr>
|
<tr>
|
||||||
|
<td><input type="checkbox" value="<%= booking.id.to_s %>" name="bookings_to_delete[]" class="check-this"></td>
|
||||||
<td><%= booking.created_at.strftime("%Y/%m/%d") %></td>
|
<td><%= booking.created_at.strftime("%Y/%m/%d") %></td>
|
||||||
<td><%= booking.email %></td>
|
<td><%= booking.email %></td>
|
||||||
<td><%= booking.name %></td>
|
<td><%= booking.name %></td>
|
||||||
|
@ -20,5 +22,56 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<a href="<%= admin_bus_booking_export_path(@bus, :format => "xlsx") %>" class="btn btn-info pull-right"><%= t("bus_booking.export") %></a>
|
<div class="pull-right">
|
||||||
|
<a href="#" id="delete-selected" style="display:none;" class="btn btn-danger"><%= t("bus_booking.delete") %></a>
|
||||||
|
<a href="<%= admin_bus_booking_export_path(@bus, :format => "xlsx") %>" class="btn btn-info"><%= t("bus_booking.export") %></a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var deleteBtn = $("#delete-selected"),
|
||||||
|
checkAllBtn = $("#checkall"),
|
||||||
|
bookings = $("input.check-this");
|
||||||
|
|
||||||
|
checkAllBtn.on("click",function(){
|
||||||
|
if($(this).is(":checked")){
|
||||||
|
bookings.prop("checked",true);
|
||||||
|
}else{
|
||||||
|
bookings.prop("checked",false);
|
||||||
|
}
|
||||||
|
showHideDeleteFn();
|
||||||
|
})
|
||||||
|
|
||||||
|
bookings.on("click",function(){
|
||||||
|
if($("input.check-this:checked").length == bookings.length){
|
||||||
|
checkAllBtn.prop("checked",true);
|
||||||
|
}else{
|
||||||
|
checkAllBtn.prop("checked",false);
|
||||||
|
}
|
||||||
|
showHideDeleteFn();
|
||||||
|
})
|
||||||
|
|
||||||
|
deleteBtn.on("click",function(){
|
||||||
|
var b = $("input.check-this:checked");
|
||||||
|
if (b.length){
|
||||||
|
var values = b.map(function(i,x){return x.value}).toArray();
|
||||||
|
console.log(values);
|
||||||
|
$.ajax({
|
||||||
|
url : "/admin/bus_bookings/deletebookings",
|
||||||
|
data : {"bus_id" : "<%= @bus.id.to_s %>", "bookings" : values},
|
||||||
|
type : "post"
|
||||||
|
}).done(function(){
|
||||||
|
window.location.reload();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
})
|
||||||
|
|
||||||
|
var showHideDeleteFn = function(){
|
||||||
|
if($("input.check-this:checked").length){
|
||||||
|
deleteBtn.show();
|
||||||
|
}else{
|
||||||
|
deleteBtn.hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
showHideDeleteFn();
|
||||||
|
</script>
|
|
@ -12,7 +12,7 @@ en:
|
||||||
delete_route: Delete Route
|
delete_route: Delete Route
|
||||||
bus_schedule: Bus Schedule
|
bus_schedule: Bus Schedule
|
||||||
reserve_now: Reserve
|
reserve_now: Reserve
|
||||||
details: Reserve Details
|
details: Reservation Details
|
||||||
reserved: Reserved
|
reserved: Reserved
|
||||||
name: Name
|
name: Name
|
||||||
email: Email
|
email: Email
|
||||||
|
@ -25,3 +25,5 @@ en:
|
||||||
posted_by: Posted By
|
posted_by: Posted By
|
||||||
cancel_reservation: Cancel Reservation
|
cancel_reservation: Cancel Reservation
|
||||||
duplicate: Duplicate
|
duplicate: Duplicate
|
||||||
|
delete: Delete
|
||||||
|
manage: Manage Reservation
|
|
@ -12,7 +12,7 @@ zh_tw:
|
||||||
delete_route: Delete Route
|
delete_route: Delete Route
|
||||||
bus_schedule: Bus Schedule
|
bus_schedule: Bus Schedule
|
||||||
reserve_now: Reserved
|
reserve_now: Reserved
|
||||||
details: Reserve Details
|
details: Reservation Details
|
||||||
reserved: Reserved
|
reserved: Reserved
|
||||||
name: Name
|
name: Name
|
||||||
email: Email
|
email: Email
|
||||||
|
@ -25,3 +25,5 @@ zh_tw:
|
||||||
posted_by: Posted By
|
posted_by: Posted By
|
||||||
cancel_reservation: Cancel Reservation
|
cancel_reservation: Cancel Reservation
|
||||||
duplicate: Duplicate
|
duplicate: Duplicate
|
||||||
|
delete: Delete
|
||||||
|
manage: Manage Reservation
|
|
@ -5,6 +5,7 @@ Rails.application.routes.draw do
|
||||||
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
||||||
namespace :admin do
|
namespace :admin do
|
||||||
post "bus_bookings/bookbus" => "bus_bookings#bookbus"
|
post "bus_bookings/bookbus" => "bus_bookings#bookbus"
|
||||||
|
post "bus_bookings/deletebookings" => "bus_bookings#deletebookings"
|
||||||
resources :bus_bookings do
|
resources :bus_bookings do
|
||||||
get "reserve"
|
get "reserve"
|
||||||
get "export"
|
get "export"
|
||||||
|
|
Loading…
Reference in New Issue