Class: Admin::SuppliersController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/admin/suppliers_controller.rb

Instance Method Summary collapse

Instance Method Details

#availableObject



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/admin/suppliers_controller.rb', line 81

def available
  if params[:q].blank?
    @available_suppliers = []
  else
    @available_suppliers = Supplier.find(:all, :conditions => ['lower(name) LIKE ?', "%#{params[:q].downcase}%"])
  end
  @available_suppliers.delete_if { |supplier| @product.supplier == supplier }
  respond_to do |format|
    format.html
    format.js {render :layout => false}
  end

end

#createObject



19
20
21
22
23
24
25
26
# File 'app/controllers/admin/suppliers_controller.rb', line 19

def create
  @supplier = Supplier.new(params[:supplier])
  if @supplier.save
    redirect_to admin_suppliers_path, :notice => "New supplier created"
  else
    render "new"
  end
end

#destroyObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/admin/suppliers_controller.rb', line 37

def destroy
  @supplier = Supplier.find(params[:id])
  @supplier.destroy
  flash[:notice] = "Supplier Successfully deleted."
  respond_with(@product) do |format|
    format.html { redirect_to collection_url }
    format.js do
      render :update do |page|
        page.redirect_to collection_url
      end
    end
  end
end

#editObject



32
33
34
35
# File 'app/controllers/admin/suppliers_controller.rb', line 32

def edit
  @supplier = Supplier.find(params[:id])
  @supplier.images.build
end

#featureObject



61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/admin/suppliers_controller.rb', line 61

def feature
  @supplier = Supplier.find(params[:supplier_id])
  if @supplier.featured == true
    @supplier.featured = false
  else
    @supplier.featured = true
  end
  @supplier.save
  flash[:notice] = "change #{@supplier.title}'s feature status to #{@supplier.featured}"
  redirect_to admin_suppliers_path
end

#indexObject



5
6
7
8
9
10
11
# File 'app/controllers/admin/suppliers_controller.rb', line 5

def index
  if current_user.has_role?("admin")
    @suppliers = Supplier.all
  else
    @supplier = current_user.supplier
  end
end

#line_itemsObject



73
74
75
# File 'app/controllers/admin/suppliers_controller.rb', line 73

def line_items
  @order = Order.find_by_number(params[:order_id])
end

#newObject



13
14
15
16
17
# File 'app/controllers/admin/suppliers_controller.rb', line 13

def new
  @supplier = Supplier.new()
  @supplier.images.build
  @status = true
end

#removeObject



95
96
97
98
99
100
# File 'app/controllers/admin/suppliers_controller.rb', line 95

def remove
  @product.supplier = nil
  @product.save
  @supplier = @product.supplier
  render :layout => false
end

#selectObject



102
103
104
105
106
107
108
# File 'app/controllers/admin/suppliers_controller.rb', line 102

def select
  @supplier = Supplier.find_by_param!(params[:id])
  @product.supplier = @supplier
  @product.save
  @supplier = @product.supplier
  render :layout => false
end

#selectedObject



77
78
79
# File 'app/controllers/admin/suppliers_controller.rb', line 77

def selected
  @supplier = @product.supplier
end

#showObject



28
29
30
# File 'app/controllers/admin/suppliers_controller.rb', line 28

def show
  @supplier = Supplier.find(params[:id])
end

#updateObject



51
52
53
54
55
56
57
58
59
# File 'app/controllers/admin/suppliers_controller.rb', line 51

def update
  @supplier = Supplier.find(params[:id])
  @status = false
  if @supplier.update_attributes(params[:supplier])
    redirect_to edit_admin_supplier_path, :notice => "Supplier updated"
  else
    render "edit"
  end
end