OSDN Git Service

Merge branch 'v05' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v05
[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, :import, :import_all]
4   
5   def index
6     @page = ProviderStatus.page params[:page]
7     @page_size = ProviderStatus.page_size params[:page_size]
8     @hide = params[:hide]
9     @provider_statuses = if @hide.blank?
10       ProviderStatus.list(@page, @page_size)
11     else
12       ProviderStatus.available_list(@page, @page_size)
13     end
14
15     respond_to do |format|
16       format.html # index.html.erb
17       format.json { render :json => @provider_statuses.to_json(ProviderStatus.list_json_opt) }
18     end
19   end
20
21   def show
22     @provider_status = ProviderStatus.show(params[:id], @admin)
23
24     respond_to do |format|
25       format.html # show.html.erb
26       format.json { render :json => @provider_status.to_json(ProviderStatus.show_json_opt) }
27     end
28   end
29
30   def edit
31     @provider_status = ProviderStatus.edit(params[:id], @admin)
32     respond_to do |format|
33       format.html 
34       format.js
35     end
36   end
37
38   def update
39     @provider_status = ProviderStatus.edit(params[:id], @admin)
40     @provider_status.attributes = params[:provider_status]
41     @provider_status.overwrite
42     respond_to do |format|
43       if @provider_status.save
44         flash[:notice] = I18n.t('provider_statuses.flash.notice.created')
45         format.html { redirect_to @provider_status }
46         format.json { head :ok }
47       else
48         format.html { render action: "edit" }
49         format.json { render json: @provider_status.errors, status: :unprocessable_entity }
50       end
51     end
52   end
53
54   def destroy
55     @provider_status = ProviderStatus.edit(params[:id], @admin)
56     respond_to do |format|
57       if @provider_status.stop
58         flash[:notice] = I18n.t('provider_statuses.flash.notice.stopped')
59         format.html { redirect_to provider_statuses_url }
60         format.json { head :ok }
61       else
62         flash[:notice] = I18n.t('provider_statuses.flash.notice.not_stopped')
63         format.html { render action: "edit" }
64         format.json { render json: @provider_status.errors, status: :unprocessable_entity }
65       end
66     end
67   end
68   
69   def licenses_import
70     @provider_status = ProviderStatus.show(params[:id], @admin)
71     raise ActiveRecord::Forbidden if @provider_status.status == 0
72     @import_result = @provider_status.licenses_import params[:date]
73     respond_to do |format|
74       format.html # show.html.erb
75       format.json { render :json => @import_result.to_json() }
76     end
77   end
78   
79   def artists_import
80     @provider_status = ProviderStatus.show(params[:id], @admin)
81     raise ActiveRecord::Forbidden if @provider_status.status == 0
82     @import_result = @provider_status.artists_import params[:date]
83     respond_to do |format|
84       format.html # show.html.erb
85       format.json { render :json => @import_result.to_json() }
86     end
87   end
88   
89   def original_pictures_import
90     @provider_status = ProviderStatus.show(params[:id], @admin)
91     raise ActiveRecord::Forbidden if @provider_status.status == 0
92     @import_result = @provider_status.original_pictures_import params[:date]
93     respond_to do |format|
94       format.html # show.html.erb
95       format.json { render :json => @import_result.to_json() }
96     end
97   end
98   
99   def import
100     @provider_status = ProviderStatus.show(params[:id], @admin)
101     raise ActiveRecord::Forbidden if @provider_status.status == 0
102     @import_result = @provider_status.import params[:date]
103     respond_to do |format|
104       format.html # show.html.erb
105       format.json { render :json => @failures.to_json() }
106     end
107   end
108   
109   def import_all
110     ProviderStatus.approve_list.each do |provider_status|
111       @provider_status = provider_status params[:date]
112     end
113     respond_to do |format|
114       format.html { render :text => 'ok'}
115       format.json { render :json => {}.to_json() }
116     end
117   end
118   
119 end