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.

427 lines
13 KiB

  1. using System;
  2. namespace UDDI.Web
  3. {
  4. public class ClientScripts
  5. {
  6. /// ****************************************************************
  7. /// public ShowHelp [static]
  8. /// ----------------------------------------------------------------
  9. /// <summary>
  10. /// Shows the given help url.
  11. /// </summary>
  12. /// ----------------------------------------------------------------
  13. /// <param name="url">
  14. /// The URL to load.
  15. /// </param>
  16. /// ----------------------------------------------------------------
  17. /// <returns>
  18. /// The client script to show the help.
  19. /// </returns>
  20. /// ****************************************************************
  21. ///
  22. public static string ShowHelp( string url )
  23. {
  24. string script = @"
  25. <script language=""javascript"">
  26. <!--
  27. ShowHelp( ""{url}"" );
  28. //-->
  29. </script>";
  30. script = script.Replace( "{url}", url.Replace( "\"", "\\\"" ) );
  31. return script;
  32. }
  33. /// ****************************************************************
  34. /// public ReloadTop [static]
  35. /// ----------------------------------------------------------------
  36. /// <summary>
  37. /// Reloads the top window with the given url.
  38. /// </summary>
  39. /// ----------------------------------------------------------------
  40. /// <param name="url">
  41. /// The URL to load in the top window.
  42. /// </param>
  43. /// ----------------------------------------------------------------
  44. /// <returns>
  45. /// The client script to reload the top window.
  46. /// </returns>
  47. /// ****************************************************************
  48. ///
  49. public static string ReloadTop( string url )
  50. {
  51. string script = @"
  52. <script language=""javascript"">
  53. <!--
  54. window.top.location = ""{url}"";
  55. //-->
  56. </script>";
  57. script = script.Replace( "{url}", url.Replace( "\"", "\\\"" ) );
  58. return script;
  59. }
  60. /// ****************************************************************
  61. /// public ReloadViewPane [static]
  62. /// ----------------------------------------------------------------
  63. /// <summary>
  64. /// Reloads the view pane with the given url.
  65. /// </summary>
  66. /// ----------------------------------------------------------------
  67. /// <param name="url">
  68. /// The URL to load in the view pane.
  69. /// </param>
  70. /// ----------------------------------------------------------------
  71. /// <returns>
  72. /// The client script to reload the view pane.
  73. /// </returns>
  74. /// ****************************************************************
  75. ///
  76. public static string ReloadViewPane( string url )
  77. {
  78. string script = @"
  79. <script language=""javascript"">
  80. <!--
  81. var view = window.parent.frames[ ""view"" ];
  82. view.location = ""{url}"";
  83. //-->
  84. </script>";
  85. script = script.Replace( "{url}", url.Replace( "\"", "\\\"" ) );
  86. return script;
  87. }
  88. /// ****************************************************************
  89. /// public ReloadExplorerPane [static]
  90. /// ----------------------------------------------------------------
  91. /// <summary>
  92. /// Reloads the explorer pane.
  93. /// </summary>
  94. /// ----------------------------------------------------------------
  95. /// <returns>
  96. /// The client script to reload the explorer pane.
  97. /// </returns>
  98. /// ****************************************************************
  99. ///
  100. public static string ReloadExplorerPane()
  101. {
  102. string script = @"
  103. <script language=""javascript"">
  104. <!--
  105. var explorer = window.parent.frames[ ""explorer"" ];
  106. var form = explorer.document.forms[ 0 ];
  107. form.submit();
  108. //-->
  109. </script>";
  110. return script;
  111. }
  112. /// ****************************************************************
  113. /// public ReloadExplorerPane [static]
  114. /// ----------------------------------------------------------------
  115. /// <summary>
  116. /// Reloads the explorer pane.
  117. /// </summary>
  118. /// ----------------------------------------------------------------
  119. /// <param name="key">
  120. /// The node key to select.
  121. /// </param>
  122. /// ----------------------------------------------------------------
  123. /// <returns>
  124. /// The client script to reload the explorer pane.
  125. /// </returns>
  126. /// ****************************************************************
  127. ///
  128. public static string ReloadExplorerPane( string key )
  129. {
  130. string script = @"
  131. <script language=""javascript"">
  132. <!--
  133. var explorer = window.parent.frames[ ""explorer"" ];
  134. var keyField = explorer.document.getElementById( ""key"" );
  135. keyField.value = ""{key}"";
  136. var form = explorer.document.forms[ 0 ];
  137. form.submit();
  138. //-->
  139. </script>";
  140. script = script.Replace( "{key}", key.Replace( "\"", "\\\"" ) );
  141. return script;
  142. }
  143. /// ****************************************************************
  144. /// public ReloadExplorerAndViewPanes [static]
  145. /// ----------------------------------------------------------------
  146. /// <summary>
  147. /// Reloads the explorer and view panes.
  148. /// </summary>
  149. /// ----------------------------------------------------------------
  150. /// <param name="url">
  151. /// The URL to load in the view pane.
  152. /// </param>
  153. ///
  154. /// <param name="key">
  155. /// The node key to select in the explorer pane.
  156. /// </param>
  157. /// ----------------------------------------------------------------
  158. /// <returns>
  159. /// The client script to reload the explorer and view panes.
  160. /// </returns>
  161. /// ****************************************************************
  162. ///
  163. public static string ReloadExplorerAndViewPanes( string url, string key )
  164. {
  165. string script = @"
  166. <script language=""javascript"">
  167. <!--
  168. var explorer = window.parent.frames[ ""explorer"" ];
  169. var view = window.parent.frames[ ""view"" ];
  170. var keyField = explorer.document.getElementById( ""key"" );
  171. keyField.value = ""{key}"";
  172. var form = explorer.document.forms[ 0 ];
  173. form.submit();
  174. view.location = ""{url}"";
  175. //-->
  176. </script>";
  177. script = script.Replace( "{url}", url.Replace( "\"", "\\\"" ) );
  178. script = script.Replace( "{key}", key.Replace( "\"", "\\\"" ) );
  179. return script;
  180. }
  181. /// ****************************************************************
  182. /// public Confirm [static]
  183. /// ----------------------------------------------------------------
  184. /// <summary>
  185. /// Displays a confirmation dialog and then proceeds to one
  186. /// of two URL's depending on the user's choice.
  187. /// </summary>
  188. /// ----------------------------------------------------------------
  189. /// <param name="message">
  190. /// The message to display.
  191. /// </param>
  192. ///
  193. /// <param name="urlOk">
  194. /// The URL to go to if the user selects OK.
  195. /// </param>
  196. /// ----------------------------------------------------------------
  197. /// <returns>
  198. /// The client script to display the confirm dialog.
  199. /// </returns>
  200. /// ****************************************************************
  201. ///
  202. public static string Confirm( string message, string urlOk )
  203. {
  204. string script = @"
  205. <script language=""javascript"">
  206. <!--
  207. var result = confirm( ""{message}"" );
  208. if( result )
  209. window.location = ""{urlOk}"";
  210. //-->
  211. </script>";
  212. script = script.Replace( "{message}", message.Replace( "\"", "\\\"" ).Replace( "\n", " " ) );
  213. script = script.Replace( "{urlOk}", urlOk.Replace( "\"", "\\\"" ) );
  214. return script;
  215. }
  216. /// ****************************************************************
  217. /// public Confirm [static]
  218. /// ----------------------------------------------------------------
  219. /// <summary>
  220. /// Displays a confirmation dialog and then proceeds to one
  221. /// of two URL's depending on the user's choice.
  222. /// </summary>
  223. /// ----------------------------------------------------------------
  224. /// <param name="message">
  225. /// The message to display.
  226. /// </param>
  227. ///
  228. /// <param name="urlOk">
  229. /// The URL to go to if the user selects OK.
  230. /// </param>
  231. ///
  232. /// <param name="urlCancel">
  233. /// The URL to go to if the user selects Cancel.
  234. /// </param>
  235. /// ----------------------------------------------------------------
  236. /// <returns>
  237. /// The client script to display the confirm dialog.
  238. /// </returns>
  239. /// ****************************************************************
  240. ///
  241. public static string Confirm( string message, string urlOk, string urlCancel )
  242. {
  243. string script = @"
  244. <script language=""javascript"">
  245. <!--
  246. var result = confirm( ""{message}"" );
  247. if( result )
  248. window.location = ""{urlOk}"";
  249. else
  250. window.location = ""{urlCancel}"";
  251. //-->
  252. </script>";
  253. script = script.Replace( "{message}", message.Replace( "\"", "\\\"" ).Replace( "\n", " " ) );
  254. script = script.Replace( "{urlOk}", urlOk.Replace( "\"", "\\\"" ) );
  255. script = script.Replace( "{urlCancel}", urlCancel.Replace( "\"", "\\\"" ) );
  256. return script;
  257. }
  258. /// ****************************************************************
  259. /// public ShowModalDialog [static]
  260. /// ----------------------------------------------------------------
  261. /// <summary>
  262. /// Displays a modal dialog.
  263. /// </summary>
  264. /// ----------------------------------------------------------------
  265. /// <param name="url">
  266. /// The URL of the dialog to display.
  267. /// </param>
  268. ///
  269. /// <param name="width">
  270. /// The width of the dialog.
  271. /// </param>
  272. ///
  273. /// <param name="height">
  274. /// The height of the dialog.
  275. /// </param>
  276. /// ----------------------------------------------------------------
  277. /// <returns>
  278. /// The client script to display the dialog.
  279. /// </returns>
  280. /// ****************************************************************
  281. ///
  282. public static string ShowModalDialog( string url, string width, string height, bool resizable, bool scrollbars, bool status )
  283. {
  284. string script = @"
  285. <script language=""javascript"">
  286. <!--
  287. window.open( ""{url}"", ""dialog"", ""directories=no, location=no, menubar=no, toolbar=no, width={width}, height={height}, resizable={resizable}, scrollbars={scrollbars}, status={status}"", true );
  288. //-->
  289. </script>";
  290. script = script.Replace( "{url}", url.Replace( "\"", "\\\"" ) );
  291. script = script.Replace( "{width}", width );
  292. script = script.Replace( "{height}", height );
  293. script = script.Replace( "{resizable}", resizable ? "yes" : "no" );
  294. script = script.Replace( "{scrollbars}", scrollbars ? "yes" : "no" );
  295. script = script.Replace( "{status}", status ? "yes" : "no" );
  296. return script;
  297. }
  298. /// ****************************************************************
  299. /// public CloseWindow [static]
  300. /// ----------------------------------------------------------------
  301. /// <summary>
  302. /// Closes the window.
  303. /// </summary>
  304. /// ----------------------------------------------------------------
  305. /// <returns>
  306. /// The client script to close the window.
  307. /// </returns>
  308. /// ****************************************************************
  309. ///
  310. public static string CloseWindow()
  311. {
  312. string script = @"
  313. <script language=""javascript"">
  314. <!--
  315. window.close();
  316. //-->
  317. </script>";
  318. return script;
  319. }
  320. }
  321. public class ClientScriptRegisterCollection : System.Collections.CollectionBase
  322. {
  323. public ClientScriptRegister this[ int index ]
  324. {
  325. get{ return (ClientScriptRegister)this.List[ index ] ; }
  326. set{ this.List[ index ]=value; }
  327. }
  328. public int Add( ClientScriptRegister script )
  329. {
  330. return this.List.Add( script );
  331. }
  332. public void Remove( ClientScriptRegister script )
  333. {
  334. this.List.Remove( script );
  335. }
  336. public void Remove( int index )
  337. {
  338. this.List.RemoveAt( index );
  339. }
  340. }
  341. public class ClientScriptRegister : System.Web.UI.WebControls.PlaceHolder
  342. {
  343. private string source;
  344. public string Source
  345. {
  346. get{ return source; }
  347. set{ source=value; }
  348. }
  349. private string language;
  350. public string Language
  351. {
  352. get{ return language; }
  353. set{ language=value; }
  354. }
  355. protected override void Render( System.Web.UI.HtmlTextWriter output )
  356. {
  357. //if source is provided, then render a link
  358. if( null!=source )
  359. {
  360. output.Write(
  361. "<script " + ((null==Language)?"": "language='"+Language+"' " )+ " src='"+ Source +"'></script>"
  362. );
  363. }
  364. else//else render the control
  365. {
  366. //render script tag
  367. if( null!=Language )
  368. output.AddAttribute( "language", Language );
  369. output.RenderBeginTag( System.Web.UI.HtmlTextWriterTag.Script );
  370. base.Render( output );
  371. //close script tag
  372. output.RenderEndTag();
  373. }
  374. }
  375. }
  376. }