diff --git a/awx/ui/static/js/forms/LicenseForm.js b/awx/ui/static/js/forms/LicenseForm.js index fcea0fa4ee..218d70e47e 100644 --- a/awx/ui/static/js/forms/LicenseForm.js +++ b/awx/ui/static/js/forms/LicenseForm.js @@ -49,7 +49,7 @@ angular.module('LicenseFormDefinition', []) tab: 'license' }, time_remaining: { - label: 'Time Left', + label: 'Time Remaining', type: 'text', readonly: true, tab: 'license' diff --git a/awx/ui/static/js/helpers/License.js b/awx/ui/static/js/helpers/License.js index f66349b3d6..0860087a3b 100644 --- a/awx/ui/static/js/helpers/License.js +++ b/awx/ui/static/js/helpers/License.js @@ -62,26 +62,41 @@ function($rootScope, $compile, CreateDialog, Store, LicenseUpdateForm, GenerateF if (parseInt(license.grace_period_remaining,10) > 86400) { title = "License Expired"; html = "
Thank you for using Ansible Tower. The Ansible Tower license " + - "has expired. You will no longer be able to add managed hosts or run playbooks after " + this.getRemainingDays(license.grace_period_remaining) + " days
"; + "has expired. "; + // trial licenses don't get a grace period + if (license.trial) { + html += "Managed hosts cannot be added and playbooks will no longer run."; + } else { + html += "After " + this.getRemainingDays(license.grace_period_remaining) + " grace days managed hosts cannot be added and playbooks will no longer run."; + } } else { title = "License Expired"; html = "Thank you for using Ansible Tower. The Ansible Tower license " + - "has expired, and the 30 day grace period has been exceeded. To continue using Tower to run playbooks and add managed hosts a " + - "valid license key is required.
"; + "has expired"; + // trial licenses don't get a grace period + html += (!license.trial) ? ", and the 30 day grace period has been exceeded." : "."; + html += " To continue using Tower to run playbooks and add managed hosts a valid license key is required."; } } else if (this.getRemainingDays(license.time_remaining) < 15) { + // Warning: license expiring in less than 15 days title = "License Warning"; html = "Thank you for using Ansible Tower. The Ansible Tower license " + - "has " + this.getRemainingDays(license.time_remaining) + " days remaining. Once the license expires you will no longer be able to add managed hosts or run playbooks.
"; + "has " + this.getRemainingDays(license.time_remaining) + " days remaining. "; + // trial licenses don't get a grace period + if (license.trial) { + html += "After the license expires playbooks will no longer run and managed hosts cannot be added."; + } else { + html += "After a short grace period of 30 days, playbooks will no longer run and managed hosts cannot be added."; + } } else if (license.free_instances <= 0) { title = "Host Count Exceeded"; html = "The Ansible Tower license has reached capacity for the number of " + - "managed hosts allowed. No additional hosts can be added.
"; + "managed hosts allowed. No additional hosts can be added. Existing playbooks can still be run against hosts already in inventory."; } else { // license is valid. the following text is displayed in the license viewer - title = "Update License"; // not actually used + title = "Update License"; html = "The Ansible Tower license is valid.
"; license_is_valid = true; } @@ -156,13 +171,11 @@ function($rootScope, $compile, CreateDialog, Store, LicenseUpdateForm, GenerateF var license = Store('license'), notify = this.shouldNotify(license), self = this, - scope, height, html, buttons, submitKey; + scope, height, html, buttons; self.scope = $rootScope.$new(); scope = self.scope; - submitKey = this.postLicense; - if (license && typeof license === 'object' && Object.keys(license).length > 0) { if (license.tested) { return true; @@ -181,7 +194,6 @@ function($rootScope, $compile, CreateDialog, Store, LicenseUpdateForm, GenerateF scope.flashMessage = null; scope.parseType = 'json'; - scope.license_json = " "; scope.removeLicenseDialogReady = scope.$on('LicenseDialogReady', function() { var e = angular.element(document.getElementById('license-modal-dialog')); @@ -190,7 +202,7 @@ function($rootScope, $compile, CreateDialog, Store, LicenseUpdateForm, GenerateF }); scope.submitLicenseKey = function() { - submitKey(scope.license_json); + self.postLicense(scope.license_json); }; if (IsAdmin()) { @@ -222,37 +234,33 @@ function($rootScope, $compile, CreateDialog, Store, LicenseUpdateForm, GenerateF height = (IsAdmin()) ? 600 : 350; - CreateDialog({ - scope: scope, - buttons: buttons, - width: 700, - height: height, - minWidth: 400, - title: html.title, - id: 'license-modal-dialog', - clonseOnEscape: false, - onClose: function() { - if (scope.codeMirror) { - scope.codeMirror.destroy(); - } - $('#license-modal-dialog').empty(); - }, - onResizeStop: function() { - if (IsAdmin()) { - TextareaResize({ - scope: scope, - textareaId: 'license_license_json', - modalId: 'license-modal-dialog', - formId: 'license-notification-body', - fld: 'license_json', - parse: true, - onChange: function() { scope.license_json_api_error = ''; } - }); - } - }, - onOpen: function() { - if (IsAdmin()) { - setTimeout(function() { + if (scope.removeLicenseReady) { + scope.removeLicenseReady(); + } + scope.removeLicenseReady = scope.$on('LicenseReady', function(e, data) { + + scope.license_json = " "; + if (data.license_info && data.license_info.valid_key !== undefined) { + scope.license_json = JSON.stringify(data.license_info, null, ' '); + } + + CreateDialog({ + scope: scope, + buttons: buttons, + width: 700, + height: height, + minWidth: 400, + title: html.title, + id: 'license-modal-dialog', + clonseOnEscape: false, + onClose: function() { + if (scope.codeMirror) { + scope.codeMirror.destroy(); + } + $('#license-modal-dialog').empty(); + }, + onResizeStop: function() { + if (IsAdmin()) { TextareaResize({ scope: scope, textareaId: 'license_license_json', @@ -262,20 +270,60 @@ function($rootScope, $compile, CreateDialog, Store, LicenseUpdateForm, GenerateF parse: true, onChange: function() { scope.license_json_api_error = ''; } }); - $('#cm-license_json-container .CodeMirror textarea').focus(); - }, 300); - } else { - $('#license-ok-button').focus(); - } - }, - callback: 'LicenseDialogReady' + } + }, + onOpen: function() { + if (IsAdmin()) { + setTimeout(function() { + TextareaResize({ + scope: scope, + textareaId: 'license_license_json', + modalId: 'license-modal-dialog', + formId: 'license-notification-body', + fld: 'license_json', + parse: true, + onChange: function() { scope.license_json_api_error = ''; } + }); + $('#cm-license_json-container .CodeMirror textarea').focus(); + }, 300); + } else { + $('#license-ok-button').focus(); + } + }, + callback: 'LicenseDialogReady' + }); }); + + self.GetLicense('LicenseReady'); + + }, + + GetLicense: function(callback, inScope) { + // Retrieve license detail + var self = this, + scope = (inScope) ? inScope : self.scope, + url = GetBasePath('config'); + Rest.setUrl(url); + Rest.get() + .success(function (data) { + if (scope && callback) { + scope.$emit(callback, data); + } + else if (scope) { + scope.$emit('CheckLicenseReady', data); + } + }) + .error(function (data, status) { + ProcessErrors($rootScope, data, status, null, { hdr: 'Error!', + msg: 'Failed to retrieve license. GET status: ' + status + }); + }); } }; }]) -.factory('LicenseViewer', ['$location', '$rootScope', '$compile', 'GenerateForm', 'Rest', 'Alert', 'GetBasePath', 'ProcessErrors', 'FormatDate', 'Prompt', 'Empty', 'LicenseForm', 'IsAdmin', 'CreateDialog', 'CheckLicense', 'TextareaResize', -function ($location, $rootScope, $compile, GenerateForm, Rest, Alert, GetBasePath, ProcessErrors, FormatDate, Prompt, Empty, LicenseForm, IsAdmin, CreateDialog, CheckLicense, TextareaResize) { +.factory('LicenseViewer', ['$location', '$rootScope', '$compile', '$filter', 'GenerateForm', 'Rest', 'Alert', 'GetBasePath', 'ProcessErrors', 'FormatDate', 'Prompt', 'Empty', 'LicenseForm', 'IsAdmin', 'CreateDialog', 'CheckLicense', 'TextareaResize', +function ($location, $rootScope, $compile, $filter, GenerateForm, Rest, Alert, GetBasePath, ProcessErrors, FormatDate, Prompt, Empty, LicenseForm, IsAdmin, CreateDialog, CheckLicense, TextareaResize) { return { createDialog: function(html) { @@ -292,12 +340,12 @@ function ($location, $rootScope, $compile, GenerateForm, Rest, Alert, GetBasePat e = angular.element(document.getElementById('license-modal-dialog')); e.empty().html(html); - if (scope.license_status === 'Invalid License Key') { + if (scope.license_status === 'Invalid License Key' || scope.license_status === 'Missing License Key') { $('#license_tabs li:eq(1)').hide(); } scope.parseType = 'json'; - scope.license_json = " "; + scope.license_json = JSON.stringify(self.license, null, ' '); h = CheckLicense.getHTML(self.getLicense(),true).body; $('#license-modal-dialog #license_tabs').append("