member roles edit
This commit is contained in:
1 parent
4e2cbac027
commit
84e4a558be
22 files changed
+975
-139
No files matched your search
@@ -3,7 +3,7 @@ class Admin::RolesController < ApplicationController
|
||||
layout "new_admin"
|
||||
before_filter :authenticate_user!
|
||||
before_filter :is_admin?
|
||||
before_filter :set_attribute, :only => [:index, :show, :new, :edit]
|
||||
before_filter :set_attribute, :only => [:index, :show, :new, :edit, :role_field, :sub_role, :add_sub_role, :edit_sub_role, :sub_role_field]
|
||||
helper Admin::AttributeValuesViewHelper
|
||||
|
||||
def index
|
||||
@@ -13,11 +13,98 @@ class Admin::RolesController < ApplicationController
|
||||
|
||||
def show
|
||||
|
||||
end
|
||||
|
||||
def role_field
|
||||
|
||||
@field_name = 'role'
|
||||
|
||||
@attribute = Role.find(params[:role_id])
|
||||
|
||||
end
|
||||
|
||||
def sub_role
|
||||
|
||||
@attribute = Role.find(params[:role_id])
|
||||
@attribute_fields_upper_object = @attribute.sub_roles
|
||||
|
||||
|
||||
end
|
||||
|
||||
def add_sub_role
|
||||
|
||||
@attribute = Role.find(params[:role_id])
|
||||
# @sub_attribute = Role.find(params[:role_id])
|
||||
|
||||
@sub_attribute = SubRole.new
|
||||
@sub_attribute.role_id = params[:role_id]
|
||||
|
||||
end
|
||||
|
||||
def edit_sub_role
|
||||
|
||||
@sub_attribute = SubRole.find(params[:role_id])
|
||||
|
||||
@attribute = Role.find(@sub_attribute.role_id)
|
||||
|
||||
@sub_attribute.role_id = @sub_attribute.role_id
|
||||
|
||||
end
|
||||
|
||||
def sub_role_field
|
||||
|
||||
@field_name = 'sub_role'
|
||||
|
||||
@sub_attribute = SubRole.find(params[:role_id])
|
||||
|
||||
@attribute = Role.find(@sub_attribute.role_id)
|
||||
|
||||
end
|
||||
|
||||
def add_attribute_field
|
||||
|
||||
if params[:sub_role]
|
||||
|
||||
@field_name = 'sub_role'
|
||||
|
||||
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
|
||||
|
||||
@attribute_field[:af_count] = @attribute_field_counter
|
||||
|
||||
@attribute = SubRole.find(params[:sub_role][:id])
|
||||
|
||||
else
|
||||
|
||||
@field_name = 'role'
|
||||
|
||||
attribute = Role.find(params[:role_id]) rescue nil
|
||||
@attribute_field_counter = attribute.attribute_fields.count
|
||||
@attribute_field = attribute.attribute_fields.build
|
||||
@attribute_field.save
|
||||
|
||||
@attribute_field[:af_count] = @attribute_field_counter
|
||||
|
||||
@attribute = Role.find(params[:role_id])
|
||||
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.js { render 'add_attribute_field' }
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
def new
|
||||
@attribute = Role.new
|
||||
render :template => 'admin/attributes/new'
|
||||
|
||||
if !params[:parent_id]
|
||||
render :template => 'admin/attributes/new'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def edit
|
||||
@@ -27,24 +114,75 @@ class Admin::RolesController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
@attribute = Role.new(params[:role])
|
||||
@attribute.save
|
||||
redirect_to :action => :index
|
||||
|
||||
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
|
||||
|
||||
end
|
||||
|
||||
def update
|
||||
@attribute = Role.find(params[:id])
|
||||
@attribute.update_attributes(params[:role])
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :action => :index }
|
||||
format.js { render 'admin/attributes/toggle_enable' }
|
||||
|
||||
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
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def destroy
|
||||
@attribute = Role.find(params[:id])
|
||||
@attribute.destroy
|
||||
redirect_to :action => :index
|
||||
|
||||
if params[:sub_role]
|
||||
|
||||
@sub_role = SubRole.find(params[:sub_role][:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @sub_role.destroy
|
||||
format.html { redirect_to(admin_role_sub_role_url(@sub_role.role_id)) }
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
@attribute = Role.find(params[:id])
|
||||
@attribute.destroy
|
||||
redirect_to :action => :index
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
class Admin::SubRolesController < RolesController
|
||||
|
||||
|
||||
end
|
||||
Reference in new issue
Block a user