Files
sx-fc/app/controllers/origami/in_juties_controller.rb
2017-08-30 15:57:15 +06:30

173 lines
6.1 KiB
Ruby

class Origami::InJutiesController < BaseOrigamiController
before_action :set_in_juty, only: %i[show edit update edit_in_juty update_for_in_juty destroy destroy_in_juty]
# GET /in_juties
# GET /in_juties.json
def index
@in_juties = InJuty.all
end
def index_in_juty
@juty_in = InJuty.where('dinning_id=?', params[:table_id])
@table = DiningFacility.find(params[:table_id])
@in_juty = InJuty.new
@juties_in = Kaminari.paginate_array(@juty_in).page(params[:page]).per(10)
end
# GET /in_juties/1
# GET /in_juties/1.json
def show
end
# GET /in_juties/new
def new
# this one use for new
@in_juty = InJuty.new
@table = DiningFacility.find(params[:table_id])
@commissioner = @in_juty.commissioner
render partial: 'form'
end
# GET /in_juties/1/edit
def edit
end
def edit_in_juty
@in_juty = InJuty.find(params[:id])
@table = DiningFacility.find(params[:table_id])
@commissioner = @in_juty.commissioner
# render json: {in_juty: @in_juty, commissioner: @commissioner}
render partial: 'form'
end
def assign_in_juty
@in_juty = InJuty.new
@table = DiningFacility.find(params[:table_id])
end
# POST /in_juties
# POST /in_juties.json
def create
@in_juty = InJuty.new(in_juty_params)
respond_to do |format|
if @in_juty.save
format.html { redirect_to origami_in_juties_path, notice: 'In juty was successfully created.' }
format.json { render :show, status: :created, location: @in_juty }
else
format.html { render :new }
format.json { render json: @in_juty.errors, status: :unprocessable_entity }
end
end
end
def create_for_in_juty
# this one use for create and update
in_juty = in_juty_params
in_time = DateTime.new in_juty['in_time(1i)'].to_i, in_juty['in_time(2i)'].to_i, in_juty['in_time(3i)'].to_i, in_juty['in_time(4i)'].to_i, in_juty['in_time(5i)'].to_i
in_time = in_time.change(offset: '+06:30')
out_time = DateTime.new in_juty['out_time(1i)'].to_i, in_juty['out_time(2i)'].to_i, in_juty['out_time(3i)'].to_i, in_juty['out_time(4i)'].to_i, in_juty['out_time(5i)'].to_i
out_time = out_time.change(offset: '+06:30')
@in_juty = InJuty.new
in_juty_id = in_juty[:id]
unless in_juty_id.nil?
@in_juty = InJuty.find(in_juty_id.to_i)
end
@in_juty.dinning_id = in_juty_params[:dinning_id]
@in_juty.commissioner_ids = in_juty_params[:commissioner_ids]
@in_juty.in_time = in_time
@in_juty.out_time = out_time
respond_to do |format|
if @in_juty.save
if in_juty_id.nil?
format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully created.' }
format.json { render :show, status: :created, location: @in_juty }
else
format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully updated.' }
format.json { render :show, status: :created, location: @in_juty }
end
else
format.html { render :new }
format.json { render json: @in_juty.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /in_juties/1
# PATCH/PUT /in_juties/1.json
def update
in_juty = in_juty_params
in_time = DateTime.new in_juty['in_time(1i)'].to_i, in_juty['in_time(2i)'].to_i, in_juty['in_time(3i)'].to_i, in_juty['in_time(4i)'].to_i, in_juty['in_time(5i)'].to_i
in_time = in_time.change(offset: '+06:30')
out_time = DateTime.new in_juty['out_time(1i)'].to_i, in_juty['out_time(2i)'].to_i, in_juty['out_time(3i)'].to_i, in_juty['out_time(4i)'].to_i, in_juty['out_time(5i)'].to_i
out_time = out_time.change(offset: '+06:30')
@in_juty.commissioner_ids = in_juty_params[:commissioner_ids]
@in_juty.in_time = in_time
@in_juty.out_time = out_time
respond_to do |format|
if @in_juty.save
format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully updated.' }
format.json { render :show, status: :ok, location: @in_juty }
else
format.html { render :edit }
format.json { render json: @in_juty.errors, status: :unprocessable_entity }
end
end
end
def update_for_in_juty
in_juty = in_juty_params
in_time = DateTime.new in_juty['in_time(1i)'].to_i, in_juty['in_time(2i)'].to_i, in_juty['in_time(3i)'].to_i, in_juty['in_time(4i)'].to_i, in_juty['in_time(5i)'].to_i
in_time = in_time.change(offset: '+06:30')
out_time = DateTime.new in_juty['out_time(1i)'].to_i, in_juty['out_time(2i)'].to_i, in_juty['out_time(3i)'].to_i, in_juty['out_time(4i)'].to_i, in_juty['out_time(5i)'].to_i
out_time = out_time.change(offset: '+06:30')
@in_juty.commissioner_ids = in_juty_params[:commissioner_ids]
@in_juty.in_time = in_time
@in_juty.out_time = out_time
respond_to do |format|
if @in_juty.save
format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully updated.' }
format.json { render :show, status: :ok, location: @in_juty }
else
format.html { render :edit }
format.json { render json: @in_juty.errors, status: :unprocessable_entity }
end
end
end
# DELETE /in_juties/1
# DELETE /in_juties/1.json
def destroy
@in_juty.destroy
respond_to do |format|
format.html { redirect_to origami_in_juties_path, notice: 'In juty was successfully removed.' }
format.json { head :no_content }
end
end
def destroy_in_juty
@table_id = params[:table_id]
@in_juty.destroy
respond_to do |format|
format.html { redirect_to origami_index_in_juty_path(@table_id), notice: 'In juty was successfully removed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_in_juty
@in_juty = InJuty.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def in_juty_params
params.require(:in_juty).permit(:id, :dinning_id, :commissioner_ids, :in_time, :out_time)
end
end