From df049ff13dadceb8eeecc960622c8796cf287bec Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Tue, 13 Sep 2011 13:53:54 +0200 Subject: Code cleanup: widget creation https://fedorahosted.org/freeipa/ticket/1788 Removed code duplication of undo links. Simplified code of widget creation to be more readable. --- install/ui/widget.js | 182 ++++++++++++++++++++------------------------------- 1 file changed, 70 insertions(+), 112 deletions(-) (limited to 'install/ui/widget.js') diff --git a/install/ui/widget.js b/install/ui/widget.js index 12a6b966..58698486 100644 --- a/install/ui/widget.js +++ b/install/ui/widget.js @@ -287,7 +287,15 @@ IPA.widget = function(spec) { return that.dirty; }; - that.create_undo = function(container) { + /** + * This function creates an undo link in the container. + * On_undo is a link click callback. It can be specified to custom + * callback. If a callback isn't set, default callback is used. If + * spefified to value other than a function, no callback is registered. + */ + that.create_undo = function(container, on_undo) { + container.append(' '); + that.undo_span = $('', { name: 'undo', @@ -295,6 +303,16 @@ IPA.widget = function(spec) { 'class': 'ui-state-highlight ui-corner-all undo', html: 'undo' }).appendTo(container); + + if(on_undo === undefined) { + on_undo = function() { + that.reset(); + }; + } + + if(typeof on_undo === 'function') { + that.undo_span.click(on_undo); + } }; that.set_dirty = function(dirty) { @@ -389,61 +407,48 @@ IPA.text_widget = function(spec) { IPA.select_range(that.input, start, end); }; - that.create = function(container) { that.widget_create(container); container.addClass('text-widget'); - $('