The IPA.multivalued_text_widget has been modified such that the
'undo all' will appear only if at least one of the values is dirty.

Ticket #1109

--
Endi S. Dewata
From 4b53e340d94465a87077c93852731e2f72d6ad95 Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Mon, 27 Jun 2011 17:31:55 -0500
Subject: [PATCH] Fixed undo all problem.

The IPA.multivalued_text_widget has been modified such that the
'undo all' will appear only if at least one of the values is dirty.

Ticket #1109
---
 install/ui/widget.js |   59 ++++++++++++++++++++++++++++++-------------------
 1 files changed, 36 insertions(+), 23 deletions(-)

diff --git a/install/ui/widget.js b/install/ui/widget.js
index 38826ee9d64515a8fd88604e2fcf2812ca314f91..96265d984190d3e4341b80970b87ba78ac8f02de 100644
--- a/install/ui/widget.js
+++ b/install/ui/widget.js
@@ -141,12 +141,13 @@ IPA.widget = function(spec) {
             }
         }
     };
+
     /**
      * This function compares the original values and the
      * values entered in the UI. If the values have changed
      * it will return true.
      */
-    that.test_dirty = function(){
+    that.test_dirty = function() {
 
         if (that.read_only) {
             return false;
@@ -233,8 +234,8 @@ IPA.widget = function(spec) {
     };
 
     that.reset = function() {
-        that.set_dirty(false);
         that.update();
+        that.set_dirty(false);
     };
 
     that.update = function() {
@@ -320,6 +321,7 @@ IPA.widget = function(spec) {
     that.widget_reset = that.reset;
     that.widget_save = that.save;
     that.widget_set_dirty = that.set_dirty;
+    that.widget_test_dirty = that.test_dirty;
 
     return that;
 };
@@ -452,35 +454,40 @@ IPA.multivalued_text_widget = function(spec) {
         }
     };
 
-    that.super_test_dirty = that.test_dirty;
-
-    that.test_dirty = function(index){
+    that.test_dirty = function(index) {
         if (index === undefined) {
-            return that.super_test_dirty();
+            return that.widget_test_dirty();
         }
+
         var row = that.get_row(index);
-        var return_value = false;
+        var input = $('input[name="'+that.name+'"]', row);
 
-        $('input[name="'+that.name+'"]', row).each(function() {
-            var input = $(this);
-            if (input.is('.strikethrough')) return_value = true;
-            var value = input.val();
+        if (input.is('.strikethrough')) {
+            return true;
+        }
 
-            if (value !== that.values[index]){
-                return_value = true;
-            }
-        });
-        return return_value;
+        var value = input.val();
+        if (value !== that.values[index]) {
+            return true;
+        }
+
+        return false;
     };
 
     that.set_dirty = function(dirty, index) {
-        that.widget_set_dirty(dirty);
+        that.dirty = dirty;
+
         if (that.undo) {
             if (dirty) {
                 that.show_undo(index);
             } else {
                 that.hide_undo(index);
             }
+
+            if (index !== undefined) {
+                // update undo all
+                that.set_dirty(that.test_dirty());
+            }
         }
     };
 
@@ -628,7 +635,7 @@ IPA.multivalued_text_widget = function(spec) {
                 var index = that.row_index(row);
                 // uncross removed value
                 input.removeClass('strikethrough');
-                that.set_dirty( that.test_dirty(index), index);
+                that.set_dirty(that.test_dirty(index), index);
                 if (that.undo) {
                     if (index < that.values.length) {
                         remove_link.css('display', 'inline');
@@ -647,7 +654,8 @@ IPA.multivalued_text_widget = function(spec) {
                     remove_link.css('display', 'none');
                 } else {
                     // remove new value
-                    row.remove();
+                    that.remove_row(index);
+                    that.set_dirty(that.test_dirty());
                 }
                 return false;
             });
@@ -656,12 +664,13 @@ IPA.multivalued_text_widget = function(spec) {
                 var index = that.row_index(row);
                 if (index < that.values.length) {
                     // restore old value
-                    that.reset(index);
                     input.removeClass('strikethrough');
                     remove_link.css('display', 'inline');
+                    that.reset(index);
                 } else {
                     // remove new value
-                    row.remove();
+                    that.remove_row(index);
+                    that.set_dirty(that.test_dirty());
                 }
             });
         }
@@ -671,6 +680,10 @@ IPA.multivalued_text_widget = function(spec) {
         that.get_row(index).remove();
     };
 
+    that.remove_rows = function() {
+        that.get_rows().remove();
+    };
+
     that.get_row = function(index) {
         return $('div[name=value]:eq('+index+')', that.container);
     };
@@ -684,8 +697,8 @@ IPA.multivalued_text_widget = function(spec) {
     };
 
     that.reset = function(index) {
-        that.set_dirty(false, index);
         that.update(index);
+        that.set_dirty(false, index);
     };
 
     that.update = function(index) {
@@ -693,7 +706,7 @@ IPA.multivalued_text_widget = function(spec) {
         var value;
 
         if (index === undefined) {
-            $('div[name=value]', that.container).remove();
+            that.remove_rows();
 
             for (var i=0; i<that.values.length; i++) {
                 value = that.values[i];
-- 
1.7.5.1

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to