OSDN Git Service

add credit
[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   is_visible: (operators) ->\r
23     switch super(operators)\r
24       when null # super return\r
25         return true\r
26       when false\r
27         return false\r
28       else\r
29         return true if @isNew()\r
30         @is_publish()\r
31   \r
32   is_usable: (operators) ->\r
33     @is_visible(operators)\r
34   \r
35   is_publish: () ->\r
36     @get('publish') > 0\r
37   \r
38   @licensed_pictures: (panels) ->\r
39     r = {}\r
40     _.each panels, (panel) ->\r
41       _.extend r, panel.licensed_pictures()\r
42     r\r
43   \r
44   licensed_pictures: () ->\r
45     r = {}\r
46     _.each @scenario_elements(), (elm) ->\r
47       return if not elm.my_class().has_picture()\r
48       pid = elm.get('picture_id')\r
49       r[pid] = elm.picture() if not r[pid]\r
50     r\r
51   \r
52   initialize: (attr = {}, options = {}) ->\r
53     @set(attr)\r
54     if @get('id')\r
55       @url = @url + @get('id')\r
56     if options.with_elements\r
57       @url = @url + '?with_elements=true'\r
58   \r
59 class Pettanr.Panels extends Backbone.Collection\r
60   model: Pettanr.Panel\r
61   url: '/panels/'\r