OSDN Git Service

v07
[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.View.Layout.Logo({\r
12       context: this, \r
13       click: () =>\r
14         @trigger('http_get', '')\r
15     })\r
16     this.$el.append(@logo.render().el)\r
17     if @author\r
18       @author_faced_label_button = @author.mini_faced_label_button({\r
19           shorten: true\r
20         }, {\r
21         context: this,\r
22         click: () =>\r
23           @trigger('http_get', @author.show_url())\r
24       })\r
25       this.$el.append(@author_faced_label_button.render().el)\r
26     if @artist\r
27       @artist_faced_label_button = @artist.mini_faced_label_button({\r
28           shorten: true\r
29         }, {\r
30         context: this,\r
31         click: () =>\r
32           @trigger('http_get', @artist.show_url())\r
33       })\r
34       this.$el.append(@artist_faced_label_button.render().el)\r
35     if @author\r
36       @quick = new Pettanr.Views.User.Account.Quick()\r
37       @listenTo(@quick, 'click:mydoc', @click_mydoc)\r
38       @listenTo(@quick, 'click:mynew', @click_mynew)\r
39       this.$el.append(@quick.render().el)\r
40     sign_out = new Pettanr.View.Button('/users/sign_out', 'sign out', {\r
41       context: this,\r
42       click: () =>\r
43         @trigger('http_post', 'users/sign_out')\r
44       class_name: 'sign_out', \r
45     })\r
46     this.$el.append(sign_out.render().el)\r
47     this\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