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;
|
2016-09-13 01:48:36 +02:00
|
|
|
var returnScrollY = $stateParams.returnScrollY;
|
2016-09-13 06:14:49 +02:00
|
|
|
var returnSearchText = $stateParams.returnSearchText;
|
2016-11-10 03:45:29 +01:00
|
|
|
var fromCurrent = $stateParams.fromCurrent;
|
2016-09-13 01:48:36 +02:00
|
|
|
|
2016-09-06 06:22:47 +02:00
|
|
|
$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) {
|
2016-09-06 06:22:47 +02:00
|
|
|
$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;
|
|
|
|
}
|
2016-09-13 04:37:59 +02:00
|
|
|
|
|
|
|
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-06 06:22:47 +02:00
|
|
|
});
|
|
|
|
});
|
2016-09-13 01:48:36 +02:00
|
|
|
|
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,
|
2016-11-10 03:45:29 +01:00
|
|
|
returnSearchText: returnSearchText,
|
|
|
|
fromCurrent: fromCurrent
|
2016-09-13 06:14:49 +02:00
|
|
|
});
|
2016-09-14 01:46:48 +02:00
|
|
|
};
|
2016-09-13 06:14:49 +02:00
|
|
|
|
2016-09-13 01:48:36 +02:00
|
|
|
$scope.close = function () {
|
2016-11-10 03:45:29 +01:00
|
|
|
if (fromCurrent) {
|
|
|
|
$state.go('tabs.current', {
|
|
|
|
animation: 'out-slide-down'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$state.go('tabs.vault', {
|
|
|
|
animation: 'out-slide-down',
|
|
|
|
scrollY: returnScrollY || 0,
|
|
|
|
searchText: returnSearchText
|
|
|
|
});
|
|
|
|
}
|
2016-09-13 01:48:36 +02:00
|
|
|
};
|
2016-09-13 04:37:59 +02:00
|
|
|
|
|
|
|
$scope.launchWebsite = function (site) {
|
|
|
|
if (site.showLaunch) {
|
2016-09-28 05:19:33 +02:00
|
|
|
$analytics.eventTrack('Launched Website');
|
2016-09-13 04:37:59 +02:00
|
|
|
chrome.tabs.create({ url: site.uri });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.clipboardError = function (e, password) {
|
2016-10-18 14:10:40 +02:00
|
|
|
toastr.info(i18n.browserNotSupportClipboard);
|
2016-09-13 04:37:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.clipboardSuccess = function (e, type) {
|
|
|
|
e.clearSelection();
|
2016-11-19 07:36:09 +01:00
|
|
|
$analytics.eventTrack('Copied ' + (type === i18nService.username ? 'Username' : 'Password'));
|
|
|
|
toastr.info(type + i18nService.valueCopied);
|
2016-09-13 04:37:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.showPassword = false;
|
|
|
|
$scope.togglePassword = function () {
|
2016-09-28 05:19:33 +02:00
|
|
|
$analytics.eventTrack('Toggled Password');
|
2016-09-13 04:37:59 +02:00
|
|
|
$scope.showPassword = !$scope.showPassword;
|
|
|
|
};
|
2016-09-06 05:43:56 +02:00
|
|
|
});
|