diff options
Diffstat (limited to 'install/ui/src/freeipa')
-rw-r--r-- | install/ui/src/freeipa/add.js | 6 | ||||
-rw-r--r-- | install/ui/src/freeipa/otptoken.js | 180 | ||||
-rw-r--r-- | install/ui/src/freeipa/qrcode.js | 27 |
3 files changed, 208 insertions, 5 deletions
diff --git a/install/ui/src/freeipa/add.js b/install/ui/src/freeipa/add.js index 23eac54d6..22761c5ad 100644 --- a/install/ui/src/freeipa/add.js +++ b/install/ui/src/freeipa/add.js @@ -84,7 +84,7 @@ IPA.entity_adder_dialog = function(spec) { that.hide_message(); that.add( function(data, text_status, xhr) { - that.added.notify(); + that.added.notify([data], that); that.show_message(that.get_success_message(data)); that.reset(); that.focus_first_element(); @@ -100,7 +100,7 @@ IPA.entity_adder_dialog = function(spec) { that.hide_message(); that.add( function(data, text_status, xhr) { - that.added.notify(); + that.added.notify([data], that); that.close(); var result = data.result.result; that.show_edit_page(that.entity, result); @@ -129,7 +129,7 @@ IPA.entity_adder_dialog = function(spec) { that.hide_message(); that.add( function(data, text_status, xhr) { - that.added.notify(); + that.added.notify([data], that); that.close(); that.notify_success(data); }, diff --git a/install/ui/src/freeipa/otptoken.js b/install/ui/src/freeipa/otptoken.js index 9a3ce6615..a80973513 100644 --- a/install/ui/src/freeipa/otptoken.js +++ b/install/ui/src/freeipa/otptoken.js @@ -26,10 +26,10 @@ define([ './reg', './details', './facet', + './qrcode', './search', './entity'], - function(IPA, $, menu, phases, reg, mod_details, mod_facet) { - + function(IPA, $, menu, phases, reg, mod_details, mod_facet, QRCode) { /** * OTP tokens module * @class @@ -195,6 +195,9 @@ return { $pre_ops: [ otptoken.adder_dialog_preop ], + $post_ops: [ + otptoken.adder_dialog_qrcode_post_op + ], fields: [ { name: 'ipatokenuniqueid', @@ -286,6 +289,176 @@ otptoken.adder_dialog = function(spec) { }; /** + * Displays text as QR code + * @class + * @extends IPA.widget + */ +otptoken.qr_widget = function(spec) { + + var that = IPA.widget(spec); + + /** + * Text to be displayed as QR Code + * @property {string} + * @readonly + */ + that.text = spec.text; + + /** + * Show link with the text instead of QR code + * @property {boolean} + */ + that.show_link = !!spec.show_link; + + /** @inheritDoc */ + that.create = function(container) { + + that.widget_create(container); + container.addClass('qrcode-widget'); + + that.div_link_control = $('<a/>', { + name: that.name, + href: '' + }).appendTo(that.container); + + that.qr_control = $('<div/>', { + name: that.name + }).appendTo(that.div_link_control); + + that.uri_control = $('<div/>', { + name: 'uri-control', + 'class': 'otp-uri', + style: 'display: none;' + }).appendTo(container); + + that.link_container = $('<div/>', { + style: 'padding: 5px 0;' + }).appendTo(container); + + that.show_uri_link = $('<a/>', { + name: 'show-uri', + href: '#', + text: 'Show configuration uri', + click: function(e) { + e.preventDefault(); + that.update_display_mode(!that.show_link); + } + }).appendTo(that.link_container); + + that.qrcode = new QRCode(that.qr_control[0], { + text: "", + width: 450, + height: 450, + colorDark : "#000000", + colorLight : "#ffffff", + correctLevel : QRCode.CorrectLevel.M + }); + + that.update(that.text); + that.update_display_mode(that.show_link); + }; + + /** + * Update displayed information with supplied values. + * @param {String|Array|null} values + */ + that.update = function(values) { + + var val; + if (typeof values === 'string') { + val = values; + } else if (values.length) { + val = values[0]; + } else { + val = ''; + } + that.text = val; + that.qrcode.makeCode(that.text); + that.uri_control.text(that.text); + that.div_link_control.prop('href', that.text); + }; + + /** + * Switches between QR code and link + * @protected + * @param {boolean} show_link + */ + that.update_display_mode = function(show_link) { + + that.show_link = !!show_link; + + if (that.show_link) { + that.show_uri_link.text('Show QR code'); + that.qr_control.hide(); + that.uri_control.show(); + } else { + that.show_uri_link.text('Show configuration uri'); + that.qr_control.show(); + that.uri_control.hide(); + } + }; + + /** + * @inheritDoc + */ + that.clear = function() { + that.qrcode.clear(); + that.link_control.text(''); + }; + + return that; +}; + +/** + * Displays text as QR code in a dialog + * @class + * @extends IPA.message_dialog + */ +otptoken.qr_dialog = function(spec) { + + var that = IPA.message_dialog(spec); + + /** + * Uses IPA.dialog UI + */ + that.create_content = that.dialog_create_content; + + return that; +}; + +/** + * OTP adder dialog post-op which enables showing of QR code after token is + * successfully added by displaying QR dialog. + * @member otptoken + */ +otptoken.adder_dialog_qrcode_post_op = function(object) { + + object.added.attach(function(data) { + + var uri = data.result.result.uri; + var qr_dialog = otptoken.qr_dialog({ + name: 'qr_dialog', + title: 'Configure your token', + widgets: [ + { + $type: 'qrcode', + name: 'qr', + text: uri + } + ] + }); + + qr_dialog.open(); + qr_dialog.show_message('Configure your token by scanning the QR code \ + below. Click on the QR core if you see this on \ + the device you want to configure.'); + }); + + + return object; +}; + +/** * Entity specification object * @member otptoken */ @@ -297,7 +470,10 @@ otptoken.spec = make_spec(); */ otptoken.register = function() { var e = reg.entity; + var w = reg.widget; + e.register({type: 'otptoken', spec: otptoken.spec}); + w.register('qrcode', otptoken.qr_widget); }; phases.on('registration', otptoken.register); diff --git a/install/ui/src/freeipa/qrcode.js b/install/ui/src/freeipa/qrcode.js new file mode 100644 index 000000000..619460e4b --- /dev/null +++ b/install/ui/src/freeipa/qrcode.js @@ -0,0 +1,27 @@ +/* Authors: + * Petr Vobornik <pvoborni@redhat.com> + * + * Copyright (C) 2013 Red Hat + * see file 'COPYING' for use and warranty information + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +// +// AMD Wrapper for QRCode.js library +// It expects that the library was already loaded. +// +define(function() { + return window.QRCode; +});
\ No newline at end of file |