On 06/30/2011 08:46 PM, Endi Sukma Dewata wrote:
On 6/30/2011 4:42 PM, Adam Young wrote:


Some issues:

1. Suppose initially you open an entry that contains a value that matches no_link_value, it will hide the link and show the label. Then suppose you open another entry that has no value, it will empty the link but leaving the label from the previous entry visible.

This is not a problem for password policy because cn will always have a value, but it might be better to change the else-clause in reset() to hide both the link and the label:

  that.link.css('display','none');
  that.label.css('display','none');

2. Optional: The no_link_value seems to be limited to a single value only. While it works fine for password policy, I suppose in other cases we might want to match multiple values or use some other logic. One solution is to put the logic that checks the value inside a method that can be overriden by the subclass.


From 52de8b34a6939fb8a06b5a62ee27f1bab369721e Mon Sep 17 00:00:00 2001
From: Adam Young <ayo...@redhat.com>
Date: Thu, 30 Jun 2011 17:38:59 -0400
Subject: [PATCH] entity link for password policy

https://fedorahosted.org/freeipa/ticket/1111

reset() now hides both the link and the label
calucalating  should_link is now a function that can be overloaded.
---
 install/ui/policy.js |   11 ++++++++-
 install/ui/widget.js |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/install/ui/policy.js b/install/ui/policy.js
index d30abbfdc8522362522fe287598ef9d7380cd2f9..cd0e499e14f4275c8f47806cc36aa9154ddf0c1b 100644
--- a/install/ui/policy.js
+++ b/install/ui/policy.js
@@ -33,8 +33,15 @@ IPA.entity_factories.pwpolicy = function() {
             sections:[
                 {
                     name : 'identity',
-                    fields:['krbmaxpwdlife','krbminpwdlife','krbpwdhistorylength',
-                            'krbpwdmindiffchars','krbpwdminlength']
+                    fields:[
+                        {
+                            factory: IPA.entity_link_widget,
+                            name: 'cn',
+                            entity: 'group',
+                            no_link_value: 'global_policy'
+                        },
+                        'krbmaxpwdlife','krbminpwdlife','krbpwdhistorylength',
+                        'krbpwdmindiffchars','krbpwdminlength']
                 }]}).
         standard_association_facets().
         adder_dialog({
diff --git a/install/ui/widget.js b/install/ui/widget.js
index a56e55250da6c123e29be779ee98e5d90790b58a..5485f0c88cc46a8beb1c5714f919c9b20f6fbfd0 100644
--- a/install/ui/widget.js
+++ b/install/ui/widget.js
@@ -1729,3 +1729,59 @@ IPA.entity_select_widget = function(spec) {
 
     return that;
 };
+
+IPA.entity_link_widget = function(spec) {
+    var that = IPA.widget(spec);
+    var no_link_value = spec.no_link_value || null;
+    var should_link = true;
+    var other_pkey = null;
+    var other_entity = spec.entity;
+
+    that.super_create = that.create;
+    that.create = function(container) {
+        that.super_create(container);
+        that.link =
+        $('<a/>', {
+            href: 'jslink',
+            title: '',
+            html: '',
+            click: function() {
+                if (should_link){
+                     IPA.nav.show_page(other_entity, 'default', other_pkey);
+                }
+                return false;
+            }
+        }).appendTo(container);
+
+        that.label = $('<label/>').
+            appendTo(container);
+    };
+    that.should_link = function(){
+        return (other_pkey !== no_link_value);
+    }
+
+    that.reset = function(record) {
+        other_pkey = null;
+        if (that.values || that.values.length > 0){
+            other_pkey = that.values[0];
+            var should_link =  that.should_link();
+            if (should_link){
+                that.link.html(other_pkey);
+                that.link.css('display','inline');
+                that.label.css('display','none');
+            }else{
+                that.label.html(other_pkey);
+                that.link.css('display','none');
+                that.label.css('display','inline');
+            }
+        }else{
+            should_link = false;
+            that.link.html('');
+            that.label.html('');
+            that.link.css('display','none');
+            that.label.css('display','none');
+        }
+    };
+
+    return that;
+};
\ No newline at end of file
-- 
1.7.5.2

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

Reply via email to