@Name en JS

Toutes les astuces sur le langage JavaScript dans Lotus Notes

@Name en JS

Messagepar Michael DELIQUE » 11 Août 2008 à 08:45

[syntax="javascript"]function name(format, username, nbCountry){
if (format === undefined || format === null || format === "") {
return "";
}
if (username === undefined || username === null || username === "") {
return "";
}
if (nbCountry === undefined || nbCountry === null || nbCountry === "" || isNaN(nbCountry) || nbCountry !== true) { /*impossible de déterminé si country est dans le nom sauf en le passant en variable*/
nbCountry = false;
}
var chaineRetour = "";
var array = [];
array = username.split('/');
var i = 0;
var i2 = 0;

if (array.length > 7) {
alert("un nom notes ne peut pas avoir plus de 7 éléments");
return "";
}

switch (format.toUpperCase()) {
case "CN":
case "COMMON":
if (array[0].substring(0, 3).toUpperCase() === "CN=") {
chaineRetour = array[0].substring(3);
}
else {
chaineRetour = array[0];
}
break;
case "ABB":
case "ABBREVIATE":
case "ABBREVIATED":
if (array[0].substring(0, 3).toUpperCase() === "CN=") {
chaineRetour = array[0].substring(3);
}
else {
chaineRetour = array[0];
}
for (i = 1, i2 = array.length; i < i2; i++) {
if (array[i].substring(0, 3).toUpperCase() === "OU=") {
chaineRetour += "/" + array[i].substring(3);
}
else
if (array[i].substring(0, 2).toUpperCase() === "O=") {
chaineRetour += "/" + array[i].substring(2);
}
else {
chaineRetour += "/" + array[i];
}
}
break;

case "CANONICALIZE":
case "CANONICALIZED":
case "CANON":
case "CA":

if (array.length === 1) {
return array[0];
}
if (array[0].substring(0, 3).toUpperCase() === "CN=") {
chaineRetour = array[0];
}
else {
chaineRetour = "CN=" + array[0];
}
var typeO = "";
for (i = 1, i2 = array.length; i < i2; i++) {

if (i === array.length - 1) {
if (i === 7) {
typeO = "C";
}
else {
if (nbCountry === true) {
typeO = "C";
}
else {
typeO = "O";
}
}

}
else
if (i === (array.length - 2)) {
if (array.length === 7) {
typeO = "O";
}
else {
if (nbCountry === true) {
typeO = "O";
}
else {
typeO = "OU";
}
}
}
else {
typeO = "OU";
}

switch (typeO) {
case "OU":
if (array[i].substring(0, 3).toUpperCase() === "OU=") {
chaineRetour += "/" + array[i];
}
else {
chaineRetour += "/OU=" + array[i];
}
break;
case "O":
if (array[i].substring(0, 2).toUpperCase() === "O=") {
chaineRetour += "/" + array[i];
}
else {
chaineRetour += "/O=" + array[i];
}
break;
case "C":
if (array[i].substring(0, 2).toUpperCase() === "C=") {
chaineRetour += "/" + array[i];
}
else {
chaineRetour += "/C=" + array[i];
}
break;
}
typeO = "";
}

break;
case "ADDRESS821":
case "821":
for (i = 1, i2 = array.length; i < i2; i++) {
if (array[i].substring(0, 3).toUpperCase() === "OU=") {
chaineRetour += "/" + array[i].substring(3);
}
else
if (array[i].substring(0, 2).toUpperCase() === "O=") {
chaineRetour += "/" + array[i].substring(2);
}
else {
chaineRetour += "/" + array[i];
}
}
if (chaineRetour.charAt(0) === "/") {
chaineRetour = chaineRetour.substring(1);
}
break;

case "OU2":
chaineRetour = "";
for (i = 1, i2 = array.length; i < i2; i++) {
if (array[i].substring(0, 3).toUpperCase() === "OU=") {
chaineRetour += '\\' + array[i].substring(3);
}
else
if (array[i].substring(0, 2).toUpperCase() === "O=") {
chaineRetour += '\\' + array[i].substring(2);
}
else {
chaineRetour += '\\' + array[i];
}
}
if (chaineRetour.charAt(0) === "\\") {
chaineRetour = chaineRetour.substring(1);
}
break;

default:
chaineRetour = username;
break;
}
return chaineRetour;
}
[/syntax]
Cordialement

Michael (SMS-Phobique)
----------------------------
"La théorie, c'est quand on sait tout et que rien ne fonctionne. La pratique, c'est quand tout fonctionne et que personne ne sait pourquoi."
Albert EINSTEIN
Avatar de l’utilisateur
Michael DELIQUE
Administrateur
Administrateur
 
Message(s) : 12183
Inscrit(e) le : 16 Déc 2004 à 10:36
Localisation : Paris/Cergy

Retour vers JavaScript