diff --git a/app/controllers/admin/property_hires_controller.rb b/app/controllers/admin/property_hires_controller.rb
index a33e0cc..e0ce112 100644
--- a/app/controllers/admin/property_hires_controller.rb
+++ b/app/controllers/admin/property_hires_controller.rb
@@ -14,6 +14,11 @@ class Admin::PropertyHiresController < OrbitAdminController
@properties = search_data(@properties,[:title]).page(params[:page]).per(10)
end
+ def my_bookings
+ @table_fields = ["property_hire.hiring_person_name", "property_hire.reason_for_hire", "property_hire.hiring_person_number", "property_hire.period", "property_hire.passed", :actions]
+ @bookings = PHire.where(:hiring_person_id => current_user.member_profile.id.to_s).desc(:created_at).page(params[:page]).per(10)
+ end
+
def new
@property = Property.new
@locations = PropertyLocation.all.desc(:created_at).collect{|loc| [loc.title, loc.id.to_s]}
@@ -64,11 +69,30 @@ class Admin::PropertyHiresController < OrbitAdminController
@booking = PHire.find(params[:id]) rescue nil
end
+ def settings
+ if PropertyHireSetting.count == 0
+ @settings = PropertyHireSetting.create
+ else
+ @settings = PropertyHireSetting.first
+ end
+ if request.request_method == "PATCH"
+ @settings.update_attributes(settings_params)
+ @settings.save
+ @saved = true
+ else
+ @saved = false
+ end
+ end
+
def delete_booking_details
booking = PHire.find(params[:id])
property = booking.property
booking.destroy
- redirect_to admin_property_hire_path(property)
+ if request.referrer.split("/").last == "my_bookings"
+ redirect_to my_bookings_admin_property_hires_path
+ else
+ redirect_to admin_property_hire_path(property)
+ end
end
def pass_booking
@@ -141,6 +165,10 @@ class Admin::PropertyHiresController < OrbitAdminController
private
+ def settings_params
+ params.require(:property_hire_setting).permit!
+ end
+
def location_params
params.require(:property_location).permit!
end
diff --git a/app/controllers/property_hires_controller.rb b/app/controllers/property_hires_controller.rb
index f8126bb..38bc037 100644
--- a/app/controllers/property_hires_controller.rb
+++ b/app/controllers/property_hires_controller.rb
@@ -149,6 +149,7 @@ class PropertyHiresController < ApplicationController
property = Property.find(booking_p[:property_id]) rescue nil
if data["success"] == true
hire = PHire.new(booking_p)
+ hire.passed = true if PropertyHireSetting.auto_approve_enabled?
hire.save
redirect_to params[:url]
else
diff --git a/app/models/property_hire_setting.rb b/app/models/property_hire_setting.rb
new file mode 100644
index 0000000..ae81271
--- /dev/null
+++ b/app/models/property_hire_setting.rb
@@ -0,0 +1,10 @@
+class PropertyHireSetting
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+ field :auto_approve, type: Boolean, :default => false
+
+ def self.auto_approve_enabled?
+ self.first.auto_approve
+ end
+end
\ No newline at end of file
diff --git a/app/views/admin/property_hires/my_bookings.html.erb b/app/views/admin/property_hires/my_bookings.html.erb
new file mode 100644
index 0000000..84dbb80
--- /dev/null
+++ b/app/views/admin/property_hires/my_bookings.html.erb
@@ -0,0 +1,42 @@
+<%= csrf_meta_tag %>
+
+
+
+
+
+ <% @bookings.each do |p_hire| %>
+
+
+ <%= p_hire.hirer_name %>
+ |
+
+ <%= p_hire.reason_for_hire %>
+ |
+
+ <%= p_hire.hiring_person_number %>
+ |
+
+ <%= p_hire.period %>
+ |
+
+ <% if p_hire.passed %>
+ Yes
+ <% else %>
+ No
+ <% end %>
+ |
+
+ View
+ Delete
+ |
+
+ <% end %>
+
+
+
+ <%= content_tag(:div, paginate(@bookings), class: "pagination pagination-centered") %>
+
\ No newline at end of file
diff --git a/app/views/admin/property_hires/settings.html.erb b/app/views/admin/property_hires/settings.html.erb
new file mode 100644
index 0000000..6e81629
--- /dev/null
+++ b/app/views/admin/property_hires/settings.html.erb
@@ -0,0 +1,40 @@
+<% content_for :page_specific_css do %>
+ <%= stylesheet_link_tag "lib/main-forms" %>
+ <%= stylesheet_link_tag "lib/fileupload" %>
+ <%= stylesheet_link_tag "lib/main-list" %>
+<% end %>
+<% content_for :page_specific_javascript do %>
+ <%= javascript_include_tag "lib/module-area" %>
+<% end %>
+<%= form_for @settings , :url => settings_admin_property_hires_path, html: {class: "form-horizontal main-forms"} do |f| %>
+
+<% end %>
\ 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 abbcabc..55a4a69 100644
--- a/app/views/admin/property_hires/show_booking_details.html.erb
+++ b/app/views/admin/property_hires/show_booking_details.html.erb
@@ -38,7 +38,7 @@
-Back
+Back
<% if can_edit_or_delete?(@booking.property) %>
<% if @booking.passed %>
" class="btn btn-warning">Reject
diff --git a/config/locales/en.yml b/config/locales/en.yml
index a8aa436..0983d75 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -8,6 +8,9 @@ en:
recurring_end_date: Recurring End Date
save: Save
property_hire: Property
+ my_bookings: My Bookings
+ settings: Settings
+ auto_approve: Auto approve
manage_locations: Manage Locations
location: Location
property_count: Property Count
diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml
index 7f32786..79d90d7 100644
--- a/config/locales/zh_tw.yml
+++ b/config/locales/zh_tw.yml
@@ -7,9 +7,12 @@ zh_tw:
week: Week
recurring_end_date: Recurring End Date
save: Save
+ my_bookings: My Bookings
+ settings: Settings
property_hire: Property
manage_locations: Manage Locations
location: Location
+ auto_approve: Auto approve
property_count: Property Count
edit_location: Edit Location
add_location: Add Location
diff --git a/config/routes.rb b/config/routes.rb
index b28d960..76a04a4 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -16,6 +16,9 @@ Rails.application.routes.draw do
delete "delete_booking_details"
end
collection do
+ get "my_bookings"
+ get "settings"
+ patch "settings"
get "manage_locations"
get "add_location"
post "create_location"
diff --git a/lib/property_hire/engine.rb b/lib/property_hire/engine.rb
index 699b0a4..56987a9 100644
--- a/lib/property_hire/engine.rb
+++ b/lib/property_hire/engine.rb
@@ -13,32 +13,38 @@ module PropertyHire
data_count 1..30
side_bar do
head_label_i18n 'property_hire.property_hire', icon_class: "icons-map"
- available_for "managers"
+ available_for "users"
active_for_controllers (['admin/property_hires'])
- head_link_path "admin_property_hires_path"
+ head_link_path "my_bookings_admin_property_hires_path"
+
+ context_link 'property_hire.my_bookings',
+ :link_path=>"my_bookings_admin_property_hires_path" ,
+ :priority=>1,
+ :active_for_action=>{'admin/property_hires'=>"my_bookings"},
+ :available_for => 'users'
context_link 'all',
:link_path=>"admin_property_hires_path" ,
- :priority=>1,
+ :priority=>2,
:active_for_action=>{'admin/property_hires'=>"index"},
- :available_for => 'users'
+ :available_for => 'sub_managers'
context_link 'new_',
:link_path=>"new_admin_property_hire_path" ,
- :priority=>2,
+ :priority=>3,
:active_for_action=>{'admin/property_hires'=>"new"},
:available_for => 'sub_managers'
context_link 'property_hire.manage_locations',
:link_path=>"manage_locations_admin_property_hires_path" ,
- :priority=>2,
+ :priority=>4,
:active_for_action=>{'admin/property_hires'=>"manage_locations"},
:available_for => 'managers'
context_link 'categories',
:link_path=>"admin_module_app_categories_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'property_hire').id}",
- :priority=>3,
+ :priority=>5,
:active_for_action=>{'admin/property_hires'=>'categories'},
:active_for_category => 'PropertyHire',
:available_for => 'managers'
@@ -46,10 +52,16 @@ module PropertyHire
context_link 'tags',
:link_path=>"admin_module_app_tags_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'property_hire').id}",
- :priority=>5,
+ :priority=>6,
:active_for_action=>{'admin/property_hires'=>'tags'},
:active_for_tag => 'PropertyHire',
:available_for => 'managers'
+
+ context_link 'property_hire.settings',
+ :link_path=>"settings_admin_property_hires_path" ,
+ :priority=>7,
+ :active_for_action=>{'admin/property_hires'=>'settings'},
+ :available_for => 'managers'
end
end
end