The update() in HBAC/Sudo details facet has been fixed to call the
callback function which will show the dirty dialog properly.

Ticket #1439

--
Endi S. Dewata
From 673b6b00c036512bff70fca7e1ec23b44ff55231 Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Thu, 7 Jul 2011 15:42:57 -0400
Subject: [PATCH] Fixed dirty dialog problems in HBAC/Sudo rules.

The update() in HBAC/Sudo details facet has been fixed to call the
callback function which will show the dirty dialog properly.

Ticket #1439
---
 install/ui/association.js |    2 +
 install/ui/details.js     |    5 +-
 install/ui/hbac.js        |   36 ++++++++-----
 install/ui/rule.js        |   20 ++++++-
 install/ui/sudo.js        |  130 +++++++++++++--------------------------------
 5 files changed, 83 insertions(+), 110 deletions(-)

diff --git a/install/ui/association.js b/install/ui/association.js
index 92ccb60581f21480c44bbd4f59e20d4295fe50e0..56a2761c1ef22b6c15725d6e726acbfe2959a1c5 100644
--- a/install/ui/association.js
+++ b/install/ui/association.js
@@ -664,6 +664,8 @@ IPA.association_table_widget = function (spec) {
 
     // methods that should be invoked by subclasses
     that.association_table_widget_init = that.init;
+    that.association_table_widget_show_add_dialog = that.show_add_dialog;
+    that.association_table_widget_show_remove_dialog = that.show_remove_dialog;
 
     return that;
 };
diff --git a/install/ui/details.js b/install/ui/details.js
index 4f01cd34c0cdf9118333c54b947a5f4cf8226376..6a2def7fb5447aba59998876bb6257f2415900c5 100644
--- a/install/ui/details.js
+++ b/install/ui/details.js
@@ -292,9 +292,8 @@ IPA.details_facet = function(spec) {
         return section;
     };
 
