1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| /// <summary>
/// On dessine le menu à partir d'un menu déjà fourni
/// </summary>
/// <param name="menuHTML"></param>
public void drawMenu(String menuHTML)
{
Literal1.Text = String.Format("<div id='divMenuCtrl'><table >{0}</table ></div>", menuHTML);
selectNode();
}
/// <summary>
/// On dessine le menu en fonctions des droits que l'on lui donne
/// </summary>
public void drawMenu(Object usr)
{
string menuHTML = String.Empty;
int countRoot = 0;
int countChild1 = 0;
int countChild2 = 0;
foreach (SiteMapNode node in SiteMap.RootNode.ChildNodes)
{
if (checkRole(node, usr))
{
menuHTML += drawRootMenu(node.Title, countRoot);
if (node.HasChildNodes)
{
menuHTML += String.Format("<tr id='mnu{0}' runat='server'><td><ul>", countRoot);
}
foreach (SiteMapNode node1 in node.ChildNodes)
{
if (checkRole(node1, usr))
{
if (node1.Description != "invisible")
menuHTML += drawChildMenu(node1.Title, countRoot, countChild1, null, node1.Url,
node1.HasChildNodes);
if (node1.HasChildNodes)
{
menuHTML += "<ul>";
}
foreach (SiteMapNode node2 in node1.ChildNodes)
{
if (node2.Description != "invisible")
menuHTML += drawChildMenu(node2.Title, countRoot, countChild1, countChild2,
node2.Url, node2.HasChildNodes);
countChild2++;
}
if (node1.HasChildNodes)
{
menuHTML += "</ul>";
}
}
countChild1++;
}
if (node.HasChildNodes)
{
menuHTML += "</ul></td></tr>";
}
}
countRoot++;
}
menuHTML+=String.Format(
"<tr class='inter'><td></td></tr><tr id='rootMnu{0}' runat='server' class='rootMenuOff'><td > <a href='{2}'>{1}</a> </td> </tr>",
9999, "LogOut", ResolveUrl("~/Common/LogOut.aspx"));
Literal1.Text = String.Format("<div id='divMenuCtrl'><table >{0}</table ></div>", menuHTML);
selectNode();
}
/// <summary>
/// Dessine un noeud enfant
/// </summary>
/// <param name="Label">Texte affiché par le menu</param>
/// <param name="rootId">Id de la catégorie</param>
/// <param name="id">Id du menu</param>
/// <param name="id2">Id du menu de second niveau</param>
/// <param name="url">Lien du menu</param>
/// <param name="childs">Définie si des enfants existent</param>
/// <returns></returns>
private static string drawChildMenu(string Label, int rootId, int id, int? id2, string url, bool childs)
{
if (childs)
return
String.Format(
"<li><a id='li{1}_{2}' onClick='javascript:toggle({1},{2}{4})' href='{3}'>{0}</a></li>", Label,
rootId, id, (String.IsNullOrEmpty(url)) ? "#" : url, (id2 == null) ? "" : "," + id2);
return String.Format("<li><a id='li{1}_{2}{4}' href='{3}'>{0}</a></li>", Label, rootId, id, url,
(id2 == null) ? "" : "_" + id2);
}
/// <summary>
/// dessine le tableau du menu root
/// </summary>
/// <param name="Label">Texte affiché par la catégorie</param>
/// <param name="id">Id de la categorie</param>
/// <returns></returns>
private static string drawRootMenu(string Label, int id)
{
return
String.Format(
"<tr class='inter'><td></td></tr><tr id='rootMnu{0}' runat='server' class='rootMenuOff'><td > <a href='javascript:toggle({0});'>{1}</a> </td> </tr>",
id, Label);
} |
Partager