OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / assets / javascripts / models / panel.js.coffee
1 class Pettanr.Panel extends Peta.Root\r
2   url: '/panels/'\r
3   \r
4   @singular: () ->\r
5     'Panel'\r
6   \r
7   @plural: () ->\r
8     'Panels'\r
9   \r
10   defaults: {\r
11     id: null,\r
12     border: 2,\r
13     publish: 0\r
14   } \r
15   \r
16   author: () ->\r
17     new Pettanr.Author({id: @get('author_id')})\r
18   \r
19   pp: () ->\r
20     new Pettanr.PanelPicture({id: @get('pp_id')})\r
21   \r
22   with_elements: () ->\r
23     new Pettanr.Panel.WithElements({id: @get('id')})\r
24   \r
25   is_visible: (operators) ->\r
26     switch super(operators)\r
27       when null # super return\r
28         return true\r
29       when false\r
30         return false\r
31       else\r
32         return true if @isNew()\r
33         @is_publish()\r
34   \r
35   overwrite: (options) ->\r
36     @set('author_id', options.operators.author.id)\r
37   \r
38   is_usable: (operators) ->\r
39     @is_visible(operators)\r
40   \r
41   is_publish: () ->\r
42     @get('publish') > 0\r
43   \r
44   @licensed_pictures: (panels) ->\r
45     r = {}\r
46     _.each panels, (panel) ->\r
47       _.extend r, panel.licensed_pictures()\r
48     r\r
49   \r
50   licensed_pictures: () ->\r
51     r = {}\r
52     _.each @scenario_elements(), (elm) ->\r
53       return if not elm.my_class().has_picture()\r
54       pid = elm.get('picture_id')\r
55       r[pid] = elm.picture() if not r[pid]\r
56     r\r
57   \r
58   my_url: () ->\r
59     '/' + @path_name() + '/' + @get('id')\r
60   \r
61   initialize: (attr = {}, options = {}) ->\r
62     @set(attr)\r
63     if @get('id')\r
64       @url = @my_url()\r
65     @bind('change:width', () ->\r
66       console.log('cng')\r
67     )\r
68   \r
69 class Pettanr.Panel.WithElements extends Pettanr.Panel\r
70   \r
71   fetch: (options) ->\r
72     @url = @my_url() + '?with_elements=true'\r
73     super(options)\r
74   \r
75   save: (attrs, options = {}) ->\r
76     @url = @my_url()\r
77     options.attrs = {panel: attrs}\r
78     method = if @isNew()\r
79       'create'\r
80     else\r
81       'update'\r
82     xhr = @sync(method, this, options)\r
83     xhr\r
84   \r
85   destroy: (options) ->\r
86     @url = @my_url()\r
87     super(options)\r
88   \r