From bc0db0312f5b9325a84894e0107a56967a68b88d Mon Sep 17 00:00:00 2001 From: chouseknecht Date: Tue, 30 Jul 2013 12:52:46 -0400 Subject: [PATCH] AC-295 Fixed View License so that empty fields are not displayed. Now demo license info makes sense. Fixed links in nag messages and here to all point to store.ansibleworks.com --- awx/ui/static/css/ansible-ui.css | 5 + awx/ui/static/js/helpers/Access.js | 10 +- awx/ui/static/lib/ansible/license.js | 193 ++++++++++++++++++++------- 3 files changed, 157 insertions(+), 51 deletions(-) diff --git a/awx/ui/static/css/ansible-ui.css b/awx/ui/static/css/ansible-ui.css index 5912af227d..c9288e8ab5 100644 --- a/awx/ui/static/css/ansible-ui.css +++ b/awx/ui/static/css/ansible-ui.css @@ -201,6 +201,11 @@ font-size: 12px; } + .note { + font-size: 12px; + padding-top: 15px; + } + legend { font-size: medium; font-weight: bold; diff --git a/awx/ui/static/js/helpers/Access.js b/awx/ui/static/js/helpers/Access.js index c8002dd981..3ac30ba793 100644 --- a/awx/ui/static/js/helpers/Access.js +++ b/awx/ui/static/js/helpers/Access.js @@ -68,8 +68,8 @@ angular.module('AccessHelper', ['RestServices', 'Utilities', 'ngCookies']) status = 'alert-info'; hdr = 'AWX Demo'; msg = 'Thank you for trying AnsibleWorks AWX. You can use this edition to manage up to 10 hosts free. ' + - 'Should you wish to acquire a license for additional servers, please visit ' + - 'ansibleworks.com/ansibleworks-awx, or ' + + 'Should you wish to acquire a license for additional servers, please ' + + 'visit the AnsibleWorks online store, or ' + 'contact info@ansibleworks.com for assistance.'; Alert(hdr, msg, status); } @@ -78,7 +78,7 @@ angular.module('AccessHelper', ['RestServices', 'Utilities', 'ngCookies']) hdr = 'License Expired'; msg = 'Your AnsibleWorks AWX License has expired and is no longer compliant. ' + 'You can continue, but you will be unable to add any additional hosts. Please ' + - 'visit ansibleworks.com/ansibleworks-awx ' + + 'visit the AnsibleWorks online store ' + 'for license and renewal information, or contact info@ansibleworks.com ' + 'for assistance.'; Alert(hdr, msg, status); @@ -87,8 +87,8 @@ angular.module('AccessHelper', ['RestServices', 'Utilities', 'ngCookies']) status = 'alert-info'; hdr = 'License Warning'; msg = 'Your AnsibleWorks AWX License has reached capacity for the number of managed ' + - 'hosts allowed. You will not be able to add any additional hosts. To extend your license, please visit ' + - 'ansibleworks.com/ansibleworks-awx., or ' + + 'hosts allowed. You will not be able to add any additional hosts. To extend your license, please ' + + 'visit the AnsibleWorks online store, or ' + 'contact info@ansibleworks.com for more information.'; Alert(hdr, msg, status, null, true); } diff --git a/awx/ui/static/lib/ansible/license.js b/awx/ui/static/lib/ansible/license.js index 37613caa41..e72b704c18 100644 --- a/awx/ui/static/lib/ansible/license.js +++ b/awx/ui/static/lib/ansible/license.js @@ -7,69 +7,170 @@ 'use strict'; -angular.module('License', ['LicenseFormDefinition', 'RestServices', 'Utilities', 'FormGenerator', 'PromptDialog']) - .factory('ViewLicense', ['$location', 'LicenseForm', 'GenerateForm', 'Rest', 'Alert', 'GetBasePath', 'ProcessErrors', +angular.module('License', ['RestServices', 'Utilities', 'FormGenerator', 'PromptDialog']) + .factory('ViewLicense', ['$location', 'GenerateForm', 'Rest', 'Alert', 'GetBasePath', 'ProcessErrors', 'FormatDate', 'Prompt', - function($location, LicenseForm, GenerateForm, Rest, Alert, GetBasePath, ProcessErrors, FormatDate, Prompt) { + function($location, GenerateForm, Rest, Alert, GetBasePath, ProcessErrors, FormatDate, Prompt) { return function() { var defaultUrl=GetBasePath('config'); var generator = GenerateForm; - var form = LicenseForm; - var base = $location.path().replace(/^\//,'').split('/')[0]; - // load the form - var scope = generator.inject(form, { mode: 'edit', modal: true, related: false}); - generator.reset(); - - scope.formModalAction = function() { - $('#form-modal').modal("hide"); - } - - scope.formModalActionLabel = 'OK'; - scope.formModalCancelShow = false; - scope.formModalInfo = 'Purchase/Extend License'; - $('#form-modal .btn-success').removeClass('btn-success').addClass('btn-none'); - $('#form-modal').addClass('skinny-modal'); - scope.formModalHeader = 'AWX License'; + var form = { + name: 'license', + well: false, + forceListeners: true, + 'class': 'horizontal-narrow', + fields: { + license_status: { + label: 'Status', + type: 'custom', + control: '
\{\{ license_status \}\}
', + readonly: true, + section: 'License' + }, + license_key: { + label: 'Key', + type: 'textarea', + section: 'License', + 'class': 'modal-input-xlarge', + readonly: true + }, + license_date: { + label: 'Expires On', + type: 'text', + readonly: true, + section: 'License' + }, + time_remaining: { + label: 'Time Left', + type: 'text', + readonly: true, + section: 'License' + }, + available_instances: { + label: 'Available', + type: 'text', + readonly: true, + section: 'Managed Hosts' + }, + current_instances: { + label: 'Used', + type: 'text', + readonly: true, + section: 'Managed Hosts' + }, + free_instances: { + label: 'Remaining', + type: 'text', + readonly: true, + section: 'Managed Hosts', + controlNGClass: 'free_instances_class', + labelNGClass: 'free_instances_class' + }, + company_name: { + label: 'Company', + type: 'text', + readonly: true, + section: 'Contact Info' + }, + contact_name: { + label: 'Contact', + type: 'text', + readonly: true, + section: 'Contact Info' + }, + contact_email: { + label: 'Contact Email', + type: 'text', + readonly: true, + section: 'Contact Info' + } + } + }; - // Respond to View JSON button - scope.formModalInfoAction = function() { - Prompt({ - hdr: 'AWX Licensing', - body: "

AWX licenses can be purchased, renewed or extended by visiting " + - "ansibleworks.com/ansibleworks-awx.

Would you like to visit the AWX licensing site now?

", - 'class': 'btn-primary', - action: function() { var href = $('#license-link').attr('href'); window.location = href; } - }); + var base = $location.path().replace(/^\//,'').split('/')[0]; + + + function empty(x) { + var result = false; + if (x === null || x === undefined || x == '') { + result = true; } + return result; + } // Retrieve detail record and prepopulate the form Rest.setUrl(defaultUrl); Rest.get() .success( function(data, status, headers, config) { for (var fld in form.fields) { - if (data['license_info'][fld]) { - scope[fld] = data['license_info'][fld]; + if (fld != 'time_remaining' && fld != 'license_status') { + if (empty(data['license_info'][fld])) { + delete form.fields[fld]; + } } } - var dt = new Date(parseInt(scope['license_date'])); - if (dt.getFullYear() == '1970') { - // date was passed in seconds rather than milliseconds - dt = new Date(parseInt(scope['license_date']) * 1000); - scope['time_remaining'] = scope['time_remaining'] + '000'; - } - scope['license_date'] = FormatDate(dt); - var days = parseInt(scope['time_remaining'] / 86400000); - var remainder = scope['time_remaining'] - (days * 86400000); - var hours = parseInt(remainder / 3600000); - remainder = remainder - (hours * 3600000); - var minutes = parseInt(remainder / 60000); - remainder = remainder - (minutes * 60000); - var seconds = parseInt(remainder / 1000); - scope['time_remaining'] = days + ' days ' + ('0' + hours).slice(-2) + ':' + ('0' + minutes).slice(-2) + ':' + ('0' + seconds).slice(-2); + if (empty(data['license_info']['license_date'])) { + delete form.fields['license_date']; + delete form.fields['time_remaining']; + } + + var scope = generator.inject(form, { mode: 'edit', modal: true, related: false}); + generator.reset(); + + scope.formModalAction = function() { + $('#form-modal').modal("hide"); + } + + scope.formModalActionLabel = 'OK'; + scope.formModalCancelShow = false; + scope.formModalInfo = 'Purchase/Extend License'; + $('#form-modal .btn-success').removeClass('btn-success').addClass('btn-none'); + $('#form-modal').addClass('skinny-modal'); + scope.formModalHeader = 'AWX License'; + + // Respond to license button + scope.formModalInfoAction = function() { + Prompt({ + hdr: 'AWX Licensing', + body: "

AWX licenses can be purchased or extended by visiting " + + "the AnsibleWorks online store. Would you like to purchase or extend your license now?

", + 'class': 'btn-primary', + action: function() { + var href = $('#license-link').attr('href'); + window.open(href, 'storeWindow'); + } + }); + } + + // Remove anything form the form that is empty + for (var fld in form.fields) { + if (data['license_info'][fld]) { + scope[fld] = data['license_info'][fld]; + } + } + + if (scope['license_date']) { + var dt = new Date(parseInt(scope['license_date'])); + if (dt.getFullYear() == '1970') { + // date was passed in seconds rather than milliseconds + dt = new Date(parseInt(scope['license_date']) * 1000); + scope['time_remaining'] = scope['time_remaining'] + '000'; + } + scope['license_date'] = FormatDate(dt); + + var days = parseInt(scope['time_remaining'] / 86400000); + var remainder = scope['time_remaining'] - (days * 86400000); + var hours = parseInt(remainder / 3600000); + remainder = remainder - (hours * 3600000); + var minutes = parseInt(remainder / 60000); + remainder = remainder - (minutes * 60000); + var seconds = parseInt(remainder / 1000); + scope['time_remaining'] = days + ' days ' + ('0' + hours).slice(-2) + ':' + ('0' + minutes).slice(-2) + ':' + ('0' + seconds).slice(-2); + } if (parseInt(scope['free_instances']) <= 0) { scope['free_instances_class'] = 'field-failure';