blob: a8a1636c7474765188bad6edb625e08378c75788 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
require 'will_paginate/array'
require 'open-uri'
class ImportsController < ChouetteController
defaults :resource_class => Import
respond_to :html, :only => [:show, :index, :destroy, :imported_file]
respond_to :js, :only => [:show, :index]
belongs_to :referential
def index
begin
index! do
build_breadcrumb :index
end
rescue Ievkit::Error => error
logger.error("Iev failure : #{error.message}")
flash[:error] = t('iev.failure')
redirect_to referential_path(@referential)
end
end
def show
begin
show! do
build_breadcrumb :show
end
rescue Ievkit::Error => error
logger.error("Iev failure : #{error.message}")
flash[:error] = t('iev.failure')
redirect_to referential_path(@referential)
end
end
def destroy
begin
destroy!
rescue Ievkit::Error => error
logger.error("Iev failure : #{error.message}")
flash[:error] = t('iev.failure')
redirect_to referential_path(@referential)
end
end
def imported_file
begin
send_file open(resource.file_path), { :type => "application/#{resource.filename_extension}", :disposition => "attachment", :filename => resource.filename }
rescue Ievkit::Error => error
logger.error("Iev failure : #{error.message}")
flash[:error] = t('iev.failure')
redirect_to referential_path(@referential)
end
end
protected
alias_method :import, :resource
def import_service
ImportService.new(@referential)
end
def resource
@import ||= import_service.find( params[:id] )
end
def collection
@imports ||= import_service.all.paginate(:page => params[:page])
end
end
|