OSDN Git Service

t#30322:create provider license import func
[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]
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         format.html { redirect_to @provider_status, notice: 'ProviderStatus was successfully updated.' }
45         format.json { head :ok }
46       else
47         format.html { render action: "edit" }
48         format.json { render json: @provider_status.errors, status: :unprocessable_entity }
49       end
50     end
51   end
52
53   def destroy
54     @provider_status = ProviderStatus.edit(params[:id], @admin)
55     @provider_status.destroy
56     respond_to do |format|
57       format.html { redirect_to comics_url }
58       format.json { head :ok }
59     end
60   end
61   
62   def licenses_import
63     @provider_status = ProviderStatus.show(params[:id], @admin)
64     raise ActiveRecord::Forbidden if @provider_status.status == 0
65     t = ymd_to_time params[:date]
66     url = export_url @provider_status.provider.demander_url, @provider_status.token, t
67     @failures = ProviderLicense.import @provider_status.provider.id, export_from_provider(url)
68     respond_to do |format|
69       format.html # show.html.erb
70       format.json { render :json => @provider_status.to_json(ProviderStatus.show_json_opt) }
71     end
72   end
73   
74 end