1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
| | (function() {
| | 'use strict';
| |
| | var HTTP_ERRORS = {
| | 401: "Unathorized action",
| | 403: "Forbidden action",
| | 500: "Server error",
| | 404: "Element not found"
| | }
| |
| | var app = angular.module('securis');
| |
| | app.controller('PackAndLicensesCtrl', [
| | '$scope',
| | '$http',
| | 'toaster',
| | '$store',
| | '$L',
| | function($scope, $http, toaster, $store, $L) {
| | $scope.licenses = [
| | {id: 1,
| | "code": "BP-SA-001-AKSJMS234",
| | "user_fullname": "Johnny Belmonte",
| | "user_email": "jb@curisit.net",
| | "status": 3},
| | {id: 2,
| | "code": "BP-SA-001-KAJSDHAJS",
| | "user_fullname": "Walter Simons",
| | "user_email": "ws@curisit.net",
| | "status": 1},
| | {id: 3,
| | "code": "BP-SA-001-ASKDGHKA",
| | "user_fullname": "Frank Belmonte",
| | "user_email": "fb@curisit.net",
| | "status": 2},
| | {id: 4,
| | "code": "BP-SA-001-BBBGGGG",
| | "user_fullname": "John Dalton",
| | "user_email": "jd@curisit.net",
| | "status": 3},
| | {id: 5,
| | "code": "BP-SA-001-AKADNAJANA",
| | "user_fullname": "Walter Martins",
| | "user_email": "wm@curisit.net",
| | "status": 3},
| | {id: 6,
| | "code": "BP-SA-001-AKANDAKS",
| | "user_fullname": "Joe Bolton",
| | "user_email": "jbol@curisit.net",
| | "status": 2}
| | ];
| |
| | $scope.maxLengthErrorMsg = function(displayname, fieldMaxlength) {
| | return $L.get("{0} length is too long (max: {1}).", $L.get(displayname), fieldMaxlength);
| | }
| | $scope.mandatoryFieldErrorMsg = function(displayname) {
| | return $L.get("'{0}' is required.", $L.get(displayname));
| | }
| | $scope.ellipsis = function(txt, len) {
| | if (!txt || txt.length <= len) return txt;
| | return txt.substring(0, len) + '...';
| | }
| | $scope.currentPackId = $store.get('currentPackId');
| |
| | }]);
| |
| | app.controller('PacksCtrl', [
| | '$scope',
| | '$http',
| | '$resource',
| | 'toaster',
| | 'Catalogs',
| | '$store',
| | '$L',
| | function($scope, $http, $resource, toaster, Catalogs, $store, $L) {
| | var packResource = $resource('/pack/:packId', {
| | packId : '@id'
| | });
| | $scope.mandatory = {
| | code: true,
| | num_licenses: true,
| | organization_id: true,
| | license_type_id: true
| | }
| | $scope.maxlength = {
| | code: 50,
| | comments: 1024
| | }
| | $scope.refs = {};
| | Catalogs.init().then(function() {
| | Catalogs.loadRefs($scope.refs, [{resource: 'organization', name: 'organization_id'},{resource: 'licensetype', name: 'license_type_id'}])
| | });
| |
| | // Used to create the form with the appropriate data
| | $scope.isNew = undefined;
| |
| | // Selected pack from listing
| | // pack is the edited pack, in creation contains the data for the new pack
| | $scope.pack = null;
| |
| | $scope.packs = packResource.query();
| |
| | $scope.save = function() {
| | var _success = function() {
| | $scope.packs = packResource.query();
| | }
| | packResource.save($scope.pack, _success)
| | }
| |
| | $scope.newPack = function() {
| | $scope.isNew = true;
| | $scope.showForm = true;
| | $scope.pack = {
| | num_licenses: 1,
| | license_type_id: !$scope.refs.license_type_id || !$scope.refs.license_type_id.length ? null : $scope.refs.license_type_id[0].id,
| | organization_id: !$scope.refs.organization_id || !$scope.refs.organization_id.length ? null : $scope.refs.organization_id[0].id
| | }
| | setTimeout(function() {
| | $('#code').focus();
| | }, 0);
| | }
| |
| | $scope.editPack = function(selectedPack) {
| | $scope.isNew = false;
| | $scope.showForm = true;
| | $scope.pack = selectedPack;
| | setTimeout(function() {
| | $('#code').focus();
| | }, 0);
| | }
| |
| | $scope.deletePack = function(selectedPack) {
| | $scope.showForm = false;
| | BootstrapDialog.confirm($L.get("The pack '{0}' will be deleted, are you sure?", selectedPack.code), function(result){
| | if(result) {
| | var promise = packResource.remove({}, {id: selectedPack.id}).$promise;
| | promise.then(function(data) {
| | $scope.selectPack(null);
| | $scope.packs = packResource.query();
| | toaster.pop('success', Catalogs.getName(), $L.get("Pack '{0}' deleted successfully", selectedPack.code));
| | },function(error) {
| | console.log(error);
| | toaster.pop('error', Catalogs.getName(), $L.get("Error deleting pack, reason: {0}. Details: {1}", $L.get(HTTP_ERRORS[error.status]), error.headers('X-SECURIS-ERROR')), 10000);
| | });
| | }
| | });
| | $scope.isNew = false;
| | }
| |
| |
| | $scope.cancel = function() {
| | $scope.showForm = false;
| | }
| |
| | $scope.selectPack = function(packId) {
| | $scope.$parent.currentPackId = packId;
| | $store.put('currentPackId', packId);
| | }
| |
| | } ]);
| |
| | })();
|
|