1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-20 07:40:57 +02:00
bitwarden-browser/src/popup/app/vault/vaultViewSiteController.js

94 lines
3.0 KiB
JavaScript
Raw Normal View History

2016-09-22 20:16:24 +02:00
angular
2016-09-06 05:43:56 +02:00
.module('bit.vault')
2016-09-28 05:19:33 +02:00
.controller('vaultViewSiteController', function ($scope, $state, $stateParams, siteService, tldjs, toastr, $q,
2016-10-18 14:10:40 +02:00
$analytics, i18nService) {
$scope.i18n = i18nService;
var returnScrollY = $stateParams.returnScrollY;
2016-09-13 06:14:49 +02:00
var returnSearchText = $stateParams.returnSearchText;
var fromCurrent = $stateParams.fromCurrent;
$scope.site = null;
2016-09-09 04:23:56 +02:00
siteService.get($stateParams.siteId, function (site) {
2016-09-22 20:16:24 +02:00
if (!site) {
return;
}
2016-09-17 05:47:50 +02:00
$q.when(site.decrypt()).then(function (model) {
$scope.site = model;
2016-09-11 05:50:51 +02:00
if (model.password) {
var maskedPassword = '';
for (var i = 0; i < model.password.length; i++) {
maskedPassword += '•';
}
$scope.site.maskedPassword = maskedPassword;
}
if (model.uri) {
$scope.site.showLaunch = model.uri.startsWith('http://') || model.uri.startsWith('https://');
var domain = tldjs.getDomain(model.uri);
if (domain) {
$scope.site.website = domain;
}
else {
$scope.site.website = model.uri;
}
}
else {
$scope.site.showLaunch = false;
}
});
});
2016-09-13 06:14:49 +02:00
$scope.edit = function (site) {
$state.go('editSite', {
animation: 'in-slide-up',
siteId: site.id,
fromView: true,
returnScrollY: returnScrollY || 0,
returnSearchText: returnSearchText,
fromCurrent: fromCurrent
2016-09-13 06:14:49 +02:00
});
};
2016-09-13 06:14:49 +02:00
$scope.close = function () {
if (fromCurrent) {
$state.go('tabs.current', {
animation: 'out-slide-down'
});
}
else {
$state.go('tabs.vault', {
animation: 'out-slide-down',
scrollY: returnScrollY || 0,
searchText: returnSearchText
});
}
};
$scope.launchWebsite = function (site) {
if (site.showLaunch) {
2016-09-28 05:19:33 +02:00
$analytics.eventTrack('Launched Website');
chrome.tabs.create({ url: site.uri });
}
};
$scope.clipboardError = function (e, password) {
2016-10-18 14:10:40 +02:00
toastr.info(i18n.browserNotSupportClipboard);
};
$scope.clipboardSuccess = function (e, type) {
e.clearSelection();
2016-09-28 05:19:33 +02:00
$analytics.eventTrack('Copied ' + type);
toastr.info(type + ' copied!');
};
$scope.showPassword = false;
$scope.togglePassword = function () {
2016-09-28 05:19:33 +02:00
$analytics.eventTrack('Toggled Password');
$scope.showPassword = !$scope.showPassword;
};
2016-09-06 05:43:56 +02:00
});