OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / controllers / comic_stories_controller.rb
1 class ComicStoriesController < ApplicationController
2   if Manifest.manifest.magic_numbers['run_mode'] == 0
3     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
4     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
5   else
6     before_filter :authenticate_reader, :only => [
7       :index, :show, :by_story, :by_comic, :by_author, :count, :count_by_story, :count_by_comic, :count_by_author
8     ]
9     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
10     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
11   end
12   
13   def index
14     filer_list
15   end
16   
17   def by_story
18     filer_list
19   end
20   
21   def by_comic
22     filer_list
23   end
24   
25   def by_author
26     filer_list
27   end
28   
29   def show
30     set_show
31     respond_to do |format|
32       show_prof_format format
33       format.json { render json: @item.to_json }
34     end
35   end
36   
37   def count
38     list_count
39   end
40   
41   def count_by_story
42     list_count
43   end
44   
45   def count_by_comic
46     list_count
47   end
48   
49   def count_by_author
50     list_count
51   end
52   
53   def new
54     form_new
55   end
56   
57   def edit
58     form_edit
59   end
60   
61   def create
62     @my_model_class = self.class.model
63     @item = @my_model_class.new
64     @item.supply_default
65     @item.attributes = params[@item.item_name]
66     @item.overwrite @operators
67     @binder = @my_model_class.binder_model.edit(@item.binder_id, @operators) if @item.binder_id
68     @panel = @my_model_class.destination_model.show(@item.destination_id, @operators) if @item.destination_id
69     
70     leaf_render_create play_scroll_path(@binder)
71   end
72   
73   def update
74     @my_model_class = self.class.model
75     @item = @my_model_class.edit(params[:id], @operators)
76     ot = @item.t
77     @item.attributes = params[@item.item_name]
78     @item.overwrite @operators
79     @binder = @my_model_class.binder_model.edit(@item.binder_id, @operators) if @item.binder_id
80     # no check permission for destination
81     # swapable hidden panel
82     #@panel = @my_model_class.destination_model.show(@item.destination_id, @operators) if @item.destination_id
83     
84     leaf_render_update ot, play_scroll_path(@binder)
85   end
86   
87   def destroy
88     @comic_story = ComicStory.edit(params[:id], @operators)
89     @comic = Comic.edit(@comic_story.comic_id, @operators) if @comic_story.comic_id
90     respond_to do |format|
91       if @comic_story.destroy_and_shorten
92         flash[:notice] = I18n.t('flash.notice.destroyed', :model => ComicStory.model_name.human)
93         format.html { redirect_to play_comic_path(@comic) }
94         format.json { head :ok }
95       else
96         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => ComicStory.model_name.human)
97         format.html { redirect_to comic_story_path(@comic_story) }
98         format.json { render json: @comic_story.errors, status: :unprocessable_entity }
99       end
100     end
101   end
102 end