From 4d18a46ee3ada751517f9bf767d5057a3bf5eb9e Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Thu, 16 Oct 2014 18:16:33 +0000
Subject: [PATCH] #2021 feature - Added Pack management (in Beta)
---
securis/src/main/resources/static/js/licenses.js | 63 +++++++++++++++++++++++++++++--
1 files changed, 58 insertions(+), 5 deletions(-)
diff --git a/securis/src/main/resources/static/js/licenses.js b/securis/src/main/resources/static/js/licenses.js
index 15a7306..a2e3a20 100644
--- a/securis/src/main/resources/static/js/licenses.js
+++ b/securis/src/main/resources/static/js/licenses.js
@@ -74,7 +74,8 @@
'$store',
'$L',
function($scope, $http, toaster, $store, $L) {
-
+ $store.set('location', '/licenses');
+
$scope.maxLengthErrorMsg = function(displayname, fieldMaxlength) {
return $L.get("{0} length is too long (max: {1}).", $L.get(displayname), fieldMaxlength);
}
@@ -101,6 +102,13 @@
var packResource = $resource('/pack/:packId', {
packId : '@id'
});
+ var PACK_STATUS = [
+ {id: 'PE', label: $L.get('Pending')},
+ {id: 'AC', label: $L.get('Active')},
+ {id: 'OH', label: $L.get('On Hold')},
+ {id: 'EX', label: $L.get('Expired')},
+ {id: 'CA', label: $L.get('Cancelled')}
+ ];
$scope.mandatory = {
code: true,
num_licenses: true,
@@ -116,6 +124,7 @@
var refFields = [{resource: 'organization', name: 'organization_id'},{resource: 'licensetype', name: 'license_type_id'}];
Catalogs.loadRefs(function(refs) {
$scope.refs = refs;
+ $scope.refs['pack_status'] = PACK_STATUS;
}, refFields);
});
@@ -128,12 +137,28 @@
$scope.packs = packResource.query();
- $scope.save = function() {
+ var _savePackData = function() {
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, $scope.isNew ? $L.get("created") : $L.get("updated")));
}
- packResource.save($scope.pack, _success)
+ var _error = function(error) {
+ console.log(error);
+ 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'))));
+ }
+ packResource.save($scope.pack, _success, _error);
+ }
+ $scope.save = function() {
+ if ($scope.pack.num_activations > 0) {
+ BootstrapDialog.confirm($L.get("The pack '{0}' has active licenses, Do you want to modify it ?", $scope.pack.code), function(answer){
+ if (answer) {
+ _savePackData();
+ }
+ });
+ } else {
+ _savePackData();
+ }
}
$scope.newPack = function() {
@@ -141,9 +166,10 @@
$scope.showForm = true;
$scope.pack = {
license_preactivation: true,
+ status: 'PE',
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
+ license_type_id: null,
+ organization_id: null //!$scope.refs.organization_id || !$scope.refs.organization_id.length ? null : $scope.refs.organization_id[0].id
}
setTimeout(function() {
$('#code').focus();
@@ -188,6 +214,33 @@
$scope.$parent.$broadcast('pack_changed', pack);
}
+ $scope.createMetadataRow = function() {
+ if (!$scope.formu.metadata) {
+ $scope.formu.metadata = [];
+ }
+ $scope.formu.metadata.push({key: '', value: '', mandatory: true});
+ }
+ $scope.removeMetadataKey = function(row_md) {
+ $scope.formu.metadata.splice( $scope.formu.metadata.indexOf(row_md), 1 );
+ }
+ $scope.updateMetadata = function() {
+ // Called when Application ID change in current field
+ var newLTId = $scope.pack['license_type_id'];
+ if (newLTId) {
+ // Only if there is a "valid" value selected we should update the metadata
+ Catalogs.getResource('licensetype').get({licenseTypeId: newLTId}).$promise.then(function(lt) {
+ $scope.pack.metadata = [];
+ lt.metadata.forEach(function(md) {
+ $scope.pack.metadata.push({
+ key: md.key,
+ value: md.value,
+ readonly: !!md.value,
+ mandatory: md.mandatory
+ });
+ });
+ });
+ }
+ }
} ]);
app.controller('LicensesCtrl', [
--
Gitblit v1.3.2