OSDN Git Service

fix event names
[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   overwrite: (options) ->\r
26     operators = options.operators\r
27     return false if not operators.author\r
28     @set('author_id', operators.author.id)\r
29   \r
30   is_visible: (operators) ->\r
31     switch super(operators)\r
32       when null # super return\r
33         return true\r
34       when false\r
35         return false\r
36       else\r
37         return true if @isNew()\r
38         @is_publish()\r
39   \r
40   overwrite: (options) ->\r
41     @set('author_id', options.operators.author.id)\r
42   \r
43   is_usable: (operators) ->\r
44     @is_visible(operators)\r
45   \r
46   is_publish: () ->\r
47     @get('publish') > 0\r
48   \r
49   @licensed_pictures: (panels) ->\r
50     r = {}\r
51     _.each panels, (panel) ->\r
52       _.extend r, panel.licensed_pictures()\r
53     r\r
54   \r
55   licensed_pictures: () ->\r
56     r = {}\r
57     _.each @scenario_elements(), (elm) ->\r
58       return if not elm.my_class().has_picture()\r
59       pid = elm.get('picture_id')\r
60       r[pid] = elm.picture() if not r[pid]\r
61     r\r
62   \r
63   my_url: () ->\r
64     '/' + @path_name() + '/' + @get('id')\r
65   \r
66   initialize: (attr = {}, options = {}) ->\r
67     @set(attr)\r
68     if @get('id')\r
69       @url = @my_url()\r
70     @bind('change:width', () ->\r
71       console.log('cng')\r
72     )\r
73   \r
74 class Pettanr.Panel.WithElements extends Pettanr.Panel\r
75   \r
76   fetch: (options) ->\r
77     @url = @my_url() + '?with_elements=true'\r
78     super(options)\r
79   \r
80   save: (attrs, options = {}) ->\r
81     @url = @my_url()\r
82     options.attrs = {panel: attrs}\r
83     method = if @isNew()\r
84       'create'\r
85     else\r
86       'update'\r
87     xhr = @sync(method, this, options)\r
88     xhr\r
89   \r
90   destroy: (options) ->\r
91     @url = @my_url()\r
92     super(options)\r
93   \r