On 2/23/2011 4:11 PM, Endi Sukma Dewata wrote:
In a details page, usually any changes done to the fields will not be
applied until the user clicks the Update button. However, if the page
contains an association table, any addition/deletion to the table will
be applied immediately.

To avoid any confusion, the user is now required to save or reset all
changes to the page before modifying the association. A dialog box will
appear if the page contains any unsaved changes.

Rebased.

--
Endi S. Dewata
From 334a44c000eceafcea082fe814795590285c277f Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Wed, 23 Feb 2011 12:35:45 -0600
Subject: [PATCH] Save changes before modifying association.

In a details page, usually any changes done to the fields will not be
applied until the user clicks the Update button. However, if the page
contains an association table, any addition/deletion to the table will
be applied immediately.

To avoid any confusion, the user is now required to save or reset all
changes to the page before modifying the association. A dialog box will
appear if the page contains any unsaved changes.
---
 install/ui/associate.js                 |   42 ++++++++++++++++++++++++++++--
 install/ui/ipa.js                       |    4 +-
 install/ui/test/data/i18n_messages.json |    3 +-
 install/ui/test/data/ipa_init.json      |    3 +-
 ipalib/plugins/internal.py              |    7 +++--
 5 files changed, 49 insertions(+), 10 deletions(-)

diff --git a/install/ui/associate.js b/install/ui/associate.js
index 600cd55c3abb99f810c8e322da83262c21b5e2c3..2f1a28d5a66e989d562c3605fa335763bcd00324 100644
--- a/install/ui/associate.js
+++ b/install/ui/associate.js
@@ -351,6 +351,28 @@ IPA.association_table_widget = function (spec) {
 
         that.table_setup(container);
 
+        var dialog = $('<div/>', {
+            html: IPA.messages.dialogs.dirty_message
+        }).appendTo(container);
+
+        var buttons = {};
+
+        buttons[IPA.messages.buttons.ok] = function() {
+            dialog.dialog('close');
+        };
+
+        dialog.dialog({
+            autoOpen: false,
+            title: IPA.messages.dialogs.dirty_title,
+            modal: true,
+            width: '20em',
+            buttons: buttons
+        });
+
+        var entity = IPA.get_entity(that.entity_name);
+        var facet_name = IPA.current_facet(entity);
+        var facet = entity.get_facet(facet_name);
+
         var button = $('input[name=remove]', container);
         button.replaceWith(IPA.action_button({
             'label': button.val(),
@@ -359,7 +381,13 @@ IPA.association_table_widget = function (spec) {
                 if ($(this).hasClass('action-button-disabled')) {
                     return false;
                 }
-                that.show_remove_dialog();
+
+                if (facet.is_dirty()) {
+                    dialog.dialog('open');
+                } else {
+                    that.show_remove_dialog();
+                }
+
                 return false;
             }
         }));
@@ -369,8 +397,16 @@ IPA.association_table_widget = function (spec) {
             'label': button.val(),
             'icon': 'ui-icon-plus',
             'click': function() {
-                if ($(this).hasClass('action-button-disabled')) return false;
-                that.show_add_dialog();
+                if ($(this).hasClass('action-button-disabled')) {
+                    return false;
+                }
+
+                if (facet.is_dirty()) {
+                    dialog.dialog('open');
+                } else {
+                    that.show_add_dialog();
+                }
+
                 return false;
             }
         }));
diff --git a/install/ui/ipa.js b/install/ui/ipa.js
index 2c07d742a71b3e0428eac0637fc75f5fc0419280..ec15332f4a3d56fd54412bba99898b8e73986ef4 100644
--- a/install/ui/ipa.js
+++ b/install/ui/ipa.js
@@ -137,7 +137,7 @@ var IPA = ( function () {
             var facet = IPA.current_entity.facets_by_name[facet_name];
             if (facet.is_dirty()){
                 var message_box =  $("<div/>",{
-                    html: IPA.messages.dirty
+                    html: IPA.messages.dialogs.dirty_message
                 }).
                     appendTo($("#navigation"));
 
@@ -148,7 +148,7 @@ var IPA = ( function () {
                 };
 
                 message_box.dialog({
-                    title: 'Dirty',
+                    title: IPA.messages.dialogs.dirty_title,
                     modal:true,
                     width: '20em',
                     buttons: buttons
diff --git a/install/ui/test/data/i18n_messages.json b/install/ui/test/data/i18n_messages.json
index 11b02c846cf3d2fc76b580555db764639e92dfeb..cca68b9455bd56b2cc6efbac02ab29d07579c883 100644
--- a/install/ui/test/data/i18n_messages.json
+++ b/install/ui/test/data/i18n_messages.json
@@ -42,12 +42,13 @@
             },
             "dialogs": {
                 "available": "Available",
+                "dirty_message": "This page has unsaved changes. Please save or revert.",
+                "dirty_title": "Dirty",
                 "hide_already_enrolled": "Hide already enrolled.",
                 "prospective": "Prospective",
                 "remove_empty": "Select ${entity} to be removed.",
                 "remove_title": "Remove ${entity}."
             },
-            "dirty": "This page has unsaved changes. Please save or revert.",
             "facets": {
                 "details": "Settings",
                 "search": "Search"
diff --git a/install/ui/test/data/ipa_init.json b/install/ui/test/data/ipa_init.json
index 99f6a6060106d449d40ff3403b1815d3582e842e..b819dab46986cd4878495392ff934be893f0ad5c 100644
--- a/install/ui/test/data/ipa_init.json
+++ b/install/ui/test/data/ipa_init.json
@@ -9505,12 +9505,13 @@
                     },
                     "dialogs": {
                         "available": "Available",
+                        "dirty_message": "This page has unsaved changes. Please save or revert.",
+                        "dirty_title": "Dirty",
                         "hide_already_enrolled": "Hide already enrolled.",
                         "prospective": "Prospective",
                         "remove_empty": "Select ${entity} to be removed.",
                         "remove_title": "Remove ${entity}."
                     },
-                    "dirty": "This page has unsaved changes. Please save or revert.",
                     "facets": {
                         "details": "Settings",
                         "search": "Search"
diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py
index 436867ba3771c05c73142c9c5787f2815756de4a..29e930c70ab78592ce1384a85c408acb61fe3987 100644
--- a/ipalib/plugins/internal.py
+++ b/ipalib/plugins/internal.py
@@ -332,10 +332,12 @@ class i18n_messages(Command):
             "view":_("View"),
             },
         "dialogs":{
+            "available":_("Available"),
+            "dirty_message":_("This page has unsaved changes. Please save or revert."),
+            "dirty_title":_("Dirty"),
+            "hide_already_enrolled":_("Hide already enrolled."),
             "remove_empty":_("Select ${entity} to be removed."),
             "remove_title":_("Remove ${entity}."),
-            "hide_already_enrolled":_("Hide already enrolled."),
-            "available":_("Available"),
             "prospective":_("Prospective"),
             },
         "facets":{
@@ -377,7 +379,6 @@ class i18n_messages(Command):
         "ajax":{
             "401":_("Your kerberos ticket is no longer valid. Please run kinit and then click 'Retry'. If this is your first time running the IPA Web UI <a href='/ipa/config/unauthorized.html'>follow these directions</a> to configure your browser.")
             },
-        "dirty":_("This page has unsaved changes. Please save or revert."),
         }
     has_output = (
         Output('messages', dict, doc=_('Dict of I18N messages')),
-- 
1.6.6.1

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

Reply via email to