diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-11-19 19:16:15 -0500 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-11-19 19:21:19 -0500 |
| commit | 261857fce969790aa87498100cf353fa494080c8 (patch) | |
| tree | c5d01aaa59c0dc65ebf4fb382dfa570d3bd15c79 /StoneIsland/www/js | |
| parent | 06910c8fd4df3daa47f5cdfcbc687b1072909f52 (diff) | |
accountview
Diffstat (limited to 'StoneIsland/www/js')
| -rw-r--r-- | StoneIsland/www/js/index.js | 4 | ||||
| -rw-r--r-- | StoneIsland/www/js/lib/account/AccountView.js | 39 | ||||
| -rw-r--r-- | StoneIsland/www/js/lib/auth/SignupView.js | 2 | ||||
| -rw-r--r-- | StoneIsland/www/js/lib/nav/NavView.js | 1 | ||||
| -rw-r--r-- | StoneIsland/www/js/sdk/auth.js | 15 | ||||
| -rw-r--r-- | StoneIsland/www/js/vendor/view/serializable.js | 9 |
6 files changed, 47 insertions, 23 deletions
diff --git a/StoneIsland/www/js/index.js b/StoneIsland/www/js/index.js index 72d105cf..07819ca4 100644 --- a/StoneIsland/www/js/index.js +++ b/StoneIsland/www/js/index.js @@ -38,6 +38,7 @@ var app = (function(){ app.curtain = new CurtainView () app.nav = new NavView () + app.account = new AccountView () app.login = new LoginView () app.logout = new LogoutView () app.signup = new SignupView () @@ -65,9 +66,6 @@ var app = (function(){ // cordova.plugins.Keyboard.disableScroll(true) } - auth.init( app.launch ) - } - app.launch = function(){ app.view = null app.router = new SiteRouter () app.router.route() diff --git a/StoneIsland/www/js/lib/account/AccountView.js b/StoneIsland/www/js/lib/account/AccountView.js new file mode 100644 index 00000000..221640c5 --- /dev/null +++ b/StoneIsland/www/js/lib/account/AccountView.js @@ -0,0 +1,39 @@ +var AccountView = View.extend({ + + initialize: function(){ + auth.init(this.ready.bind(this)) + }, + + ready: function(){ + if (auth.logged_in()) { + this.logged_in() + } + else { + this.logged_out() + } + }, + + populateAddresses: function(data){ + data.AddressBook.forEach(function(address){ + if (addressBookItem.isDefault) { + // populate app.shipping.address + } + else if (addressBookItem.isBillingDefault) { + // populate app.billing.address + } + }) + }, + + logged_in: function(){ + sdk.address.list({ + success: this.populateAddresses.bind(this) + }) + $("#nav .login").hide() + $("#nav .account, #nav .logout").show() + }, + logged_out: function(){ + $("#nav .login").show() + $("#nav .account, #nav .logout").hide() + }, + +}) diff --git a/StoneIsland/www/js/lib/auth/SignupView.js b/StoneIsland/www/js/lib/auth/SignupView.js index 0cfbf8b4..24eb0d09 100644 --- a/StoneIsland/www/js/lib/auth/SignupView.js +++ b/StoneIsland/www/js/lib/auth/SignupView.js @@ -39,7 +39,7 @@ var SignupView = FormView.extend({ }, success: function(data){ - auth.view_logged_in() + app.account.logged_in() }, error: function(data){ diff --git a/StoneIsland/www/js/lib/nav/NavView.js b/StoneIsland/www/js/lib/nav/NavView.js index 1a519de7..baa4df69 100644 --- a/StoneIsland/www/js/lib/nav/NavView.js +++ b/StoneIsland/www/js/lib/nav/NavView.js @@ -14,6 +14,7 @@ var NavView = View.extend({ "click .faq": "faq", "click .search": "search", + "click .main": "back", "click .account_back": "back", "click .profile": "profile", "click .payment": "payment", diff --git a/StoneIsland/www/js/sdk/auth.js b/StoneIsland/www/js/sdk/auth.js index 572823c3..548e67f4 100644 --- a/StoneIsland/www/js/sdk/auth.js +++ b/StoneIsland/www/js/sdk/auth.js @@ -24,12 +24,8 @@ var auth = sdk.auth = (function(){ auth.get_user(function(){ if (auth.logged_in()) { auth.get_cart() - auth.view_logged_in() } - else { - auth.view_logged_out() - } - fn && fn() + fn && fn( auth.logged_in() ) }) } @@ -57,15 +53,6 @@ var auth = sdk.auth = (function(){ cart.id = localStorage.getItem("yoox.cart_id") || -1 cb && cb() } - - auth.view_logged_in = function(){ - $("#nav .login").hide() - $("#nav .account, #nav .logout").show() - } - auth.view_logged_out = function(){ - $("#nav .login").show() - $("#nav .account, #nav .logout").hide() - } auth.log_out = function(){ auth.access_token = "" diff --git a/StoneIsland/www/js/vendor/view/serializable.js b/StoneIsland/www/js/vendor/view/serializable.js index 5dfca06e..80218266 100644 --- a/StoneIsland/www/js/vendor/view/serializable.js +++ b/StoneIsland/www/js/vendor/view/serializable.js @@ -46,8 +46,7 @@ var SerializableView = View.extend({ save: function(e){ e && e.preventDefault() - var data = this.serialize() - var errors = this.validate(data) + var errors = this.validate() if (errors) { this.show_errors(errors) return @@ -56,15 +55,15 @@ var SerializableView = View.extend({ this.hide_errors() } - // app.curtain.show() + app.curtain.show("loading") this.action({ data: data, success: function(data){ - // app.curtain.hide() + app.curtain.hide("loading") this.success(data) }.bind(this), error: function(data){ - // app.curtain.hide() + app.curtain.hide("loading") this.error(data) }.bind(this), }) |
