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/aci.js | 3 - install/ui/widget.js | 182 ++++++++++++++++++++------------------------------- 2 files changed, 70 insertions(+), 115 deletions(-) diff --git a/install/ui/aci.js b/install/ui/aci.js index e447391cc..5dcd69d44 100644 --- a/install/ui/aci.js +++ b/install/ui/aci.js @@ -271,9 +271,6 @@ IPA.attributes_widget = function(spec) { if (that.undo) { that.create_undo(container); - that.get_undo().click(function(){ - that.reset(); - }); } if (that.object_type){ diff --git a/install/ui/widget.js b/install/ui/widget.js index 12a6b966c..586984868 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'); - $('