2016-09-11 05:30:17 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngdoc function
|
|
|
|
* @name passmanApp.controller:MenuCtrl
|
|
|
|
* @description
|
|
|
|
* # MenuCtrl
|
|
|
|
* Controller of the passmanApp
|
|
|
|
*/
|
|
|
|
angular.module('passmanApp')
|
2016-09-16 20:01:25 +08:00
|
|
|
.controller('MenuCtrl', ['$scope', 'VaultService', 'SettingsService', '$location', '$rootScope', 'TagService',
|
|
|
|
function ($scope, VaultService, SettingsService, $location, $rootScope, TagService) {
|
2016-09-23 18:30:50 +08:00
|
|
|
$rootScope.logout = function () {
|
2016-09-16 20:01:25 +08:00
|
|
|
SettingsService.setSetting('defaultVaultPass', false);
|
|
|
|
$rootScope.$broadcast('logout');
|
|
|
|
$location.path('/');
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.selectedTags = [];
|
|
|
|
$scope.getTags = function ($query) {
|
|
|
|
return TagService.searchTag($query);
|
|
|
|
};
|
|
|
|
|
2016-09-25 02:16:57 +08:00
|
|
|
$scope.$watch(function(){
|
|
|
|
return VaultService.getActiveVault()
|
|
|
|
}, function(vault){
|
|
|
|
$scope.active_vault = vault;
|
|
|
|
});
|
|
|
|
|
2016-09-21 00:38:49 +08:00
|
|
|
$scope.filtered_tags = [];
|
|
|
|
$rootScope.$on('limit_tags_in_list', function (evt, tags) {
|
|
|
|
$scope.filtered_tags = [];
|
|
|
|
for (var i = 0; i < tags.length; i++) {
|
|
|
|
var tag = {
|
|
|
|
text: tags[i]
|
|
|
|
};
|
|
|
|
|
|
|
|
var found = false;
|
|
|
|
for (var x = 0; x < $scope.selectedTags.length; x++) {
|
|
|
|
if($scope.selectedTags[x].text === tag.text){
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(found === false){
|
|
|
|
$scope.filtered_tags.push(tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-09-16 20:01:25 +08:00
|
|
|
$scope.$watch('selectedTags', function () {
|
|
|
|
$rootScope.$broadcast('selected_tags_updated', $scope.selectedTags)
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
$scope.tagClicked = function (tag) {
|
|
|
|
$scope.selectedTags.push(tag)
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.available_tags = TagService.getTags();
|
|
|
|
|
|
|
|
$scope.$watch(function () {
|
2016-09-21 00:38:49 +08:00
|
|
|
if ($scope.selectedTags.length === 0) {
|
|
|
|
return TagService.getTags();
|
|
|
|
} else {
|
|
|
|
return $scope.filtered_tags;
|
|
|
|
}
|
2016-09-16 20:01:25 +08:00
|
|
|
}, function (tags) {
|
|
|
|
$scope.available_tags = tags;
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
$scope.toggleDeleteTime = function () {
|
|
|
|
if ($scope.delete_time > 0) {
|
|
|
|
$scope.delete_time = 0;
|
|
|
|
} else {
|
|
|
|
$scope.delete_time = 1;
|
|
|
|
}
|
|
|
|
$rootScope.$broadcast('set_delete_time', $scope.delete_time);
|
|
|
|
};
|
|
|
|
}]);
|