OSDN Git Service

0f752d5edcdfabc9a702db18a6004701aeaf6f75
[pettanr/pettanr.git] / app / assets / javascripts / views / users / account.js.coffee
1 # page header for signed in user\r
2 class Pettanr.Views.User.Account extends Pettanr.View\r
3   tagName: 'div'\r
4   \r
5   initialize: (options) ->\r
6     @author = Pettanr.cache.operators.author\r
7     @artist = Pettanr.cache.operators.artist\r
8   \r
9   render: () ->\r
10     this.$el.html('')\r
11     @logo = new Pettanr.Views.Common.Logo({})\r
12     @listenTo(@logo, 'click', @logo_click)\r
13     this.$el.append(@logo.render().el)\r
14     if @author\r
15       @author_mini_faced_label = @author.mini_faced_label({\r
16         context: this,\r
17         click: () =>\r
18           @trigger('http_get', @author.show_url())\r
19       })\r
20       this.$el.append(@author_mini_faced_label.render().el)\r
21     if @artist\r
22       @artist_mini_faced_label = @artist.mini_faced_label({\r
23         context: this,\r
24         click: () =>\r
25           @trigger('http_get', @artist.show_url())\r
26       })\r
27       this.$el.append(@artist_mini_faced_label.render().el)\r
28     if @author\r
29       @quick = new Pettanr.Views.User.Account.Quick()\r
30       @listenTo(@quick, 'click:mydoc', @click_mydoc)\r
31       @listenTo(@quick, 'click:mynew', @click_mynew)\r
32       this.$el.append(@quick.render().el)\r
33     sign_out = new Tag.A({\r
34       attr: {href: '/users/sign_out'}, \r
35       class_name: 'sign_out', \r
36       content: 'sign out'\r
37     })\r
38     @listenTo(sign_out, 'click', @sign_out_click)\r
39     this.$el.append(sign_out.render().el)\r
40     this\r
41   \r
42   logo_click: () ->\r
43     @trigger('http_get', '')\r
44   \r
45   sign_out_click: () ->\r
46     @trigger('http_post', 'users/sign_out')\r
47     return false\r
48   \r
49   click_mydoc: (url) ->\r
50     @trigger('http_get', url)\r
51     return false\r
52   \r
53   click_mynew: (url) ->\r
54     @trigger('http_get', url)\r
55     return false\r
56   \r
57 class Pettanr.Views.User.Account.Quick extends Pettanr.View\r
58   tagName: 'span'\r
59   \r
60   initialize: (options) ->\r
61   \r
62   render: () ->\r
63     this.$el.html('')\r
64     @home()\r
65     this\r
66   \r
67   home: () ->\r
68     params = {\r
69       controller: 'folders',\r
70       action: 'index',\r
71       path: '/my documents/'\r
72     }\r
73     list = Locmare.ListGroup.list(\r
74       'folders', 'index', params\r
75     )\r
76     list.open(this, {\r
77       success: (items) => \r
78         if !_.isEmpty(list.items())\r
79           @mydoc = list.items()[0]\r
80           @add_mydoc()\r
81           @create()\r
82     })\r
83   \r
84   create: () ->\r
85     params = {\r
86       controller: 'folders',\r
87       action: 'index',\r
88       path: '/my documents/create/'\r
89     }\r
90     list = Locmare.ListGroup.list(\r
91       'folders', 'index', params\r
92     )\r
93     list.open(this, {\r
94       success: (items) => \r
95         if !_.isEmpty(list.items())\r
96           @mynew = list.items()[0]\r
97           @add_mynew()\r
98     })\r
99   \r
100   add_mydoc: () ->\r
101     mydoc_icon = new  Pettanr.Views.User.Account.LinkedMydocIcon({item: @mydoc, half: true})\r
102     @listenTo(mydoc_icon, 'click', @click_mydoc_icon)\r
103     this.$el.append(mydoc_icon.render().el)\r
104   \r
105   add_mynew: () ->\r
106     mynew_icon = new  Pettanr.Views.User.Account.LinkedCreateIcon({item: @mynew, half: true})\r
107     @listenTo(mynew_icon, 'click', @click_mynew_icon)\r
108     this.$el.append(mynew_icon.render().el)\r
109   \r
110   click_mydoc_icon: () ->\r
111     @trigger('click:mydoc', @mydoc.show_url())\r
112   \r
113   click_mynew_icon: () ->\r
114     @trigger('click:mynew', @mynew.show_url())\r
115   \r
116 class Pettanr.Views.User.Account.LinkedMydocIcon extends Tag.A\r
117   \r
118   initialize: (options) ->\r
119     item = options.item\r
120     half = options.half\r
121     img = new Pettanr.Image.SymbolImg({\r
122       attr: {src: '/images/home.gif'}, half: half\r
123     })\r
124     super({\r
125       attr: {href: '/' + item.show_url()}, \r
126       content: img.render().el\r
127     })\r
128   \r
129 class Pettanr.Views.User.Account.LinkedCreateIcon extends Tag.A\r
130   \r
131   initialize: (options) ->\r
132     item = options.item\r
133     half = options.half\r
134     img = new Pettanr.Image.SymbolImg({\r
135       attr: {src: '/images/inspire.gif'}, half: half\r
136     })\r
137     super({\r
138       attr: {href: '/' + item.show_url()}, \r
139       content: img.render().el\r
140     })\r
141   \r