From 776af82572b56d9c66a2eadabdb5bced9316648a Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Tue, 30 Aug 2011 13:39:53 +0200 Subject: Enable update and reset button only if dirty https://fedorahosted.org/freeipa/ticket/1697 Original problem: WEBUI: Update automount location refer to unknown command Update name of the automount location (Policy -> Automount -> custom_location -> Settings -> Update) in the WEBUI refer to an unknown command. Solution: Tracking dirty state in field -> section -> details facet. 'Reset' and 'Updates' in details facet are enabled only if facet is dirty. Removes the problem above and 'no modification to be performed' annoyance. --- install/ui/details.js | 54 ++++++++++++++++++++++++++++++++++++++++---- install/ui/test/ipa_tests.js | 32 ++++++++++++++++++++++++++ install/ui/widget.js | 42 ++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 4 deletions(-) diff --git a/install/ui/details.js b/install/ui/details.js index a0a44e7b2..4f7e4a29a 100644 --- a/install/ui/details.js +++ b/install/ui/details.js @@ -40,6 +40,9 @@ IPA.details_section = function(spec) { that.entity = spec.entity; that.fields = $.ordered_map(); + that.dirty = false; + that.dirty_changed = IPA.observer(); + that.get_field = function(name) { return that.fields.get(name); }; @@ -47,6 +50,7 @@ IPA.details_section = function(spec) { that.add_field = function(field) { field.entity = that.entity; that.fields.put(field.name, field); + field.dirty_changed.attach(that.field_dirty_changed); return field; }; @@ -117,6 +121,20 @@ IPA.details_section = function(spec) { } }; + that.field_dirty_changed = function(dirty) { + var old = that.dirty; + + if(dirty) { + that.dirty = true; + } else { + that.dirty = that.is_dirty(); + } + + if(old !== that.dirty) { + that.dirty_changed.notify([that.dirty], that); + } + }; + that.is_dirty = function() { var fields = that.fields.values; for (var i=0; i