|
| 1 | +import angular from 'angular' |
| 2 | +import _ from 'lodash' |
| 3 | + |
1 | 4 | (function() {
|
2 |
| - 'use strict'; |
| 5 | + 'use strict' |
| 6 | + |
3 | 7 | var _supportedAccounts = [
|
4 |
| - { provider: "dribbble", className: "fa-dribbble", displayName: "Dribbble", disabled: false, order: 6, colorClass: 'el-dribble', featured: true}, |
5 |
| - { provider: "linkedin", className: "fa-linkedin", displayName: "LinkedIn", disabled: true, order: 5, colorClass: 'el-linkedin', featured: true}, |
6 |
| - { provider: "stackoverflow", className: "fa-stack-overflow", displayName: "Stack Overflow", disabled: false, order: 3, colorClass: 'el-stackoverflow'}, |
7 |
| - { provider: "behance", className: "fa-behance", displayName: "Behance", disabled: true, order: 2, colorClass: 'el-behance'}, |
8 |
| - { provider: "github", className: "fa-github", displayName: "Github", disabled: false, order: 1, colorClass: 'el-github', featured: true}, |
9 |
| - { provider: "bitbucket", className: "fa-bitbucket", displayName: "Bitbucket", disabled: false, order: 7, colorClass: 'el-bitbucket'}, |
10 |
| - { provider: "twitter", className: "fa-twitter", displayName: "Twitter", disabled: true, order: 4, colorClass: 'el-twitter'}, |
11 |
| - { provider: "weblink", className: "fa-globe", displayName: "Web Links", disabled: true, order: -1, colorClass: 'el-weblinks'} |
12 |
| - // TODO add more |
13 |
| - ]; |
| 8 | + { provider: 'dribbble', className: 'fa-dribbble', displayName: 'Dribbble', disabled: false, order: 6, colorClass: 'el-dribble', featured: true}, |
| 9 | + { provider: 'linkedin', className: 'fa-linkedin', displayName: 'LinkedIn', disabled: true, order: 5, colorClass: 'el-linkedin', featured: true}, |
| 10 | + { provider: 'stackoverflow', className: 'fa-stack-overflow', displayName: 'Stack Overflow', disabled: false, order: 3, colorClass: 'el-stackoverflow'}, |
| 11 | + { provider: 'behance', className: 'fa-behance', displayName: 'Behance', disabled: true, order: 2, colorClass: 'el-behance'}, |
| 12 | + { provider: 'github', className: 'fa-github', displayName: 'Github', disabled: false, order: 1, colorClass: 'el-github', featured: true}, |
| 13 | + { provider: 'bitbucket', className: 'fa-bitbucket', displayName: 'Bitbucket', disabled: false, order: 7, colorClass: 'el-bitbucket'}, |
| 14 | + { provider: 'twitter', className: 'fa-twitter', displayName: 'Twitter', disabled: true, order: 4, colorClass: 'el-twitter'}, |
| 15 | + { provider: 'weblink', className: 'fa-globe', displayName: 'Web Links', disabled: true, order: -1, colorClass: 'el-weblinks'} |
| 16 | + ] |
14 | 17 |
|
15 | 18 | angular.module('tcUIComponents')
|
16 | 19 | .directive('externalAccounts', function() {
|
17 | 20 | return {
|
18 | 21 | restrict: 'E',
|
19 |
| - templateUrl: 'directives/external-account/external-account.directive.html', |
| 22 | + template: require('./external-account')(), |
20 | 23 | scope: {
|
21 | 24 | linkedAccounts: '=',
|
22 | 25 | readOnly: '='
|
23 | 26 | },
|
24 | 27 | controller: ['$log', '$scope', 'ExternalAccountService', 'toaster',
|
25 | 28 | function($log, $scope, ExternalAccountService, toaster) {
|
26 | 29 |
|
27 |
| - $log = $log.getInstance("ExtAccountDirectiveCtrl") |
| 30 | + $log = $log.getInstance('ExtAccountDirectiveCtrl') |
28 | 31 |
|
29 |
| - var _accountList = _.clone(_supportedAccounts, true); |
30 |
| - _.remove(_accountList, function(al) { return al.order < 0}); |
| 32 | + var _accountList = _.clone(_supportedAccounts, true) |
| 33 | + _.remove(_accountList, function(al) { return al.order < 0}) |
31 | 34 | $scope.$watchCollection('linkedAccounts', function(newValue, oldValue) {
|
32 | 35 | if (newValue) {
|
33 | 36 | angular.forEach(_accountList, function(account) {
|
34 | 37 | var _linkedAccount = _.find(newValue, function(p) {
|
35 | 38 | return p.provider === account.provider
|
36 |
| - }); |
37 |
| - var accountStatus = _.get(_linkedAccount, 'data.status', null); |
| 39 | + }) |
| 40 | + var accountStatus = _.get(_linkedAccount, 'data.status', null) |
38 | 41 | if (!_linkedAccount) {
|
39 |
| - account.status = 'unlinked'; |
| 42 | + account.status = 'unlinked' |
40 | 43 | } else if(accountStatus && accountStatus.toLowerCase() === 'pending') {
|
41 |
| - account.status = 'pending'; |
| 44 | + account.status = 'pending' |
42 | 45 | } else {
|
43 |
| - account.status = 'linked'; |
| 46 | + account.status = 'linked' |
44 | 47 | }
|
45 |
| - }); |
46 |
| - $scope.accountList = _accountList; |
| 48 | + }) |
| 49 | + $scope.accountList = _accountList |
47 | 50 | } else {
|
48 | 51 | // reset the status for all accounts
|
49 | 52 | angular.forEach(_accountList, function(account) {
|
50 |
| - delete account.status; |
51 |
| - }); |
| 53 | + delete account.status |
| 54 | + }) |
52 | 55 | }
|
53 |
| - }); |
| 56 | + }) |
54 | 57 |
|
55 | 58 | $scope.handleClick = function(provider, status) {
|
56 | 59 | var provider = _.find(_supportedAccounts, function(s) {
|
57 |
| - return s.provider === provider; |
58 |
| - }); |
| 60 | + return s.provider === provider |
| 61 | + }) |
59 | 62 | if (status === 'linked') {
|
60 |
| - $log.debug(String.supplant('UnLinking to ' + provider.displayName)); |
61 |
| - _unlink(provider); |
| 63 | + $log.debug(String.supplant('UnLinking to ' + provider.displayName)) |
| 64 | + _unlink(provider) |
62 | 65 | } else if (status === 'unlinked') {
|
63 |
| - $log.debug(String.supplant('Linking to ' + provider.displayName)); |
64 |
| - _link(provider); |
| 66 | + $log.debug(String.supplant('Linking to ' + provider.displayName)) |
| 67 | + _link(provider) |
65 | 68 | }
|
66 |
| - }; |
| 69 | + } |
67 | 70 |
|
68 | 71 | function _link(provider) {
|
69 | 72 | ExternalAccountService.linkExternalAccount(provider.provider, null)
|
70 | 73 | .then(function(resp) {
|
71 |
| - $log.debug("Social account linked: " + JSON.stringify(resp)); |
72 |
| - $scope.linkedAccounts.push(resp.linkedAccount); |
73 |
| - toaster.pop('success', "Success", |
| 74 | + $log.debug('Social account linked: ' + JSON.stringify(resp)) |
| 75 | + $scope.linkedAccounts.push(resp.linkedAccount) |
| 76 | + toaster.pop('success', 'Success', |
74 | 77 | String.supplant(
|
75 |
| - "Your {provider} account has been linked. Data from your linked account will be visible on your profile shortly.", |
| 78 | + 'Your {provider} account has been linked. Data from your linked account will be visible on your profile shortly.', |
76 | 79 | {provider: provider.displayName}
|
77 | 80 | )
|
78 |
| - ); |
| 81 | + ) |
79 | 82 | })
|
80 | 83 | .catch(function(resp) {
|
81 | 84 | if (resp.status === 'SOCIAL_PROFILE_ALREADY_EXISTS') {
|
82 |
| - $log.info("Social profile already linked to another account"); |
83 |
| - toaster.pop('error', "Whoops!", |
| 85 | + $log.info('Social profile already linked to another account') |
| 86 | + toaster.pop('error', 'Whoops!', |
84 | 87 | String.supplant(
|
85 |
| - "This {provider} account is linked to another account. \ |
86 |
| - If you think this is an error please contact <a href=\"mailTo:[email protected]\">[email protected]</a>.", |
| 88 | + 'This {provider} account is linked to another account. \ |
| 89 | + If you think this is an error please contact <a href=\"mailTo:[email protected]\">[email protected]</a>.', |
87 | 90 | {provider: provider.displayName }
|
88 | 91 | )
|
89 |
| - ); |
| 92 | + ) |
90 | 93 | } else {
|
91 |
| - $log.error("Fatal Error: _link: " + resp.msg); |
92 |
| - toaster.pop('error', "Whoops!", "Sorry, we are unable to add your account right now. Please try again later. If the problem persists, please contact <a href=\"mailTo:[email protected]\">[email protected]</a>."); |
| 94 | + $log.error('Fatal Error: _link: ' + resp.msg) |
| 95 | + toaster.pop('error', 'Whoops!', 'Sorry, we are unable to add your account right now. Please try again later. If the problem persists, please contact <a href=\"mailTo:[email protected]\">[email protected]</a>.') |
93 | 96 | }
|
94 |
| - }); |
| 97 | + }) |
95 | 98 | }
|
96 | 99 |
|
97 | 100 | function _unlink(provider) {
|
98 | 101 | return ExternalAccountService.unlinkExternalAccount(provider.provider)
|
99 | 102 | .then(function(resp) {
|
100 |
| - $log.debug("Social account unlinked: " + JSON.stringify(resp)); |
| 103 | + $log.debug('Social account unlinked: ' + JSON.stringify(resp)) |
101 | 104 | var toRemove = _.findIndex($scope.linkedAccounts, function(la) {
|
102 |
| - return la.provider === provider.provider; |
103 |
| - }); |
| 105 | + return la.provider === provider.provider |
| 106 | + }) |
104 | 107 | if (toRemove > -1) {
|
105 | 108 | // remove from the linkedAccounts array
|
106 |
| - $scope.linkedAccounts.splice(toRemove, 1); |
| 109 | + $scope.linkedAccounts.splice(toRemove, 1) |
107 | 110 | }
|
108 |
| - toaster.pop('success', "Success", |
| 111 | + toaster.pop('success', 'Success', |
109 | 112 | String.supplant(
|
110 |
| - "Your {provider} account has been unlinked.", |
| 113 | + 'Your {provider} account has been unlinked.', |
111 | 114 | {provider: provider.displayName}
|
112 | 115 | )
|
113 |
| - ); |
| 116 | + ) |
114 | 117 | })
|
115 | 118 | .catch(function(resp) {
|
116 |
| - var msg = resp.msg; |
| 119 | + var msg = resp.msg |
117 | 120 | if (resp.status === 'SOCIAL_PROFILE_NOT_EXIST') {
|
118 |
| - $log.info("Social profile not linked to account"); |
119 |
| - msg = "{provider} account is not linked to your account. If you think this is an error please contact <a href=\"mailTo:[email protected]\">[email protected]</a>."; |
| 121 | + $log.info('Social profile not linked to account') |
| 122 | + msg = '{provider} account is not linked to your account. If you think this is an error please contact <a href=\"mailTo:[email protected]\">[email protected]</a>.' |
120 | 123 | } else {
|
121 |
| - $log.error("Fatal error: _unlink: " + msg); |
122 |
| - msg = "Sorry! We are unable to unlink your {provider} account. If problem persists, please contact <a href=\"mailTo:[email protected]\">[email protected]</a>"; |
| 124 | + $log.error('Fatal error: _unlink: ' + msg) |
| 125 | + msg = 'Sorry! We are unable to unlink your {provider} account. If problem persists, please contact <a href=\"mailTo:[email protected]\">[email protected]</a>' |
123 | 126 | }
|
124 |
| - toaster.pop('error', "Whoops!", String.supplant(msg, {provider: provider.displayName })); |
125 |
| - }); |
| 127 | + toaster.pop('error', 'Whoops!', String.supplant(msg, {provider: provider.displayName })) |
| 128 | + }) |
126 | 129 | }
|
127 | 130 | }
|
128 | 131 | ]
|
129 |
| - }; |
| 132 | + } |
130 | 133 | })
|
131 | 134 | .filter('providerData', function() {
|
132 | 135 | return function(input, field) {
|
133 | 136 | return _.result(_.find(_supportedAccounts, function(s) {
|
134 |
| - return s.provider === input.provider; |
135 |
| - }), field) || ""; |
136 |
| - }; |
137 |
| - }); |
138 |
| -})(); |
| 137 | + return s.provider === input.provider |
| 138 | + }), field) || '' |
| 139 | + } |
| 140 | + }) |
| 141 | +})() |
0 commit comments