diff options
author | Kevin McCarthy <kmccarth@redhat.com> | 2007-08-30 15:10:48 -0700 |
---|---|---|
committer | Kevin McCarthy <kmccarth@redhat.com> | 2007-08-30 15:10:48 -0700 |
commit | 90a34f386555ca8352e38b6186136a6750517116 (patch) | |
tree | 8630bdfde242b3be1d80355f560643807ab177b0 | |
parent | 59f843517dff81784d81ca54acf5956a136b7d65 (diff) | |
download | freeipa-90a34f386555ca8352e38b6186136a6750517116.tar.gz freeipa-90a34f386555ca8352e38b6186136a6750517116.tar.xz freeipa-90a34f386555ca8352e38b6186136a6750517116.zip |
Add auto-suggest for uid and email fields.
-rw-r--r-- | ipa-server/ipa-gui/ipagui/controllers.py | 76 | ||||
-rw-r--r-- | ipa-server/ipa-gui/ipagui/templates/master.kid | 1 | ||||
-rw-r--r-- | ipa-server/ipa-gui/ipagui/templates/usereditform.kid | 56 | ||||
-rw-r--r-- | ipa-server/ipa-gui/ipagui/templates/usernewform.kid | 89 | ||||
-rw-r--r-- | ipa-server/ipa-gui/ipagui/templates/usershow.kid | 30 |
5 files changed, 181 insertions, 71 deletions
diff --git a/ipa-server/ipa-gui/ipagui/controllers.py b/ipa-server/ipa-gui/ipagui/controllers.py index d767f268..5771ebe3 100644 --- a/ipa-server/ipa-gui/ipagui/controllers.py +++ b/ipa-server/ipa-gui/ipagui/controllers.py @@ -189,6 +189,82 @@ class Root(controllers.RootController): return password + @expose() + def suggest_uid(self, givenname, sn): + if (len(givenname) == 0) or (len(sn) == 0): + return "" + + uid = givenname[0] + sn[:7] + try: + client.get_user_by_uid(uid) + except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND): + return uid + + uid = givenname[:7] + sn[0] + try: + client.get_user_by_uid(uid) + except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND): + return uid + + uid = (givenname + sn)[:8] + try: + client.get_user_by_uid(uid) + except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND): + return uid + + uid = sn[:8] + try: + client.get_user_by_uid(uid) + except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND): + return uid + + suffix = 2 + template = givenname[0] + sn[:7] + while suffix < 20: + uid = template[:8 - len(str(suffix))] + str(suffix) + try: + client.get_user_by_uid(uid) + except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND): + return uid + suffix += 1 + + return "" + + @expose() + def suggest_email(self, givenname, sn): + if (len(givenname) == 0) or (len(sn) == 0): + return "" + + # TODO - get from config + domain = "freeipa.org" + + return "%s.%s@%s" % (givenname, sn, domain) + + + # TODO - mail is currently not indexed nor searchable. + # implement when it's done + # email = givenname + "." + sn + domain + # users = client.find_users(email, ['mail']) + # if len(filter(lambda u: u['mail'] == email, users[1:])) == 0: + # return email + + # email = self.suggest_uid(givenname, sn) + domain + # users = client.find_users(email, ['mail']) + # if len(filter(lambda u: u['mail'] == email, users[1:])) == 0: + # return email + + # suffix = 2 + # template = givenname + "." + sn + # while suffix < 20: + # email = template + str(suffix) + domain + # users = client.find_users(email, ['mail']) + # if len(filter(lambda u: u['mail'] == email, users[1:])) == 0: + # return email + # suffix += 1 + + # return "" + + ######### # Group # diff --git a/ipa-server/ipa-gui/ipagui/templates/master.kid b/ipa-server/ipa-gui/ipagui/templates/master.kid index 8e8d2655..2f39afc4 100644 --- a/ipa-server/ipa-gui/ipagui/templates/master.kid +++ b/ipa-server/ipa-gui/ipagui/templates/master.kid @@ -10,6 +10,7 @@ @import "${tg.url('/static/css/style.css')}"; </style> <script type="text/javascript" charset="utf-8" src="${tg.url('/static/javascript/prototype.js')}"></script> + <script type="text/javascript" charset="utf-8" src="${tg.url('/static/javascript/scriptaculous.js?load=effects')}"></script> </head> <body py:match="item.tag=='{http://www.w3.org/1999/xhtml}body'" py:attrs="item.items()"> diff --git a/ipa-server/ipa-gui/ipagui/templates/usereditform.kid b/ipa-server/ipa-gui/ipagui/templates/usereditform.kid index 771d94d4..cef7f116 100644 --- a/ipa-server/ipa-gui/ipagui/templates/usereditform.kid +++ b/ipa-server/ipa-gui/ipagui/templates/usereditform.kid @@ -7,6 +7,34 @@ py:replace="field.display(value_for(field), **params_for(field))" /> + <div class="formsection">Identity Details</div> + <table class="formtable" cellpadding="2" cellspacing="0" border="0"> + <tr> + <th> + <label class="fieldlabel" for="${user.givenname.field_id}" + py:content="user.givenname.label" />: + </th> + <td> + <span py:replace="user.givenname.display(value_for(user.givenname))" /> + <span py:if="tg.errors.get('givenname')" class="fielderror" + py:content="tg.errors.get('givenname')" /> + + </td> + </tr> + + <tr> + <th> + <label class="fieldlabel" for="${user.sn.field_id}" + py:content="user.sn.label" />: + </th> + <td> + <span py:replace="user.sn.display(value_for(user.sn))" /> + <span py:if="tg.errors.get('sn')" class="fielderror" + py:content="tg.errors.get('sn')" /> + </td> + </tr> + </table> + <div class="formsection">Account Details</div> <table class="formtable" cellpadding="2" cellspacing="0" border="0"> <tr> @@ -85,34 +113,6 @@ </tr> </table> - <div class="formsection">Identity Details</div> - <table class="formtable" cellpadding="2" cellspacing="0" border="0"> - <tr> - <th> - <label class="fieldlabel" for="${user.givenname.field_id}" - py:content="user.givenname.label" />: - </th> - <td> - <span py:replace="user.givenname.display(value_for(user.givenname))" /> - <span py:if="tg.errors.get('givenname')" class="fielderror" - py:content="tg.errors.get('givenname')" /> - - </td> - </tr> - - <tr> - <th> - <label class="fieldlabel" for="${user.sn.field_id}" - py:content="user.sn.label" />: - </th> - <td> - <span py:replace="user.sn.display(value_for(user.sn))" /> - <span py:if="tg.errors.get('sn')" class="fielderror" - py:content="tg.errors.get('sn')" /> - </td> - </tr> - </table> - <div class="formsection">Contact Details</div> <table class="formtable" cellpadding="2" cellspacing="0" border="0"> <tr> diff --git a/ipa-server/ipa-gui/ipagui/templates/usernewform.kid b/ipa-server/ipa-gui/ipagui/templates/usernewform.kid index df5fd55f..c766327f 100644 --- a/ipa-server/ipa-gui/ipagui/templates/usernewform.kid +++ b/ipa-server/ipa-gui/ipagui/templates/usernewform.kid @@ -2,6 +2,67 @@ class="simpleroster"> <form action="${action}" name="${name}" method="${method}" class="tableform"> + <div class="formsection">Identity Details</div> + <table class="formtable" cellpadding="2" cellspacing="0" border="0"> + <tr> + <th> + <label class="fieldlabel" for="${user.givenname.field_id}" + py:content="user.givenname.label" />: + </th> + <td> + <span py:replace="user.givenname.display(value_for(user.givenname))" /> + <span py:if="tg.errors.get('givenname')" class="fielderror" + py:content="tg.errors.get('givenname')" /> + + </td> + </tr> + + <tr> + <th> + <label class="fieldlabel" for="${user.sn.field_id}" + py:content="user.sn.label" />: + </th> + <td> + <span py:replace="user.sn.display(value_for(user.sn))" /> + <span py:if="tg.errors.get('sn')" class="fielderror" + py:content="tg.errors.get('sn')" /> + <script type="text/javascript"> + function autofill(self) { + givenname = document.getElementById('form_givenname'); + sn = document.getElementById('form_sn'); + if ((givenname.value == "") || (sn.value == "")) { + return; + } + uid = document.getElementById('form_uid'); + mail = document.getElementById('form_mail'); + if (uid.value == "") { + new Ajax.Request('${tg.url('/suggest_uid')}', { + method: 'get', + parameters: {'givenname': givenname.value, 'sn': sn.value}, + onSuccess: function(transport) { + uid.value = transport.responseText; + new Effect.Highlight(uid); + } + }); + } + if (mail.value == "") { + new Ajax.Request('${tg.url('/suggest_email')}', { + method: 'get', + parameters: {'givenname': givenname.value, 'sn': sn.value}, + onSuccess: function(transport) { + mail.value = transport.responseText; + new Effect.Highlight(mail); + } + }); + } + } + document.getElementById('form_givenname').onchange = autofill + document.getElementById('form_sn').onchange = autofill + </script> + </td> + </tr> + </table> + <div class="formsection">Account Details</div> <table class="formtable" cellpadding="2" cellspacing="0" border="0"> <tr> @@ -63,34 +124,6 @@ </tr> </table> - <div class="formsection">Identity Details</div> - <table class="formtable" cellpadding="2" cellspacing="0" border="0"> - <tr> - <th> - <label class="fieldlabel" for="${user.givenname.field_id}" - py:content="user.givenname.label" />: - </th> - <td> - <span py:replace="user.givenname.display(value_for(user.givenname))" /> - <span py:if="tg.errors.get('givenname')" class="fielderror" - py:content="tg.errors.get('givenname')" /> - - </td> - </tr> - - <tr> - <th> - <label class="fieldlabel" for="${user.sn.field_id}" - py:content="user.sn.label" />: - </th> - <td> - <span py:replace="user.sn.display(value_for(user.sn))" /> - <span py:if="tg.errors.get('sn')" class="fielderror" - py:content="tg.errors.get('sn')" /> - </td> - </tr> - </table> - <div class="formsection">Contact Details</div> <table class="formtable" cellpadding="2" cellspacing="0" border="0"> <tr> diff --git a/ipa-server/ipa-gui/ipagui/templates/usershow.kid b/ipa-server/ipa-gui/ipagui/templates/usershow.kid index c21ff12b..2ffd1a4e 100644 --- a/ipa-server/ipa-gui/ipagui/templates/usershow.kid +++ b/ipa-server/ipa-gui/ipagui/templates/usershow.kid @@ -8,41 +8,41 @@ <body> <h2>View Person</h2> - <div class="formsection">Account Details</div> + <div class="formsection">Identity Details</div> <table class="formtable" cellpadding="2" cellspacing="0" border="0"> <tr> <th> - <label class="fieldlabel" py:content="fields.uid.label" />: + <label class="fieldlabel" py:content="fields.givenname.label" />: </th> - <td>${user.get("uid")}</td> + <td>${user.get("givenname")}</td> </tr> <tr> <th> - <label class="fieldlabel" py:content="fields.uidnumber.label" />: + <label class="fieldlabel" py:content="fields.sn.label" />: </th> - <td>${user.get("uidnumber")}</td> + <td>${user.get("sn")}</td> </tr> + </table> + + <div class="formsection">Account Details</div> + <table class="formtable" cellpadding="2" cellspacing="0" border="0"> <tr> <th> - <label class="fieldlabel" py:content="fields.gidnumber.label" />: + <label class="fieldlabel" py:content="fields.uid.label" />: </th> - <td>${user.get("gidnumber")}</td> + <td>${user.get("uid")}</td> </tr> - </table> - - <div class="formsection">Identity Details</div> - <table class="formtable" cellpadding="2" cellspacing="0" border="0"> <tr> <th> - <label class="fieldlabel" py:content="fields.givenname.label" />: + <label class="fieldlabel" py:content="fields.uidnumber.label" />: </th> - <td>${user.get("givenname")}</td> + <td>${user.get("uidnumber")}</td> </tr> <tr> <th> - <label class="fieldlabel" py:content="fields.sn.label" />: + <label class="fieldlabel" py:content="fields.gidnumber.label" />: </th> - <td>${user.get("sn")}</td> + <td>${user.get("gidnumber")}</td> </tr> </table> |