OSDN Git Service

t#30328:pull porting
[pettanr/pettanr.git] / app / controllers / provider_statuses_controller.rb
1 class ProviderStatusesController < ApplicationController
2   layout 'test' if MagicNumber['test_layout']
3   before_filter :authenticate_admin!, :only => [:index, :show, :edit, :update, :destroy, :licenses_import, :artists_import, :original_pictures_import]
4   
5   private
6   
7   def licenses_port
8     licenses = export_by('licenses_export', @provider_status, params[:date])
9     return nil unless licenses
10     ProviderLicense.import @provider_status.provider.id, licenses
11   end
12   
13   def artists_port
14     artists = export_by('artists_export', @provider_status, params[:date])
15     return nil unless artists
16     ProviderArtist.import @provider_status.provider.id, artists
17   end
18   
19   def original_pictures_port
20     original_pictures = export_by('original_pictures_export', @provider_status, params[:date])
21     return nil unless original_pictures
22     pictures = export_by('pictures_export', @provider_status, params[:date])
23     return nil unless pictures
24     ProviderOriginalPicture.import @provider_status.provider.id, original_pictures, pictures
25   end
26   
27   public
28   
29   def index
30     @page = ProviderStatus.page params[:page]
31     @page_size = ProviderStatus.page_size params[:page_size]
32     @hide = params[:hide]
33     @provider_statuses = if @hide.blank?
34       ProviderStatus.list(@page, @page_size)
35     else
36       ProviderStatus.available_list(@page, @page_size)
37     end
38
39     respond_to do |format|
40       format.html # index.html.erb
41       format.json { render :json => @provider_statuses.to_json(ProviderStatus.list_json_opt) }
42     end
43   end
44
45   def show
46     @provider_status = ProviderStatus.show(params[:id], @admin)
47
48     respond_to do |format|
49       format.html # show.html.erb
50       format.json { render :json => @provider_status.to_json(ProviderStatus.show_json_opt) }
51     end
52   end
53
54   def edit
55     @provider_status = ProviderStatus.edit(params[:id], @admin)
56     respond_to do |format|
57       format.html 
58       format.js
59     end
60   end
61
62   def update
63     @provider_status = ProviderStatus.edit(params[:id], @admin)
64     @provider_status.attributes = params[:provider_status]
65     @provider_status.overwrite
66     respond_to do |format|
67       if @provider_status.save
68         flash[:notice] = I18n.t('provider_statuses.flash.notice.created')
69         format.html { redirect_to @provider_status }
70         format.json { head :ok }
71       else
72         format.html { render action: "edit" }
73         format.json { render json: @provider_status.errors, status: :unprocessable_entity }
74       end
75     end
76   end
77
78   def destroy
79     @provider_status = ProviderStatus.edit(params[:id], @admin)
80     respond_to do |format|
81       if @provider_status.stop
82         flash[:notice] = I18n.t('provider_statuses.flash.notice.stopped')
83         format.html { redirect_to provider_statuses_url }
84         format.json { head :ok }
85       else
86         flash[:notice] = I18n.t('provider_statuses.flash.notice.not_stopped')
87         format.html { render action: "edit" }
88         format.json { render json: @provider_status.errors, status: :unprocessable_entity }
89       end
90     end
91   end
92   
93   def licenses_import
94     @provider_status = ProviderStatus.show(params[:id], @admin)
95     raise ActiveRecord::Forbidden if @provider_status.status == 0
96     @failures = licenses_port
97     respond_to do |format|
98       format.html # show.html.erb
99       format.json { render :json => @failures.to_json() }
100     end
101   end
102   
103   def artists_import
104     @provider_status = ProviderStatus.show(params[:id], @admin)
105     raise ActiveRecord::Forbidden if @provider_status.status == 0
106     @failures = artists_port
107     respond_to do |format|
108       format.html # show.html.erb
109       format.json { render :json => @failures.to_json() }
110     end
111   end
112   
113   def original_pictures_import
114     @provider_status = ProviderStatus.show(params[:id], @admin)
115     raise ActiveRecord::Forbidden if @provider_status.status == 0
116     @failures = original_pictures_port
117     respond_to do |format|
118       format.html # show.html.erb
119       format.json { render :json => @failures.to_json() }
120     end
121   end
122   
123 end