Sha256: e66b295a4689d1e0c881c0ad06c43298f4cdc9d955691cf89650369279df835f

Contents?: true

Size: 1.83 KB

Versions: 33

Compression:

Stored size: 1.83 KB

Contents

module CabooseStore
  class VendorsController < CabooseStore::ApplicationController
    
    # GET /admin/vendors/status-options
    def status_options
      options = Array.new
      
      ['Active', 'Inactive', 'Deleted'].each do |status|
        options << {
          :text  => status,
          :value => status
        }
      end
      
      render :json => options
    end
    
    # GET /admin/vendors/new
    def admin_new
      render :layout => 'caboose/admin'
    end
    
    # POST /admin/vendors/create
    def admin_create
      render :json => { :success => false, :message => 'Must define a name' } and return if params[:name].nil? || params[:name].empty?
      
      vendor        = Vendor.new
      vendor.name   = params[:name]
      vendor.status = 'Inactive'
      
      render :json => { :success => vendor.save, :redirect => "/admin/vendors/#{vendor.id}/edit" }
    end
    
    # GET /admin/vendors
    def admin_index
      @pager = Caboose::Pager.new(params, {
        'name_like' => ''
      }, {
        'model'          => 'CabooseStore::Vendor',
        'sort'           => 'name',
        'desc'           => false,
        'base_url'       => '/admin/vendors',
        'items_per_page' => 25,
        'use_url_params' => false
      });
      
      @vendors = @pager.items
      
      render :layout => 'caboose/admin'
    end
    
    # GET /admin/vendors/:id/edit
    def admin_edit
      @vendor = Vendor.find(params[:id])
      render :layout => 'caboose/admin'
    end
    
    # PUT /admin/vendors/:id/update
    def admin_update
      vendor = Vendor.find(params[:id])
      
      params.each do |name, value|
        case name
          when 'name'   then vendor.name   = value
          when 'status' then vendor.status = value
        end
      end
      
      render :json => { :success => vendor.save }
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
caboose-store-0.0.23 app/controllers/caboose_store/vendors_controller.rb
caboose-store-0.0.22 app/controllers/caboose_store/vendors_controller.rb
caboose-store-0.0.21 app/controllers/caboose_store/vendors_controller.rb
caboose-store-0.0.20 app/controllers/caboose_store/vendors_controller.rb
caboose-store-0.0.19 app/controllers/caboose_store/vendors_controller.rb
caboose-store-0.0.18 app/controllers/caboose_store/vendors_controller.rb
caboose-store-0.0.17 app/controllers/caboose_store/vendors_controller.rb
caboose-store-0.0.16 app/controllers/caboose_store/vendors_controller.rb
caboose-store-0.0.15 app/controllers/caboose_store/vendors_controller.rb
caboose-store-0.0.14 app/controllers/caboose_store/vendors_controller.rb
caboose-store-0.0.13 app/controllers/caboose_store/vendors_controller.rb
caboose-store-0.0.12 app/controllers/caboose_store/vendors_controller.rb
caboose-store-0.0.11 app/controllers/caboose_store/vendors_controller.rb