OSDN Git Service

fix manifest
[pettanr/pettanr.git] / app / controllers / licenses_controller.rb
index 4051865..a742413 100644 (file)
@@ -2,6 +2,7 @@ class LicensesController < ApplicationController
   before_filter :authenticate_resource_reader, :only => [
     :by_license_group, :by_system_picture, :count_by_license_group, :count_by_system_picture
   ]
+  before_filter :authenticate_admin, :only => [:new, :create, :edit, :update, :destroy]
 
   def self.model
     License
@@ -55,4 +56,58 @@ class LicensesController < ApplicationController
     list_count
   end
   
+  def new
+    form_new
+  end
+  
+  def edit
+    form_edit
+  end
+  
+  def create
+    @item = self.class.model.new
+    @item.supply_default 
+    @item.attributes = params[:license]
+    @item.overwrite @operators
+
+    if @item.save
+      respond_to do |format|
+        flash[:notice] = I18n.t('flash.notice.created', :model => self.class.model.model_name.human)
+        format.html { redirect_to @item }
+        format.json { render json: @item.to_json(self.class.model.show_json_opt), status: :created, location: @item }
+      end
+    else
+      flash[:notice] = I18n.t('flash.notice.not_created', :model => self.class.model.model_name.human)
+      render_new
+        format.html { render action: "new" }
+        format.json { render json: @item.errors, status: :unprocessable_entity }
+    end
+  end
+
+  def update
+    @item = self.class.model.edit(params[:id], @operators)
+    self.class.model.fold_extend_settings params[:license]
+    @item.attributes = params[:license]
+    @item.overwrite 
+    respond_to do |format|
+      if @item.save
+        flash[:notice] = I18n.t('flash.notice.updated', :model => self.class.model.model_name.human)
+        format.html { redirect_to @item }
+        format.json { head :ok }
+      else
+        flash[:notice] = I18n.t('flash.notice.not_updated', :model => self.class.model.model_name.human)
+        format.html { render action: "edit" }
+        format.json { render json: @item.errors, status: :unprocessable_entity }
+      end
+    end
+  end
+
+  def destroy
+    @item = self.class.model.edit(params[:id], @operators)
+    respond_to do |format|
+        flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => self.class.model.model_name.human)
+        format.html { redirect_to @item }
+        format.json { render json: @item.errors, status: :unprocessable_entity }
+    end
+  end
 end