OSDN Git Service

fix initial page
authoryasushiito <yas@pen-chan.jp>
Fri, 17 Oct 2014 10:04:26 +0000 (19:04 +0900)
committeryasushiito <yas@pen-chan.jp>
Fri, 17 Oct 2014 10:04:26 +0000 (19:04 +0900)
app/assets/javascripts/main.js.coffee
app/assets/javascripts/models/user.js.coffee
app/assets/javascripts/views/users/index.js.coffee

index 50055e8..eb01666 100644 (file)
@@ -28,30 +28,18 @@ $ ->
   r = new Pettanr.Views.Top.Index({})\r
   $("#header").html(r.render().el)\r
   \r
-  # try getting current user(copy paste from users/index)\r
-  user = new Backbone.Model()\r
-  user.url = '/users/sign_in'\r
-  user.save({}, {\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
-  \r
   window.onbeforeunload = (e)->\r
     return('leave?')\r
   window.router = new Pettanr.Router()\r
-  Backbone.history.start({pushState: true})\r
-  window.router.navigate('', true)\r
+  Backbone.history.start({silent: true, pushState: true})\r
+  \r
+  # try getting current user(copy paste from users/index)\r
+  user = new Pettanr.User.Current()\r
+  user.save({}, (current_user) ->\r
+    r = new Pettanr.Views.Top.Account({operators: window.operators})\r
+    $('#account').html(r.render().el)\r
+    window.router.home()\r
+  )\r
   \r
   t: () ->\r
     #i = new Pettanr.Balloon({id: 49})\r
index 469fde4..131c2e8 100644 (file)
@@ -14,3 +14,26 @@ class Pettanr.User extends Backbone.Model
     if @id\r
       @url = @url + @id\r
   \r
+class Pettanr.User.Current extends Pettanr.User\r
+  \r
+  save: (model_attr, after_save = null) ->\r
+    _this = this\r
+    super(model_attr, {\r
+      success: (model, response, options) ->\r
+        author = new Pettanr.Author(_this.get('author')) if _this.get('author')\r
+        artist = new Pettanr.Artist(_this.get('artist')) if _this.get('artist')\r
+        window.operators = new Pettanr.Operator({\r
+          user: _this, \r
+          author: author, \r
+          artist: artist\r
+        })\r
+        if after_save\r
+          after_save(_this)\r
+      error: (model, response, options) ->\r
+        r = new Pettanr.Views.User.Index({})\r
+        $("#pettanr").html(r.render().el)\r
+    })\r
+  \r
+  initialize: () ->\r
+    @url = '/users/sign_in'\r
+  \r
index b2d5fc5..878b4f4 100644 (file)
@@ -14,22 +14,11 @@ class Pettanr.Views.User.Index extends Backbone.View
   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
+    user = new Pettanr.User.Current()\r
+    user.save({user: {email: m, password: p}}, (current_user) ->\r
+      r = new Pettanr.Views.Top.Account({operators: window.operators})\r
+      $('#account').html(r.render().el)\r
+      window.router.home()\r
+    )\r
     return false\r
   \r