OSDN Git Service

mrg
[pettanr/pettanr.git] / app / controllers / comics_controller.rb
1 class ComicsController < 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, :play, :by_story, :by_author, :count, :count_by_story, :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 self.model
14     Comic
15   end
16   
17   def index
18     filer_list
19   end
20   
21   def by_story
22     filer_list
23   end
24   
25   def by_author
26     filer_list
27   end
28   
29   def show_html_format format
30     format.html {
31       play_list = Locmare::ListGroup.list 'comic_story', 'play'
32       @play_count = play_list.count(@operators, 
33         {:id => @item.id, :my_play => @item.own?(@operators)}
34       )
35     }
36   end
37   
38   def show
39     set_show
40     respond_to do |format|
41       show_html_format format
42       show_prof_format format
43       show_json_format format
44       format.atom 
45       format.rss 
46     end
47   end
48   
49   def play
50     @item = self.class.model.show(params[:id], @operators)
51     set_play
52     @items = @list.items(@operators, 
53       {:id => params[:id], :my_play => @item.own?(@operators)},
54       0, -1 # no limit
55     )
56     @count = @items.count
57     # no pager
58     respond_to do |format|
59       format.html {
60         if @item.own? @operators
61           @new_story_items = assist_items('story', 'private')
62         end
63       }
64       format.json { render json: @items.to_json }
65     end
66   end
67   
68   def count
69     list_count
70   end
71   
72   def count_by_story
73     list_count
74   end
75   
76   def count_by_author
77     list_count
78   end
79   
80   def new
81     form_new
82   end
83   
84   def edit
85     form_edit
86   end
87   
88   def create
89     set_model
90     @item = @my_model_class.new
91     @item.supply_default 
92     @my_model_class.fold_extend_settings params[@my_model_class.item_name]
93     @item.attributes = params[@my_model_class.item_name]
94     @item.overwrite @operators
95     render_create
96   end
97   
98   def update
99     set_edit
100     @my_model_class.fold_extend_settings params[@my_model_class.item_name]
101     @item.attributes = params[@my_model_class.item_name]
102     @item.overwrite @operators
103     render_update
104   end
105   
106   def destroy
107     @item = Comic.edit(params[:id], @operators)
108     respond_to do |format|
109       if @item.destroy_with_leafs
110         flash[:notice] = I18n.t('flash.notice.destroyed', :model => Comic.model_name.human)
111         format.html { redirect_to '/home/comics' }
112         format.json { head :ok }
113       else
114         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Comic.model_name.human)
115         format.html { redirect_to @item }
116         format.json { render json: @item.errors, status: :unprocessable_entity }
117       end
118     end
119   end
120 end