OSDN Git Service

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