| .. | .. |
|---|
| 159 | 159 | return LIC_STATUSES[status]; |
|---|
| 160 | 160 | } |
|---|
| 161 | 161 | |
|---|
| 162 | + var _createSuccessCallback = function(actionName, message, _innerCallback) { |
|---|
| 163 | + return function() { |
|---|
| 164 | + _innerCallback && _innerCallback(); |
|---|
| 165 | + toaster.pop('success', actionName, message); |
|---|
| 166 | + } |
|---|
| 167 | + } |
|---|
| 168 | + var _createErrorCallback = function(pack, actionName, _innerCallback) { |
|---|
| 169 | + return function(error) { |
|---|
| 170 | + console.log(error); |
|---|
| 171 | + _innerCallback && _innerCallback(); |
|---|
| 172 | + toaster.pop('error', actionName, $L.get("Error on action '{0}', pack '{1}'. Reason: {2}", actionName, pack.code, $L.get(error.headers('X-SECURIS-ERROR')))); |
|---|
| 173 | + } |
|---|
| 174 | + } |
|---|
| 175 | + this.getPacksList = function(pack, _onsuccess, _onerror) { |
|---|
| 176 | + return packResource.query(_onsuccess, _onerror); |
|---|
| 177 | + } |
|---|
| 178 | + this.activate = function(license, _onsuccess, _onerror) { |
|---|
| 179 | + console.log('Activation on license: ' + license.id); |
|---|
| 180 | + var _success = _createSuccessCallback($L.get('Activation'), $L.get("License '{0}' {1} successfully", license.code, $L.get("activated")), _onsuccess); |
|---|
| 181 | + var _error = _createErrorCallback(license, $L.get('Activation'), _onerror); |
|---|
| 182 | + licenseResource.activate({id: license.id}, _success, _error); |
|---|
| 183 | + } |
|---|
| 184 | + this.block = function(license, _onsuccess, _onerror) { |
|---|
| 185 | + console.log('Block on license: ' + license.id); |
|---|
| 186 | + var _success = _createSuccessCallback($L.get('Block'), $L.get("License '{0}' {1} successfully", license.code, $L.get("blocked")), _onsuccess); |
|---|
| 187 | + var _error = _createErrorCallback(license, $L.get('Block'), _onerror); |
|---|
| 188 | + licenseResource.putonhold({id: license.id}, _success, _error); |
|---|
| 189 | + } |
|---|
| 190 | + this.unblock = function(license, _onsuccess, _onerror) { |
|---|
| 191 | + console.log('Unblock on license: ' + license.id); |
|---|
| 192 | + var _success = _createSuccessCallback($L.get('Unblock'), $L.get("License '{0}' {1} successfully", license.code, $L.get("unblocked")), _onsuccess); |
|---|
| 193 | + var _error = _createErrorCallback(license, $L.get('Unblock'), _onerror); |
|---|
| 194 | + licenseResource.putonhold({id: license.id}, _success, _error); |
|---|
| 195 | + } |
|---|
| 196 | + this.cancel = function(license, extra_data, _onsuccess, _onerror) { |
|---|
| 197 | + console.log('Cancellation on license: ' + license.id); |
|---|
| 198 | + var _success = _createSuccessCallback($L.get('Cancellation'), $L.get("License '{0}' {1} successfully", license.code, $L.get("cancelled")), _onsuccess); |
|---|
| 199 | + var _error = _createErrorCallback(license, $L.get('Cancellation'), _onerror); |
|---|
| 200 | + var params = angular.extend({id: license.id}, extra_data); |
|---|
| 201 | + licenseResource.cancel(params, _success, _error); |
|---|
| 202 | + } |
|---|
| 203 | + this.delete = function(license, _onsuccess, _onerror) { |
|---|
| 204 | + console.log('Delete on license: ' + license.id); |
|---|
| 205 | + var _success = _createSuccessCallback($L.get('Deletion'), $L.get("License '{0}' {1} successfully", license.code, $L.get("deleted")), _onsuccess); |
|---|
| 206 | + var _error = _createErrorCallback(license, $L.get('Deletion'), _onerror); |
|---|
| 207 | + licenseResource.delete({licenseId: license.id}, _success, _error); |
|---|
| 208 | + } |
|---|
| 162 | 209 | }]); |
|---|
| 163 | 210 | |
|---|
| 164 | 211 | app.directive('fileLoader', |
|---|
| .. | .. |
|---|
| 217 | 264 | $scope.mandatoryFieldErrorMsg = function(displayname) { |
|---|
| 218 | 265 | return $L.get("'{0}' is required.", $L.get(displayname)); |
|---|
| 219 | 266 | } |
|---|
| 267 | + $scope.field1ShouldBeGreaterThanField2 = function(field1, field2) { |
|---|
| 268 | + return $L.get("{0} should be greater than {1}", $L.get(field1), $L.get(field2)); |
|---|
| 269 | + } |
|---|
| 220 | 270 | $scope.ellipsis = function(txt, len) { |
|---|
| 221 | 271 | if (!txt || txt.length <= len) return txt; |
|---|
| 222 | 272 | return txt.substring(0, len) + '...'; |
|---|
| .. | .. |
|---|
| 269 | 319 | $scope.packs = Packs.getPacksList(); |
|---|
| 270 | 320 | |
|---|
| 271 | 321 | $scope.save = function() { |
|---|
| 272 | | - if ($scope.pack.num_activations > 0) { |
|---|
| 273 | | - BootstrapDialog.confirm($L.get("The pack '{0}' has active licenses, Do you want to modify it ?", $scope.pack.code), function(answer){ |
|---|
| 274 | | - if (answer) { |
|---|
| 275 | | - Packs.savePackData($scope.pack, $scope.isNew, function() { |
|---|
| 276 | | - if (!$scope.isNew) $scope.showForm = false; |
|---|
| 277 | | - $scope.packs = Packs.getPacksList(); |
|---|
| 278 | | - }); |
|---|
| 279 | | - } |
|---|
| 280 | | - }); |
|---|
| 281 | | - } else { |
|---|
| 282 | | - Packs.savePackData($scope.pack, $scope.isNew, function() { |
|---|
| 283 | | - if (!$scope.isNew) { |
|---|
| 284 | | - $scope.showForm = false; |
|---|
| 285 | | - } else { |
|---|
| 286 | | - $scope.newPack(); |
|---|
| 287 | | - } |
|---|
| 288 | | - $scope.packs = Packs.getPacksList(); |
|---|
| 289 | | - }); |
|---|
| 290 | | - } |
|---|
| 322 | + Packs.savePackData($scope.pack, $scope.isNew, function() { |
|---|
| 323 | + if (!$scope.isNew) { |
|---|
| 324 | + $scope.showForm = false; |
|---|
| 325 | + } else { |
|---|
| 326 | + $scope.newPack(); |
|---|
| 327 | + } |
|---|
| 328 | + $scope.packs = Packs.getPacksList(); |
|---|
| 329 | + }); |
|---|
| 291 | 330 | } |
|---|
| 292 | 331 | |
|---|
| 293 | 332 | /** |
|---|
| 294 | 333 | * Execute an action over the pack, activation, onhold, cancellation |
|---|
| 295 | 334 | */ |
|---|
| 296 | 335 | $scope.execute = function(action, pack) { |
|---|
| 297 | | - |
|---|
| 298 | | - Packs[action](pack || $scope.pack, function() { |
|---|
| 299 | | - if (!$scope.isNew) $scope.showForm = false; |
|---|
| 300 | | - $scope.packs = Packs.getPacksList(); |
|---|
| 301 | | - }); |
|---|
| 336 | + var _execute = function(extra_data) { |
|---|
| 337 | + Packs[action](pack || $scope.pack, extra_data, function() { |
|---|
| 338 | + if (!$scope.isNew) $scope.showForm = false; |
|---|
| 339 | + $scope.packs = Packs.getPacksList(); |
|---|
| 340 | + }); |
|---|
| 341 | + } |
|---|
| 342 | + if (action === 'delete') { |
|---|
| 343 | + BootstrapDialog.confirm($L.get("The pack '{0}' will be deleted, are you sure ?", $scope.pack.code), function(answer) { |
|---|
| 344 | + if (answer) { |
|---|
| 345 | + _execute(); |
|---|
| 346 | + } |
|---|
| 347 | + }); |
|---|
| 348 | + } else { |
|---|
| 349 | + if (action === 'cancel') { |
|---|
| 350 | + BootstrapDialog.show({ |
|---|
| 351 | + title: $L.get("Pack cancellation"), |
|---|
| 352 | + type: BootstrapDialog.TYPE_DANGER, |
|---|
| 353 | + message: function(dialog) { |
|---|
| 354 | + var $content = $('<div></div>'); |
|---|
| 355 | + var $message = $('<div></div>'); |
|---|
| 356 | + var pageToLoad = dialog.getData('pageToLoad'); |
|---|
| 357 | + $message.append($('<label/>').text($L.get("The pack '{0}' and all its licenses will be cancelled, this action cannot be undone", $scope.pack.code))); |
|---|
| 358 | + $content.append($message); |
|---|
| 359 | + |
|---|
| 360 | + var $message = $('<div style="margin-top:10pt;"/>'); |
|---|
| 361 | + var pageToLoad = dialog.getData('pageToLoad'); |
|---|
| 362 | + $message.append($('<label style="margin-right:5pt;"/>').text($L.get("Cancellation reason:") + " ")); |
|---|
| 363 | + $message.append($('<input type="text" style="width:100%;" maxlength="512" id="_cancellation_reason"/>')); |
|---|
| 364 | + $content.append($message); |
|---|
| 365 | + return $content; |
|---|
| 366 | + }, |
|---|
| 367 | + closable: true, |
|---|
| 368 | + buttons: [{ |
|---|
| 369 | + id: 'btn-cancel', |
|---|
| 370 | + label: $L.get('Close'), |
|---|
| 371 | + cssClass: 'btn-default', |
|---|
| 372 | + action: function(dialogRef) { |
|---|
| 373 | + dialogRef.close(); |
|---|
| 374 | + } |
|---|
| 375 | + }, { |
|---|
| 376 | + id: 'btn-ok', |
|---|
| 377 | + label: $L.get('Cancel pack'), |
|---|
| 378 | + cssClass: 'btn-primary', |
|---|
| 379 | + action: function(dialogRef){ |
|---|
| 380 | + var reason = $('#_cancellation_reason').val(); |
|---|
| 381 | + console.log('Ready to cancel pack, by reason: ' + reason); |
|---|
| 382 | + if (!reason) { |
|---|
| 383 | + $('#_cancellation_reason').focus(); |
|---|
| 384 | + } else { |
|---|
| 385 | + _execute({reason: reason}); |
|---|
| 386 | + dialogRef.close(); |
|---|
| 387 | + } |
|---|
| 388 | + } |
|---|
| 389 | + }] |
|---|
| 390 | + }); |
|---|
| 391 | + } else { |
|---|
| 392 | + _execute(); |
|---|
| 393 | + } |
|---|
| 394 | + } |
|---|
| 302 | 395 | } |
|---|
| 303 | 396 | |
|---|
| 304 | 397 | |
|---|
| .. | .. |
|---|
| 309 | 402 | license_preactivation: true, |
|---|
| 310 | 403 | status: 'CR', |
|---|
| 311 | 404 | num_licenses: 1, |
|---|
| 405 | + init_valid_date: new Date(), |
|---|
| 406 | + default_valid_period: 30, |
|---|
| 312 | 407 | license_type_id: null, |
|---|
| 313 | 408 | organization_id: null //!$scope.refs.organization_id || !$scope.refs.organization_id.length ? null : $scope.refs.organization_id[0].id |
|---|
| 314 | 409 | } |
|---|