OSDN Git Service

t#30328:create op import ...and pull
[pettanr/pettanr.git] / app / controllers / provider_statuses_controller.rb
index 9395eea..e40643a 100644 (file)
@@ -1,6 +1,6 @@
 class ProviderStatusesController < ApplicationController
   layout 'test' if MagicNumber['test_layout']
-  before_filter :authenticate_admin!, :only => [:index, :show, :edit, :update, :destroy, :licenses_import, :artists_import]
+  before_filter :authenticate_admin!, :only => [:index, :show, :edit, :update, :destroy, :licenses_import, :artists_import, :original_pictures_import]
 
   def index
     @page = ProviderStatus.page params[:page]
@@ -41,7 +41,8 @@ class ProviderStatusesController < ApplicationController
     @provider_status.overwrite
     respond_to do |format|
       if @provider_status.save
-        format.html { redirect_to @provider_status, notice: 'ProviderStatus was successfully updated.' }
+        flash[:notice] = I18n.t('provider_statuses.flash.notice.created')
+        format.html { redirect_to @provider_status }
         format.json { head :ok }
       else
         format.html { render action: "edit" }
@@ -52,10 +53,16 @@ class ProviderStatusesController < ApplicationController
 
   def destroy
     @provider_status = ProviderStatus.edit(params[:id], @admin)
-    @provider_status.destroy
     respond_to do |format|
-      format.html { redirect_to comics_url }
-      format.json { head :ok }
+      if @provider_status.stop
+        flash[:notice] = I18n.t('provider_statuses.flash.notice.stopped')
+        format.html { redirect_to provider_statuses_url }
+        format.json { head :ok }
+      else
+        flash[:notice] = I18n.t('provider_statuses.flash.notice.not_stopped')
+        format.html { render action: "edit" }
+        format.json { render json: @provider_status.errors, status: :unprocessable_entity }
+      end
     end
   end
   
@@ -83,4 +90,16 @@ class ProviderStatusesController < ApplicationController
     end
   end
   
+  def original_pictures_import
+    @provider_status = ProviderStatus.show(params[:id], @admin)
+    raise ActiveRecord::Forbidden if @provider_status.status == 0
+    original_pictures = export_by('original_pictures_export', @provider_status, params[:date])
+    pictures = export_by('pictures_export', @provider_status, params[:date])
+    @failures = ProviderOriginalPicture.import @provider_status.provider.id, original_pictures, pictures
+    respond_to do |format|
+      format.html # show.html.erb
+      format.json { render :json => @failures.to_json() }
+    end
+  end
+  
 end