Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

258 lines
6.5 KiB

  1. using System;
  2. using System.Collections;
  3. using System.Web.UI;
  4. using UDDI;
  5. namespace UDDI.Web
  6. {
  7. public class ContextMenu : Control
  8. {
  9. protected ArrayList menuItems = new ArrayList();
  10. protected static string popupScript = @"
  11. <script language='javascript'>
  12. var popup = null;
  13. var popupArgs = null;
  14. var popupNode = null;
  15. function HideAnyPopups()
  16. {
  17. if( null != popup )
  18. HidePopup( popup );
  19. popup = null;
  20. }
  21. function HidePopup( popup )
  22. {
  23. var ctrl = document.getElementById( popup );
  24. ctrl.style.display = ""none"";
  25. }
  26. </script>";
  27. protected static string contextMenuScript = @"
  28. <script language='javascript'>
  29. function ShowContextMenu( node, menu, args )
  30. {
  31. HideAnyPopups();
  32. var e = window.event;
  33. var cm = document.getElementById( menu );
  34. popupNode = node;
  35. popupArgs = args;
  36. cm.style.display = """";
  37. if( cm.clientWidth > document.body.clientWidth )
  38. cm.style.pixelLeft = 0;
  39. else if( e.clientX + cm.clientWidth > document.body.clientWidth )
  40. cm.style.pixelLeft = document.body.clientWidth - cm.clientWidth - 5;
  41. else
  42. cm.style.pixelLeft = e.clientX;
  43. cm.style.pixelLeft += document.body.scrollLeft;
  44. if( cm.clientHeight > document.body.clientHeight )
  45. cm.style.pixelTop = 0;
  46. else if( e.clientY + cm.clientHeight > document.body.clientHeight )
  47. cm.style.pixelTop = document.body.clientHeight - cm.clientHeight - 5;
  48. else
  49. cm.style.pixelTop = e.clientY;
  50. cm.style.pixelTop += document.body.scrollTop;
  51. popup = menu;
  52. e.cancelBubble = true;
  53. e.returnValue = false;
  54. }
  55. function ContextMenu_OnClick( url, target )
  56. {
  57. HideAnyPopups();
  58. if( null != popupArgs )
  59. {
  60. if( url.indexOf( '?' ) >= 0 )
  61. url += ""&"" + popupArg;
  62. else
  63. url += ""?"" + popupArgs;
  64. }
  65. document.body.style.cursor = 'wait';
  66. if( null == target || ""_self"" == target )
  67. window.location = url;
  68. else
  69. window.parent.frames[ target ].location = url;
  70. }
  71. function ContextMenu_OnSeparatorClick()
  72. {
  73. var e = window.event;
  74. e.cancelBubble = true;
  75. e.returnValue = false;
  76. }
  77. </script>";
  78. public ContextMenu()
  79. {
  80. }
  81. protected override void OnInit( EventArgs e )
  82. {
  83. if( !Page.IsClientScriptBlockRegistered( "UDDI.Web.Popup" ) )
  84. Page.RegisterClientScriptBlock( "UDDI.Web.Popup", popupScript );
  85. if( !Page.IsClientScriptBlockRegistered( "UDDI.Web.ContextMenu" ) )
  86. Page.RegisterClientScriptBlock( "UDDI.Web.ContextMenu", contextMenuScript );
  87. }
  88. protected override void AddParsedSubObject( object obj )
  89. {
  90. if( obj is MenuItem || obj is MenuSeparator )
  91. menuItems.Add( obj );
  92. }
  93. protected override void Render( HtmlTextWriter output )
  94. {
  95. output.Write( "<div id='" + this.ID + "' class='contextMenu' style='display: none'>" );
  96. output.Write( "<table cellpadding='0' cellspacing='0' border='0'>" );
  97. foreach( object item in menuItems )
  98. {
  99. if( item is MenuItem )
  100. {
  101. MenuItem menuItem = (MenuItem)item;
  102. if( menuItem.Visible && menuItem.AccessAllowed )
  103. {
  104. output.Write( "<tr><td class='menuItem' valign='top' onclick='" + menuItem.OnClick +
  105. "' oncontextmenu='" + menuItem.OnClick + "' onmouseover='this.className=\"menuItemHover\";" );
  106. if( !Utility.StringEmpty( menuItem.StatusText ) )
  107. output.Write( " window.status=\"" + Localization.GetString( menuItem.StatusText ) + "\"" );
  108. output.Write( "' onmouseout='this.className=\"menuItem\"; window.status=\"\"'><img src='" +
  109. menuItem.ImageUrl + "' border='0' align='absmiddle' class='menuImage'>&nbsp;&nbsp;" );
  110. if( menuItem.Bold )
  111. output.Write( "<b>" );
  112. output.Write( "<nobr>" + Localization.GetString( menuItem.Text ) + "</nobr>" );
  113. if( menuItem.Bold )
  114. output.Write( "</b>" );
  115. output.Write( "</td></tr>" );
  116. }
  117. }
  118. else if( item is MenuSeparator )
  119. {
  120. MenuSeparator separator = (MenuSeparator)item;
  121. if( separator.Visible && separator.AccessAllowed )
  122. output.Write( "<tr><td class='menuSeparator' onclick='ContextMenu_OnSeparatorClick()' oncontextmenu='ContextMenu_OnSeparatorClick()'><hr></td></tr>" );
  123. }
  124. }
  125. output.Write( "</table>" );
  126. output.Write( "</div>" );
  127. }
  128. }
  129. public class MenuItem : Control
  130. {
  131. protected bool bold = false;
  132. protected string imageUrl = null;
  133. protected string onClick = null;
  134. protected string statusText = null;
  135. protected string text = null;
  136. protected RoleType requiredRole = RoleType.Anonymous;
  137. public bool Bold
  138. {
  139. get { return bold; }
  140. set { bold = value; }
  141. }
  142. public string ImageUrl
  143. {
  144. get { return imageUrl; }
  145. set { imageUrl = value; }
  146. }
  147. public string OnClick
  148. {
  149. get { return onClick; }
  150. set { onClick = value; }
  151. }
  152. public string StatusText
  153. {
  154. get { return statusText; }
  155. set { statusText = value; }
  156. }
  157. public string Text
  158. {
  159. get { return text; }
  160. set { text = value; }
  161. }
  162. public RoleType RequiredRole
  163. {
  164. get { return requiredRole; }
  165. set { requiredRole = value; }
  166. }
  167. public bool AccessAllowed
  168. {
  169. get
  170. {
  171. return
  172. ( RoleType.Anonymous == requiredRole ) ||
  173. ( RoleType.User == requiredRole && UDDI.Context.User.IsUser ) ||
  174. ( RoleType.Publisher == requiredRole && UDDI.Context.User.IsPublisher ) ||
  175. ( RoleType.Coordinator == requiredRole && UDDI.Context.User.IsCoordinator ) ||
  176. ( RoleType.Administrator == requiredRole && UDDI.Context.User.IsAdministrator );
  177. }
  178. }
  179. public MenuItem()
  180. {
  181. }
  182. }
  183. public class MenuSeparator : Control
  184. {
  185. protected RoleType requiredRole = RoleType.Anonymous;
  186. public MenuSeparator()
  187. {
  188. }
  189. public RoleType RequiredRole
  190. {
  191. get { return requiredRole; }
  192. set { requiredRole = value; }
  193. }
  194. public bool AccessAllowed
  195. {
  196. get
  197. {
  198. return
  199. ( RoleType.Anonymous == requiredRole ) ||
  200. ( RoleType.User == requiredRole && UDDI.Context.User.IsUser ) ||
  201. ( RoleType.Publisher == requiredRole && UDDI.Context.User.IsPublisher ) ||
  202. ( RoleType.Coordinator == requiredRole && UDDI.Context.User.IsCoordinator ) ||
  203. ( RoleType.Administrator == requiredRole && UDDI.Context.User.IsAdministrator );
  204. }
  205. }
  206. }
  207. }