| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- class WarehousesController < ApplicationController
- ##--- Abilities
- load_and_authorize_resource
- ##--- Breadcrum_rails
- add_breadcrumb I18n.t("breadcrumbs." + controller_name), :warehouses_path
- add_breadcrumb "Nuevo Almacén ", :new_warehouse_path, only: :new
- add_breadcrumb "Editar Almacén", :edit_warehouse_path, only: :edit
- before_action :set_warehouse, only: [:show, :edit, :update, :destroy]
- before_action :get_filters, only: [:index, :show, :edit, :new]
- # GET /warehouses
- # GET /warehouses.json
- def index
- @warehouses = Warehouse.all
- end
- # GET /warehouses/1
- # GET /warehouses/1.json
- def show; end
- # GET /warehouses/new
- def new
- @warehouse = Warehouse.new
- end
- # GET /warehouses/1/edit
- def edit; end
- # POST /warehouses
- # POST /warehouses.json
- def create
- @warehouse = Warehouse.new(warehouse_params)
- @warehouse.prefix.upcase!
- respond_to do |format|
- message = "Almacén #{@warehouse.name} creado."
- @warehouse.audit_comment = message
- if @warehouse.save
- format.js
- else
- format.html { render :new }
- format.js
- format.json { render json: @warehouse.errors, status: :unprocessable_entity }
- end
- end
- end
- # PATCH/PUT /warehouses/1
- # PATCH/PUT /warehouses/1.json
- def update
- respond_to do |format|
- message = "Almacén #{@warehouse.name} modificado."
- @warehouse.audit_comment = message
- if @warehouse.update(warehouse_params)
- format.js
- else
- format.html { render :edit }
- format.js
- format.json { render json: @warehouse.errors, status: :unprocessable_entity }
- end
- end
- end
- # DELETE /warehouses/1
- # DELETE /warehouses/1.json
- def destroy
- message = "Almacén #{@warehouse.name} eliminado."
- @warehouse.audit_comment = message
- @warehouse.destroy
- respond_to do |format|
- format.html { redirect_to warehouses_url, notice: message }
- format.json { head :no_content }
- end
- end
- def update_status
- warehouse = Warehouse.find(params[:warehouse_id])
- warehouse.status =
- if warehouse.active?
- "inactive"
- elsif warehouse.inactive?
- "active"
- end
- respond_to do |format|
- message = "El almacen " + warehouse.name + " fue " + (warehouse.active? ? "activado" : "desactivado") + "."
- warehouse.audit_comment = message
- if warehouse.save(validate: false)
- format.html { redirect_to warehouses_path, warning: message }
- format.json { head :no_content }
- else
- format.html { redirect_to warehouses_path }
- format.json { render json: warehouse.errors, status: :unprocessable_entity }
- end
- end
- end
- private
- # Use callbacks to share common setup or constraints between actions.
- def set_warehouse
- @warehouse = Warehouse.find(params[:id])
- end
- def get_filters
- @current_page =
- if params[:current_page].blank?
- 1
- else
- params[:current_page]
- end
- @filter = params[:filter]
- end
- # Never trust parameters from the scary internet, only allow the white list through.
- def warehouse_params
- params.require(:warehouse).permit(:name, :status, :prefix)
- end
- end
|