This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/app/controllers/admin/roles_controller.rb

194 lines
4.0 KiB
Ruby
Raw Normal View History

class Admin::RolesController < OrbitBackendController
2011-12-23 10:34:21 +00:00
2012-11-22 10:20:11 +00:00
layout "new_admin"
2011-12-23 10:34:21 +00:00
before_filter :authenticate_user!
before_filter :is_admin?
2013-01-08 08:58:01 +00:00
before_filter :set_attribute, :only => [:index, :show, :new, :edit, :role_field, :sub_role, :add_sub_role, :edit_sub_role, :sub_role_field]
2012-11-22 10:20:11 +00:00
helper Admin::AttributeValuesViewHelper
2012-11-26 02:08:06 +00:00
2011-12-23 10:34:21 +00:00
def index
@attributes = Role.all.entries
render :template => 'admin/attributes/index'
end
def show
2013-01-08 08:58:01 +00:00
end
def role_field
@field_name = 'role'
2013-01-08 08:58:01 +00:00
@attribute = Role.find(params[:role_id])
2013-01-08 08:58:01 +00:00
end
def sub_role
@attribute = Role.find(params[:role_id])
@attribute_fields_upper_object = @attribute.sub_roles
2013-01-08 08:58:01 +00:00
end
def add_sub_role
@attribute = Role.find(params[:role_id])
# @sub_attribute = Role.find(params[:role_id])
2013-01-08 08:58:01 +00:00
@sub_attribute = SubRole.new
2013-01-08 08:58:01 +00:00
@sub_attribute.role_id = params[:role_id]
end
def edit_sub_role
@sub_attribute = SubRole.find(params[:role_id])
2013-01-08 08:58:01 +00:00
@attribute = Role.find(@sub_attribute.role_id)
2013-01-08 08:58:01 +00:00
@sub_attribute.role_id = @sub_attribute.role_id
end
def sub_role_field
@field_name = 'sub_role'
@sub_attribute = SubRole.find(params[:role_id])
2013-01-08 08:58:01 +00:00
@attribute = Role.find(@sub_attribute.role_id)
2013-01-08 08:58:01 +00:00
end
def add_attribute_field
if params[:sub_role]
2013-01-08 08:58:01 +00:00
@field_name = 'sub_role'
2013-01-08 08:58:01 +00:00
attribute = SubRole.find(params[:sub_role][:id]) rescue nil
@attribute_field_counter = attribute.attribute_fields.count
@attribute_field = attribute.attribute_fields.build
@attribute_field.save
2013-01-08 08:58:01 +00:00
@attribute_field[:af_count] = @attribute_field_counter
2013-01-08 08:58:01 +00:00
@attribute = SubRole.find(params[:sub_role][:id])
2013-01-08 08:58:01 +00:00
else
2013-01-08 08:58:01 +00:00
@field_name = 'role'
2013-01-08 08:58:01 +00:00
attribute = Role.find(params[:role_id]) rescue nil
@attribute_field_counter = attribute.attribute_fields.count
@attribute_field = attribute.attribute_fields.build
@attribute_field.save
2013-01-08 08:58:01 +00:00
@attribute_field[:af_count] = @attribute_field_counter
2013-01-08 08:58:01 +00:00
@attribute = Role.find(params[:role_id])
2013-01-08 08:58:01 +00:00
end
2013-01-08 08:58:01 +00:00
respond_to do |format|
2013-01-08 08:58:01 +00:00
format.js { render 'add_attribute_field' }
end
2013-01-08 08:58:01 +00:00
2011-12-23 10:34:21 +00:00
end
def new
@attribute = Role.new
2013-01-08 08:58:01 +00:00
if !params[:parent_id]
2013-01-08 08:58:01 +00:00
render :template => 'admin/attributes/new'
end
2011-12-23 10:34:21 +00:00
end
def edit
@attribute = Role.find(params[:id])
2012-11-26 02:08:06 +00:00
@attribute_fields_upper_object = @attribute.sub_roles
2011-12-23 10:34:21 +00:00
render :template => 'admin/attributes/edit'
end
def create
2013-01-08 08:58:01 +00:00
if params[:sub_role]
@sub_role = SubRole.new(params[:sub_role])
# @sub_role.role_id = params[:id]
respond_to do |format|
if @sub_role.save
format.html { redirect_to(admin_role_sub_role_url(params[:sub_role][:role_id])) }
end
end
else
@attribute = Role.new(params[:role])
@attribute.save
redirect_to :action => :index
end
2011-12-23 10:34:21 +00:00
end
def update
2013-01-08 08:58:01 +00:00
if params[:sub_role]
@sub_role = SubRole.find(params[:sub_role][:id])
@sub_role.update_attributes(params[:sub_role])
@sub_role.attribute_fields.each{|t| t.destroy if t["to_delete"] == true}
respond_to do |format|
format.html { redirect_to(admin_role_sub_role_url(@sub_role.role_id)) }
format.js { render 'toggle_enable' }
end
else
@attribute = Role.find(params[:id])
@attribute.update_attributes(params[:role])
@attribute.attribute_fields.each{|t| t.destroy if t["to_delete"] == true}
respond_to do |format|
format.html { redirect_to :action => :index }
format.js { render 'admin/attributes/toggle_enable' }
end
2011-12-23 10:34:21 +00:00
end
2013-01-08 08:58:01 +00:00
2011-12-23 10:34:21 +00:00
end
def destroy
2013-01-08 08:58:01 +00:00
if params[:sub_role]
2013-01-08 08:58:01 +00:00
@sub_role = SubRole.find(params[:sub_role][:id])
2013-01-08 08:58:01 +00:00
respond_to do |format|
if @sub_role.destroy
format.html { redirect_to(admin_role_sub_role_url(@sub_role.role_id)) }
2013-01-08 08:58:01 +00:00
end
end
else
2013-01-08 08:58:01 +00:00
@attribute = Role.find(params[:id])
@attribute.destroy
redirect_to :action => :index
end
2011-12-23 10:34:21 +00:00
end
protected
def set_attribute
@attribute_type = 'role'
@class = 'roles'
end
end