-    that.section = function(section) {
-        that.add_section(section);
-        return that;
+    that.get_section = function(name) {
+        return that.sections.get(name);
     };
 
     that.create_section = function(spec) {
diff --git a/install/ui/hbac.js b/install/ui/hbac.js
index dc85d572bf1eef19fd3c56d66c7ca8bad4fc276f..022e26a0def23b6d14fd3a25c3ecc881f5c7a03e 100644
--- a/install/ui/hbac.js
+++ b/install/ui/hbac.js
@@ -22,7 +22,7 @@
 
 /* REQUIRES: ipa.js, details.js, search.js, add.js, entity.js */
 
-IPA.entity_factories.hbacrule = function () {
+IPA.entity_factories.hbacrule = function() {
     return IPA.entity_builder().
         entity('hbacrule').
         search_facet({
@@ -65,7 +65,7 @@ IPA.entity_factories.hbacrule = function () {
         build();
 };
 
-IPA.entity_factories.hbacsvc = function () {
+IPA.entity_factories.hbacsvc = function() {
     return IPA.entity_builder().
         entity('hbacsvc').
         search_facet({
@@ -81,7 +81,7 @@ IPA.entity_factories.hbacsvc = function () {
 };
 
 
-IPA.entity_factories.hbacsvcgroup = function () {
+IPA.entity_factories.hbacsvcgroup = function() {
     return IPA.entity_builder().
         entity('hbacsvcgroup').
         search_facet({
@@ -109,7 +109,7 @@ IPA.entity_factories.hbacsvcgroup = function () {
         build();
 };
 
-IPA.hbacsvcgroup_member_hbacsvc_table_widget = function (spec) {
+IPA.hbacsvcgroup_member_hbacsvc_table_widget = function(spec) {
 
     spec = spec || {};
 
@@ -148,7 +148,7 @@ IPA.hbacsvcgroup_member_hbacsvc_table_widget = function (spec) {
 
 
 
-IPA.hbacrule_details_facet = function (spec) {
+IPA.hbacrule_details_facet = function(spec) {
 
     spec = spec || {};
 
@@ -205,7 +205,9 @@ IPA.hbacrule_details_facet = function (spec) {
             that.add_section(section);
         }
 
-        var category = section.radio({ name: 'usercategory' });
+        var category = section.add_field(IPA.radio_widget({
+            name: 'usercategory'
+        }));
         section.add_field(IPA.rule_association_table_widget({
             'id': that.entity_name+'-memberuser_user',
             'name': 'memberuser_user', 'category': category,
@@ -244,7 +246,9 @@ IPA.hbacrule_details_facet = function (spec) {
             that.add_section(section);
         }
 
-        category = section.radio({ 'name': 'hostcategory' });
+        category = section.add_field(IPA.radio_widget({
+            name: 'hostcategory'
+        }));
         section.add_field(IPA.rule_association_table_widget({
             'id': that.entity_name+'-memberhost_host',
             'name': 'memberhost_host', 'category': category,
@@ -283,7 +287,9 @@ IPA.hbacrule_details_facet = function (spec) {
             that.add_section(section);
         }
 
-        category = section.radio({ 'name': 'servicecategory' });
+        category = section.add_field(IPA.radio_widget({
+            name: 'servicecategory'
+        }));
         section.add_field(IPA.rule_association_table_widget({
             'id': that.entity_name+'-memberservice_hbacsvc',
             'name': 'memberservice_hbacsvc', 'category': category,
@@ -322,7 +328,9 @@ IPA.hbacrule_details_facet = function (spec) {
             that.add_section(section);
         }
 
-        category = section.radio({ 'name': 'sourcehostcategory' });
+        category = section.add_field(IPA.radio_widget({
+            name: 'sourcehostcategory'
+        }));
         section.add_field(IPA.rule_association_table_widget({
             'id': that.entity_name+'-sourcehost_host',
             'name': 'sourcehost_host', 'category': category,
@@ -336,7 +344,7 @@ IPA.hbacrule_details_facet = function (spec) {
         that.details_facet_init();
     };
 
-    that.update = function() {
+    that.update = function(on_success, on_error) {
 
         var pkey = IPA.nav.get_state(that.entity_name+'-pkey');
 
@@ -513,9 +521,11 @@ IPA.hbacrule_details_facet = function (spec) {
             'name': 'hbac_details_update',
             'on_success': function(data, text_status, xhr) {
                 that.refresh();
+                if (on_success) on_success(data, text_status, xhr);
             },
             'on_error': function(xhr, text_status, error_thrown) {
                 that.refresh();
+                if (on_error) on_error(xhr, text_status, error_thrown);
             }
         });
 
@@ -544,7 +554,7 @@ IPA.hbacrule_details_facet = function (spec) {
 };
 
 
-IPA.hbacrule_details_general_section = function (spec){
+IPA.hbacrule_details_general_section = function(spec) {
 
     spec = spec || {};
 
@@ -692,7 +702,7 @@ IPA.hbacrule_details_general_section = function (spec){
     return that;
 };
 
-IPA.hbacrule_accesstime_widget = function (spec) {
+IPA.hbacrule_accesstime_widget = function(spec) {
 
     spec = spec || {};
 
@@ -1011,7 +1021,7 @@ IPA.hbacrule_accesstime_widget = function (spec) {
     return that;
 };
 
-IPA.hbac_deny_warning_dialog = function (container) {
+IPA.hbac_deny_warning_dialog = function(container) {
     var dialog = IPA.dialog({
         'title': 'HBAC Deny Rules found'
     });
diff --git a/install/ui/rule.js b/install/ui/rule.js
index 4969ffb5dc7bf38861a0668a473b1a81ae4c0880..106b870bbc1767c685e6da158bc141b6f80a8a71 100644
--- a/install/ui/rule.js
+++ b/install/ui/rule.js
@@ -22,7 +22,7 @@
 
 /* REQUIRES: ipa.js, details.js, search.js, add.js, entity.js */
 
-IPA.rule_details_section = function (spec){
+IPA.rule_details_section = function(spec) {
 
     spec = spec || {};
 
@@ -124,7 +124,7 @@ IPA.rule_details_section = function (spec){
 };
 
 
-IPA.rule_association_table_widget = function (spec) {
+IPA.rule_association_table_widget = function(spec) {
 
     spec = spec || {};
 
@@ -132,6 +132,22 @@ IPA.rule_association_table_widget = function (spec) {
 
     that.category = spec.category;
 
+    that.show_add_dialog = function() {
+        if (that.category) {
+            var values = that.category.save();
+            if (values[0] !== '') return;
+        }
+        that.association_table_widget_show_add_dialog();
+    };
+
+    that.show_remove_dialog = function() {
+        if (that.category) {
+            var values = that.category.save();
+            if (values[0] !== '') return;
+        }
+        that.association_table_widget_show_remove_dialog();
+    };
+
     that.add = function(values, on_success, on_error) {
 
         var pkey = IPA.nav.get_state(that.entity_name+'-pkey');
diff --git a/install/ui/sudo.js b/install/ui/sudo.js
index 0ed46d8cd89b55dc6f846319e270674a12730de3..4b5686be02d8570fdd1e6da284ea1c450b3c047b 100644
--- a/install/ui/sudo.js
+++ b/install/ui/sudo.js
@@ -23,7 +23,7 @@
 /* REQUIRES: ipa.js, details.js, search.js, add.js, entity.js */
 
 
-IPA.entity_factories.sudorule = function () {
+IPA.entity_factories.sudorule = function() {
 
     return IPA.entity_builder().
         entity('sudorule').
@@ -39,7 +39,7 @@ IPA.entity_factories.sudorule = function () {
         build();
 };
 
-IPA.entity_factories.sudocmd = function () {
+IPA.entity_factories.sudocmd = function() {
 
     return IPA.entity_builder().
         entity( 'sudocmd').
@@ -93,7 +93,7 @@ IPA.entity_factories.sudocmd = function () {
 
 };
 
-IPA.entity_factories.sudocmdgroup = function () {
+IPA.entity_factories.sudocmdgroup = function() {
     return IPA.entity_builder().
         entity('sudocmdgroup').
         search_facet({
@@ -150,7 +150,7 @@ IPA.entity_factories.sudocmdgroup = function () {
 /*
 * TODO:  user the serial associator to perform back end operations.
 */
-IPA.sudocmd_member_sudocmdgroup_table_widget = function (spec) {
+IPA.sudocmd_member_sudocmdgroup_table_widget = function(spec) {
 
     spec = spec || {};
 
@@ -257,7 +257,7 @@ IPA.sudocmd_member_sudocmdgroup_table_widget = function (spec) {
 IPA.sudo = {};
 
 
-IPA.sudorule_details_facet = function (spec) {
+IPA.sudorule_details_facet = function(spec) {
 
     spec = spec || {};
 
@@ -298,7 +298,9 @@ IPA.sudorule_details_facet = function (spec) {
     });
     that.add_section(section);
 
-    var category = section.radio({ name: 'usercategory' });
+    var category = section.add_field(IPA.radio_widget({
+        name: 'usercategory'
+    }));
     section.add_field(IPA.sudorule_association_table_widget({
         'id': that.entity_name+'-memberuser_user',
         'name': 'memberuser_user', 'category': category,
@@ -326,7 +328,9 @@ IPA.sudorule_details_facet = function (spec) {
     });
     that.add_section(section);
 
-    category = section.radio({ 'name': 'hostcategory' });
+    category = section.add_field(IPA.radio_widget({
+        name: 'hostcategory'
+    }));
     section.add_field(IPA.sudorule_association_table_widget({
         'id': that.entity_name+'-memberhost_host',
         'name': 'memberhost_host', 'category': category,
@@ -351,7 +355,7 @@ IPA.sudorule_details_facet = function (spec) {
     });
     that.add_section(section);
 
-    that.update = function() {
+    that.update = function(on_success, on_error) {
 
         var pkey = IPA.nav.get_state(that.entity_name+'-pkey');
 
@@ -519,9 +523,11 @@ IPA.sudorule_details_facet = function (spec) {
             'name': 'sudorule_details_update',
             'on_success': function(data, text_status, xhr) {
                 that.refresh();
+                if (on_success) on_success(data, text_status, xhr);
             },
             'on_error': function(xhr, text_status, error_thrown) {
                 that.refresh();
+                if (on_error) on_error(xhr, text_status, error_thrown);
             }
         });
 
@@ -549,7 +555,7 @@ IPA.sudorule_details_facet = function (spec) {
 };
 
 
-IPA.sudo.rule_details_general_section = function (spec){
+IPA.sudo.rule_details_general_section = function(spec) {
 
     spec = spec || {};
 
@@ -675,7 +681,7 @@ IPA.sudo.rule_details_general_section = function (spec){
 };
 
 
-IPA.sudo.rule_details_command_section = function (spec){
+IPA.sudo.rule_details_command_section = function(spec) {
 
     spec = spec || {};
 
@@ -683,31 +689,31 @@ IPA.sudo.rule_details_command_section = function (spec){
 
     that.init = function() {
 
-        var category = that.radio({'name': 'cmdcategory'});
+        var category = that.add_field(IPA.radio_widget({
+            name: 'cmdcategory'
+        }));
 
-        that.add_field(IPA.sudorule_command_table_widget({
+        that.add_field(IPA.rule_association_table_widget({
             'id': that.entity_name+'-memberallowcmd_sudocmd',
             'name': 'memberallowcmd_sudocmd', 'label': 'Command',
-            'category': category, 'section': that,
+            'category': category,
             'other_entity': 'sudocmd', 'add_method': 'add_allow_command', 'remove_method': 'remove_allow_command'
         }));
-        that.add_field(IPA.sudorule_command_table_widget({
+        that.add_field(IPA.rule_association_table_widget({
             'id': that.entity_name+'-memberallowcmd_sudocmdgroup',
             'name': 'memberallowcmd_sudocmdgroup', 'label': 'Groups',
-            'category': category, 'section': that,
+            'category': category,
             'other_entity': 'sudocmdgroup', 'add_method': 'add_allow_command', 'remove_method': 'remove_allow_command'
         }));
 
-        that.add_field(IPA.sudorule_command_table_widget({
+        that.add_field(IPA.rule_association_table_widget({
             'id': that.entity_name+'-memberdenycmd_sudocmd',
             'name': 'memberdenycmd_sudocmd', 'label': 'Command',
-            'section': that,
             'other_entity': 'sudocmd', 'add_method': 'add_deny_command', 'remove_method': 'remove_deny_command'
         }));
-        that.add_field(IPA.sudorule_command_table_widget({
+        that.add_field(IPA.rule_association_table_widget({
             'id': that.entity_name+'-memberdenycmd_sudocmdgroup',
             'name': 'memberdenycmd_sudocmdgroup', 'label': 'Groups',
-            'section': that,
             'other_entity': 'sudocmdgroup', 'add_method': 'add_deny_command', 'remove_method': 'remove_deny_command'
         }));
 
@@ -839,7 +845,7 @@ IPA.sudo.rule_details_command_section = function (spec){
 };
 
 
-IPA.sudo.rule_details_runas_section = function (spec){
+IPA.sudo.rule_details_runas_section = function(spec) {
 
     spec = spec || {};
 
@@ -847,7 +853,11 @@ IPA.sudo.rule_details_runas_section = function (spec){
 
     that.init = function() {
 
-        var category = that.radio({ name: 'ipasudorunasusercategory', label: 'Run as User category' });
+        var category = that.add_field(IPA.radio_widget({
+            name: 'ipasudorunasusercategory',
+            label: 'Run as User category'
+        }));
+
         that.add_field(IPA.sudorule_association_table_widget({
             'id': that.entity_name+'-runasruser_user',
             'name': 'ipasudorunas_user', 'label': 'Users', 'category': category,
@@ -859,7 +869,11 @@ IPA.sudo.rule_details_runas_section = function (spec){
             'other_entity': 'group', 'add_method': 'add_runasuser', 'remove_method': 'remove_runasuser'
         }));
 
-        category = that.radio({ name: 'ipasudorunasgroupcategory', label: 'Run as Group category' });
+        category = that.add_field(IPA.radio_widget({
+            name: 'ipasudorunasgroupcategory',
+            label: 'Run as Group category'
+        }));
+
         that.add_field(IPA.sudorule_association_table_widget({
             'id': that.entity_name+'-runasgroup_group',
             'name': 'ipasudorunasgroup_group', 'label': 'Groups', 'category': category,
@@ -1036,7 +1050,7 @@ IPA.sudo.rule_details_runas_section = function (spec){
 };
 
 
-IPA.sudorule_association_table_widget = function (spec) {
+IPA.sudorule_association_table_widget = function(spec) {
 
     spec = spec || {};
 
@@ -1077,7 +1091,7 @@ IPA.sudorule_association_table_widget = function (spec) {
 };
 
 
-IPA.sudo.rule_association_adder_dialog = function (spec) {
+IPA.sudo.rule_association_adder_dialog = function(spec) {
 
     spec = spec || {};
 
@@ -1230,71 +1244,3 @@ IPA.sudo.rule_association_adder_dialog = function (spec) {
 
     return that;
 };
-
-
-IPA.sudorule_command_table_widget = function (spec) {
-
-    spec = spec || {};
-
-    var that = IPA.association_table_widget(spec);
-
-    that.category = spec.category;
-    that.section = spec.section;
-
-    that.add = function(values, on_success, on_error) {
-
-        var pkey = IPA.nav.get_state(that.entity_name+'-pkey');
-
-        var batch = IPA.batch_command({
-            'on_success': on_success,
-            'on_error': on_error
-        });
-
-        var command;
-
-        if (that.category) {
-            command = IPA.command({
-                entity: that.entity_name,
-                method: 'mod',
-                args: [pkey],
-                options: {all: true, rights: true},
-                on_success: function() {
-                    var record = {};
-                    record[that.category.name] = [''];
-                    that.category.load(record);
-                }
-            });
-            command.set_option(that.category.name, '');
-            batch.add_command(command);
-        }
-
-        command = IPA.command({
-            entity: that.entity_name,
-            method: that.add_method,
-            args: [pkey]
-        });
-        command.set_option(that.other_entity, values.join(','));
-        batch.add_command(command);
-
-        batch.execute();
-    };
-
-    that.remove = function(values, on_success, on_error) {
-
-        var pkey = IPA.nav.get_state(that.entity_name+'-pkey');
-
-        var command = IPA.command({
-            entity: that.entity_name,
-            method: that.remove_method,
-            args: [pkey],
-            on_success: on_success,
-            on_error: on_error
-        });
-
-        command.set_option(that.other_entity, values.join(','));
-
-        command.execute();
-    };
-
-    return that;
-};
-- 
1.7.4

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

Reply via email to