OSDN Git Service

fix: speech css
[pettanr/pettanr.git] / app / models / folder.rb
1 class Folder < Peta::SystemResource
2   acts_as_nested_set
3   
4   validates :name, :presence => true, :uniqueness => true, :length => {:maximum => 200}
5   validates :controller_name, :length => {:maximum => 200}
6   validates :action_name, :length => {:maximum => 200}
7   validates :category_id, :presence => true, :numericality => true
8   validates :t, :presence => true, :numericality => true
9   
10   #remove last dir name
11   def dir
12     r = name.split('/')
13     r.pop
14     r.join '/'
15   end
16   
17   def caption
18     name.gsub(/\/$/, '').split('/').last
19   end
20   
21   def filer_caption
22     self.caption
23   end
24   
25   def remote_name
26     '/' + self.controller_name.to_s + '/' + self.action_name.to_s
27   end
28   
29   def self.add_local parent, name
30     key = parent.name + name + '/'
31     attr = {
32       :name => key, :category_id => 0, :t => 0
33     }
34     if i = self.find_by_name(key)
35       i.attributes = attr
36       i.save
37     else
38       i = self.create attr
39     end
40     i.move_to_child_of parent
41     i
42   end
43   
44   def self.add_remote parent, name, controller_name = nil, action_name = nil
45     key = parent.name + name + '/'
46     attr = {
47       :name => key, :category_id => 10, :t => 0, 
48       :controller_name => (controller_name || name), 
49       :action_name => action_name
50     }
51     if i = self.find_by_name(key)
52       i.attributes = attr
53       i.save
54     else
55       i = self.create attr
56     end
57     i.move_to_child_of parent
58     i
59   end
60   
61   def self.generate
62     if r = self.find_by_name('/')
63     else
64       r = self.create :name => '/', :category_id => 0, :t => 0
65     end
66     #
67     # child of root
68     #
69     manga = self.add_local r, 'manga'
70     o = self.add_local r, 'people'
71     doc = self.add_local r, 'documents'
72     mydoc = self.add_local r, 'my documents'
73     sr = self.add_local r, 'system_resource'
74     
75     # child of /manga
76     manga_scroll = self.add_remote manga, 'scrolls'
77     manga_panel = self.add_remote manga, 'panels'
78     
79     # child of /people  (owner)
80     au = self.add_remote o, 'authors'
81     ar = self.add_remote o, 'artists'
82     
83     # child of /documents
84     docman = self.add_local doc, 'manga'
85     docpic = self.add_local doc, 'pictures'
86     docparts = self.add_local doc, 'parts'
87     docidx = self.add_local doc, 'index'
88     # child of /documents/manga
89     docman_scroll = self.add_remote docman, 'scrolls'
90     docman_panel = self.add_remote docman, 'panels'
91     # child of /documents/pictures
92     docpic_resource_picture = self.add_remote docpic, 'resource_pictures'
93     # child of /documents/parts
94     docparts_panel_picture = self.add_remote docparts, 'panel_pictures'
95     docparts_speech_balloon = self.add_remote docparts, 'speech_balloons'
96     docparts_balloon = self.add_remote docparts, 'balloons'
97     docparts_speech = self.add_remote docparts, 'speeches'
98     docparts_ground_picture = self.add_remote docparts, 'ground_pictures'
99     docparts_ground_color = self.add_remote docparts, 'ground_colors'
100     # child of /documents/index  (all public contents)
101     docidx_scroll = self.add_remote docidx, 'scrolls'
102     docidx_scroll_panel = self.add_remote docidx, 'scroll_panels'
103     docidx_comic = self.add_remote docidx, 'comics'
104     docidx_comic_story = self.add_remote docidx, 'comic_stories'
105     docidx_story = self.add_remote docidx, 'stories'
106     docidx_story_sheet = self.add_remote docidx, 'story_sheets'
107     docidx_sheet = self.add_remote docidx, 'sheets'
108     docidx_sheet_panel = self.add_remote docidx, 'sheet_panels'
109     docidx_panel = self.add_remote docidx, 'panels'
110     docidx_panel_picture = self.add_remote docidx, 'panel_pictures'
111     docidx_speech_balloon = self.add_remote docidx, 'speech_balloons'
112     docidx_balloon = self.add_remote docidx, 'balloons'
113     docidx_speech = self.add_remote docidx, 'speeches'
114     docidx_ground_picture = self.add_remote docidx, 'ground_pictures'
115     docidx_ground_color = self.add_remote docidx, 'ground_colors'
116     docidx_resource_picture = self.add_remote docidx, 'resource_pictures'
117     
118     # child of /my documents
119     mydocman = self.add_local mydoc, 'manga'
120     mydocpic = self.add_local mydoc, 'pictures'
121     mydocparts = self.add_local mydoc, 'parts'
122     mydocidx = self.add_local mydoc, 'index'
123     mydocedt = self.add_local mydoc, 'create'
124     # child of /my documents/manga
125     mydocman_scroll = self.add_remote mydocman, 'scrolls', 'home', 'scrolls'
126     mydocman_panel = self.add_remote mydocman, 'panels', 'home', 'panels'
127     # child of /my documents/pictures
128     mydocpic_original_picture = self.add_remote mydocpic, 'original_pictures'
129     mydocpic_resource_picture = self.add_remote mydocpic, 'resource_pictures', 'home', 'resource_pictures'
130     # child of /my documents/parts
131     mydocparts_panel_picture = self.add_remote mydocparts, 'panel_pictures'
132     mydocparts_speech_balloon = self.add_remote mydocparts, 'speech_balloons'
133     mydocparts_balloon = self.add_remote mydocparts, 'balloons'
134     mydocparts_speech = self.add_remote mydocparts, 'speeches'
135     mydocparts_ground_picture = self.add_remote mydocparts, 'ground_pictures'
136     mydocparts_ground_color = self.add_remote mydocparts, 'ground_colors'
137     # child of /my documents/index
138     mydocidx_scroll = self.add_remote mydocidx, 'scrolls', 'home', 'scrolls'
139     mydocidx_scroll_panel = self.add_remote mydocidx, 'scroll_panels', 'home', 'scroll_panels'
140     mydocidx_comic = self.add_remote mydocidx, 'comics', 'home', 'comics'
141     mydocidx_comic_story = self.add_remote mydocidx, 'comic_stories', 'home', 'comic_stories'
142     mydocidx_story = self.add_remote mydocidx, 'stories', 'home', 'stories'
143     mydocidx_story_sheet = self.add_remote mydocidx, 'story_sheets', 'home', 'story_sheets'
144     mydocidx_sheet = self.add_remote mydocidx, 'sheets', 'home', 'sheets'
145     mydocidx_sheet_panel = self.add_remote mydocidx, 'sheet_panels', 'home', 'sheet_panels'
146     mydocidx_panel = self.add_remote mydocidx, 'panels', 'home', 'panels'
147     mydocidx_panel_picture = self.add_remote mydocidx, 'panel_pictures', 'home', 'panel_pictures'
148     mydocidx_speech_balloon = self.add_remote mydocidx, 'speech_balloons', 'home', 'speech_balloons'
149     mydocidx_balloon = self.add_remote mydocidx, 'balloons', 'home', 'balloons'
150     mydocidx_speech = self.add_remote mydocidx, 'speeches', 'home', 'speeches'
151     mydocidx_ground_picture = self.add_remote mydocidx, 'ground_pictures', 'home', 'ground_pictures'
152     mydocidx_ground_color = self.add_remote mydocidx, 'ground_colors', 'home', 'ground_colors'
153     mydocpic_original_picture = self.add_remote mydocpic, 'original_pictures'
154     mydocidx_resource_picture = self.add_remote mydocidx, 'resource_pictures', 'home', 'resource_pictures'
155     # child of /my documents/create
156     mydocedt_scroll = self.add_remote mydocedt, 'new scroll', 'scrolls', 'new'
157     mydocedt_panel = self.add_remote mydocedt, 'new panel', 'panels', 'new'
158     mydocedt_original_picture = self.add_remote mydocedt, 'upload picture', 'original_pictures', 'new'
159     # child of /my documents/create/index
160     mydocedtidx = self.add_local mydocedt, 'index'
161     mydocedtidx_scroll = self.add_remote mydocedtidx, 'new scroll', 'scrolls', 'new'
162     mydocedtidx_comic = self.add_remote mydocedtidx, 'new comic', 'comics', 'new'
163     mydocedtidx_story = self.add_remote mydocedtidx, 'new story', 'stories', 'new'
164     mydocedtidx_sheet = self.add_remote mydocedtidx, 'new sheet', 'sheets', 'new'
165     mydocedtidx_panel = self.add_remote mydocedtidx, 'new panel', 'panels', 'new'
166     
167     # child of /system_resource
168     sbt = self.add_remote sr, 'speech_balloon_templates'
169     lg = self.add_remote sr, 'license_groups'
170     ls = self.add_remote sr, 'licenses'
171     sp = self.add_remote sr, 'system_pictures'
172     wf = self.add_remote sr, 'writing_formats'
173     
174   end
175   
176 end