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.

822 lines
25 KiB

  1. // ==============================================================
  2. // Microsoft Server Appliance
  3. // Task-level JavaScript functions
  4. //
  5. // Copyright (c) 1999 - 2000 Microsoft Corporation. All rights reserved.
  6. // ==============================================================
  7. <!-- Copyright (c) 1999 - 2000 Microsoft Corporation. All rights reserved-->
  8. //-------------------------------------------------------------------------
  9. //
  10. // Function : Task
  11. //
  12. // Synopsis : Initialize the Task class
  13. //
  14. // Arguments: None
  15. //
  16. // Returns : None
  17. //
  18. //-------------------------------------------------------------------------
  19. function Task() {
  20. // static JScript properties
  21. NavClick = NavClick;
  22. KeyPress = KeyPress;
  23. PageType = PageType;
  24. BackDisabled = BackDisabled;
  25. NextDisabled = NextDisabled;
  26. FinishDisabled = FinishDisabled;
  27. CancelDisabled = CancelDisabled;
  28. CancelDirect = CancelDirect;
  29. FinishDirect = FinishDirect;
  30. }
  31. //-------------------------------------------------------------------------
  32. //
  33. // Function : ExitTask
  34. //
  35. // Synopsis : Sets up return page at the end of task wizard
  36. //
  37. // Arguments: None
  38. //
  39. // Returns : None
  40. //
  41. //-------------------------------------------------------------------------
  42. function ExitTask() {
  43. var strReturnURL;
  44. strReturnURL = document.frmTask.ReturnURL.value;
  45. if (strReturnURL=='')
  46. {
  47. strReturnURL = 'http://' + top.location.hostname + VirtualRoot + 'default.asp';
  48. }
  49. if (strReturnURL.indexOf('?') != -1)
  50. {
  51. strReturnURL += "&";
  52. }
  53. else
  54. {
  55. strReturnURL += "?";
  56. }
  57. strReturnURL += "R=" + Math.random();
  58. top.location=strReturnURL;
  59. }
  60. //-------------------------------------------------------------------------
  61. //
  62. // Function : PageInit
  63. //
  64. // Synopsis : Initialize the Task class
  65. //
  66. // Arguments: None
  67. //
  68. // Returns : None
  69. //
  70. //-------------------------------------------------------------------------
  71. var id = 0
  72. var sid =0
  73. function PageInit()
  74. {
  75. document.onkeypress = HandleKeyPress;
  76. window.clearTimeout();
  77. Task.NavClick = false;
  78. Task.KeyPress = false;
  79. Task.PageType = document.frmTask.PageType.value;
  80. if (document.frmTask.FinishDirect.value == -1)
  81. Task.FinishDirect = true;
  82. else
  83. Task.FinishDirect = false;
  84. if (document.frmTask.CancelDirect.value == -1)
  85. Task.CancelDirect = true;
  86. else
  87. Task.CancelDirect = false;
  88. if (document.frmTask.PageName.value == "TaskExtension")
  89. {
  90. SetupEmbedValues();
  91. }
  92. if (IsIE())
  93. {
  94. if (top.footer.document.frmFooter)
  95. {
  96. top.footer.Init();
  97. }
  98. }
  99. else
  100. {
  101. if (parent.footer.document.layers.length > 0)
  102. {
  103. top.footer.Init();
  104. }
  105. }
  106. Init();
  107. SetTaskButtons();
  108. }
  109. //-------------------------------------------------------------------------
  110. //
  111. // Function : SetTaskButtons
  112. //
  113. // Synopsis : Sets task wizard button state
  114. //
  115. // Arguments: None
  116. //
  117. // Returns : None
  118. //
  119. //-------------------------------------------------------------------------
  120. function SetTaskButtons()
  121. {
  122. if((document.all && top.footer.frmFooter != null)||(document.layers && parent.frames[1].window.document.layers.length == 3))
  123. {
  124. switch (document.frmTask.TaskType.value)
  125. {
  126. case "wizard" :
  127. switch (document.frmTask.PageName.value)
  128. {
  129. case "Intro":
  130. if (!Task.NextDisabled)
  131. {
  132. if(document.layers)
  133. {
  134. parent.frames[1].window.document.layers[0].document.forms[0].elements[1].focus();
  135. }
  136. else
  137. {
  138. parent.footer.frmFooter.butBack.disabled = true;
  139. parent.footer.frmFooter.butNext.focus();
  140. }
  141. }
  142. break;
  143. case "Finish":
  144. if (!Task.FinishDisabled)
  145. {
  146. if(document.layers)
  147. {
  148. parent.frames[1].window.document.layers[1].document.forms[0].elements[1].focus();
  149. }
  150. else
  151. {
  152. parent.footer.frmFooter.butFinish.focus();
  153. }
  154. }
  155. break;
  156. default:
  157. if((document.frmTask.PageName.value).indexOf("Finish") !=-1)
  158. {
  159. if (!Task.FinishDisabled)
  160. {
  161. if(document.layers)
  162. {
  163. parent.frames[1].window.document.layers[1].document.forms[0].elements[1].focus();
  164. }
  165. else
  166. {
  167. parent.footer.frmFooter.butFinish.focus();
  168. }
  169. }
  170. }
  171. else
  172. {
  173. if (!Task.NextDisabled)
  174. {
  175. if(document.layers)
  176. {
  177. parent.frames[1].window.document.layers[0].document.forms[0].elements[1].focus();
  178. }
  179. else
  180. {
  181. parent.footer.frmFooter.butNext.focus();
  182. }
  183. }
  184. }
  185. break;
  186. }
  187. break;
  188. case "prop":
  189. if (!Task.NextDisabled)
  190. {
  191. if(document.layers)
  192. {
  193. parent.frames[1].window.document.layers[2].document.forms[0].elements[0].focus();
  194. }
  195. else
  196. {
  197. parent.footer.frmFooter.butOK.focus();
  198. }
  199. }
  200. break;
  201. default:
  202. break;
  203. }
  204. }
  205. else
  206. {
  207. window.setTimeout("SetTaskButtons()",400);
  208. }
  209. }
  210. //-------------------------------------------------------------------------
  211. //
  212. // Function : SetupEmbedValues
  213. //
  214. // Synopsis : Extracts form values for the current embedded page.
  215. // Uses values to set current form elements,
  216. // e.g., sets a radio button to its state when the page
  217. // was last posted.
  218. //
  219. // Arguments: None
  220. //
  221. // Returns : None
  222. //
  223. //-------------------------------------------------------------------------
  224. function SetupEmbedValues() {
  225. var arrName = new Array;
  226. var arrValue = new Array;
  227. var i;
  228. var intIndex = document.frmTask.EmbedPageIndex.value;
  229. var strInput = document.frmTask.elements['EmbedValues'+intIndex].value;
  230. var strNameD = ";;"; // name delimiter
  231. var strValueD = ";"; // value delimiter
  232. if (strInput != "") {
  233. if (strInput.substring(0, 2) == strNameD)
  234. strInput = strInput.substring(2, strInput.length + 1);
  235. intIndex = 0;
  236. intPos1 = strInput.indexOf(strValueD);
  237. intPos2 = -2;
  238. do {
  239. arrName[intIndex] = Trim(strInput.substring(intPos2+2, intPos1));
  240. intPos2 = strInput.indexOf(strNameD, intPos1);
  241. if (intPos2 == -1)
  242. intPos2 = strInput.length + 1; // assumes no end delimiter
  243. arrValue[intIndex] = Trim(strInput.substring(intPos1+1, intPos2));
  244. if (intPos2+1 < strInput.length)
  245. intPos1 = strInput.indexOf(strValueD, intPos2 + 2);
  246. else
  247. break;
  248. intIndex = intIndex+1;
  249. }
  250. while (intPos1 != 0);
  251. for (i=0;i<arrName.length;i++) {
  252. if (document.frmTask.elements[arrName[i]] != null)
  253. document.frmTask.elements[arrName[i]].value = arrValue[i];
  254. }
  255. }
  256. }
  257. //-------------------------------------------------------------------------
  258. //
  259. // Function : HandleKeyPress
  260. //
  261. // Synopsis : Event handler for key presses
  262. //
  263. // Arguments: evnt(IN) - event describing the key pressed
  264. //
  265. // Returns : None
  266. //
  267. //-------------------------------------------------------------------------
  268. function HandleKeyPress(evnt) {
  269. var intKeyCode;
  270. var Task1 = top.main.Task
  271. if (Task1 == null)
  272. {
  273. return;
  274. }
  275. if (Task1.KeyPress==true || Task1.NavClick==true) {
  276. return;
  277. }
  278. if (IsIE())
  279. intKeyCode = window.event.keyCode;
  280. else
  281. intKeyCode = evnt.which;
  282. if (intKeyCode == 27)
  283. {
  284. Task1.KeyPress = true;
  285. top.main.Cancel();
  286. }
  287. if ( (intKeyCode==98 ||intKeyCode==66) && Task1.PageType == "standard")//key code for "B"
  288. {
  289. Task1.KeyPress = true;
  290. top.main.Back();
  291. }
  292. if ( (intKeyCode==110 ||intKeyCode==78) && (Task1.PageType == "intro" ||Task1.PageType == "standard"))//key code for "N"
  293. {
  294. Task1.KeyPress = true;
  295. top.main.Next();
  296. }
  297. if ((intKeyCode==102 ||intKeyCode==70) && Task1.PageType == "finish")//key code for "F"
  298. {
  299. Task1.KeyPress = true;
  300. top.main.FinishShell();
  301. }
  302. }
  303. //-------------------------------------------------------------------------
  304. //
  305. // Function : DisplayErr
  306. //
  307. // Synopsis : Display error msg
  308. //
  309. // Arguments: ErrMsg(IN) - error msg to display
  310. //
  311. // Returns : None
  312. //
  313. //-------------------------------------------------------------------------
  314. function DisplayErr(ErrMsg) {
  315. var strErrMsg = '<img src="' + VirtualRoot + 'images/critical_g.gif" border=0>&nbsp;&nbsp;' + ErrMsg
  316. if (IsIE()) {
  317. document.all("divErrMsg").innerHTML = strErrMsg;
  318. }
  319. else {
  320. alert(ErrMsg);
  321. }
  322. }
  323. //-------------------------------------------------------------------------
  324. //
  325. // Function : Next
  326. //
  327. // Synopsis : Handle next button being clicked
  328. //
  329. // Arguments: None
  330. //
  331. // Returns : None
  332. //
  333. //-------------------------------------------------------------------------
  334. function Next() {
  335. if (Task.NavClick == false && !Task.NextDisabled) {
  336. if (ValidatePage()) {
  337. DisableNext();
  338. DisableBack();
  339. DisableCancel();
  340. DisableFinish();
  341. DisableOK();
  342. Task.NavClick = true;
  343. SetData();
  344. document.frmTask.Method.value = "NEXT";
  345. document.frmTask.submit();
  346. return true;
  347. }
  348. else {
  349. Task.NavClick = false;
  350. Task.KeyPress = false;
  351. return false;
  352. }
  353. }
  354. else
  355. return false;
  356. }
  357. //-------------------------------------------------------------------------
  358. //
  359. // Function : Back
  360. //
  361. // Synopsis : Handle back button being clicked
  362. //
  363. // Arguments: None
  364. //
  365. // Returns : None
  366. //
  367. //-------------------------------------------------------------------------
  368. function Back() {
  369. if (Task.NavClick == false && Task.PageType != "intro" && !Task.BackDisabled) {
  370. DisableNext();
  371. DisableBack();
  372. DisableCancel();
  373. DisableFinish();
  374. DisableOK();
  375. Task.NavClick = true;
  376. document.frmTask.Method.value = "BACK";
  377. document.frmTask.submit();
  378. }
  379. }
  380. //-------------------------------------------------------------------------
  381. //
  382. // Function : Cancel
  383. //
  384. // Synopsis : Handle cancel button being clicked
  385. //
  386. // Arguments: None
  387. //
  388. // Returns : None
  389. //
  390. //-------------------------------------------------------------------------
  391. function Cancel() {
  392. if (Task.NavClick == false && !Task.CancelDisabled) {
  393. Task.NavClick = true;
  394. DisableCancel();
  395. DisableNext();
  396. DisableBack();
  397. DisableFinish();
  398. DisableOK();
  399. if (Task.CancelDirect)
  400. {
  401. ExitTask();
  402. }
  403. else {
  404. document.frmTask.target= "_top";
  405. document.frmTask.Method.value = "CANCEL";
  406. document.frmTask.submit();
  407. }
  408. }
  409. }
  410. //-------------------------------------------------------------------------
  411. //
  412. // Function : FinishShell
  413. //
  414. // Synopsis : Handle finish button being clicked
  415. //
  416. // Arguments: None
  417. //
  418. // Returns : None
  419. //
  420. //-------------------------------------------------------------------------
  421. function FinishShell() {
  422. if (Task.NavClick == false && !Task.FinishDisabled) {
  423. Task.NavClick = true;
  424. DisableCancel();
  425. DisableNext();
  426. DisableBack();
  427. DisableFinish();
  428. DisableOK();
  429. if (Task.FinishDirect) {
  430. ExitTask();
  431. }
  432. else {
  433. SetData();
  434. document.frmTask.target= "_top";
  435. document.frmTask.Method.value = "FINISH";
  436. document.frmTask.submit();
  437. }
  438. }
  439. }
  440. //-------------------------------------------------------------------------
  441. //
  442. // Function : DisableNext
  443. //
  444. // Synopsis : Disables the next button
  445. //
  446. // Arguments: None
  447. //
  448. // Returns : None
  449. //
  450. //-------------------------------------------------------------------------
  451. function DisableNext() {
  452. if (top.frmTask == null) {
  453. // If footer isn't loaded yet.
  454. window.setTimeout('DisableNext();',50);
  455. return;
  456. }
  457. if (top.frmTask.butNext != null)
  458. top.frmTask.butNext.disabled = true;
  459. Task.NextDisabled = true;
  460. }
  461. //-------------------------------------------------------------------------
  462. //
  463. // Function : EnableNext
  464. //
  465. // Synopsis : Enables the next button
  466. //
  467. // Arguments: None
  468. //
  469. // Returns : None
  470. //
  471. //-------------------------------------------------------------------------
  472. function EnableNext() {
  473. if (top.frmTask == null)
  474. {
  475. // If footer isn't loaded yet.
  476. window.setTimeout('EnableNext();',50);
  477. return;
  478. }
  479. if (top.frmTask.butNext != null)
  480. top.frmTask.butNext.disabled = false;
  481. Task.NextDisabled = false;
  482. }
  483. //-------------------------------------------------------------------------
  484. //
  485. // Function : DisableBack
  486. //
  487. // Synopsis : Disables the back button
  488. //
  489. // Arguments: None
  490. //
  491. // Returns : None
  492. //
  493. //-------------------------------------------------------------------------
  494. function DisableBack() {
  495. if (top.footer.frmFooter == null)
  496. {
  497. // If footer isn't loaded yet.
  498. window.setTimeout('DisableBack();',50);
  499. return;
  500. }
  501. if (top.footer.frmFooter.butBack != null)
  502. top.footer.frmFooter.butBack.disabled = true;
  503. Task.BackDisabled = true;
  504. }
  505. //-------------------------------------------------------------------------
  506. //
  507. // Function : EnableBack
  508. //
  509. // Synopsis : Enables the back button
  510. //
  511. // Arguments: None
  512. //
  513. // Returns : None
  514. //
  515. //-------------------------------------------------------------------------
  516. function EnableBack() {
  517. if (top.footer.frmFooter== null)
  518. {
  519. // If footer isn't loaded yet.
  520. window.setTimeout('EnableBack();',50);
  521. return;
  522. }
  523. if (top.footer.frmFooter.butBack != null)
  524. top.footer.frmFooter.butBack.disabled = false;
  525. Task.BackDisabled = false;
  526. }
  527. //-------------------------------------------------------------------------
  528. //
  529. // Function : DisableFinish
  530. //
  531. // Synopsis : Disables the finish button
  532. //
  533. // Arguments: None
  534. //
  535. // Returns : None
  536. //
  537. //-------------------------------------------------------------------------
  538. function DisableFinish() {
  539. if (top.footer.frmFooter == null)
  540. {
  541. // If footer isn't loaded yet.
  542. window.setTimeout('DisableFinish();',50);
  543. return;
  544. }
  545. if (top.footer.frmFooter.butFinish != null)
  546. top.footer.frmFooter.butFinish.disabled = true;
  547. Task.FinishDisabled = true;
  548. }
  549. //-------------------------------------------------------------------------
  550. //
  551. // Function : EnableFinish
  552. //
  553. // Synopsis : Enables the finish button
  554. //
  555. // Arguments: None
  556. //
  557. // Returns : None
  558. //
  559. //-------------------------------------------------------------------------
  560. function EnableFinish() {
  561. if (top.footer.frmFooter == null)
  562. {
  563. // If footer isn't loaded yet.
  564. window.setTimeout('EnableFinish();',50);
  565. return;
  566. }
  567. if (top.footer.frmFooter.butFinish != null)
  568. top.footer.frmFooter.butFinish.disabled = false;
  569. Task.FinishDisabled = false;
  570. }
  571. //-------------------------------------------------------------------------
  572. //
  573. // Function : DisableCancel
  574. //
  575. // Synopsis : Disables the cancel button
  576. //
  577. // Arguments: None
  578. //
  579. // Returns : None
  580. //
  581. //-------------------------------------------------------------------------
  582. function DisableCancel() {
  583. if (top.footer.frmFooter == null)
  584. {
  585. // If footer isn't loaded yet.
  586. window.setTimeout('DisableCancel();',50);
  587. return;
  588. }
  589. if (top.footer.frmFooter.butCancel != null)
  590. {
  591. top.footer.frmFooter.butCancel.disabled = true;
  592. }
  593. Task.CancelDisabled = true;
  594. }
  595. //-------------------------------------------------------------------------
  596. //
  597. // Function : EnableCancel
  598. //
  599. // Synopsis : Enables the cancel button
  600. //
  601. // Arguments: None
  602. //
  603. // Returns : None
  604. //
  605. //-------------------------------------------------------------------------
  606. function EnableCancel() {
  607. if (top.footer.frmFooter== null)
  608. {
  609. // If footer isn't loaded yet.
  610. window.setTimeout('EnableCancel();',50);
  611. return;
  612. }
  613. if (top.footer.frmFooter.butCancel != null)
  614. {
  615. top.footer.frmFooter.butCancel.disabled = false;
  616. }
  617. Task.CancelDisabled = false;
  618. }
  619. //-------------------------------------------------------------------------
  620. //
  621. // Function : DisableOK
  622. //
  623. // Synopsis : Disables the OK button
  624. //
  625. // Arguments: None
  626. //
  627. // Returns : None
  628. //
  629. //-------------------------------------------------------------------------
  630. function DisableOK() {
  631. if (top.footer.frmFooter == null)
  632. {
  633. // If footer isn't loaded yet.
  634. window.setTimeout('DisableOK();',50);
  635. return;
  636. }
  637. if (top.footer.frmFooter.butOK != null)
  638. top.footer.frmFooter.butOK.disabled = true;
  639. Task.FinishDisabled = true;
  640. }
  641. //-------------------------------------------------------------------------
  642. //
  643. // Function : EnableOK
  644. //
  645. // Synopsis : Enables the OK button
  646. //
  647. // Arguments: None
  648. //
  649. // Returns : None
  650. //
  651. //-------------------------------------------------------------------------
  652. function EnableOK() {
  653. if (top.footer.frmFooter== null)
  654. {
  655. // If footer isn't loaded yet.
  656. window.setTimeout('EnableOK();',50);
  657. return;
  658. }
  659. if (top.footer.frmFooter.butOK != null)
  660. top.footer.frmFooter.butOK.disabled = false;
  661. Task.FinishDisabled = false;
  662. }
  663. //-------------------------------------------------------------------------
  664. //
  665. // Function : isValidFileName
  666. //
  667. // Synopsis : validates that file name has correct syntax
  668. //
  669. // Arguments: filePath(IN) - file name with path to validate
  670. //
  671. // Returns : true/false
  672. //
  673. //-------------------------------------------------------------------------
  674. function isValidFileName(filePath)
  675. {
  676. reInvalid = /[\/\*\?"<>\|]/;
  677. if (reInvalid.test(filePath))
  678. return false;
  679. reColomn2 = /:{2,}/;
  680. reColomn1 = /:{1,}/;
  681. if ( reColomn2.test(filePath) || ( filePath.charAt(1) != ':' && reColomn1.test(filePath) ))
  682. return false;
  683. reEndSlash = /\\ *$/;
  684. if (reEndSlash.test(filePath))
  685. return false;
  686. reEndColomn = /: *$/;
  687. if (reEndColomn.test(filePath))
  688. return false;
  689. reAllSpaces = /[^ ]/;
  690. if (!reAllSpaces.test(filePath))
  691. return false;
  692. return true;
  693. }
  694. //-------------------------------------------------------------------------
  695. //
  696. // Function : HandleKeyPressIFrame
  697. //
  698. // Synopsis : key press event handler for IFRAME
  699. //
  700. // Arguments: evnt(IN) - event describing the key pressed
  701. //
  702. // Returns : None
  703. //
  704. //-------------------------------------------------------------------------
  705. function HandleKeyPressIFrame(evnt) {
  706. var intKeyCode;
  707. var frameMain = window.top.main;
  708. if (Task.KeyPress==true || Task.NavClick==true) {
  709. return;
  710. }
  711. Task.KeyPress = true;
  712. if (IsIE())
  713. intKeyCode = window.event.keyCode;
  714. else
  715. intKeyCode = evnt.which;
  716. if (intKeyCode == 13)
  717. {
  718. frameMain.Next();
  719. }
  720. if (intKeyCode == 27) {
  721. frameMain.Cancel();
  722. }
  723. }