From eb87b8c31931e682cbb927896d1d60a0266e1263 Mon Sep 17 00:00:00 2001 From: Petr Voborník Date: Mon, 6 Feb 2012 14:52:09 +0100 Subject: UI support for ssh keys To user and host details pages was added ipasshpubkey attribute. New widget for ssh public keys was created. https://fedorahosted.org/freeipa/ticket/2340 --- install/ui/field.js | 95 ++++++++-- install/ui/host.js | 7 +- install/ui/ipa.css | 9 +- install/ui/test/data/host_mod.json | 1 + install/ui/test/data/host_show.json | 1 + .../ui/test/data/host_show_dev.example.com.json | 1 + .../ui/test/data/host_show_test.example.com.json | 1 + install/ui/test/data/ipa_init.json | 11 ++ install/ui/test/data/user_details_refresh.json | 13 ++ install/ui/test/data/user_mod.json | 13 ++ install/ui/test/data/user_show.json | 13 ++ install/ui/test/widget_tests.js | 2 +- install/ui/user.js | 9 +- install/ui/widget.js | 208 ++++++++++++++++++++- 14 files changed, 358 insertions(+), 26 deletions(-) (limited to 'install/ui') diff --git a/install/ui/field.js b/install/ui/field.js index c79c59bb4..46802be6c 100644 --- a/install/ui/field.js +++ b/install/ui/field.js @@ -148,22 +148,28 @@ IPA.field = function(spec) { that.load = function(record) { that.record = record; - var value = record[that.name]; - if (value instanceof Array) { - that.values = value; - } else { - that.values = value !== undefined ? [value] : []; - } - - if (!that.values.length) { - that.values = ['']; - } + that.values = that.get_value(record, that.name); that.load_writable(record); that.reset(); }; + that.get_value = function(record, name) { + + var value = record[name]; + + if (!(value instanceof Array)) { + value = value !== undefined ? [value] : []; + } + + if (!value.length) { + value = ['']; + } + + return value; + }; + that.load_writable = function(record) { that.writable = true; @@ -272,16 +278,21 @@ IPA.field = function(spec) { //compare values in array if (values.length !== that.values.length) return true; - values.sort(); - that.values.sort(); + return !that.dirty_are_equal(that.values, values); + }; - for (var i=0; i', { + 'class': 'sshkey-status', + text: '' + }).appendTo(container); + + that.link = $('', { + type: that.type, + 'class': 'sshkey-set', + name: that.name, + href: '#show-certificate', + title: that.tooltip, + text: IPA.messages.objects.sshkeystore.show_set_key, + onclick: function() { + that.open_edit_dialog(); + return false; + } + }).appendTo(container); + + if (that.undo) { + that.create_undo(container); + } + + that.create_error_link(container); + }; + + that.update = function(values) { + + var key = values && values.length ? values[0] : null; + + if (!key || key === '') { + key = {}; + } + + that.key = $.extend({}, key); + + if (that.key.key && that.key.key !== '' && + that.key.fingerprint && that.key.fingerprint !== '') { + that.originally_set = true; + that.original_key = that.key.key; + } + that.update_link(); + }; + + that.set_deleted = function(deleted) { + if (deleted) { + that.status_label.addClass('strikethrough'); + } else { + that.status_label.removeClass('strikethrough'); + } + }; + + that.save = function() { + var value = that.key.key; + value = value ? [value] : ['']; + return value; + }; + + that.update_link = function() { + var text = that.get_status(); + that.status_label.text(text); + }; + + that.get_status = function() { + + var text = ''; + var value = that.key.key; + + if (that.original_key) { + + if (value !== that.original_key) { + if (value === '') { + text = IPA.messages.objects.sshkeystore.status_mod_ns; + } else { + text = IPA.messages.objects.sshkeystore.status_mod_s; + } + } else { + text = that.key.fingerprint; + } + + } else { + + if (!value || value === '') { + text = IPA.messages.objects.sshkeystore.status_new_ns; + } else { + text = IPA.messages.objects.sshkeystore.status_new_s; + } + } + + return text; + }; + + that.set_user_value = function(value) { + + var previous = that.key.key; + that.key.key = value; + that.update_link(); + + if (value !== previous) { + that.value_changed.notify([], that); + } + }; + + that.open_edit_dialog = function() { + + var dialog = that.create_edit_dialog(); + dialog.open(); + }; + + that.create_edit_dialog = function() { + + var dialog = IPA.dialog({ + title: IPA.messages.objects.sshkeystore.set_dialog_title, + width: 500, + height: 380 + }); + + dialog.message = IPA.messages.objects.sshkeystore.set_dialog_help; + + dialog.create_button({ + name: 'update', + label: IPA.messages.buttons.set, + click: function() { + var value = dialog.textarea.val(); + that.set_user_value(value); + dialog.close(); + } + }); + + dialog.create_button({ + name: 'cancel', + label: IPA.messages.buttons.cancel, + click: function() { + dialog.close(); + } + }); + + dialog.create = function() { + + dialog.container.append(dialog.message); + + dialog.textarea = $('