forked from saurabh/orbit4-5
96 lines
2.2 KiB
Ruby
96 lines
2.2 KiB
Ruby
class Admin::RolesController < OrbitMemberController
|
|
before_action :set_role, only: [:show, :edit , :update, :destroy]
|
|
before_action :set_attribute, only: [:role_field]
|
|
helper Admin::AttributeValuesViewHelper
|
|
|
|
def index
|
|
@roles = Role.all.asc("_id").entries
|
|
end
|
|
|
|
def show
|
|
end
|
|
|
|
def new
|
|
@role = Role.new
|
|
render layout: false
|
|
end
|
|
|
|
def edit
|
|
render layout: false
|
|
end
|
|
|
|
def create
|
|
@role = Role.new(role_params)
|
|
if @role.save
|
|
redirect_to admin_roles_url
|
|
else
|
|
@role = Role.new(role_params)
|
|
flash.now[:error] = t('create.error.category')
|
|
render action: :new
|
|
end
|
|
end
|
|
|
|
def update
|
|
if params[:role][:attribute_fields]
|
|
role_params[:attribute_fields].each do |a|
|
|
@field_name = 'role'
|
|
field_status = a.last[:id].present?
|
|
@attribute_field = AttributeField.add_attribute_field(@role, a.last, a.last[:id], field_status)
|
|
@attribute = @role
|
|
end
|
|
flash.now[:notice] = "Updated Fields"
|
|
@role.attribute_fields.each{|t| t.destroy if t["to_delete"] == true}
|
|
respond_to do |format|
|
|
format.js { render 'add_attribute_field' }
|
|
end
|
|
else
|
|
if @role.update_attributes(role_params)
|
|
@role.attribute_fields.each{|t| t.destroy if t["to_delete"] == true}
|
|
redirect_to admin_roles_url
|
|
else
|
|
flash.now[:error] = t('update.error.category')
|
|
render action: :edit
|
|
end
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@role.destroy
|
|
respond_to do |format|
|
|
format.html { redirect_to admin_roles_url }
|
|
format.js { render 'admin/roles/destroy' }
|
|
end
|
|
end
|
|
|
|
def toggle
|
|
@role = Role.find(params[:role_id])
|
|
@role.disabled = @role.disabled ? false : true
|
|
@role.save!
|
|
redirect_to action: :index
|
|
end
|
|
|
|
def role_field
|
|
@field_name = 'role'
|
|
@attribute = Role.find(params[:role_id])
|
|
end
|
|
|
|
private
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
def set_role
|
|
@role = Role.find(params[:id])
|
|
end
|
|
|
|
# Never trust parameters from the scary internet, only allow the white list through.
|
|
def role_params
|
|
params.require(:role).permit!
|
|
end
|
|
|
|
protected
|
|
|
|
def set_attribute
|
|
@attribute_type = 'role'
|
|
@class = 'roles'
|
|
end
|
|
|
|
end
|