rsanchez
2014-10-16 4d18a46ee3ada751517f9bf767d5057a3bf5eb9e
securis/src/main/resources/static/js/licenses.js
....@@ -74,7 +74,8 @@
7474 '$store',
7575 '$L',
7676 function($scope, $http, toaster, $store, $L) {
77
-
77
+ $store.set('location', '/licenses');
78
+
7879 $scope.maxLengthErrorMsg = function(displayname, fieldMaxlength) {
7980 return $L.get("{0} length is too long (max: {1}).", $L.get(displayname), fieldMaxlength);
8081 }
....@@ -101,6 +102,13 @@
101102 var packResource = $resource('/pack/:packId', {
102103 packId : '@id'
103104 });
105
+ var PACK_STATUS = [
106
+ {id: 'PE', label: $L.get('Pending')},
107
+ {id: 'AC', label: $L.get('Active')},
108
+ {id: 'OH', label: $L.get('On Hold')},
109
+ {id: 'EX', label: $L.get('Expired')},
110
+ {id: 'CA', label: $L.get('Cancelled')}
111
+ ];
104112 $scope.mandatory = {
105113 code: true,
106114 num_licenses: true,
....@@ -116,6 +124,7 @@
116124 var refFields = [{resource: 'organization', name: 'organization_id'},{resource: 'licensetype', name: 'license_type_id'}];
117125 Catalogs.loadRefs(function(refs) {
118126 $scope.refs = refs;
127
+ $scope.refs['pack_status'] = PACK_STATUS;
119128 }, refFields);
120129 });
121130
....@@ -128,12 +137,28 @@
128137
129138 $scope.packs = packResource.query();
130139
131
- $scope.save = function() {
140
+ var _savePackData = function() {
132141 var _success = function() {
133142 if (!$scope.isNew) $scope.showForm = false;
134143 $scope.packs = packResource.query();
144
+ toaster.pop('success', Catalogs.getName(), $L.get("Pack '{0}' {1} successfully", $scope.pack.code, $scope.isNew ? $L.get("created") : $L.get("updated")));
135145 }
136
- packResource.save($scope.pack, _success)
146
+ var _error = function(error) {
147
+ console.log(error);
148
+ toaster.pop('error', Catalogs.getName(), $L.get("Error {0} pack '{1}'. Reason: {2}", $scope.isNew ? $L.get("creating") : $L.get("updating"), $scope.pack.code, $L.get(error.headers('X-SECURIS-ERROR'))));
149
+ }
150
+ packResource.save($scope.pack, _success, _error);
151
+ }
152
+ $scope.save = function() {
153
+ if ($scope.pack.num_activations > 0) {
154
+ BootstrapDialog.confirm($L.get("The pack '{0}' has active licenses, Do you want to modify it ?", $scope.pack.code), function(answer){
155
+ if (answer) {
156
+ _savePackData();
157
+ }
158
+ });
159
+ } else {
160
+ _savePackData();
161
+ }
137162 }
138163
139164 $scope.newPack = function() {
....@@ -141,9 +166,10 @@
141166 $scope.showForm = true;
142167 $scope.pack = {
143168 license_preactivation: true,
169
+ status: 'PE',
144170 num_licenses: 1,
145
- license_type_id: !$scope.refs.license_type_id || !$scope.refs.license_type_id.length ? null : $scope.refs.license_type_id[0].id,
146
- organization_id: !$scope.refs.organization_id || !$scope.refs.organization_id.length ? null : $scope.refs.organization_id[0].id
171
+ license_type_id: null,
172
+ organization_id: null //!$scope.refs.organization_id || !$scope.refs.organization_id.length ? null : $scope.refs.organization_id[0].id
147173 }
148174 setTimeout(function() {
149175 $('#code').focus();
....@@ -188,6 +214,33 @@
188214 $scope.$parent.$broadcast('pack_changed', pack);
189215 }
190216
217
+ $scope.createMetadataRow = function() {
218
+ if (!$scope.formu.metadata) {
219
+ $scope.formu.metadata = [];
220
+ }
221
+ $scope.formu.metadata.push({key: '', value: '', mandatory: true});
222
+ }
223
+ $scope.removeMetadataKey = function(row_md) {
224
+ $scope.formu.metadata.splice( $scope.formu.metadata.indexOf(row_md), 1 );
225
+ }
226
+ $scope.updateMetadata = function() {
227
+ // Called when Application ID change in current field
228
+ var newLTId = $scope.pack['license_type_id'];
229
+ if (newLTId) {
230
+ // Only if there is a "valid" value selected we should update the metadata
231
+ Catalogs.getResource('licensetype').get({licenseTypeId: newLTId}).$promise.then(function(lt) {
232
+ $scope.pack.metadata = [];
233
+ lt.metadata.forEach(function(md) {
234
+ $scope.pack.metadata.push({
235
+ key: md.key,
236
+ value: md.value,
237
+ readonly: !!md.value,
238
+ mandatory: md.mandatory
239
+ });
240
+ });
241
+ });
242
+ }
243
+ }
191244 } ]);
192245
193246 app.controller('LicensesCtrl', [