added auto approve and users can delete the entries

This commit is contained in:
Harry Bomrah 2018-02-05 17:15:50 +08:00
parent 610f824628
commit 849cf2e680
10 changed files with 152 additions and 10 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,42 @@
<%= csrf_meta_tag %>
<table class="table main-list">
<thead>
<tr class="sort-header">
<% @table_fields.each do |f| %>
<%= thead(f) %>
<% end %>
</tr>
</thead>
<tbody>
<% @bookings.each do |p_hire| %>
<tr>
<td>
<%= p_hire.hirer_name %>
</td>
<td>
<%= p_hire.reason_for_hire %>
</td>
<td>
<%= p_hire.hiring_person_number %>
</td>
<td>
<%= p_hire.period %>
</td>
<td>
<% if p_hire.passed %>
<span class="badge badge-success">Yes</span>
<% else %>
<span class="badge badge-important">No</span>
<% end %>
</td>
<td>
<a href="<%= show_booking_details_admin_property_hire_path(p_hire, :page => params[:page]) %>" class="btn btn-info">View</a>
<a href="<%= delete_booking_details_admin_property_hire_path(p_hire, :page => params[:page]) %>" class="btn btn-danger" data-method="delete" data-confirm="Are you sure?">Delete</a>
</td>
</tr>
<% end %>
</tbody>
</table>
<div class="bottomnav clearfix">
<%= content_tag(:div, paginate(@bookings), class: "pagination pagination-centered") %>
</div>

View File

@ -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| %>
<fieldset>
<% if @saved %>
<div class="alert alert-success">Settings saved.</div>
<% end %>
<!-- Input Area -->
<div class="input-area">
<!-- Module Tabs -->
<div class="nav-name"><strong><%= t(:module) %></strong></div>
<ul class="nav nav-pills module-nav">
<li class="active"><a href="#basic" data-toggle="tab"><%= t(:basic) %></a></li>
</ul>
<!-- Module -->
<div class="tab-content module-area">
<!-- Basic Module -->
<div class="tab-pane fade in active" id="basic">
<div class="control-group">
<%= f.label :auto_approve, t("property_hire.auto_approve"), :class => "control-label muted" %>
<div class="controls">
<%= f.check_box :auto_approve %>
</div>
</div>
</div>
</div>
</div>
<!-- Form Actions -->
<div class="form-actions">
<%= f.submit t('submit'), class: 'btn btn-primary' %>
</div>
</fieldset>
<% end %>

View File

@ -38,7 +38,7 @@
</tr>
</tbody>
</table>
<a href="<%= admin_property_hire_path(@booking.property, :page => params[:page]) %>" class="btn btn-warning">Back</a>
<a href="" onclick="window.history.back();return false;" class="btn btn-warning">Back</a>
<% if can_edit_or_delete?(@booking.property) %>
<% if @booking.passed %>
<a href="<%= pass_booking_admin_property_hire_path(@booking, :status => "reject") %>" class="btn btn-warning">Reject</a>

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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