From 8f9ddb058f922fbd33c4d15986eeb1f5be521cc5 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Mon, 11 Apr 2011 20:22:38 -0500 Subject: Entitlement import. The entitlement facet will invoke entitle_status to check the entitlement status and show the appropriate buttons. If it's unregistered it will show Register and Import button. If it's registered it will show the Consume button only. If it's imported it will show the Import button only. The Import button will open a dialog box for importing entitlement certificate. Ticket #277 --- install/ui/entitle.js | 278 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 251 insertions(+), 27 deletions(-) (limited to 'install/ui/entitle.js') diff --git a/install/ui/entitle.js b/install/ui/entitle.js index 6c2c8727d..4c9cd13c6 100644 --- a/install/ui/entitle.js +++ b/install/ui/entitle.js @@ -26,7 +26,8 @@ IPA.entitle = {}; IPA.entitle.unregistered = 'unregistered'; -IPA.entitle.registered = 'registered'; +IPA.entitle.online = 'online'; +IPA.entitle.offline = 'offline'; IPA.entity_factories.entitle = function() { @@ -69,9 +70,9 @@ IPA.entity_factories.entitle = function() { }). standard_association_facets(). dialog({ - factory: IPA.entitle.register_dialog, - name: 'register', - title: 'Register Entitlements', + factory: IPA.entitle.register_online_dialog, + name: 'online_registration', + title: 'Registration', fields: [ { name: 'username', @@ -86,10 +87,24 @@ IPA.entity_factories.entitle = function() { } ] }). + dialog({ + factory: IPA.entitle.register_offline_dialog, + name: 'offline_registration', + title: 'Import Certificate', + message: 'Enter the Base64-encoded entitlement certificate below:', + label: 'Import', + fields: [ + { + name: 'certificate', + label: 'Certificate', + undo: false + } + ] + }). dialog({ factory: IPA.entitle.consume_dialog, name: 'consume', - title: 'Consume Entitlements', + title: 'Consume Entitlement', fields: [ { name: 'quantity', @@ -97,6 +112,20 @@ IPA.entity_factories.entitle = function() { undo: false } ] + }). + dialog({ + factory: IPA.entitle.import_dialog, + name: 'import', + title: 'Import Certificate', + message: 'Enter the Base64-encoded entitlement certificate below:', + label: 'Import', + fields: [ + { + name: 'certificate', + label: 'Certificate', + undo: false + } + ] }); return builder.build(); @@ -108,18 +137,44 @@ IPA.entitle.entity = function(spec) { var that = IPA.entity(spec); - that.get_certificates = function(on_success, on_error) { + that.status = IPA.entitle.unregistered; + + that.get_status = function(on_success, on_error) { var command = IPA.command({ - name: 'entitle_get' + (that.status == IPA.entitle.registered ? '' : '_unregistered'), + name: 'entitle_status_'+that.status, entity: 'entitle', - method: 'get', + method: 'status', on_success: function(data, text_status, xhr) { - that.status = IPA.entitle.registered; + if (data.result.result.uuid == 'IMPORTED') { + that.status = IPA.entitle.offline; + } else { + that.status = IPA.entitle.online; + } + if (on_success) { on_success.call(this, data, text_status, xhr); } }, + on_error: function(xhr, text_status, error_thrown) { + that.status = IPA.entitle.unregistered; + + if (on_error) { + on_error.call(this, xhr, text_status, error_thrown); + } + }, + retry: false + }); + + command.execute(); + }; + + that.get_certificates = function(on_success, on_error) { + + var command = IPA.command({ + entity: 'entitle', + method: 'get', + on_success: on_success, on_error: on_error, retry: false }); @@ -127,7 +182,7 @@ IPA.entitle.entity = function(spec) { command.execute(); }; - that.register = function(username, password, on_success, on_error) { + that.register_online = function(username, password, on_success, on_error) { var command = IPA.command({ entity: 'entitle', @@ -135,7 +190,25 @@ IPA.entitle.entity = function(spec) { args: [ username ], options: { password: password }, on_success: function(data, text_status, xhr) { - that.status = IPA.entitle.registered; + that.status = IPA.entitle.online; + if (on_success) { + on_success.call(this, data, text_status, xhr); + } + }, + on_error: on_error + }); + + command.execute(); + }; + + that.register_offline = function(certificate, on_success, on_error) { + + var command = IPA.command({ + entity: 'entitle', + method: 'import', + args: [ certificate ], + on_success: function(data, text_status, xhr) { + that.status = IPA.entitle.offline; if (on_success) { on_success.call(this, data, text_status, xhr); } @@ -159,6 +232,19 @@ IPA.entitle.entity = function(spec) { command.execute(); }; + that.import_certificate = function(certificate, on_success, on_error) { + + var command = IPA.command({ + entity: 'entitle', + method: 'import', + args: [ certificate ], + on_success: on_success, + on_error: on_error + }); + + command.execute(); + }; + return that; }; @@ -178,17 +264,37 @@ IPA.entitle.search_facet = function(spec) { 'class': 'search-buttons' }).appendTo(li); + that.register_buttons = $('', { + style: 'display: none;' + }).appendTo(buttons); + $('', { type: 'button', - name: 'register', + name: 'register_online', value: 'Register' + }).appendTo(that.register_buttons); + + $('', { + type: 'button', + name: 'register_offline', + value: 'Import' + }).appendTo(that.register_buttons); + + that.consume_buttons = $('', { + style: 'display: none;' }).appendTo(buttons); $('', { type: 'button', name: 'consume', value: 'Consume' - }).appendTo(buttons); + }).appendTo(that.consume_buttons); + + $('', { + type: 'button', + name: 'import', + value: 'Import' + }).appendTo(that.consume_buttons); }; that.setup = function(container) { @@ -197,17 +303,27 @@ IPA.entitle.search_facet = function(spec) { var action_panel = that.get_action_panel(); - var button = $('input[name=register]', action_panel); - that.register_button = IPA.action_button({ + var button = $('input[name=register_online]', action_panel); + that.register_online_button = IPA.action_button({ label: 'Register', icon: 'ui-icon-plus', click: function() { - var dialog = that.entity.get_dialog('register'); + var dialog = that.entity.get_dialog('online_registration'); dialog.open(that.container); } }); - that.register_button.css('display', 'none'); - button.replaceWith(that.register_button); + button.replaceWith(that.register_online_button); + + button = $('input[name=register_offline]', action_panel); + that.register_offline_button = IPA.action_button({ + label: 'Import', + icon: 'ui-icon-plus', + click: function() { + var dialog = that.entity.get_dialog('offline_registration'); + dialog.open(that.container); + } + }); + button.replaceWith(that.register_offline_button); button = $('input[name=consume]', action_panel); that.consume_button = IPA.action_button({ @@ -219,16 +335,35 @@ IPA.entitle.search_facet = function(spec) { dialog.open(that.container); } }); - that.consume_button.css('display', 'none'); button.replaceWith(that.consume_button); + + button = $('input[name=import]', action_panel); + that.import_button = IPA.action_button({ + label: 'Import', + icon: 'ui-icon-plus', + style: 'display: none;', + click: function() { + var dialog = that.entity.get_dialog('import'); + dialog.open(that.container); + } + }); + button.replaceWith(that.import_button); }; that.refresh = function() { function on_success(data, text_status, xhr) { - that.register_button.css('display', 'none'); - that.consume_button.css('display', 'inline'); + that.register_buttons.css('display', 'none'); + that.consume_buttons.css('display', 'inline'); + + if (that.entity.status == IPA.entitle.online) { + that.consume_button.css('display', 'inline'); + that.import_button.css('display', 'none'); + } else { + that.consume_button.css('display', 'none'); + that.import_button.css('display', 'inlnie'); + } that.table.empty(); @@ -250,22 +385,63 @@ IPA.entitle.search_facet = function(spec) { function on_error(xhr, text_status, error_thrown) { - that.register_button.css('display', 'inline'); - that.consume_button.css('display', 'none'); + that.register_buttons.css('display', 'inline'); + that.consume_buttons.css('display', 'none'); var summary = $('span[name=summary]', that.table.tfoot).empty(); summary.append(error_thrown.message); } - that.entity.get_certificates( - on_success, + that.entity.get_status( + function(data, text_status, xhr) { + that.entity.get_certificates( + on_success, + on_error); + }, on_error); }; return that; }; -IPA.entitle.register_dialog = function(spec) { +IPA.entitle.certificate_dialog = function(spec) { + + spec = spec || {}; + + var that = IPA.dialog(spec); + + that.width = spec.width || 500; + that.height = spec.height || 400; + that.message = spec.message; + that.label = spec.label; + + that.get_certificate = function() { + var certificate = that.textarea.val(); + return IPA.cert.BEGIN_CERTIFICATE+'\n'+ + $.trim(certificate)+'\n'+ + IPA.cert.END_CERTIFICATE+'\n'; + }; + + that.create = function() { + that.container.append(that.message); + that.container.append('
'); + that.container.append('
'); + + that.container.append(IPA.cert.BEGIN_CERTIFICATE); + that.container.append('
'); + + that.textarea = $('