|
5 | 5 | import Cocktail from 'cocktail'; |
6 | 6 | import BaseView from './base'; |
7 | 7 | import Template from 'templates/connect_another_service.mustache'; |
| 8 | +import UserAgentMixin from '../lib/user-agent-mixin'; |
| 9 | +import VerificationReasonMixin from './mixins/verification-reason-mixin'; |
| 10 | + |
| 11 | +const SERVICES = [ |
| 12 | + { |
| 13 | + description: 'A Secure Notepad App.', |
| 14 | + image: 'notes', |
| 15 | + links: { |
| 16 | + android: 'https://play.google.com/store/apps/details?id=org.mozilla.testpilot.notes&hl=en', |
| 17 | + }, |
| 18 | + name: 'Notes', |
| 19 | + }, |
| 20 | + { |
| 21 | + description: 'Save articles, videos and stories from any publication, page or app.', |
| 22 | + image: 'pocket', |
| 23 | + links: { |
| 24 | + android: 'https://getpocket.com/ff_signin?s=pocket&t=login', |
| 25 | + ios: 'https://getpocket.com/ff_signin?s=pocket&t=login' |
| 26 | + }, |
| 27 | + name: 'Pocket', |
| 28 | + }, |
| 29 | + { |
| 30 | + description: 'Take your passwords everywhere with Firefox Lockbox.', |
| 31 | + image: 'lockbox', |
| 32 | + links: { |
| 33 | + ios: 'https://itunes.apple.com/us/app/firefox-lockbox/id1314000270?mt=8', |
| 34 | + }, |
| 35 | + name: 'Lockbox', |
| 36 | + }, |
| 37 | + { |
| 38 | + description: 'Detects threats against your online accounts.', |
| 39 | + image: 'monitor', |
| 40 | + links: { |
| 41 | + website: 'https://monitor.firefox.com/', |
| 42 | + }, |
| 43 | + name: 'Monitor', |
| 44 | + }, |
| 45 | + { |
| 46 | + description: 'Screenshots made simple.', |
| 47 | + image: 'screenshots', |
| 48 | + links: { |
| 49 | + website: 'https://screenshots.firefox.com/', |
| 50 | + }, |
| 51 | + name: 'Screenshots', |
| 52 | + } |
| 53 | +]; |
| 54 | + |
8 | 55 |
|
9 | 56 | const View = BaseView.extend({ |
10 | 57 | className: 'connect-another-service', |
11 | 58 | template: Template, |
12 | 59 |
|
13 | | - setInitialContext (context) { |
14 | | - const services = [ |
15 | | - { |
16 | | - description: 'A Secure Notepad App.', |
17 | | - image: 'notes', |
18 | | - link: 'https://play.google.com/store/apps/details?id=org.mozilla.testpilot.notes&hl=en', |
19 | | - name: 'Notes', |
20 | | - }, |
21 | | - { |
22 | | - description: 'Save articles, videos and stories from any publication, page or app.', |
23 | | - image: 'pocket', |
24 | | - link: 'https://getpocket.com/ff_signin?s=pocket&t=login', |
25 | | - name: 'Pocket', |
26 | | - }, |
27 | | - { |
28 | | - description: 'Take your passwords everywhere with Firefox Lockbox.', |
29 | | - image: 'lockbox', |
30 | | - link: 'https://itunes.apple.com/us/app/firefox-lockbox/id1314000270?mt=8', |
31 | | - name: 'Lockbox', |
32 | | - }, |
33 | | - { |
34 | | - description: 'Detects threats against your online accounts.', |
35 | | - image: 'monitor', |
36 | | - link: 'https://monitor.firefox.com/', |
37 | | - name: 'Monitor', |
38 | | - } |
39 | | - ]; |
| 60 | + setInitialContext(context) { |
| 61 | + const services = this._filterServices(); |
| 62 | + const isSignIn = this.isSignIn(); |
| 63 | + const isSignUp = this.isSignUp(); |
| 64 | + const showSuccessMessage = this._showSuccessMessage(); |
40 | 65 |
|
41 | 66 | context.set({ |
42 | | - 'connect-services': services |
| 67 | + 'connect-services': services, |
| 68 | + isSignIn, |
| 69 | + isSignUp, |
| 70 | + showSuccessMessage |
43 | 71 | }); |
44 | 72 | }, |
| 73 | + |
| 74 | + _filterServices() { |
| 75 | + const { |
| 76 | + isFirefoxAndroid, |
| 77 | + isFirefoxIos, |
| 78 | + isOtherAndroid, |
| 79 | + isOtherIos, |
| 80 | + } = this.getContext(); |
| 81 | + |
| 82 | + const supportedServices = SERVICES.filter((service) => { |
| 83 | + if (service.links.android && (isFirefoxAndroid || isOtherAndroid)) { |
| 84 | + service.link = service.links.android; |
| 85 | + return service; |
| 86 | + } else if (service.links.ios && (isFirefoxIos || isOtherIos)) { |
| 87 | + service.link = service.links.ios; |
| 88 | + return service; |
| 89 | + } else if (service.links.website) { |
| 90 | + service.link = service.links.website; |
| 91 | + return service; |
| 92 | + } |
| 93 | + }); |
| 94 | + |
| 95 | + return supportedServices; |
| 96 | + }, |
| 97 | + |
| 98 | + _showSuccessMessage() { |
| 99 | + return !! this.model.get('showSuccessMessage') || |
| 100 | + !! this.getSearchParam('showSuccessMessage'); |
| 101 | + } |
45 | 102 | }); |
46 | 103 |
|
47 | 104 |
|
48 | 105 | Cocktail.mixin( |
49 | 106 | View, |
| 107 | + UserAgentMixin, |
| 108 | + VerificationReasonMixin, |
50 | 109 | ); |
51 | 110 |
|
52 | 111 | module.exports = View; |
0 commit comments