91 lines
2.6 KiB
Ruby
91 lines
2.6 KiB
Ruby
class CompanyActivitiesController < ApplicationController
|
|
before_action :authenticate_user!
|
|
include ApplicationHelper
|
|
before_action :check_access
|
|
before_action :set_company_activity, only: %i[show edit update destroy]
|
|
|
|
def check_access
|
|
redirect_to not_found unless role?('company_activities')
|
|
end
|
|
|
|
# GET /company_activities or /company_activities.json
|
|
def index
|
|
@company_activities = CompanyActivity.all
|
|
end
|
|
|
|
# GET /company_activities/1 or /company_activities/1.json
|
|
def show; end
|
|
|
|
# GET /company_activities/new
|
|
def new
|
|
@company_activity = CompanyActivity.new
|
|
end
|
|
|
|
# GET /company_activities/1/edit
|
|
def edit; end
|
|
|
|
# POST /company_activities or /company_activities.json
|
|
def create
|
|
@company_activity = CompanyActivity.new(company_activity_params)
|
|
|
|
respond_to do |format|
|
|
if @company_activity.save
|
|
format.html { redirect_to company_activities_url, notice: 'Utworzono pomyślnie.' }
|
|
format.json { render :show, status: :created, location: @company_activity }
|
|
else
|
|
format.html { render :new, status: :unprocessable_entity }
|
|
format.json { render json: @company_activity.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# PATCH/PUT /company_activities/1 or /company_activities/1.json
|
|
def update
|
|
respond_to do |format|
|
|
if @company_activity.update(company_activity_params)
|
|
format.html { redirect_to company_activities_url, notice: 'Zaktualizowano pomyślnie.' }
|
|
format.json { render :show, status: :ok, location: @company_activity }
|
|
else
|
|
format.html { render :edit, status: :unprocessable_entity }
|
|
format.json { render json: @company_activity.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# DELETE /company_activities/1 or /company_activities/1.json
|
|
def destroy
|
|
@company_activity.destroy
|
|
|
|
respond_to do |format|
|
|
format.html { redirect_to company_activities_url, notice: 'Usunięto pomyślnie.' }
|
|
format.json { head :no_content }
|
|
end
|
|
end
|
|
|
|
def chg_prio
|
|
par = params[:ord].tr('sort_', '')
|
|
parray = par.split(',')
|
|
temp_i = 1
|
|
parray.each do |pa|
|
|
exp = CompanyActivity.where(id: pa).first
|
|
next if exp.blank?
|
|
|
|
exp.prio = temp_i
|
|
exp.save
|
|
temp_i += 1
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
def set_company_activity
|
|
@company_activity = CompanyActivity.find(params[:id])
|
|
end
|
|
|
|
# Only allow a list of trusted parameters through.
|
|
def company_activity_params
|
|
params.require(:company_activity).permit(:name, :description)
|
|
end
|
|
end
|