From c4d513ca26fe80946a5d90264de5d8e13e4ea974 Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Thu, 23 Oct 2014 17:21:24 +0000
Subject: [PATCH] #2021 feature - Added pack actions in server and in frontend
---
securis/src/main/resources/static/js/licenses.js | 71 ++++++++++++++++++++++++++++++++---
1 files changed, 65 insertions(+), 6 deletions(-)
diff --git a/securis/src/main/resources/static/js/licenses.js b/securis/src/main/resources/static/js/licenses.js
index 09a33bd..a7d5761 100644
--- a/securis/src/main/resources/static/js/licenses.js
+++ b/securis/src/main/resources/static/js/licenses.js
@@ -101,11 +101,20 @@
'$store',
'$L',
function($scope, $http, $resource, toaster, Catalogs, $store, $L) {
- var packResource = $resource('/pack/:packId', {
- packId : '@id'
- });
+ var packResource = $resource('/pack/:packId/:action',
+ {
+ packId : '@id',
+ action : '@action'
+ },
+ {
+ activate: {
+ method: "POST",
+ params: {action: "activate"}
+ }
+ }
+ );
var PACK_STATUS = [
- {id: 'PE', label: $L.get('Pending')},
+ {id: 'CR', label: $L.get('Created')},
{id: 'AC', label: $L.get('Active')},
{id: 'OH', label: $L.get('On Hold')},
{id: 'EX', label: $L.get('Expired')},
@@ -165,13 +174,31 @@
_savePackData();
}
}
+
+ /**
+ * Execute an action over the pack, activation, onhold, cancellation
+ */
+ $scope.execute = function(action) {
+ console.log('Action: '+ action +' on pack: ' + $scope.pack.id);
+ var _success = function() {
+ if (!$scope.isNew) $scope.showForm = false;
+ $scope.packs = packResource.query();
+ toaster.pop('success', Catalogs.getName(), $L.get("Pack '{0}' {1} successfully", $scope.pack.code, $L.get("activated")));
+ }
+ var _error = function(error) {
+ console.log(error);
+ toaster.pop('error', Catalogs.getName(), $L.get("Error {0} pack '{1}'. Reason: {2}", $L.get("activating"), $scope.pack.code, $L.get(error.headers('X-SECURIS-ERROR'))));
+ }
+ packResource.activate({id: $scope.pack.id}, _success, _error);
+ }
+
$scope.newPack = function() {
$scope.isNew = true;
$scope.showForm = true;
$scope.pack = {
license_preactivation: true,
- status: 'PE',
+ status: 'CR',
num_licenses: 1,
license_type_id: null,
organization_id: null //!$scope.refs.organization_id || !$scope.refs.organization_id.length ? null : $scope.refs.organization_id[0].id
@@ -190,7 +217,13 @@
if (!(selectedPack.end_valid_date instanceof Date)) {
selectedPack.end_valid_date = new Date(selectedPack.end_valid_date);
}
+
$scope.pack = selectedPack;
+
+ //$scope.pack.organization_name = $scope.getLabelFromId('organization_id', $scope.pack.organization_id);
+ $scope.pack.license_type_name = $scope.getLabelFromId('license_type_id', $scope.pack.license_type_id);
+ $scope.pack.status_name = $scope.getLabelFromId('pack_status', $scope.pack.status);
+
setTimeout(function() {
$('#code').focus();
}, 0);
@@ -223,6 +256,16 @@
$scope.$parent.currentPack = pack;
$store.put('currentPack', pack);
$scope.$parent.$broadcast('pack_changed', pack);
+ }
+
+ $scope.getLabelFromId = function(field, myid) {
+ var label = null;
+ $scope.refs[field].forEach(function (elem) {
+ if (elem.id === myid) {
+ label = elem.label;
+ }
+ });
+ return label;
}
$scope.createMetadataRow = function() {
@@ -264,6 +307,7 @@
function($scope, $http, $resource, toaster, $store, $L) {
$scope.$on('pack_changed', function(evt, message) {
$scope.licenses = licenseResource.query({packId: $scope.currentPack.id});
+ $scope.creationAvailable = $scope.currentPack.status == 'AC';
if ($scope.showForm) {
if ($scope.isNew) {
$scope.license.pack_id = $scope.currentPack.id
@@ -296,7 +340,8 @@
}
});
$scope.mandatory = {
- code: true
+ code: true,
+ email: true
}
$scope.maxlength = {
code: 50,
@@ -356,6 +401,20 @@
});
return;
}
+ if (!$scope.creationAvailable) {
+ BootstrapDialog.show({
+ title: $L.get('Pack not active'),
+ type: BootstrapDialog.TYPE_WARNING,
+ message: $L.get('Current pack is not active, so licenses cannot be created'),
+ buttons: [{
+ label: 'OK',
+ action: function(dialog) {
+ dialog.close();
+ }
+ }]
+ });
+ return;
+ }
$scope.isNew = true;
$scope.showForm = true;
--
Gitblit v1.3.2