diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/parking_stalls_controller.rb | 48 | ||||
-rw-r--r-- | app/models/parking_stall.rb | 14 | ||||
-rw-r--r-- | app/models/tenant.rb | 2 | ||||
-rw-r--r-- | app/models/user.rb | 2 | ||||
-rw-r--r-- | app/views/parking_stalls/_form.html.haml | 2 | ||||
-rw-r--r-- | app/views/parking_stalls/_form_core.html.haml | 2 | ||||
-rw-r--r-- | app/views/parking_stalls/_index_core.html.haml | 6 | ||||
-rw-r--r-- | app/views/parking_stalls/index.html.haml | 2 | ||||
-rw-r--r-- | app/views/parking_stalls/show.html.haml | 8 |
9 files changed, 60 insertions, 26 deletions
diff --git a/app/controllers/parking_stalls_controller.rb b/app/controllers/parking_stalls_controller.rb index 42931ed..d1bc0c7 100644 --- a/app/controllers/parking_stalls_controller.rb +++ b/app/controllers/parking_stalls_controller.rb @@ -1,41 +1,69 @@ class ParkingStallsController < ApplicationController + + load_resource :tenant + load_resource :user + load_and_authorize_resource :parking_stall, :through => [:user, :tenant ] + + before_filter :set_and_authorize_parent + before_filter :spread_breadcrumbs + def index - @parking_stalls = ParkingStall.all end def show - @parking_stall = ParkingStall.find(params[:id]) end def new - @parking_stall = ParkingStall.new + @parking_stall.lot = 'default' + @parking_stall.name = ParkingStall.order(:name).last.try(:name).to_i + 1 end def create - @parking_stall = ParkingStall.new(params[:parking_stall]) + @parking_stall = @parent.parking_stalls.build(params[:parking_stall]) if @parking_stall.save - redirect_to @parking_stall, :notice => t('parking_stalls.controller.successfuly_created') + redirect_to [@parent, @parking_stall], :notice => t('parking_stalls.controller.successfuly_created') else render :new end end def edit - @parking_stall = ParkingStall.find(params[:id]) end def update - @parking_stall = ParkingStall.find(params[:id]) if @parking_stall.update_attributes(params[:parking_stall]) - redirect_to @parking_stall, :notice => t('parking_stalls.controller.successfuly_updated') + redirect_to [@parent, @parking_stall], :notice => t('parking_stalls.controller.successfuly_updated') else render :edit end end def destroy - @parking_stall = ParkingStall.find(params[:id]) @parking_stall.destroy - redirect_to parking_stalls_url, :notice => t('parking_stalls.controller.successfuly_destroyed') + m = method( :"#{@parent.class.name.underscore}_parking_stalls_url" ) + redirect_to m.(@parent), :notice => t('parking_stalls.controller.successfuly_destroyed') + end + + private + def set_and_authorize_parent + @parent = @user || @tenant + authorize! :read, @parent + end + + def spread_breadcrumbs + if @user + add_breadcrumb t("users.index.page_title"), tenant_users_path(@user.current_tenant) + add_breadcrumb @user, tenant_user_path(@user.current_tenant, @user) + add_breadcrumb t("parking_stalls.index.page_title"), user_parking_stalls_path(@user) + if @parking_stall && !@parking_stall.new_record? + add_breadcrumb @parking_stall, user_parking_stall_path(@user, @parking_stall) + end + end + if @tenant + add_breadcrumb t("parking_stalls.index.page_title"), tenant_parking_stalls_path(@tenant) + if @parking_stall && !@parking_stall.new_record? + add_breadcrumb @parking_stall, tenant_parking_stall_path(@tenant, @parking_stall) + end + end end end diff --git a/app/models/parking_stall.rb b/app/models/parking_stall.rb index 52223a8..6af1fcd 100644 --- a/app/models/parking_stall.rb +++ b/app/models/parking_stall.rb @@ -1,3 +1,17 @@ class ParkingStall < ActiveRecord::Base attr_accessible :name, :lot, :parking_stallable_id, :parking_stallable_type, :comment + + belongs_to :parking_stallable, :polymorphic => true, :touch => true + + validates :name, + :presence => true, + :uniqueness => true + + validates :lot, + :presence => true + + def to_s + name.to_s + end + end diff --git a/app/models/tenant.rb b/app/models/tenant.rb index 419ac3a..0622f52 100644 --- a/app/models/tenant.rb +++ b/app/models/tenant.rb @@ -39,6 +39,8 @@ class Tenant < ActiveRecord::Base has_many :automatic_call_distributors, :as => :automatic_call_distributorable, :dependent => :destroy has_many :acd_agents, :through => :automatic_call_distributors + has_many :parking_stalls, :as => :parking_stallable, :dependent => :destroy + # Phone numbers of the tenant. # has_many :phone_number_ranges_phone_numbers, :through => :phone_number_ranges, :source => :phone_numbers, :readonly => true diff --git a/app/models/user.rb b/app/models/user.rb index afb3f04..fdcd617 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -87,6 +87,8 @@ class User < ActiveRecord::Base validate :current_tenant_is_included_in_tenants, :if => Proc.new{ |user| user.current_tenant_id } belongs_to :gs_node + + has_many :parking_stalls, :as => :parking_stallable, :dependent => :destroy # Avatar like photo mount_uploader :image, ImageUploader diff --git a/app/views/parking_stalls/_form.html.haml b/app/views/parking_stalls/_form.html.haml index 5b1523b..60b60b7 100644 --- a/app/views/parking_stalls/_form.html.haml +++ b/app/views/parking_stalls/_form.html.haml @@ -1,4 +1,4 @@ -= simple_form_for(@parking_stall) do |f| += simple_form_for([@parent, @parking_stall]) do |f| = f.error_notification = render "form_core", :f => f diff --git a/app/views/parking_stalls/_form_core.html.haml b/app/views/parking_stalls/_form_core.html.haml index db68f99..add5c53 100644 --- a/app/views/parking_stalls/_form_core.html.haml +++ b/app/views/parking_stalls/_form_core.html.haml @@ -1,6 +1,4 @@ .inputs = f.input :name, :label => t('parking_stalls.form.name.label'), :hint => conditional_hint('parking_stalls.form.name.hint') = f.input :lot, :label => t('parking_stalls.form.lot.label'), :hint => conditional_hint('parking_stalls.form.lot.hint') - = f.input :parking_stallable_id, :label => t('parking_stalls.form.parking_stallable_id.label'), :hint => conditional_hint('parking_stalls.form.parking_stallable_id.hint') - = f.input :parking_stallable_type, :label => t('parking_stalls.form.parking_stallable_type.label'), :hint => conditional_hint('parking_stalls.form.parking_stallable_type.hint') = f.input :comment, :label => t('parking_stalls.form.comment.label'), :hint => conditional_hint('parking_stalls.form.comment.hint') diff --git a/app/views/parking_stalls/_index_core.html.haml b/app/views/parking_stalls/_index_core.html.haml index fb317a0..9f25217 100644 --- a/app/views/parking_stalls/_index_core.html.haml +++ b/app/views/parking_stalls/_index_core.html.haml @@ -2,8 +2,6 @@ %tr %th= t('parking_stalls.index.name') %th= t('parking_stalls.index.lot') - %th= t('parking_stalls.index.parking_stallable_id') - %th= t('parking_stalls.index.parking_stallable_type') %th= t('parking_stalls.index.comment') @@ -11,7 +9,5 @@ %tr %td= parking_stall.name %td= parking_stall.lot - %td= parking_stall.parking_stallable_id - %td= parking_stall.parking_stallable_type %td= parking_stall.comment - =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => parking_stall}
\ No newline at end of file + =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => parking_stall.parking_stallable, :child => parking_stall}
\ No newline at end of file diff --git a/app/views/parking_stalls/index.html.haml b/app/views/parking_stalls/index.html.haml index 9472ff0..7f82bbe 100644 --- a/app/views/parking_stalls/index.html.haml +++ b/app/views/parking_stalls/index.html.haml @@ -3,4 +3,4 @@ - if @parking_stalls && @parking_stalls.count > 0 = render "index_core", :parking_stalls => @parking_stalls -= render :partial => 'shared/create_link', :locals => {:child_class => ParkingStall}
\ No newline at end of file += render :partial => 'shared/create_link', :locals => {:parent => @parent, :child_class => ParkingStall}
\ No newline at end of file diff --git a/app/views/parking_stalls/show.html.haml b/app/views/parking_stalls/show.html.haml index a95c111..583a0ee 100644 --- a/app/views/parking_stalls/show.html.haml +++ b/app/views/parking_stalls/show.html.haml @@ -7,13 +7,7 @@ %strong= t('parking_stalls.show.lot') + ":" = @parking_stall.lot %p - %strong= t('parking_stalls.show.parking_stallable_id') + ":" - = @parking_stall.parking_stallable_id -%p - %strong= t('parking_stalls.show.parking_stallable_type') + ":" - = @parking_stall.parking_stallable_type -%p %strong= t('parking_stalls.show.comment') + ":" = @parking_stall.comment -= render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @parking_stall }
\ No newline at end of file += render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @parking_stall.parking_stallable, :child => @parking_stall } |