passman/js/app/controllers/menu.js

205 lines
7.1 KiB
JavaScript
Raw Normal View History

2016-10-19 23:44:19 +08:00
/**
* Nextcloud - passman
*
* @copyright Copyright (c) 2016, Sander Brand (brantje@gmail.com)
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es)
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
2016-10-08 01:56:29 +08:00
(function () {
'use strict';
2016-09-11 05:30:17 +08:00
2016-10-08 01:56:29 +08:00
/**
* @ngdoc function
* @name passmanApp.controller:MenuCtrl
* @description
* # MenuCtrl
* Controller of the passmanApp
*/
angular.module('passmanApp')
2016-10-18 01:29:05 +08:00
.controller('MenuCtrl', ['$scope', 'VaultService', '$location', '$rootScope', 'TagService','SettingsService',
function ($scope, VaultService, $location, $rootScope, TagService, SettingsService) {
2016-10-08 01:56:29 +08:00
$rootScope.logout = function () {
SettingsService.setSetting('defaultVaultPass', false);
TagService.resetTags();
2016-10-08 01:56:29 +08:00
$rootScope.$broadcast('logout');
$location.path('/');
};
2016-10-08 01:56:29 +08:00
$scope.selectedTags = [];
$scope.getTags = function ($query) {
return TagService.searchTag($query);
};
$scope.$watch(function () {
return VaultService.getActiveVault();
}, function (vault) {
$scope.active_vault = vault;
});
2016-09-25 02:16:57 +08:00
2016-09-21 00:38:49 +08:00
$scope.filtered_tags = [];
2016-10-08 01:56:29 +08:00
$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]
};
2016-09-21 00:38:49 +08:00
2016-10-08 01:56:29 +08:00
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-21 00:38:49 +08:00
}
2016-10-08 01:56:29 +08:00
}
});
2016-09-21 00:38:49 +08:00
2016-10-08 01:56:29 +08:00
$scope.$watch('selectedTags', function () {
$rootScope.$broadcast('selected_tags_updated', $scope.selectedTags);
}, true);
$scope.tagSelected = function (tag) {
for (var i = 0; i < $scope.selectedTags.length; i++) {
if($scope.selectedTags[i].text === tag.text){
return true;
}
}
return false;
};
$scope.removeTagFromSelected = function (tag) {
var where =-1;
for (var i = 0; i < $scope.selectedTags.length; i++) {
if($scope.selectedTags[i].text === tag.text){
where=i;
}
}
if(where === -1){
//console.log("Cant remove selected Tag, Tag not present!");
}
$scope.selectedTags.splice(where, 1);
};
$scope.clearForm = function () {
document.getElementById('tagsearch').value="";
};
$scope.tagClickedString = function (tagtext) {
var tag=[];
tag.text=tagtext;
$scope.tagClicked(tag);
};
$scope.tagClicked = function (tag) {
//check if tag already selected
if(!$scope.tagSelected(tag)){
$scope.selectedTags.push(tag);
}else{
//console.log("Already selected Tag!");
$scope.removeTagFromSelected(tag);
}
2016-10-08 01:56:29 +08:00
};
$scope.clickedNavigationItem="all";
$scope.filterCredentialBySpecial = function (string) {
$scope.clickedNavigationItem=string;
if(string !== "nav_trashbin"){
$scope.delete_time=0;
$rootScope.$broadcast('set_delete_time', $scope.delete_time);
}
if(string === "all"){
$scope.selectedTags =[];
}
$rootScope.$broadcast('filterSpecial',string);
//close settings when item is selected
$scope.settingsShown=false;
};
$scope.collapsedDefaultValue=false;
$scope.tagCollapsibleOpen=VaultService.getVaultSetting("vaultTagCollapsedState",$scope.collapsedDefaultValue);
$scope.tagCollapsibleClicked = function () {
if (VaultService.getVaultSetting("vaultTagCollapsedState",$scope.collapsedDefaultValue) === true) {
VaultService.setVaultSetting("vaultTagCollapsedState",false);
} else {
VaultService.setVaultSetting("vaultTagCollapsedState",true);
}
};
$scope.tagCollapsibleState = function () {
if(VaultService.getVaultSetting('vaultTagCollapsedState',$scope.collapsedDefaultValue)){
return "";
}
return "open";
};
$scope.legacyNavbar = VaultService.getVaultSetting("vaultTagCollapsedState",false);
$scope.legacyNavbarChecked = function () {
if (VaultService.getVaultSetting("vaultNavBarLegacy",false)) {
VaultService.setVaultSetting("vaultNavBarLegacy",false);
} else {
VaultService.setVaultSetting("vaultNavBarLegacy",true);
}
$scope.legacyNavbar=VaultService.getVaultSetting("vaultNavBarLegacy",false);
};
$scope.legacyNavbarCheckedState = function () {
$scope.legacyNavbar=VaultService.getVaultSetting("vaultNavBarLegacy",false);
if($scope.legacyNavbar){
return true;
}
return false;
};
$rootScope.$on('credentials_loaded', function () {
$rootScope.$broadcast('selected_tags_updated', $scope.selectedTags);
});
2016-10-08 01:56:29 +08:00
$scope.available_tags = TagService.getTags();
2016-10-08 01:56:29 +08:00
$scope.$watch(function () {
if ($scope.selectedTags.length === 0) {
return TagService.getTags();
} else {
return TagService.getTags();
//Always show all tags
//return $scope.filtered_tags;
2016-10-08 01:56:29 +08:00
}
}, function (tags) {
//Always show all tags
//$scope.available_tags = tags;
$scope.available_tags = TagService.getTags();
2016-10-08 01:56:29 +08:00
}, true);
2016-10-08 01:56:29 +08:00
$scope.toggleDeleteTime = function () {
if ($scope.delete_time > 0) {
$scope.delete_time = 0;
} else {
$scope.delete_time = 1;
this.filterCredentialBySpecial('nav_trashbin');
2016-10-08 01:56:29 +08:00
}
$rootScope.$broadcast('set_delete_time', $scope.delete_time);
};
}]);
}());