OSDN Git Service

fix: views
[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_mini_faced_label = @author.mini_faced_label({\r
19         context: this,\r
20         click: () =>\r
21           @trigger('http_get', @author.show_url())\r
22       })\r
23       this.$el.append(@author_mini_faced_label.render().el)\r
24     if @artist\r
25       @artist_mini_faced_label = @artist.mini_faced_label({\r
26         context: this,\r
27         click: () =>\r
28           @trigger('http_get', @artist.show_url())\r
29       })\r
30       this.$el.append(@artist_mini_faced_label.render().el)\r
31     if @author\r
32       @quick = new Pettanr.Views.User.Account.Quick()\r
33       @listenTo(@quick, 'click:mydoc', @click_mydoc)\r
34       @listenTo(@quick, 'click:mynew', @click_mynew)\r
35       this.$el.append(@quick.render().el)\r
36     sign_out = new Tag.A({\r
37       attr: {href: '/users/sign_out'}, \r
38       class_name: 'sign_out', \r
39       content: 'sign out'\r
40     })\r
41     @listenTo(sign_out, 'click', @sign_out_click)\r
42     this.$el.append(sign_out.render().el)\r
43     this\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