| .. | .. |
|---|
| 74 | 74 | '$store', |
|---|
| 75 | 75 | '$L', |
|---|
| 76 | 76 | function($scope, $http, toaster, $store, $L) { |
|---|
| 77 | | - |
|---|
| 77 | + $store.set('location', '/licenses'); |
|---|
| 78 | + |
|---|
| 78 | 79 | $scope.maxLengthErrorMsg = function(displayname, fieldMaxlength) { |
|---|
| 79 | 80 | return $L.get("{0} length is too long (max: {1}).", $L.get(displayname), fieldMaxlength); |
|---|
| 80 | 81 | } |
|---|
| .. | .. |
|---|
| 101 | 102 | var packResource = $resource('/pack/:packId', { |
|---|
| 102 | 103 | packId : '@id' |
|---|
| 103 | 104 | }); |
|---|
| 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 | + ]; |
|---|
| 104 | 112 | $scope.mandatory = { |
|---|
| 105 | 113 | code: true, |
|---|
| 106 | 114 | num_licenses: true, |
|---|
| .. | .. |
|---|
| 116 | 124 | var refFields = [{resource: 'organization', name: 'organization_id'},{resource: 'licensetype', name: 'license_type_id'}]; |
|---|
| 117 | 125 | Catalogs.loadRefs(function(refs) { |
|---|
| 118 | 126 | $scope.refs = refs; |
|---|
| 127 | + $scope.refs['pack_status'] = PACK_STATUS; |
|---|
| 119 | 128 | }, refFields); |
|---|
| 120 | 129 | }); |
|---|
| 121 | 130 | |
|---|
| .. | .. |
|---|
| 128 | 137 | |
|---|
| 129 | 138 | $scope.packs = packResource.query(); |
|---|
| 130 | 139 | |
|---|
| 131 | | - $scope.save = function() { |
|---|
| 140 | + var _savePackData = function() { |
|---|
| 132 | 141 | var _success = function() { |
|---|
| 133 | 142 | if (!$scope.isNew) $scope.showForm = false; |
|---|
| 134 | 143 | $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"))); |
|---|
| 135 | 145 | } |
|---|
| 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 | + } |
|---|
| 137 | 162 | } |
|---|
| 138 | 163 | |
|---|
| 139 | 164 | $scope.newPack = function() { |
|---|
| .. | .. |
|---|
| 141 | 166 | $scope.showForm = true; |
|---|
| 142 | 167 | $scope.pack = { |
|---|
| 143 | 168 | license_preactivation: true, |
|---|
| 169 | + status: 'PE', |
|---|
| 144 | 170 | 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 |
|---|
| 147 | 173 | } |
|---|
| 148 | 174 | setTimeout(function() { |
|---|
| 149 | 175 | $('#code').focus(); |
|---|
| .. | .. |
|---|
| 188 | 214 | $scope.$parent.$broadcast('pack_changed', pack); |
|---|
| 189 | 215 | } |
|---|
| 190 | 216 | |
|---|
| 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 | + } |
|---|
| 191 | 244 | } ]); |
|---|
| 192 | 245 | |
|---|
| 193 | 246 | app.controller('LicensesCtrl', [ |
|---|