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.

818 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. window.setTimeout("SetTaskButtons()",400);
  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. }
  206. //-------------------------------------------------------------------------
  207. //
  208. // Function : SetupEmbedValues
  209. //
  210. // Synopsis : Extracts form values for the current embedded page.
  211. // Uses values to set current form elements,
  212. // e.g., sets a radio button to its state when the page
  213. // was last posted.
  214. //
  215. // Arguments: None
  216. //
  217. // Returns : None
  218. //
  219. //-------------------------------------------------------------------------
  220. function SetupEmbedValues() {
  221. var arrName = new Array;
  222. var arrValue = new Array;
  223. var i;
  224. var intIndex = document.frmTask.EmbedPageIndex.value;
  225. var strInput = document.frmTask.elements['EmbedValues'+intIndex].value;
  226. var strNameD = ";;"; // name delimiter
  227. var strValueD = ";"; // value delimiter
  228. if (strInput != "") {
  229. if (strInput.substring(0, 2) == strNameD)
  230. strInput = strInput.substring(2, strInput.length + 1);
  231. intIndex = 0;
  232. intPos1 = strInput.indexOf(strValueD);
  233. intPos2 = -2;
  234. do {
  235. arrName[intIndex] = Trim(strInput.substring(intPos2+2, intPos1));
  236. intPos2 = strInput.indexOf(strNameD, intPos1);
  237. if (intPos2 == -1)
  238. intPos2 = strInput.length + 1; // assumes no end delimiter
  239. arrValue[intIndex] = Trim(strInput.substring(intPos1+1, intPos2));
  240. if (intPos2+1 < strInput.length)
  241. intPos1 = strInput.indexOf(strValueD, intPos2 + 2);
  242. else
  243. break;
  244. intIndex = intIndex+1;
  245. }
  246. while (intPos1 != 0);
  247. for (i=0;i<arrName.length;i++) {
  248. if (document.frmTask.elements[arrName[i]] != null)
  249. document.frmTask.elements[arrName[i]].value = arrValue[i];
  250. }
  251. }
  252. }
  253. //-------------------------------------------------------------------------
  254. //
  255. // Function : HandleKeyPress
  256. //
  257. // Synopsis : Event handler for key presses
  258. //
  259. // Arguments: evnt(IN) - event describing the key pressed
  260. //
  261. // Returns : None
  262. //
  263. //-------------------------------------------------------------------------
  264. function HandleKeyPress(evnt) {
  265. var intKeyCode;
  266. var Task1 = top.main.Task
  267. if (Task1 == null)
  268. {
  269. return;
  270. }
  271. if (Task1.KeyPress==true || Task1.NavClick==true) {
  272. return;
  273. }
  274. if (IsIE())
  275. intKeyCode = window.event.keyCode;
  276. else
  277. intKeyCode = evnt.which;
  278. if (intKeyCode == 27)
  279. {
  280. Task1.KeyPress = true;
  281. top.main.Cancel();
  282. }
  283. if ( (intKeyCode==98 ||intKeyCode==66) && Task1.PageType == "standard")//key code for "B"
  284. {
  285. Task1.KeyPress = true;
  286. top.main.Back();
  287. }
  288. if ( (intKeyCode==110 ||intKeyCode==78) && (Task1.PageType == "intro" ||Task1.PageType == "standard"))//key code for "N"
  289. {
  290. Task1.KeyPress = true;
  291. top.main.Next();
  292. }
  293. if ((intKeyCode==102 ||intKeyCode==70) && Task1.PageType == "finish")//key code for "F"
  294. {
  295. Task1.KeyPress = true;
  296. top.main.FinishShell();
  297. }
  298. }
  299. //-------------------------------------------------------------------------
  300. //
  301. // Function : DisplayErr
  302. //
  303. // Synopsis : Display error msg
  304. //
  305. // Arguments: ErrMsg(IN) - error msg to display
  306. //
  307. // Returns : None
  308. //
  309. //-------------------------------------------------------------------------
  310. function DisplayErr(ErrMsg) {
  311. var strErrMsg = '<img src="' + VirtualRoot + 'images/critical_g.gif" border=0>&nbsp;&nbsp;' + ErrMsg
  312. if (IsIE()) {
  313. document.all("divErrMsg").innerHTML = strErrMsg;
  314. }
  315. else {
  316. alert(ErrMsg);
  317. }
  318. }
  319. //-------------------------------------------------------------------------
  320. //
  321. // Function : Next
  322. //
  323. // Synopsis : Handle next button being clicked
  324. //
  325. // Arguments: None
  326. //
  327. // Returns : None
  328. //
  329. //-------------------------------------------------------------------------
  330. function Next() {
  331. if (Task.NavClick == false && !Task.NextDisabled) {
  332. if (ValidatePage()) {
  333. DisableNext();
  334. DisableBack();
  335. DisableCancel();
  336. DisableFinish();
  337. DisableOK();
  338. Task.NavClick = true;
  339. SetData();
  340. document.frmTask.Method.value = "NEXT";
  341. document.frmTask.submit();
  342. return true;
  343. }
  344. else {
  345. Task.NavClick = false;
  346. Task.KeyPress = false;
  347. return false;
  348. }
  349. }
  350. else
  351. return false;
  352. }
  353. //-------------------------------------------------------------------------
  354. //
  355. // Function : Back
  356. //
  357. // Synopsis : Handle back button being clicked
  358. //
  359. // Arguments: None
  360. //
  361. // Returns : None
  362. //
  363. //-------------------------------------------------------------------------
  364. function Back() {
  365. if (Task.NavClick == false && Task.PageType != "intro" && !Task.BackDisabled) {
  366. DisableNext();
  367. DisableBack();
  368. DisableCancel();
  369. DisableFinish();
  370. DisableOK();
  371. Task.NavClick = true;
  372. document.frmTask.Method.value = "BACK";
  373. document.frmTask.submit();
  374. }
  375. }
  376. //-------------------------------------------------------------------------
  377. //
  378. // Function : Cancel
  379. //
  380. // Synopsis : Handle cancel button being clicked
  381. //
  382. // Arguments: None
  383. //
  384. // Returns : None
  385. //
  386. //-------------------------------------------------------------------------
  387. function Cancel() {
  388. if (Task.NavClick == false && !Task.CancelDisabled) {
  389. Task.NavClick = true;
  390. DisableCancel();
  391. DisableNext();
  392. DisableBack();
  393. DisableFinish();
  394. DisableOK();
  395. if (Task.CancelDirect)
  396. {
  397. ExitTask();
  398. }
  399. else {
  400. document.frmTask.target= "_top";
  401. document.frmTask.Method.value = "CANCEL";
  402. document.frmTask.submit();
  403. }
  404. }
  405. }
  406. //-------------------------------------------------------------------------
  407. //
  408. // Function : FinishShell
  409. //
  410. // Synopsis : Handle finish button being clicked
  411. //
  412. // Arguments: None
  413. //
  414. // Returns : None
  415. //
  416. //-------------------------------------------------------------------------
  417. function FinishShell() {
  418. if (Task.NavClick == false && !Task.FinishDisabled) {
  419. Task.NavClick = true;
  420. DisableCancel();
  421. DisableNext();
  422. DisableBack();
  423. DisableFinish();
  424. DisableOK();
  425. if (Task.FinishDirect) {
  426. ExitTask();
  427. }
  428. else {
  429. SetData();
  430. document.frmTask.target= "_top";
  431. document.frmTask.Method.value = "FINISH";
  432. document.frmTask.submit();
  433. }
  434. }
  435. }
  436. //-------------------------------------------------------------------------
  437. //
  438. // Function : DisableNext
  439. //
  440. // Synopsis : Disables the next button
  441. //
  442. // Arguments: None
  443. //
  444. // Returns : None
  445. //
  446. //-------------------------------------------------------------------------
  447. function DisableNext() {
  448. if (top.frmTask == null) {
  449. // If footer isn't loaded yet.
  450. window.setTimeout('DisableNext();',50);
  451. return;
  452. }
  453. if (top.frmTask.butNext != null)
  454. top.frmTask.butNext.disabled = true;
  455. Task.NextDisabled = true;
  456. }
  457. //-------------------------------------------------------------------------
  458. //
  459. // Function : EnableNext
  460. //
  461. // Synopsis : Enables the next button
  462. //
  463. // Arguments: None
  464. //
  465. // Returns : None
  466. //
  467. //-------------------------------------------------------------------------
  468. function EnableNext() {
  469. if (top.frmTask == null)
  470. {
  471. // If footer isn't loaded yet.
  472. window.setTimeout('EnableNext();',50);
  473. return;
  474. }
  475. if (top.frmTask.butNext != null)
  476. top.frmTask.butNext.disabled = false;
  477. Task.NextDisabled = false;
  478. }
  479. //-------------------------------------------------------------------------
  480. //
  481. // Function : DisableBack
  482. //
  483. // Synopsis : Disables the back button
  484. //
  485. // Arguments: None
  486. //
  487. // Returns : None
  488. //
  489. //-------------------------------------------------------------------------
  490. function DisableBack() {
  491. if (top.footer.frmFooter == null)
  492. {
  493. // If footer isn't loaded yet.
  494. window.setTimeout('DisableBack();',50);
  495. return;
  496. }
  497. if (top.footer.frmFooter.butBack != null)
  498. top.footer.frmFooter.butBack.disabled = true;
  499. Task.BackDisabled = true;
  500. }
  501. //-------------------------------------------------------------------------
  502. //
  503. // Function : EnableBack
  504. //
  505. // Synopsis : Enables the back button
  506. //
  507. // Arguments: None
  508. //
  509. // Returns : None
  510. //
  511. //-------------------------------------------------------------------------
  512. function EnableBack() {
  513. if (top.footer.frmFooter== null)
  514. {
  515. // If footer isn't loaded yet.
  516. window.setTimeout('EnableBack();',50);
  517. return;
  518. }
  519. if (top.footer.frmFooter.butBack != null)
  520. top.footer.frmFooter.butBack.disabled = false;
  521. Task.BackDisabled = false;
  522. }
  523. //-------------------------------------------------------------------------
  524. //
  525. // Function : DisableFinish
  526. //
  527. // Synopsis : Disables the finish button
  528. //
  529. // Arguments: None
  530. //
  531. // Returns : None
  532. //
  533. //-------------------------------------------------------------------------
  534. function DisableFinish() {
  535. if (top.footer.frmFooter == null)
  536. {
  537. // If footer isn't loaded yet.
  538. window.setTimeout('DisableFinish();',50);
  539. return;
  540. }
  541. if (top.footer.frmFooter.butFinish != null)
  542. top.footer.frmFooter.butFinish.disabled = true;
  543. Task.FinishDisabled = true;
  544. }
  545. //-------------------------------------------------------------------------
  546. //
  547. // Function : EnableFinish
  548. //
  549. // Synopsis : Enables the finish button
  550. //
  551. // Arguments: None
  552. //
  553. // Returns : None
  554. //
  555. //-------------------------------------------------------------------------
  556. function EnableFinish() {
  557. if (top.footer.frmFooter == null)
  558. {
  559. // If footer isn't loaded yet.
  560. window.setTimeout('EnableFinish();',50);
  561. return;
  562. }
  563. if (top.footer.frmFooter.butFinish != null)
  564. top.footer.frmFooter.butFinish.disabled = false;
  565. Task.FinishDisabled = false;
  566. }
  567. //-------------------------------------------------------------------------
  568. //
  569. // Function : DisableCancel
  570. //
  571. // Synopsis : Disables the cancel button
  572. //
  573. // Arguments: None
  574. //
  575. // Returns : None
  576. //
  577. //-------------------------------------------------------------------------
  578. function DisableCancel() {
  579. if (top.footer.frmFooter == null)
  580. {
  581. // If footer isn't loaded yet.
  582. window.setTimeout('DisableCancel();',50);
  583. return;
  584. }
  585. if (top.footer.frmFooter.butCancel != null)
  586. {
  587. top.footer.frmFooter.butCancel.disabled = true;
  588. }
  589. Task.CancelDisabled = true;
  590. }
  591. //-------------------------------------------------------------------------
  592. //
  593. // Function : EnableCancel
  594. //
  595. // Synopsis : Enables the cancel button
  596. //
  597. // Arguments: None
  598. //
  599. // Returns : None
  600. //
  601. //-------------------------------------------------------------------------
  602. function EnableCancel() {
  603. if (top.footer.frmFooter== null)
  604. {
  605. // If footer isn't loaded yet.
  606. window.setTimeout('EnableCancel();',50);
  607. return;
  608. }
  609. if (top.footer.frmFooter.butCancel != null)
  610. {
  611. top.footer.frmFooter.butCancel.disabled = false;
  612. }
  613. Task.CancelDisabled = false;
  614. }
  615. //-------------------------------------------------------------------------
  616. //
  617. // Function : DisableOK
  618. //
  619. // Synopsis : Disables the OK button
  620. //
  621. // Arguments: None
  622. //
  623. // Returns : None
  624. //
  625. //-------------------------------------------------------------------------
  626. function DisableOK() {
  627. if (top.footer.frmFooter == null)
  628. {
  629. // If footer isn't loaded yet.
  630. window.setTimeout('DisableOK();',50);
  631. return;
  632. }
  633. if (top.footer.frmFooter.butOK != null)
  634. top.footer.frmFooter.butOK.disabled = true;
  635. Task.FinishDisabled = true;
  636. }
  637. //-------------------------------------------------------------------------
  638. //
  639. // Function : EnableOK
  640. //
  641. // Synopsis : Enables the OK button
  642. //
  643. // Arguments: None
  644. //
  645. // Returns : None
  646. //
  647. //-------------------------------------------------------------------------
  648. function EnableOK() {
  649. if (top.footer.frmFooter== null)
  650. {
  651. // If footer isn't loaded yet.
  652. window.setTimeout('EnableOK();',50);
  653. return;
  654. }
  655. if (top.footer.frmFooter.butOK != null)
  656. top.footer.frmFooter.butOK.disabled = false;
  657. Task.FinishDisabled = false;
  658. }
  659. //-------------------------------------------------------------------------
  660. //
  661. // Function : isValidFileName
  662. //
  663. // Synopsis : validates that file name has correct syntax
  664. //
  665. // Arguments: filePath(IN) - file name with path to validate
  666. //
  667. // Returns : true/false
  668. //
  669. //-------------------------------------------------------------------------
  670. function isValidFileName(filePath)
  671. {
  672. reInvalid = /[\/\*\?"<>\|]/;
  673. if (reInvalid.test(filePath))
  674. return false;
  675. reColomn2 = /:{2,}/;
  676. reColomn1 = /:{1,}/;
  677. if ( reColomn2.test(filePath) || ( filePath.charAt(1) != ':' && reColomn1.test(filePath) ))
  678. return false;
  679. reEndSlash = /\\ *$/;
  680. if (reEndSlash.test(filePath))
  681. return false;
  682. reEndColomn = /: *$/;
  683. if (reEndColomn.test(filePath))
  684. return false;
  685. reAllSpaces = /[^ ]/;
  686. if (!reAllSpaces.test(filePath))
  687. return false;
  688. return true;
  689. }
  690. //-------------------------------------------------------------------------
  691. //
  692. // Function : HandleKeyPressIFrame
  693. //
  694. // Synopsis : key press event handler for IFRAME
  695. //
  696. // Arguments: evnt(IN) - event describing the key pressed
  697. //
  698. // Returns : None
  699. //
  700. //-------------------------------------------------------------------------
  701. function HandleKeyPressIFrame(evnt) {
  702. var intKeyCode;
  703. var frameMain = window.top.main;
  704. if (Task.KeyPress==true || Task.NavClick==true) {
  705. return;
  706. }
  707. Task.KeyPress = true;
  708. if (IsIE())
  709. intKeyCode = window.event.keyCode;
  710. else
  711. intKeyCode = evnt.which;
  712. if (intKeyCode == 13)
  713. {
  714. frameMain.Next();
  715. }
  716. if (intKeyCode == 27) {
  717. frameMain.Cancel();
  718. }
  719. }