On 02/10/2011 06:46 PM, Endi Sukma Dewata wrote:
On 2/10/2011 5:02 PM, Adam Young wrote:
On 02/10/2011 04:42 PM, Endi Sukma Dewata wrote:
On 2/10/2011 3:27 PM, Adam Young wrote:


NACK. As discussed over IRC, the "is_dirty" functionality is not
working for permissions that have an "object by type" target.

Was worse than that, load was broken.

It still has some problems:

1. Updating a permission with a filter doesn't work. Clicking the update button didn't execute anything, the undo button didn't disappear.

2. Resetting the user details page is not working properly, some fields did not get reset. I think the addition of undo_span in widgets.js is not needed and causing a problem because not all (custom) widgets will call create_undo().

Filter not set was due to incomplete filter_text attribute-rights work around undo_span is now wrapped in jquery select, so that it there is no undo, it works correctly.
From 70a7496c6026a2ebe77535ac5abb84dae26303ab Mon Sep 17 00:00:00 2001
From: Adam Young <ayo...@redhat.com>
Date: Mon, 7 Feb 2011 23:02:43 -0500
Subject: [PATCH] target section without radio buttons
 ACI target section refactored into an array of widget-like objects.
 The radio buttons have been replaced by a select box.  THe select is not visible on the details page.

---
 install/ui/aci.js            |  467 +++++++++++++++++++++---------------------
 install/ui/dialog.js         |    7 +
 install/ui/test/aci_tests.js |   43 +++-
 install/ui/widget.js         |    7 +-
 4 files changed, 277 insertions(+), 247 deletions(-)

