class CheckoutTypesController < ApplicationController load_and_authorize_resource before_filter :get_user_group # GET /checkout_types # GET /checkout_types.json def index if @user_group @checkout_types = @user_group.checkout_types.order('checkout_types.position') else @checkout_types = CheckoutType.order(:position) end respond_to do |format| format.html # index.html.erb format.json { render json: @checkout_types } end end # GET /checkout_types/1 # GET /checkout_types/1.json def show if @user_group @checkout_type = @user_group.checkout_types.find(params[:id]) end respond_to do |format| format.html # show.html.erb format.json { render json: @checkout_type } end end # GET /checkout_types/new # GET /checkout_types/new.json def new if @user_group @checkout_type = @user_group.checkout_types.new else @checkout_type = CheckoutType.new end respond_to do |format| format.html # new.html.erb format.json { render json: @checkout_type } end end # GET /checkout_types/1/edit def edit end # POST /checkout_types # POST /checkout_types.json def create if @user_group @checkout_type = @user_group.checkout_types.new(checkout_type_params) else @checkout_type = CheckoutType.new(checkout_type_params) end respond_to do |format| if @checkout_type.save format.html { redirect_to @checkout_type, notice: t('controller.successfully_created', model: t('activerecord.models.checkout_type')) } format.json { render json: @checkout_type, status: :created, location: @checkout_type } else format.html { render action: "new" } format.json { render json: @checkout_type.errors, status: :unprocessable_entity } end end end # PUT /checkout_types/1 # PUT /checkout_types/1.json def update if params[:move] move_position(@checkout_type, params[:move]) return end respond_to do |format| if @checkout_type.update_attributes(checkout_type_params) format.html { redirect_to @checkout_type, notice: t('controller.successfully_updated', model: t('activerecord.models.checkout_type')) } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @checkout_type.errors, status: :unprocessable_entity } end end end # DELETE /checkout_types/1 # DELETE /checkout_types/1.json def destroy if @user_group @checkout_type = @user_group.checkout_types.find(params[:id]) end @checkout_type.destroy respond_to do |format| format.html { redirect_to checkout_types_url } format.json { head :no_content } end end private def checkout_type_params params.require(:checkout_type).permit(:name, :display_name, :note) end end