1 | /* global API */ |
||
2 | |||
3 | /** |
||
4 | * Nextcloud - passman |
||
5 | * |
||
6 | * @copyright Copyright (c) 2016, Sander Brand ([email protected]) |
||
7 | * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected]) |
||
8 | * @license GNU AGPL version 3 or any later version |
||
9 | * |
||
10 | * This program is free software: you can redistribute it and/or modify |
||
11 | * it under the terms of the GNU Affero General Public License as |
||
12 | * published by the Free Software Foundation, either version 3 of the |
||
13 | * License, or (at your option) any later version. |
||
14 | * |
||
15 | * This program is distributed in the hope that it will be useful, |
||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
18 | * GNU Affero General Public License for more details. |
||
19 | * |
||
20 | * You should have received a copy of the GNU Affero General Public License |
||
21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
22 | * |
||
23 | */ |
||
24 | |||
25 | (function () { |
||
26 | 'use strict'; |
||
27 | |||
28 | /** |
||
29 | * @ngdoc function |
||
30 | * @name passmanApp.controller:MainCtrl |
||
31 | * @description |
||
32 | * # MainCtrl |
||
33 | * Controller of the passmanApp |
||
34 | */ |
||
35 | angular.module('passmanExtension') |
||
36 | .controller('MainCtrl', ['$scope', 'Settings', '$location', '$rootScope', '$timeout', function ($scope, Settings, $window, $rootScope, $timeout) { |
||
37 | var port = API.runtime.connect(null, { |
||
38 | name: "PassmanCommunication" |
||
39 | }); |
||
40 | |||
41 | |||
42 | var messageParser = function (message) { |
||
43 | var e = message.split(':'); |
||
44 | |||
45 | switch (e[0]) { |
||
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
46 | case "credential_amount": |
||
47 | $scope.credential_amount = e[1]; |
||
48 | $scope.refreshing_credentials = false; |
||
49 | } |
||
50 | |||
51 | $scope.$apply(); |
||
52 | }; |
||
53 | |||
54 | /** |
||
55 | * Connect to the background service |
||
56 | */ |
||
57 | var initApp = function () { |
||
58 | port.onMessage.addListener(messageParser); |
||
59 | API.runtime.sendMessage(API.runtime.id, {method: "getMasterPasswordSet"}).then(function (isPasswordSet) { |
||
60 | //First check attributes |
||
61 | if (!isPasswordSet) { |
||
62 | return; |
||
63 | } |
||
64 | $scope.refreshing_credentials = true; |
||
65 | setTimeout(function () { |
||
66 | port.postMessage("credential_amount"); |
||
67 | }, 500); |
||
68 | }); |
||
69 | }; |
||
70 | |||
71 | |||
72 | $scope.refreshing_credentials = false; |
||
73 | $scope.refresh = function () { |
||
74 | $scope.refreshing_credentials = true; |
||
75 | API.runtime.sendMessage(API.runtime.id, {method: "getCredentials"}).then(function () { |
||
76 | setTimeout(function () { |
||
77 | port.postMessage("credential_amount"); |
||
78 | }, 1900); |
||
79 | }); |
||
80 | }; |
||
81 | |||
82 | $scope.menuIsOpen = false; |
||
83 | $scope.bodyOverflow = false; |
||
84 | $scope.showHeader = true; |
||
85 | |||
86 | $scope.toggleMenu = function () { |
||
87 | $scope.menuIsOpen = !$scope.menuIsOpen; |
||
88 | $scope.bodyOverflow = true; |
||
89 | $timeout(function () { |
||
90 | $scope.bodyOverflow = false; |
||
91 | }, 1500); |
||
92 | }; |
||
93 | |||
94 | $rootScope.$on('hideHeader', function () { |
||
95 | $scope.showHeader = false; |
||
96 | }); |
||
97 | |||
98 | $rootScope.$on('showHeader', function () { |
||
99 | $scope.showHeader = true; |
||
100 | }); |
||
101 | |||
102 | API.runtime.sendMessage(API.runtime.id, {'method': 'getRuntimeSettings'}).then(function (settings) { |
||
103 | $rootScope.app_settings = settings; |
||
104 | if (!settings || Object.keys(settings).length === 0) { |
||
105 | window.location = '#!/setup'; |
||
106 | } else if (settings.hasOwnProperty('isInstalled')) { |
||
107 | window.location = '#!/locked'; |
||
108 | } else { |
||
109 | initApp(); |
||
110 | } |
||
111 | }); |
||
112 | |||
113 | |||
114 | $scope.goto = function (page) { |
||
115 | window.location = '#!/' + page; |
||
116 | $scope.menuIsOpen = false; |
||
117 | }; |
||
118 | |||
119 | |||
120 | $scope.lockExtension = function () { |
||
121 | API.runtime.sendMessage(API.runtime.id, { |
||
122 | method: "setMasterPassword", |
||
123 | args: {password: null} |
||
124 | }).then(function () { |
||
125 | window.location = '#!/locked'; |
||
126 | }); |
||
127 | }; |
||
128 | }]); |
||
129 | }()); |
||
130 | |||
131 |