From 01cb4660b2a3e9cdf12dc469d176145f31e0ddfb Mon Sep 17 00:00:00 2001 From: Andrew Lovett-Barron Date: Sun, 17 Dec 2017 21:52:17 -0700 Subject: [PATCH] Variety of fixes focusing on login flow and culling errors --- _config.yml | 2 +- _includes/header.html | 2 +- _layouts/home.html | 2 +- js/form.js | 9 +++------ js/grant.js | 3 ++- js/main.js | 47 +++++++++++++++++++++---------------------- js/user.js | 5 +++-- 7 files changed, 34 insertions(+), 36 deletions(-) diff --git a/_config.yml b/_config.yml index 4922164..273054e 100644 --- a/_config.yml +++ b/_config.yml @@ -14,7 +14,7 @@ # You can create any custom variable you would like, and they will be accessible # in the templates via {{ site.myvariable }}. title: Grant Calculator -email: your-email@example.com +email: alb@andrewlb.com description: >- # this means to ignore newlines until "baseurl:" Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for diff --git a/_includes/header.html b/_includes/header.html index 3b7a8c4..8ea594c 100644 --- a/_includes/header.html +++ b/_includes/header.html @@ -2,7 +2,7 @@
diff --git a/_layouts/home.html b/_layouts/home.html index 0366b12..6ae42a7 100644 --- a/_layouts/home.html +++ b/_layouts/home.html @@ -22,7 +22,7 @@

Find the True Value of your Grant Application

- +
diff --git a/js/form.js b/js/form.js index 2453715..964ef69 100644 --- a/js/form.js +++ b/js/form.js @@ -11,6 +11,7 @@ gc.Views = gc.Views || {}; }, initialize: function() { var _this = this + console.log("Init form",this.el) if($(this.el).hasClass('page')) { this.collection.getID() this.getFields() @@ -19,7 +20,6 @@ gc.Views = gc.Views || {}; submitForm: function(e) { var _this = this - console.log("Form clicked") var l = $(this.el).find('input').length var t = {} @@ -27,17 +27,14 @@ gc.Views = gc.Views || {}; t[$(i).attr('id')] = $(i).val() }) - - console.log(t) - this.collection.sendData( t, function(data,status) { - console.log(data) + // Redirect if(String(data).match('/')) { + console.log("Redirecting") window.location.replace(data) } }) - }, submitField: function(e) { diff --git a/js/grant.js b/js/grant.js index f6194f0..6d01ce5 100644 --- a/js/grant.js +++ b/js/grant.js @@ -90,7 +90,8 @@ gc.Collections = gc.Collections || {}; }, error : function(request,error) { - alert("Get Error: "+JSON.stringify(request)); + // alert("Get Error: "+JSON.stringify(request)); + callback() } }); } diff --git a/js/main.js b/js/main.js index 7dd5cbc..a2c170a 100644 --- a/js/main.js +++ b/js/main.js @@ -19,30 +19,29 @@ var getAPIPath = function getAPIPath() { } function checkAuth(callback) { - if(window.location.href !== window.gc.home) { - $.ajax({ - url : window.gc.api + '/auth', - type : 'GET', - xhrFields: { - withCredentials: true - }, - headers: { - 'Access-Control-Allow-Origin': true - }, - crossDomain: true, - success : function(data,status,xfr) { - console.log("Authenticated"); - callback() - }, - error : function(request,error) - { - if(window.location.href !== window.gc.home) window.location.replace(window.gc.home) - else console.log("Already logged out") - } - }); - } else { - callback() - } + console.log("Checking auth") + $.ajax({ + url : window.gc.api + '/auth', + type : 'GET', + xhrFields: { + withCredentials: true + }, + headers: { + 'Access-Control-Allow-Origin': true + }, + crossDomain: true, + success : function(data,status,xfr) { + console.log("Authenticated",data); + if(window.location.href == window.gc.home) window.location.replace(window.gc.home+'/list') + callback() + }, + error : function(request,error) + { + if(window.location.href !== window.gc.home) window.location.replace(window.gc.home) + else console.log("Already logged out") + callback() + } + }); } var getUrlParameter = function getUrlParameter(sParam) { diff --git a/js/user.js b/js/user.js index 3b17417..8c74c71 100644 --- a/js/user.js +++ b/js/user.js @@ -45,7 +45,7 @@ gc.Collections = gc.Collections || {}; dataType:'json', data: data, success : function(data,status,xfr) { - console.log("Put Success: ",data,status,xfr) + console.log("Put Success: ", data, status, xfr) callback(data,status) }, error : function(request,error) @@ -75,7 +75,8 @@ gc.Collections = gc.Collections || {}; }, error : function(request,error) { - alert("Get Error: "+JSON.stringify(request)); + // alert("Get Error: "+JSON.stringify(request)); + callback() } }); }