2015-12-09 04:35:05 +01:00
|
|
|
angular
|
|
|
|
.module('bit.global')
|
|
|
|
|
2017-04-15 05:30:58 +02:00
|
|
|
.controller('mainController', function ($scope, $state, authService, appSettings, toastr, $window, $document) {
|
2015-12-09 04:35:05 +01:00
|
|
|
var vm = this;
|
|
|
|
vm.bodyClass = '';
|
|
|
|
vm.searchVaultText = null;
|
|
|
|
vm.version = appSettings.version;
|
|
|
|
|
|
|
|
$scope.currentYear = new Date().getFullYear();
|
|
|
|
|
|
|
|
$scope.$on('$viewContentLoaded', function () {
|
2017-03-25 15:43:19 +01:00
|
|
|
authService.getUserProfile().then(function (profile) {
|
|
|
|
vm.userProfile = profile;
|
|
|
|
});
|
2017-03-07 06:36:27 +01:00
|
|
|
|
2015-12-09 04:35:05 +01:00
|
|
|
if ($.AdminLTE) {
|
|
|
|
if ($.AdminLTE.layout) {
|
|
|
|
$.AdminLTE.layout.fix();
|
|
|
|
$.AdminLTE.layout.fixSidebar();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($.AdminLTE.pushMenu) {
|
|
|
|
$.AdminLTE.pushMenu.expandOnHover();
|
|
|
|
}
|
2017-02-23 06:45:54 +01:00
|
|
|
|
|
|
|
$(document).off('click', '.sidebar li a');
|
2015-12-09 04:35:05 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) {
|
|
|
|
vm.searchVaultText = null;
|
|
|
|
|
|
|
|
if (toState.data.bodyClass) {
|
|
|
|
vm.bodyClass = toState.data.bodyClass;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
vm.bodyClass = '';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.searchVault = function () {
|
2017-03-02 04:47:24 +01:00
|
|
|
$state.go('backend.user.vault');
|
2015-12-09 04:35:05 +01:00
|
|
|
};
|
|
|
|
|
2017-01-03 04:26:32 +01:00
|
|
|
$scope.addLogin = function () {
|
|
|
|
$scope.$broadcast('vaultAddLogin');
|
2015-12-09 04:35:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.addFolder = function () {
|
|
|
|
$scope.$broadcast('vaultAddFolder');
|
|
|
|
};
|
2017-04-15 04:49:51 +02:00
|
|
|
|
|
|
|
// Append dropdown menus to body
|
2017-04-15 05:30:58 +02:00
|
|
|
var bodyScrollbarWidth,
|
|
|
|
bodyDropdownMenu;
|
2017-04-15 04:49:51 +02:00
|
|
|
var dropdownHelpers = {
|
|
|
|
scrollbarWidth: function () {
|
|
|
|
if (!bodyScrollbarWidth) {
|
|
|
|
var bodyElem = $('body');
|
|
|
|
bodyElem.addClass('bit-position-body-scrollbar-measure');
|
2017-04-15 05:30:58 +02:00
|
|
|
bodyScrollbarWidth = $window.innerWidth - bodyElem[0].clientWidth;
|
2017-04-15 04:49:51 +02:00
|
|
|
bodyScrollbarWidth = isFinite(bodyScrollbarWidth) ? bodyScrollbarWidth : 0;
|
|
|
|
bodyElem.removeClass('bit-position-body-scrollbar-measure');
|
|
|
|
}
|
|
|
|
|
|
|
|
return bodyScrollbarWidth;
|
|
|
|
},
|
2017-04-15 05:30:58 +02:00
|
|
|
scrollbarInfo: function () {
|
2017-04-15 04:49:51 +02:00
|
|
|
return {
|
2017-04-15 05:30:58 +02:00
|
|
|
width: dropdownHelpers.scrollbarWidth(),
|
|
|
|
visible: $document.height() > $($window).height()
|
2017-04-15 04:49:51 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-04-15 05:30:58 +02:00
|
|
|
$(window).on('show.bs.dropdown', function (e) {
|
|
|
|
var target = $(e.target);
|
|
|
|
if (!target.hasClass('dropdown-to-body')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bodyDropdownMenu = target.find('.dropdown-menu');
|
2017-04-15 04:49:51 +02:00
|
|
|
var body = $('body');
|
2017-04-15 05:30:58 +02:00
|
|
|
body.append(bodyDropdownMenu.detach());
|
2017-04-15 04:49:51 +02:00
|
|
|
|
2017-04-15 05:30:58 +02:00
|
|
|
var eOffset = target.offset();
|
2017-04-15 04:49:51 +02:00
|
|
|
var css = {
|
|
|
|
display: 'block',
|
2017-04-15 05:30:58 +02:00
|
|
|
top: eOffset.top + target.outerHeight()
|
2017-04-15 04:49:51 +02:00
|
|
|
};
|
|
|
|
|
2017-04-15 05:30:58 +02:00
|
|
|
if (bodyDropdownMenu.hasClass('dropdown-menu-right')) {
|
|
|
|
var scrollbarInfo = dropdownHelpers.scrollbarInfo();
|
2017-04-15 04:49:51 +02:00
|
|
|
var scrollbarWidth = 0;
|
2017-04-15 05:30:58 +02:00
|
|
|
if (scrollbarInfo.visible && scrollbarInfo.width) {
|
|
|
|
scrollbarWidth = scrollbarInfo.width;
|
2017-04-15 04:49:51 +02:00
|
|
|
}
|
|
|
|
|
2017-04-15 05:30:58 +02:00
|
|
|
css.right = $window.innerWidth - scrollbarWidth - (eOffset.left + target.prop('offsetWidth')) + 'px';
|
2017-04-15 04:49:51 +02:00
|
|
|
css.left = 'auto';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
css.left = eOffset.left + 'px';
|
|
|
|
css.right = 'auto';
|
|
|
|
}
|
|
|
|
|
2017-04-15 05:30:58 +02:00
|
|
|
bodyDropdownMenu.css(css);
|
2017-04-15 04:49:51 +02:00
|
|
|
});
|
|
|
|
|
2017-04-15 05:30:58 +02:00
|
|
|
$(window).on('hide.bs.dropdown', function (e) {
|
|
|
|
var target = $(e.target);
|
|
|
|
if (!target.hasClass('dropdown-to-body')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
target.append(bodyDropdownMenu.detach());
|
|
|
|
bodyDropdownMenu.hide();
|
2017-04-15 04:49:51 +02:00
|
|
|
});
|
2015-12-09 04:35:05 +01:00
|
|
|
});
|