/
activation-key-add-subscriptions.controller.js
74 lines (64 loc) · 2.75 KB
/
activation-key-add-subscriptions.controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* @ngdoc object
* @name Bastion.activation-keys.controller:ActivationKeyAddSubscriptionsController
*
* @requires $scope
* @requires $state
* @requires $location
* @requires translate
* @requires Nutupane
* @requires CurrentOrganization
* @requires Subscription
* @requires ActivationKey
* @requires SubscriptionsHelper
*
* @description
* Provides the functionality for the activation key add subscriptions pane.
*/
angular.module('Bastion.activation-keys').controller('ActivationKeyAddSubscriptionsController',
['$scope', '$state', '$location', 'translate', 'Nutupane', 'CurrentOrganization', 'Subscription', 'ActivationKey', 'SubscriptionsHelper',
function ($scope, $state, $location, translate, Nutupane, CurrentOrganization, Subscription, ActivationKey, SubscriptionsHelper) {
var params;
params = {
'activation_key_id': $scope.$stateParams.activationKeyId,
'organization_id': CurrentOrganization,
'search': $location.search().search || "",
'sort_order': 'ASC',
'available_for': 'activation_key'
};
$scope.contentNutupane = new Nutupane(Subscription, params);
$scope.detailsTable = $scope.contentNutupane.table;
$scope.isAdding = false;
$scope.contentNutupane.setSearchKey('subscriptionSearch');
$scope.contentNutupane.masterOnly = true;
$scope.groupedSubscriptions = {};
$scope.$watch('detailsTable.rows', function (rows) {
$scope.groupedSubscriptions = SubscriptionsHelper.groupByProductName(rows);
});
$scope.disableAddButton = function () {
return $scope.detailsTable.numSelected === 0 || $scope.isAdding;
};
$scope.addSelected = function () {
var selected;
selected = SubscriptionsHelper.getSelectedSubscriptionAmounts($scope.detailsTable);
$scope.isAdding = true;
ActivationKey.addSubscriptions({id: $scope.activationKey.id, 'subscriptions': selected}, function () {
$scope.successMessages.push(translate("Successfully added %s subscriptions.").replace('%s', selected.length));
$scope.isAdding = false;
$scope.contentNutupane.refresh();
}, function (response) {
$scope.$parent.errorMessages = response.data.displayMessage;
$scope.isAdding = false;
});
};
$scope.amountSelectorValues = function (subscription) {
var value, values;
values = [];
for (value = 1; value < subscription.quantity && values.length < 5; value += 1) {
values.push(value);
}
values.push(subscription.quantity);
return values;
};
}]
);