OSDN Git Service

fix new element dialog
[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   overwrite: (options) ->\r
33     @set('author_id', options.operators.author.id)\r
34   \r
35   is_usable: (operators) ->\r
36     @is_visible(operators)\r
37   \r
38   is_publish: () ->\r
39     @get('publish') > 0\r
40   \r
41   @licensed_pictures: (panels) ->\r
42     r = {}\r
43     _.each panels, (panel) ->\r
44       _.extend r, panel.licensed_pictures()\r
45     r\r
46   \r
47   licensed_pictures: () ->\r
48     r = {}\r
49     _.each @scenario_elements(), (elm) ->\r
50       return if not elm.my_class().has_picture()\r
51       pid = elm.get('picture_id')\r
52       r[pid] = elm.picture() if not r[pid]\r
53     r\r
54   \r
55   initialize: (attr = {}, options = {}) ->\r
56     @set(attr)\r
57     if @get('id')\r
58       @url = @url + @get('id')\r
59     if options.with_elements\r
60       @url = @url + '?with_elements=true'\r
61     @bind('change:width', () ->\r
62       console.log('cng')\r
63     )\r
64   \r