Entitlement download.

A Download link has been added to download entitlement certificates.
This commit is contained in:
Endi S. Dewata 2011-04-14 15:43:57 -05:00 committed by Adam Young
parent 8f9ddb058f
commit fc7c1cbb6a
6 changed files with 81 additions and 41 deletions

View File

@ -74,7 +74,7 @@ IPA.cert.parse_dn = function(dn) {
return result; return result;
}; };
IPA.cert.get_dialog = function(spec) { IPA.cert.download_dialog = function(spec) {
spec = spec || {}; spec = spec || {};
@ -82,8 +82,9 @@ IPA.cert.get_dialog = function(spec) {
that.width = spec.width || 500; that.width = spec.width || 500;
that.height = spec.height || 400; that.height = spec.height || 400;
that.add_pem_delimiters = typeof spec.add_pem_delimiters == 'undefined' ? true : spec.add_pem_delimiters;
that.usercertificate = spec.usercertificate || ''; that.certificate = spec.certificate || '';
that.add_button(IPA.messages.buttons.close, function() { that.add_button(IPA.messages.buttons.close, function() {
that.close(); that.close();
@ -95,10 +96,15 @@ IPA.cert.get_dialog = function(spec) {
style: 'width: 100%; height: 275px;' style: 'width: 100%; height: 275px;'
}).appendTo(that.container); }).appendTo(that.container);
textarea.val( var certificate = that.certificate;
IPA.cert.BEGIN_CERTIFICATE+'\n'+
that.usercertificate+'\n'+ if (that.add_pem_delimiters) {
IPA.cert.END_CERTIFICATE); certificate = IPA.cert.BEGIN_CERTIFICATE+'\n'+
that.certificate+'\n'+
IPA.cert.END_CERTIFICATE;
}
textarea.val(certificate);
}; };
return that; return that;
@ -675,9 +681,9 @@ IPA.cert.status_widget = function(spec) {
title = title.replace('${entity}', that.entity_label); title = title.replace('${entity}', that.entity_label);
title = title.replace('${primary_key}', entity_name); title = title.replace('${primary_key}', entity_name);
var dialog = IPA.cert.get_dialog({ var dialog = IPA.cert.download_dialog({
'title': title, title: title,
'usercertificate': entity_certificate certificate: entity_certificate
}); });
dialog.init(); dialog.init();

View File

@ -274,11 +274,8 @@ IPA.dialog = function(spec) {
var field; var field;
if (field_spec instanceof Object) { if (field_spec instanceof Object) {
if (field_spec.factory) { var factory = field_spec.factory || IPA.text_widget;
field = field_spec.factory(field_spec); field = factory(field_spec);
} else {
field = IPA.text_widget(field_spec);
}
} else { } else {
var field_name = field_spec; var field_name = field_spec;
field = IPA.text_widget({ name: field_name, undo: false }); field = IPA.text_widget({ name: field_name, undo: false });

View File

@ -56,6 +56,11 @@ IPA.entity_factories.entitle = function() {
{ {
name: 'end', name: 'end',
label: 'End' label: 'End'
},
{
factory: IPA.entitle.certificate_column,
name: 'certificate',
label: 'Certificate'
} }
] ]
}). }).
@ -404,6 +409,36 @@ IPA.entitle.search_facet = function(spec) {
return that; return that;
}; };
IPA.entitle.certificate_column = function(spec) {
spec = spec || {};
var that = IPA.column(spec);
that.setup = function(container, record) {
container.empty();
var certificate = record[that.name];
$('<a/>', {
'href': '#download',
'html': 'Download',
'click': function() {
var dialog = IPA.cert.download_dialog({
title: 'Download Certificate',
certificate: certificate,
add_pem_delimiters: false
});
dialog.init();
dialog.open();
return false;
}
}).appendTo(container);
};
return that;
};
IPA.entitle.certificate_dialog = function(spec) { IPA.entitle.certificate_dialog = function(spec) {
spec = spec || {}; spec = spec || {};

View File

@ -559,42 +559,43 @@ IPA.entity_builder = function(){
} }
facet.add_section(current_section); facet.add_section(current_section);
var fields = spec.fields; var fields = spec.fields;
if (fields){ if (fields) {
var i; for (var i=0; i<fields.length; i++) {
var field_spec = fields[i];
var field; var field;
for (i =0; i < fields.length; i += 1){
field = fields[i]; if (field_spec instanceof Object) {
if (field instanceof Object){ field_spec.entity_name = entity.name;
field.entity_name = entity.name; var factory = field_spec.factory || IPA.text_widget;
current_section.add_field(field.factory(field)); field = factory(field_spec);
}else{ } else {
field = IPA.text_widget({ field = IPA.text_widget({
name:field, name: field_spec,
entity_name:entity.name entity_name: entity.name
}); });
current_section.add_field(field);
} }
current_section.add_field(field);
} }
} }
} }
that.entity = function(spec) { that.entity = function(spec) {
if (spec instanceof Object){ if (spec instanceof Object) {
var factory = spec.factory || IPA.entity; var factory = spec.factory || IPA.entity;
entity = factory(spec); entity = factory(spec);
} else { } else {
var name = spec; entity = IPA.entity({ name: spec });
entity = IPA.entity({name: name});
} }
return that; return that;
}; };
that.dialog = function(spec) { that.dialog = function(spec) {
var dialog; var dialog;
if (spec.factory) { if (spec instanceof Object){
dialog = spec.factory(spec); var factory = spec.factory || IPA.dialog;
dialog = factory(spec);
} else { } else {
dialog = IPA.dialog(spec); dialog = IPA.dialog({ name: spec });
} }
entity.dialog(dialog); entity.dialog(dialog);
return that; return that;

View File

@ -414,13 +414,16 @@ IPA.search_facet = function(spec) {
var columns = spec.columns || []; var columns = spec.columns || [];
for (var i=0; i<columns.length; i++) { for (var i=0; i<columns.length; i++) {
var column = columns[i]; var column_spec = columns[i];
if (column instanceof Object) { var column;
var factory = column.factory || IPA.column;
that.add_column(factory(column)); if (column_spec instanceof Object) {
var factory = column_spec.factory || IPA.column;
column = factory(column_spec);
} else { } else {
that.create_column({ name: column }); column = IPA.column({ name: column_spec });
} }
that.add_column(column);
} }
return that; return that;

View File

@ -1007,14 +1007,12 @@ IPA.column = function (spec) {
var that = {}; var that = {};
if (spec.format){
that.format = spec.format;
}
that.name = spec.name; that.name = spec.name;
that.label = spec.label; that.label = spec.label;
that.primary_key = spec.primary_key; that.primary_key = spec.primary_key;
that.width = spec.width; that.width = spec.width;
that.entity_name = spec.entity_name; that.entity_name = spec.entity_name;
that.format = spec.format;
that.setup = spec.setup || setup; that.setup = spec.setup || setup;