From 6d3622c600a82f889e77809c982d996974335e62 Mon Sep 17 00:00:00 2001 From: Pavel Vomacka Date: Tue, 26 Apr 2016 08:44:03 +0200 Subject: Add widget for showing multiple certificates Certs widget is based on multivalued widget and adds ability to add new certificate and delete it. Each line is cert_widget. https://fedorahosted.org/freeipa/ticket/5108 https://fedorahosted.org/freeipa/ticket/5381 Reviewed-By: Petr Vobornik --- install/ui/src/freeipa/certificate.js | 172 +++++++++++++++++++++------------- 1 file changed, 108 insertions(+), 64 deletions(-) (limited to 'install/ui/src/freeipa/certificate.js') diff --git a/install/ui/src/freeipa/certificate.js b/install/ui/src/freeipa/certificate.js index 1ea4c1bac..0aa270039 100755 --- a/install/ui/src/freeipa/certificate.js +++ b/install/ui/src/freeipa/certificate.js @@ -113,6 +113,25 @@ IPA.cert.parse_dn = function(dn) { return result; }; +IPA.cert.get_base64 = function(text) { + /* + * Input is assumed to be base64 or PEM formatted certificate. + * The function just cuts the '-----BEGIN CERTIFICATE----' and + * '-----END CERTIFICATE-----' strings if they are present. + * Returns only base64 blob. + */ + + var match = IPA.cert.PEM_CERT_REGEXP.exec(text); + + if (match) { + match = match[2].replace(/\s*/g, ''); + return $.trim(match); + } + + text = text.replace(/\s*/g, ''); + return $.trim(text); +}; + IPA.cert.pem_format_base64 = function(text) { /* * Input is assumed to be base64 possibly with embedded whitespace. @@ -547,31 +566,6 @@ IPA.cert.load_policy = function(spec) { //store cert directly to facet. FIXME: introduce concept of models that.container.certificate = certificate; that.notify_loaded(); - - // initialize another load of certificate because current entity - // show commands don't contain revocation_reason so previous data - // might be slightly incorrect - if (!that.has_reason && certificate && certificate.certificate && - IPA.cert.is_enabled()) { - that.load_revocation_reason(certificate.serial_number); - } - }; - - that.load_revocation_reason = function(serial_number) { - if (serial_number === null || serial_number === undefined) return; - - rpc.command({ - entity: 'cert', - method: 'show', - args: [serial_number], - on_success: function(data, text_status, xhr) { - // copy it so consumers can notice the difference - that.container.certificate = lang.clone(that.container.certificate); - var cert = that.container.certificate; - cert.revocation_reason = data.result.result.revocation_reason; - that.notify_loaded(); - } - }).execute(); }; that.notify_loaded = function() { @@ -1011,57 +1005,108 @@ IPA.cert.status_field = function(spec) { return that; }; -IPA.cert.cert_widget = function(spec) { + +/** + * Certificates widget + * + * Multivalued widget with certificate widget instead of text widget. + * + * @class + * @extends IPA.multivalued_widget + */ +IPA.cert.certs_widget = function(spec) { spec = spec || {}; - spec.css_class = spec.css_class || 'certificate-widget'; + spec.child_spec = spec.child_spec || { + $factory: IPA.cert.cert_widget, + css_class: 'certificate-widget', + facet: spec.facet + }; - var that = IPA.input_widget(spec); - that.certs_visible = false; + spec.item_name = 'cert'; - that.create = function(container) { + spec.custom_actions = spec.custom_actions === undefined ? true : + spec.custom_actions; - that.widget_create(container); - that.content_el = $('
').appendTo(container); + spec.adder_dialog_spec = { + name: 'cert-add-dialog', + title: '@i18n:objects.cert.new_certificate', + sections: [ + { + show_header: false, + fields: [ + { + $type: 'textarea', + name: 'new_cert', + label: '@i18n:objects.cert.new_cert_format', + required: true, + rows: 15 + } + ], + layout: + { + $factory: widget_mod.fluid_layout, + widget_cls: 'col-sm-12', + label_cls: 'col-sm-6 control-label' + } + } + ] }; - that.create_status = function(name, text, icon) { + var that = IPA.custom_command_multivalued_widget(spec); - var status = $('