|
3 | 3 |
|
4 | 4 | window.balancedSetupFunctions = []; |
5 | 5 |
|
6 | | - |
7 | | -function hackTheLogin () { |
8 | | - if (window.TESTING) { |
9 | | - return; |
10 | | - } |
11 | | - |
12 | | - // TODO: refactor this nastiness. |
13 | | - // what happens is that ember-auth uses async: false which does not work in |
14 | | - // firefox. so instead, what we do is hack in auth **before** the app begins |
15 | | - // working. this means that if the user is already logged in then ember-auth |
16 | | - // is going to think that they are all good to go and the async: false |
17 | | - // won't break our flow. |
18 | | - window.Balanced.deferReadiness(); |
19 | | - |
20 | | - function fin () { |
21 | | - window.Balanced.advanceReadiness(); |
22 | | - } |
23 | | - |
24 | | - $.ajax({ |
25 | | - type: 'POST', |
26 | | - url: Ember.ENV.BALANCED.AUTH, |
27 | | - xhrFields: { |
28 | | - withCredentials: true |
29 | | - } |
30 | | - }).success(function (r) { |
31 | | - var csrfToken = r.csrf; |
32 | | - Balanced.NET.ajaxHeaders['X-CSRFToken'] = csrfToken; |
33 | | - var authCookie = Balanced.Auth.retrieveLogin(); |
34 | | - if (authCookie) { |
35 | | - $.ajax('https://auth.balancedpayments.com/logins', { |
36 | | - type: 'POST', |
37 | | - xhrFields: { |
38 | | - withCredentials: true |
39 | | - }, |
40 | | - data: { uri: authCookie } |
41 | | - }).success(function (login) { |
42 | | - Balanced.Analytics.trackEvent('login-success', {remembered: true}); |
43 | | - |
44 | | - // set the auth stuff manually |
45 | | - Balanced.Auth.setAuthProperties( |
46 | | - true, |
47 | | - Balanced.User.find(login.user_uri), |
48 | | - login.user_id, |
49 | | - login.user_id, |
50 | | - false |
51 | | - ); |
52 | | - fin(); |
53 | | - }).error(fin); |
54 | | - } else { |
55 | | - fin(); |
56 | | - } |
57 | | - }).error(fin); |
58 | | -} |
59 | | - |
60 | 6 | /* |
61 | | - Creates a new instance of an Ember application and |
62 | | - specifies what HTML element inside index.html Ember |
63 | | - should manage for you. |
64 | | - */ |
| 7 | +Creates a new instance of an Ember application and |
| 8 | +specifies what HTML element inside index.html Ember |
| 9 | +should manage for you. |
| 10 | +*/ |
65 | 11 | window.setupBalanced = function (divSelector) { |
66 | 12 |
|
67 | | - // default to #balanced-app if not specified |
68 | | - divSelector = divSelector || '#balanced-app'; |
69 | | - window.Balanced = Ember.Application.create({ |
70 | | - rootElement: divSelector, |
71 | | - LOG_TRANSITIONS: true, |
72 | | - |
73 | | - customEvents: { |
74 | | - // key is the jquery event, value is the name used in views |
75 | | - changeDate: 'changeDate' |
76 | | - } |
77 | | - }); |
78 | | - |
79 | | - hackTheLogin(); |
80 | | - |
81 | | - window.Balanced.onLoad = function () { |
82 | | - // initialize anything that needs to be done on application load |
83 | | - Balanced.Analytics.init(Ember.ENV.BALANCED); |
84 | | - }; |
85 | | - |
86 | | - _.each(window.balancedSetupFunctions, function (setupFunction) { |
87 | | - setupFunction(); |
88 | | - }); |
| 13 | + // default to #balanced-app if not specified |
| 14 | + divSelector = divSelector || '#balanced-app'; |
| 15 | + window.Balanced = Ember.Application.create({ |
| 16 | + rootElement: divSelector, |
| 17 | + LOG_TRANSITIONS: true, |
| 18 | + |
| 19 | + customEvents: { |
| 20 | + // key is the jquery event, value is the name used in views |
| 21 | + changeDate: 'changeDate' |
| 22 | + } |
| 23 | + }); |
| 24 | + |
| 25 | + window.Balanced.onLoad = function () { |
| 26 | + // initialize anything that needs to be done on application load |
| 27 | + Balanced.Analytics.init(Ember.ENV.BALANCED); |
| 28 | + }; |
| 29 | + |
| 30 | + _.each(window.balancedSetupFunctions, function (setupFunction) { |
| 31 | + setupFunction(); |
| 32 | + }); |
89 | 33 | }; |
0 commit comments