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
This commit is contained in:
Endi S. Dewata
2011-04-11 20:22:38 -05:00
committed by Adam Young
parent 740416c8fb
commit 8f9ddb058f
6 changed files with 292 additions and 28 deletions

View File

@@ -26,7 +26,8 @@
IPA.entitle = {}; IPA.entitle = {};
IPA.entitle.unregistered = 'unregistered'; IPA.entitle.unregistered = 'unregistered';
IPA.entitle.registered = 'registered'; IPA.entitle.online = 'online';
IPA.entitle.offline = 'offline';
IPA.entity_factories.entitle = function() { IPA.entity_factories.entitle = function() {
@@ -69,9 +70,9 @@ IPA.entity_factories.entitle = function() {
}). }).
standard_association_facets(). standard_association_facets().
dialog({ dialog({
factory: IPA.entitle.register_dialog, factory: IPA.entitle.register_online_dialog,
name: 'register', name: 'online_registration',
title: 'Register Entitlements', title: 'Registration',
fields: [ fields: [
{ {
name: 'username', 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({ dialog({
factory: IPA.entitle.consume_dialog, factory: IPA.entitle.consume_dialog,
name: 'consume', name: 'consume',
title: 'Consume Entitlements', title: 'Consume Entitlement',
fields: [ fields: [
{ {
name: 'quantity', name: 'quantity',
@@ -97,6 +112,20 @@ IPA.entity_factories.entitle = function() {
undo: false 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(); return builder.build();
@@ -108,18 +137,44 @@ IPA.entitle.entity = function(spec) {
var that = IPA.entity(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({ var command = IPA.command({
name: 'entitle_get' + (that.status == IPA.entitle.registered ? '' : '_unregistered'), name: 'entitle_status_'+that.status,
entity: 'entitle', entity: 'entitle',
method: 'get', method: 'status',
on_success: function(data, text_status, xhr) { 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) { if (on_success) {
on_success.call(this, data, text_status, xhr); 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, on_error: on_error,
retry: false retry: false
}); });
@@ -127,7 +182,7 @@ IPA.entitle.entity = function(spec) {
command.execute(); 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({ var command = IPA.command({
entity: 'entitle', entity: 'entitle',
@@ -135,7 +190,25 @@ IPA.entitle.entity = function(spec) {
args: [ username ], args: [ username ],
options: { password: password }, options: { password: password },
on_success: function(data, text_status, xhr) { 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) { if (on_success) {
on_success.call(this, data, text_status, xhr); on_success.call(this, data, text_status, xhr);
} }
@@ -159,6 +232,19 @@ IPA.entitle.entity = function(spec) {
command.execute(); 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; return that;
}; };
@@ -178,17 +264,37 @@ IPA.entitle.search_facet = function(spec) {
'class': 'search-buttons' 'class': 'search-buttons'
}).appendTo(li); }).appendTo(li);
that.register_buttons = $('<span/>', {
style: 'display: none;'
}).appendTo(buttons);
$('<input/>', { $('<input/>', {
type: 'button', type: 'button',
name: 'register', name: 'register_online',
value: 'Register' value: 'Register'
}).appendTo(that.register_buttons);
$('<input/>', {
type: 'button',
name: 'register_offline',
value: 'Import'
}).appendTo(that.register_buttons);
that.consume_buttons = $('<span/>', {
style: 'display: none;'
}).appendTo(buttons); }).appendTo(buttons);
$('<input/>', { $('<input/>', {
type: 'button', type: 'button',
name: 'consume', name: 'consume',
value: 'Consume' value: 'Consume'
}).appendTo(buttons); }).appendTo(that.consume_buttons);
$('<input/>', {
type: 'button',
name: 'import',
value: 'Import'
}).appendTo(that.consume_buttons);
}; };
that.setup = function(container) { that.setup = function(container) {
@@ -197,17 +303,27 @@ IPA.entitle.search_facet = function(spec) {
var action_panel = that.get_action_panel(); var action_panel = that.get_action_panel();
var button = $('input[name=register]', action_panel); var button = $('input[name=register_online]', action_panel);
that.register_button = IPA.action_button({ that.register_online_button = IPA.action_button({
label: 'Register', label: 'Register',
icon: 'ui-icon-plus', icon: 'ui-icon-plus',
click: function() { click: function() {
var dialog = that.entity.get_dialog('register'); var dialog = that.entity.get_dialog('online_registration');
dialog.open(that.container); dialog.open(that.container);
} }
}); });
that.register_button.css('display', 'none'); button.replaceWith(that.register_online_button);
button.replaceWith(that.register_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); button = $('input[name=consume]', action_panel);
that.consume_button = IPA.action_button({ that.consume_button = IPA.action_button({
@@ -219,16 +335,35 @@ IPA.entitle.search_facet = function(spec) {
dialog.open(that.container); dialog.open(that.container);
} }
}); });
that.consume_button.css('display', 'none');
button.replaceWith(that.consume_button); 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() { that.refresh = function() {
function on_success(data, text_status, xhr) { function on_success(data, text_status, xhr) {
that.register_button.css('display', 'none'); that.register_buttons.css('display', 'none');
that.consume_button.css('display', 'inline'); 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(); that.table.empty();
@@ -250,22 +385,63 @@ IPA.entitle.search_facet = function(spec) {
function on_error(xhr, text_status, error_thrown) { function on_error(xhr, text_status, error_thrown) {
that.register_button.css('display', 'inline'); that.register_buttons.css('display', 'inline');
that.consume_button.css('display', 'none'); that.consume_buttons.css('display', 'none');
var summary = $('span[name=summary]', that.table.tfoot).empty(); var summary = $('span[name=summary]', that.table.tfoot).empty();
summary.append(error_thrown.message); summary.append(error_thrown.message);
} }
that.entity.get_certificates( that.entity.get_status(
on_success, function(data, text_status, xhr) {
that.entity.get_certificates(
on_success,
on_error);
},
on_error); on_error);
}; };
return that; 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('<br/>');
that.container.append('<br/>');
that.container.append(IPA.cert.BEGIN_CERTIFICATE);
that.container.append('<br/>');
that.textarea = $('<textarea/>', {
style: 'width: 100%; height: 225px;'
}).appendTo(that.container);
that.container.append('<br/>');
that.container.append(IPA.cert.END_CERTIFICATE);
};
return that;
};
IPA.entitle.register_online_dialog = function(spec) {
spec = spec || {}; spec = spec || {};
@@ -275,7 +451,7 @@ IPA.entitle.register_dialog = function(spec) {
var record = {}; var record = {};
that.save(record); that.save(record);
that.entity.register( that.entity.register_online(
record.username, record.username,
record.password, record.password,
function() { function() {
@@ -293,6 +469,30 @@ IPA.entitle.register_dialog = function(spec) {
return that; return that;
}; };
IPA.entitle.register_offline_dialog = function(spec) {
spec = spec || {};
var that = IPA.entitle.certificate_dialog(spec);
that.add_button(that.label, function() {
that.entity.register_offline(
that.get_certificate(),
function() {
var facet = that.entity.get_facet('search');
facet.refresh();
that.close();
}
);
});
that.add_button(IPA.messages.buttons.cancel, function() {
that.close();
});
return that;
};
IPA.entitle.consume_dialog = function(spec) { IPA.entitle.consume_dialog = function(spec) {
spec = spec || {}; spec = spec || {};
@@ -319,3 +519,27 @@ IPA.entitle.consume_dialog = function(spec) {
return that; return that;
}; };
IPA.entitle.import_dialog = function(spec) {
spec = spec || {};
var that = IPA.entitle.certificate_dialog(spec);
that.add_button(that.label, function() {
that.entity.import_certificate(
that.get_certificate(),
function() {
var facet = that.entity.get_facet('search');
facet.refresh();
that.close();
}
);
});
that.add_button(IPA.messages.buttons.cancel, function() {
that.close();
});
return that;
};

View File

@@ -479,6 +479,10 @@ span.ui-icon-search {
margin-left: 1em !important; margin-left: 1em !important;
} }
[title="Import"] {
margin-left: 1em !important;
}
[title="mail"] { [title="mail"] {
margin-top: 0em !important; margin-top: 0em !important;
} }

View File

@@ -0,0 +1,12 @@
{
"error": null,
"id": null,
"result": {
"result": {
"consumed": 1,
"product": "Multiplier Product Client Pack (50)",
"quantity": 1,
"uuid": "IMPORTED"
}
}
}

View File

@@ -0,0 +1,12 @@
{
"error": null,
"id": 0,
"result": {
"result": {
"consumed": 2,
"product": "MKT-multiplier-client-50",
"quantity": 250,
"uuid": "IMPORTED"
}
}
}

View File

@@ -0,0 +1,12 @@
{
"error": null,
"id": 0,
"result": {
"result": {
"consumed": 2,
"product": "MKT-multiplier-client-50",
"quantity": 250,
"uuid": "a3865364-33cc-4ce3-b000-0f08498cc085"
}
}
}