diff --git a/install/ui/aci.js b/install/ui/aci.js
index e515902c5c83451389b5c9dde8115e087f9686f3..db1267936bf4f6a12ae8eadc278f27fc075b6f51 100644
--- a/install/ui/aci.js
+++ b/install/ui/aci.js
@@ -36,6 +36,8 @@ IPA.attributes_widget = function(spec) {
 
     that.create = function(container) {
 
+        that.container = container;
+
         that.table = $('<table/>', {
             id:id,
             'class':'search-table aci-attribute-table'
@@ -200,6 +202,9 @@ IPA.hidden_widget = function(spec) {
     that.reset = function(){
 
     };
+    that.is_dirty = function(){
+        return false;
+    }
     return that;
 };
 
@@ -221,265 +226,263 @@ IPA.target_section = function(spec) {
     spec = spec || {};
 
     var that = IPA.details_section(spec);
-
     that.undo = typeof spec.undo == 'undefined' ? true : spec.undo;
 
-    var groupings = ['aci_by_type',  'aci_by_query', 'aci_by_group',
-                     'aci_by_filter' ];
-    var inputs = ['input', 'select', 'textarea'];
-
-    function disable_inputs() {
-        for (var g = 0; g < groupings.length; g += 1 ){
-            for (var t = 0 ; t < inputs.length; t += 1){
-                $('.' + groupings[g] + ' '+ inputs[t]).
-                    attr('disabled', 'disabled');
+    that.filter_text = IPA.text_widget({name: 'filter', undo: that.undo});
+    that.subtree_textarea = IPA.textarea_widget({
+        name: 'subtree',
+        cols: 30, rows: 1,
+        undo: that.undo
+    });
+    that.group_select = IPA.entity_select_widget(
+        {name: 'targetgroup', entity:'group', undo: that.undo});
+    that.type_select = IPA.select_widget({name: 'type', undo: that.undo});
+    that.attribute_table = IPA.attributes_widget({name: 'attrs', undo: that.undo});
+    //TODO make the add_dialog.save not require fields, just use the record
+    that.add_field(that.filter_text);
+    that.add_field(that.subtree_textarea);
+    that.add_field(that.group_select );
+    that.add_field(that.type_select);
+    that.add_field(that.attribute_table);
+
+    var target_types = [
+        {
+            name:'filter',
+            create: function(dl){
+
+                $('<dt/>').
+                    append($('<label/>', {
+                        text: 'Filter'
+                    })).
+                    appendTo(dl);
+
+                var dd = $('<dd/>', {
+                    'class': 'aci_by_filter first'
+                }).appendTo(dl);
+
+                var span = $('<span/>', {
+                    name: 'filter'
+                }).appendTo(dd);
+
+                that.filter_text.create(span);
+            },
+            load: function(record){
+                that.filter_text.load(record);
+            },
+            save: function(record){
+                record.filter = that.filter_text.save()[0];
+            }
+        },
+        {
+            name:'subtree',
+            create:function(dl) {
+             $('<dt/>').
+                 append($('<label/>', {
+                     text: 'By Subtree'
+                 })).
+                 appendTo(dl);
+             var dd = $('<dd/>', {
+                 'class': 'aci_by_query first'
+             }).appendTo(dl);
+             var span = $('<span/>', {
+                 name: 'subtree'
+             }).appendTo(dd);
+             that.subtree_textarea.create(span);
+            },
+            load: function(record){
+                that.subtree_textarea.load(record);
+            },
+            save: function(record){
+                record.subtree = that.subtree_textarea.save()[0];
+            }
+        },
+        {name:'targetgroup',
+         create:  function (dl) {
+             $('<dt/>').
+                 append($('<label/>', {
+                     text: 'Target Group'
+                 })).
+                 appendTo(dl);
+             var dd = $('<dd/>', {
+                 'class': 'aci_by_group first'
+             }).appendTo(dl);
+             var span = $('<span/>', {
+                 name: 'targetgroup'
+             }).appendTo(dd);
+             that.group_select.create(span);
+         },
+         load: function(record){
+             that.group_select.entity_select.val(record.targetgroup);
+         },
+         save: function(record){
+             record.targetgroup = that.group_select.save()[0];
+         }
+        },
+        {name:'type',
+         create:   function(dl) {
+             $('<dt/>').
+                 append($('<label/>', {
+                     text: 'Object By Type'
+                 })).
+                 appendTo(dl);
+             var dd = $('<dd/>', {
+                 'class': 'aci_by_type first'
+             }).appendTo(dl);
+             var span = $('<span/>', {
+                 name: 'type'
+             }).appendTo(dd);
+             that.type_select.create(span);
+             span = $('<span/>', {
+                 name: 'attrs'
+             }).appendTo(dl);
+
+             that.attribute_table.create(span);
+
+             var select = that.type_select.select;
+
+             select.change(function() {
+                 that.attribute_table.object_type = that.type_select.save()[0];
+                 that.attribute_table.reset();
+             });
+             select.append($('<option/>', {
+                 value: '',
+                 text: ''
+             }));
+             var type_params = IPA.get_param_info('permission', 'type');
+             for (var i=0; i<type_params.values.length; i++){
+                 select.append($('<option/>', {
+                     value: type_params.values[i],
+                     text: type_params.values[i]
+                 }));
+             }
+             that.type_select.update = function() {
+                 that.type_select.select_update();
+                 that.attribute_table.object_type = that.type_select.save()[0];
+                 that.attribute_table.reset();
+             };
+         },
+         load: function(record){
+             that.type_select.load(record);
+             that.attribute_table.object_type = record.type;
+             that.attribute_table.reset();
+         },
+         save: function(record){
+            record.type = that.type_select.save()[0];
+            record.attrs =  that.attribute_table.save().join(',');
+         }
+        }] ;
+
+    var target_type = target_types[0];
+    var class_prefix = '.aci-target-';
+
+    function show_target_type(type_to_show){
+        for (var i =0 ; i < target_types.length; i +=1){
+            if ( target_types[i].name === type_to_show){
+                target_type = target_types[i];
+                $(class_prefix + type_to_show,that.container).
+                    css('display', 'block');
+            }else{
+                $(class_prefix + target_types[i].name, that.container).
+                    css('display', 'none');
             }
         }
-    }
-    function enable_by(grouping) {
-        for (var t = 0 ; t < inputs.length; t += 1){
-            $('.' + grouping + ' '+ inputs[t]).
-                attr('disabled', '');
-        }
-    }
-
-    function display_filter_target(dl) {
-        $('<dt/>').
-        append($('<input/>', {
-            type: 'radio',
-            name: 'aci_type',
-            checked: 'true',
-            id: 'aci_by_filter'
-        })).
-        append($('<label/>', {
-            text: 'Filter'
-        })).
-        appendTo(dl);
-
-        var dd = $('<dd/>', {
-            'class': 'aci_by_filter first'
-        }).appendTo(dl);
-
-        var span = $('<span/>', {
-            name: 'filter'
-        }).appendTo(dd);
-
-        that.filter_text.create(span);
-    }
-
-
-    function display_type_target(dl) {
-        $('<dt/>').
-        append($('<input/>', {
-            type: 'radio',
-            name: 'aci_type',
-            checked: 'true',
-            id: 'aci_by_type'
-        })).
-        append($('<label/>', {
-            text: 'Object By Type'
-        })).
-        appendTo(dl);
-
-        var dd = $('<dd/>', {
-            'class': 'aci_by_type first'
-        }).appendTo(dl);
 
-        var span = $('<span/>', {
-            name: 'type'
-        }).appendTo(dd);
-
-        that.type_select.create(span);
-
-        span = $('<span/>', {
-            name: 'attrs'
-        }).appendTo(dl);
-
-        that.attribute_table.create(span);
-    }
-
-    function display_query_target(dl) {
-        $('<dt/>').
-        append($('<input/>', {
-            type: 'radio',
-            name: 'aci_type',
-            id: 'aci_by_query'
-        })).
-        append($('<label/>', {
-            text: 'By Subtree'
-        })).
-        appendTo(dl);
-
-        var dd = $('<dd/>', {
-            'class': 'aci_by_query first'
-        }).appendTo(dl);
-
-        var span = $('<span/>', {
-            name: 'subtree'
-        }).appendTo(dd);
-
-        that.subtree_textarea.create(span);
     }
-
-    function display_group_target(dl) {
-        $('<dt/>').
-            append($('<input />', {
-                type: 'radio',
-                name: 'aci_type',
-                id: 'aci_by_group'
-            })).
-            append($('<label/>', {
-                text: 'Target Group'
-            })).
-            appendTo(dl);
-
-        var dd = $('<dd/>', {
-            'class': 'aci_by_group first'
-        }).appendTo(dl);
-
-        var span = $('<span/>', {
-            name: 'targetgroup'
-        }).appendTo(dd);
-
-        that.group_select.create(span);
-    }
-
     that.create = function(container) {
+
         var dl =  $('<dl/>', {
-            'class': 'aci-target'
+            'class': 'aci-target-select',
+            style:'display:none'
         }).appendTo(container);
-
-        display_filter_target(dl);
-        display_query_target(dl);
-        display_group_target(dl);
-        display_type_target(dl);
-
-        $('#aci_by_filter', dl).click(function() {
-            disable_inputs();
-            enable_by(groupings[3]);
-        });
-
-        $('#aci_by_type', dl).click(function() {
-            disable_inputs();
-            enable_by(groupings[0]);
-        });
-
-        $('#aci_by_query', dl).click(function() {
-            disable_inputs();
-            enable_by(groupings[1]);
-        });
-
-        $('#aci_by_group', dl).click(function() {
-            disable_inputs();
-            enable_by(groupings[2]);
-        });
-
-        $('#aci_by_type', dl).click();
-    };
-
-    that.setup = function(container) {
-        that.section_setup(container);
-
-        var select = that.type_select.select;
-
-        select.change(function() {
-            that.attribute_table.object_type = that.type_select.save()[0];
-            that.attribute_table.reset();
-        });
-
-        select.append($('<option/>', {
-            value: '',
-            text: ''
-        }));
-
-        var type_params = IPA.get_param_info('permission', 'type');
-        for (var i=0; i<type_params.values.length; i++){
-            select.append($('<option/>', {
-                value: type_params.values[i],
-                text: type_params.values[i]
+        $('<dt>Target On </dt>').appendTo(dl);
+
+        if (!that.undo){
+            dl.css('display','block');
+        }
+        that.target_type_select =  $('<select></select>',{
+            change:function(){
+                show_target_type(this.value);
+            }});
+
+        $('<dd/>').append(that.target_type_select).appendTo(dl);;
+
+        for (var i = 0 ; i < target_types.length; i += 1){
+            target_type = target_types[i];
+            dl =  $('<dl/>', {
+                'class': 'aci-target-' + target_type.name,
+                style: 'display:none'
+            }).appendTo(container);
+
+            that.target_type_select.append($('<option/>',{
+                text: target_type.name,
+                value : target_type.name
             }));
+            target_type.create(dl);
         }
-
-        that.type_select.update = function() {
-            that.type_select.select_update();
-            that.attribute_table.object_type = that.type_select.save()[0];
-            that.attribute_table.reset();
-        };
+        /*
+           default for the add dialog
+        */
+        target_type = target_types[0];
+        that.target_type_select.val( target_type.name);
+        $(class_prefix + target_type.name).css('display', 'block');
     };
 
-    function set_aci_type(record) {
-        if (record.filter) {
-            $('#aci_by_filter').click();
+    function reset_target_widgets(){
+        that.filter_text.record = null;
+        that.subtree_textarea.record = null;
+        that.group_select.record = null;
+        that.type_select.record = null;
+        that.attribute_table.record = null;
 
-        } else if (record.subtree) {
-            $('#aci_by_query').click();
+        that.filter_text.reset();
+        that.subtree_textarea.reset();
+        that.group_select.reset();
+        that.type_select.reset();
+        that.attribute_table.reset();
+    }
 
-        } else if (record.targetgroup) {
-            $('#aci_by_group').click();
+    function set_target_type(record) {
 
-        } else if (record.type) {
-            $('#aci_by_type').click();
 
-        } else {
+        reset_target_widgets();
+
+        var target_type_name ;
+        for (var i = 0 ; i < target_types.length; i += 1){
+            target_type = target_types[i];
+            if (record[target_type.name]){
+                target_type_name = target_type.name;
+                break;
+            }
+        }
+        if (!target_type_name){
             alert('permission with invalid target specification');
+            return;
         }
+
+        $(class_prefix+target_type_name).css('display', 'block');
+        that.target_type_select.val( target_type_name);
+        target_type.load(record);
     }
-
-    that.load = function(record) {
-
-        set_aci_type(record);
-        that.attribute_table.object_type = record.type;
-
+    that.load = function(record){
         that.section_load(record);
-    };
-
+        that.reset();
+    }
     that.reset = function() {
-
-        set_aci_type(that.record);
-        that.attribute_table.object_type = that.record.type;
-
+        for (var i = 0 ; i < target_types.length ; i +=1 ){
+            $(class_prefix + target_types[i].name).css('display', 'none');
+        }
+        if (that.record){
+            set_target_type(that.record);
+            that.attribute_table.object_type = that.record.type;
+        }else{
+            reset_target_widgets();
+        }
         that.section_reset();
-    };
 
-    that.init = function() {
-        that.filter_text = IPA.text_widget({name: 'filter', undo: that.undo});
-        that.add_field(that.filter_text);
-
-        that.subtree_textarea = IPA.textarea_widget({
-            name: 'subtree',
-            cols: 30, rows: 1,
-            undo: that.undo
-        });
-        that.add_field(that.subtree_textarea);
-
-        that.group_select = IPA.entity_select_widget(
-            {name: 'targetgroup', entity:'group', undo: that.undo});
-        that.add_field(that.group_select);
-
-        that.type_select = IPA.select_widget({name: 'type', undo: that.undo});
-        that.add_field(that.type_select);
-
-        that.attribute_table = IPA.attributes_widget({name: 'attrs', undo: that.undo});
-        that.add_field(that.attribute_table);
     };
 
     that.save = function(record) {
-
-        var record_type = $("input[name='aci_type']:checked").attr('id');
-
-        if (record_type === 'aci_by_group') {
-            record.targetgroup = that.group_select.save()[0];
-
-        } else if (record_type === 'aci_by_type') {
-            record.type = that.type_select.save()[0];
-            record.attrs =   that.attribute_table.save().join(',');
-
-        } else if (record_type === 'aci_by_query') {
-            record.subtree = that.subtree_textarea.save([0]);
-
-        } else if (record_type === 'aci_by_filter') {
-            record.filter = that.filter_text.save()[0];
-        }
+        target_type.save(record);
     };
 
     return that;
diff --git a/install/ui/dialog.js b/install/ui/dialog.js
index b1f84a98bbd11a827415664d1357cdf90cb90fb3..281deeb1c49b580ce77d7101aa2db0261a59b59a 100644
--- a/install/ui/dialog.js
+++ b/install/ui/dialog.js
@@ -234,6 +234,13 @@ IPA.dialog = function(spec) {
             var field = that.fields[i];
             field.reset();
         }
+        for (var j=0; j<that.sections.length; j++) {
+            var section = that.sections[j];
+
+            if (section.reset) {
+                section.reset();
+            }
+        }
     };
 
     that.dialog_init = that.init;
diff --git a/install/ui/test/aci_tests.js b/install/ui/test/aci_tests.js
index d1a5cb6bfa586a58c2e2cea609fd7169e9f7b6e5..ff8b5de04fdef6582f2a5ad02f4d709cadaddc54 100644
--- a/install/ui/test/aci_tests.js
+++ b/install/ui/test/aci_tests.js
@@ -130,33 +130,54 @@ test("IPA.rights_widget.", function() {
 test("Testing aci grouptarget.", function() {
     var sample_data_filter_only = {"targetgroup":"ipausers"};
     target_section.load(sample_data_filter_only);
-    ok($('#aci_by_group')[0].checked, 'aci_by_group control selected');
-    ok ($('#targetgroup-entity-select option').length > 2,'group select populated');
+
+    var selected = $(target_section.type_select+":selected");
+
+    same(selected.val(), 'targetgroup' , 'group control selected');
+    ok ($('#targetgroup-entity-select option').length > 2,
+        'group select populated');
 
 });
 
-
-
-test("Testing aci object type.", function() {
+test("Testing type target.", function() {
     var sample_data_filter_only = {"type":"hostgroup"};
+
     target_section.load(sample_data_filter_only);
-    ok($('.aci-attribute', target_container).length > 4);
-    ok($('#aci_by_type')[0].checked, 'aci_by_type control selected');
+    var selected = $(target_section.type_select+":selected");
+    same(selected.val(), 'type', 'type selected');
+
+    $("input[type=checkbox]").attr("checked",true);
+    var response_record = {};
+    target_section.save(response_record);
+    same(response_record.type, sample_data_filter_only.type,
+         "saved type matches sample data");
+    ok((response_record.attrs.length > 10),
+       "response length shows some attrs set");
 
 });
 
 
-test("Testing aci filter only.", function() {
+test("Testing filter target.", function() {
 
     var sample_data_filter_only = {"filter":"somevalue"};
 
     target_section.load(sample_data_filter_only);
 
-    var filter_radio = $('#aci_by_filter');
+    var selected = $(target_section.type_select+":selected");
+    same(selected.val(), 'filter', 'filter selected');
+});
+
+
+
+test("Testing subtree target.", function() {
 
-    ok(filter_radio.length,'find "filter_only_radio" control');
-    ok(filter_radio[0].checked,'filter_only_radio control is checked');
+    var sample_data = {
+        subtree:"ldap:///cn=*,cn=roles,cn=accounts,dc=example,dc=co"};
 
+    target_section.load(sample_data);
+    var record = {};
+    target_section.save(record);
+    same(record.subtree, sample_data.subtree, 'subtree set correctly');
 });
 
 
diff --git a/install/ui/widget.js b/install/ui/widget.js
index eb2f70cfc0407d36fa6dd04ef7a4e9acb2f82853..871c296cabdc8f8b027146b60d086db428975fe7 100644
--- a/install/ui/widget.js
+++ b/install/ui/widget.js
@@ -59,6 +59,7 @@ IPA.widget = function(spec) {
     that.validate_input = spec.validate_input || validate_input;
     that.valid = true;
     that.param_info = spec.param_info;
+    that.values = [];
 
     that.__defineGetter__("entity_name", function(){
         return that._entity_name;
@@ -113,9 +114,10 @@ IPA.widget = function(spec) {
     }
 
     function create(container) {
+        that.container = container;
     }
 
-    function setup(container) {
+    function setup(container){
         that.container = container;
     }
 
@@ -875,9 +877,6 @@ IPA.select_widget = function(spec) {
             container.append(' ');
             that.create_undo(container);
         }
-    };
-
-    that.setup = function(container) {
 
         that.widget_setup(container);
 
-- 
1.7.3.5

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

Reply via email to