This repository has been archived by the owner on Apr 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 120
/
ready.js
110 lines (92 loc) · 2.67 KB
/
ready.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Handle sign_up_complete and reset_password_complete.
* Prints a message to the user that says
* "All ready! You can go visit {{ service }}"
*/
'use strict';
define([
'underscore',
'views/base',
'stache!templates/ready',
'lib/session',
'lib/xss',
'lib/strings',
'lib/auth-errors',
'lib/promise',
'views/mixins/service-mixin',
'views/marketing_snippet'
],
function (_, BaseView, Template, Session, Xss, Strings,
AuthErrors, p, ServiceMixin, MarketingSnippet) {
var View = BaseView.extend({
template: Template,
className: 'ready',
initialize: function (options) {
options = options || {};
this.type = options.type;
this.language = options.language;
},
beforeRender: function () {
if (this.relier.has('service')) {
this.setupOAuth();
}
},
context: function () {
var serviceName = this.relier.get('serviceName');
return {
service: this.relier.get('service'),
serviceName: serviceName,
signUp: this.is('sign_up'),
resetPassword: this.is('reset_password')
};
},
events: {
'click #redirectTo': BaseView.preventDefaultThen('submit')
},
afterRender: function () {
var graphic = this.$el.find('.graphic');
graphic.addClass('pulse');
// Finish the WebChannel flow
if (this.isOAuthSameBrowser() && this.relier.get('webChannelId')) {
this.submit();
}
return this._createMarketingSnippet();
},
_createMarketingSnippet: function () {
var marketingSnippet = new MarketingSnippet({
type: this.type,
service: this.relier.get('service'),
language: this.language,
el: this.$('.marketing-area'),
metrics: this.metrics
});
this.trackSubview(marketingSnippet);
return marketingSnippet.render();
},
submit: function () {
var self = this;
return p().then(function () {
if (self.isOAuthSameBrowser()) {
return self.finishOAuthFlow({
source: self.type
})
.then(function () {
// clear any stale OAuth information
Session.clear('oauth');
});
} else {
// We aren't expecting this case to happen.
self.displayError(AuthErrors.toError('UNEXPECTED_ERROR'));
}
});
},
is: function (type) {
return this.type === type;
}
});
_.extend(View.prototype, ServiceMixin);
return View;
});