OSDN Git Service

fix sign in header
[pettanr/pettanr.git] / app / assets / javascripts / views / users / index.js.coffee
diff --git a/app/assets/javascripts/views/users/index.js.coffee b/app/assets/javascripts/views/users/index.js.coffee
new file mode 100644 (file)
index 0000000..b2d5fc5
--- /dev/null
@@ -0,0 +1,35 @@
+class Pettanr.Views.User.Index extends Backbone.View\r
+  tagName: 'div'\r
+  \r
+  initialize: (options) ->\r
+    @operators = options.operators\r
+  \r
+  render: () ->\r
+    this.$el.html('')\r
+    t = _.template($("#sign_in").html())\r
+    this.$el.append(t())\r
+    @delegateEvents({'submit': 'sign_in'})\r
+    this\r
+  \r
+  sign_in: () ->\r
+    m = $('#user_email').val()\r
+    p = $('#user_password').val()\r
+    user = new Backbone.Model()\r
+    user.url = '/users/sign_in'\r
+    user.save({user: {email: m, password: p}}, {\r
+      success: (model, response, options) ->\r
+        author = new Pettanr.Author(user.get('author')) if user.get('author')\r
+        artist = new Pettanr.Artist(user.get('artist')) if user.get('artist')\r
+        window.operators = new Pettanr.Operator({\r
+          user: user, \r
+          author: author, \r
+          artist: artist\r
+        })\r
+        r = new Pettanr.Views.Top.Account({operators: window.operators})\r
+        $('#account').html(r.render().el)\r
+        window.router.navigate('', true)\r
+      error: (model, response, options) ->\r
+        response.status\r
+    })\r
+    return false\r
+  \r