class UserGroupsController < ApplicationController
    before_filter :check_access, :set_locale  
    def create
       UserGroup.create(:name_rus => params[:group][:name_rus])
       redirect_to settings_user_groups_path
    end 
    def edit
       @group=UserGroup.find(params[:id])
    end
    def update_access
       @group_id=params[:id]
       @access=JSON.parse(params[:settings])
       @access.each do |menu|
                if menu["status"] == false
                    UserAccess.where(:menu_id => menu["id"]).where(:user_group_id => @group_id).destroy_all
                else
                   if UserAccess.where(:menu_id => menu["id"]).where(:user_group_id => @group_id).count == 0; UserAccess.create(:menu_id => menu["id"],:user_group_id => @group_id);end
                end
       end
       render :text => 'ok'
    end
    def destroy
        group_id=UserGroup.find(params[:id])
        group_id.destroy
        redirect_to settings_user_groups_path
    end
end
