OSDN Git Service

temp
[pettanr/pettanr.git] / app / controllers / artists_controller.rb
1 class ArtistsController < ApplicationController
2   layout 'test' if MagicNumber['test_layout']
3   if MagicNumber['run_mode'] == 0
4     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
5     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
6   else
7     before_filter :authenticate_resource_reader, :only => [:index, :show, :resource_pictures]
8     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
9     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
10   end
11   before_filter :authenticate_admin!, :only => [:list, :browse]
12
13   @@model = Artist
14   def index
15     set_filer
16
17     respond_to do |format|
18       format_filer format
19       format.json { render json: @items.to_json(@@model.list_json_opt) }
20     end
21   end
22
23   def show
24     @item = Artist.show(params[:id], @operators)
25
26     respond_to do |format|
27       format.html {
28         @artist = @item
29       }
30       format_prof format
31       format.json { render :json => @item.to_json(Artist.show_json_opt) }
32     end
33   end
34
35   def resource_pictures
36     @artist = Artist.show(params[:id], @operators)
37     @page = Author.page params[:page]
38     @page_size = Author.resource_picture_page_size params[:page_size]
39     @resource_pictures = ResourcePicture.himlist(@artist, @page, @page_size)
40     respond_to do |format|
41       format.html {
42         @paginate = ResourcePicture.himlist_paginate(@artist, @page, @page_size)
43       }
44       format.json { render json: @resource_pictures.to_json(ResourcePicture.list_json_opt) }
45     end
46   end
47   
48   def count
49     @artist = {:count => Artist.visible_count}
50     respond_to do |format|
51       format.json { render json: @artist.to_json }
52     end
53   end
54   
55   def list
56     @artists = Artist.all
57
58     respond_to do |format|
59       format.html { render layout: 'system' }
60       format.json { render json: @artists }
61     end
62   end
63
64   def browse
65     @artist = Artist.find(params[:id])
66
67     respond_to do |format|
68       format.html { render layout: 'system' }
69       format.json { render json: @artist }
70     end
71   end
72
73   def new
74     @artist = Artist.new
75     @artist.supply_default 
76
77     respond_to do |format|
78       format.html # new.html.erb
79       format.js
80       format.json { render json: @artist.to_json(Artist.show_json_opt) }
81     end
82   end
83
84   def edit
85     @artist = Artist.edit(params[:id], @operators)
86     respond_to do |format|
87       format.html 
88       format.js
89     end
90   end
91
92   def create
93     @artist = Artist.new()
94     @artist.supply_default 
95     @artist.attributes = params[:artist]
96     @artist.overwrite @operators
97     respond_to do |format|
98       if @artist.save
99         flash[:notice] = I18n.t('flash.notice.created', :model => Artist.model_name.human)
100         format.html { redirect_to root_path }
101         format.json { render json: @artist.to_json(Artist.show_json_opt), status: :created, location: @artist }
102       else
103         flash[:notice] = I18n.t('flash.notice.not_created', :model => Artist.model_name.human)
104         format.html { render action: "new" }
105         format.json { render json: @artist.errors, status: :unprocessable_entity }
106       end
107     end
108   end
109
110   def update
111     @artist = Artist.edit(params[:id], @operators)
112     @artist.attributes = params[:artist]
113     @artist.overwrite @operators
114
115     respond_to do |format|
116       if @artist.save
117         flash[:notice] = I18n.t('flash.notice.updated', :model => Artist.model_name.human)
118         format.html { redirect_to '/home/configure' }
119         format.json { head :ok }
120       else
121         flash[:notice] = I18n.t('flash.notice.not_updated', :model => Artist.model_name.human)
122         format.html { render action: "edit" }
123         format.json { render json: @artist.errors, status: :unprocessable_entity }
124       end
125     end
126   end
127
128   def destroy
129     @artist = Artist.edit(params[:id], @operators)
130     @artist.destroy
131
132     respond_to do |format|
133       format.html { redirect_to artists_url }
134       format.json { head :ok }
135     end
136   end
137 end