home *** CD-ROM | disk | FTP | other *** search
/ Draw 3 / Draw 3.iso / AOL90 / COMP01.000 / %AFIXPATH% / 10003GPFUS.udp / out / flow.js < prev    next >
Encoding:
JavaScript  |  2004-09-27  |  9.9 KB  |  331 lines

  1. // Auto Fix flow
  2. // Copyright (c) GTek Technologies Ltd.
  3.  
  4. //======== Plugins are initialized on first call to getObj() method =====================
  5.  
  6. var g_oXML = new ADPPlugin("Name=msxml,ProgID=Microsoft.XMLDOM"); // creates Xml Parser Object
  7. var g_oHideAb3 = new ADPPlugin("Name=HideAb3,DllName=HideAb3,FuncName=GetHiderDispatch");
  8.  
  9. // Main Elements Objects in XML
  10. var flowSequenceXML;
  11. var eventColletionXML;
  12.  
  13. var f_obj, f_objType, f_id, f_event, f_spanStep, f_hideStep; // XML flow seq. attributes
  14. var e_flowId, e_statId, e_obj, e_visible; // XML event / message collection attributes
  15.  
  16. var g_sJsResult; // Js Function Events - relates to flow_func.js
  17. var bGetHide = false; // HideAb3 run flag
  18. var acsTimeout;
  19. var bAcsWait = false; // default - don't wait for AOL API return codes
  20.  
  21. //======== XML Functions ================================================================
  22.  
  23. function loadXML(fileXML) { // loads Xml Document 
  24.    g_oXML.getObj().async = "false";
  25.    g_oXML.getObj().onreadystatechange = verify;
  26.    g_oXML.getObj().load(fileXML);
  27.    flowSequenceXML = g_oXML.getObj().documentElement.childNodes(0);
  28.    eventColletionXML = g_oXML.getObj().documentElement.childNodes(1);
  29. }
  30.  
  31. function verify() {
  32.    if (g_oXML.getObj().readyState != 4)
  33.       return false; // else = returns true (automatic)
  34. }
  35.     
  36. function getXmlMatch(currFlag) { // matchs Xml Data to AF Events
  37.    if (bAcsWait) { // breaks until AOL API returns complete
  38.       acsTimeout = setTimeout(getXmlMatch, 2000);
  39.       return true;
  40.    }
  41.    
  42.    for (i=0;i<eventColletionXML.childNodes.length;i++) {
  43.       loadEvents(i); // sets XML data into variables;
  44.  
  45.       if (e_flowId == currFlag) {
  46.          hideProgBar(true);
  47.          sendStat(e_statId);
  48.          
  49.          if (e_visible == "true") { // in case of message display
  50.                 g_oAdp.Vars("CurrentADP") = "goEndAF";
  51.                 window.location.replace(g_oAdp.Vars("StartHtm") + "?msgId=" + e_obj);
  52.          } else {
  53.             eval(e_obj); // runs function from XML by its full string form
  54.          }
  55.          
  56.          return true;
  57.         }
  58.     }
  59.  
  60.    return false;
  61. }
  62.  
  63. function loadFlow(itemLocation) {
  64.    f_obj = flowSequenceXML.childNodes(itemLocation).getAttribute("obj");
  65.    f_objType = flowSequenceXML.childNodes(itemLocation).getAttribute("objType");
  66.    f_id = flowSequenceXML.childNodes(itemLocation).getAttribute("id");
  67.    f_event = flowSequenceXML.childNodes(itemLocation).getAttribute("waitFor");
  68.    f_spanStep = flowSequenceXML.childNodes(itemLocation).getAttribute("spanOn");
  69.    f_hideStep = flowSequenceXML.childNodes(itemLocation).getAttribute("mayBeHidden");
  70. }
  71.  
  72. function loadEvents(itemLocation) {
  73.    e_flowId = eventColletionXML.childNodes(itemLocation).getAttribute("flowId");
  74.     e_statId = eventColletionXML.childNodes(itemLocation).getAttribute("statId");
  75.     e_obj = eventColletionXML.childNodes(itemLocation).getAttribute("obj");
  76.     e_visible = eventColletionXML.childNodes(itemLocation).getAttribute("bVisible");
  77. }
  78.  
  79. //======== AOLCoach CallBacks ===========================================================
  80.  
  81. var g_sFixStatus = "";
  82.  
  83. function Trainer_OnLessonStatus(sStatus) {
  84.    g_sFixStatus = sStatus; // ACP - errors and values (resolution - ACP1)
  85. }
  86.  
  87. function Trainer_OnLessonStart() {
  88.    g_sFixStatus = "";
  89. }
  90.  
  91. function Trainer_OnLessonFinish() {
  92.    g_oHideAb3.getObj().Stop;
  93.    var sResult = g_oIni.getObj().String("AdpData", "result", getIniPath());
  94.     
  95.    if (sResult == "Reboot") // closes ADP in case of pending reboot
  96.          closeAdp();
  97.         
  98.    if (sResult != "") { // catchs Events
  99.       if (!getXmlMatch(sResult))
  100.          goStep("next");
  101.    } else { // handles ACP errors
  102.       if (!getXmlMatch(g_sFixStatus))
  103.          goStep("next");
  104.    }
  105. }
  106.  
  107. //======== Dynamic GUI Creation functions ===============================================
  108.  
  109. function loadSteps() {
  110.     for (i=0;i<flowSequenceXML.childNodes.length;i++) {
  111.       loadFlow(i); // sets XML data into variables
  112.       
  113.       if (f_id != null && !isStepHidden(f_hideStep))
  114.          appendTable(i);
  115.     }
  116.     
  117.    document.getElementById('BackgroundHeader').innerHTML = g_hdrStr; // creates Adp Header
  118.     createBullets();
  119.     hideProgBar(false);
  120. }
  121.  
  122. function appendTable(currentItem) {
  123.     currentTD = document.getElementById(f_id);
  124.    
  125.    if (currentItem == g_oAdp.Vars("currentStep")) { // Current Step
  126.       setTableStyle(currentTD, false, "CurrentItem");
  127.    } else if (currentItem < g_oAdp.Vars("currentStep")) { // Completed Step
  128.       setTableStyle(currentTD, true, "CompletedItem");
  129.    } else { // Future Step
  130.       setTableStyle(currentTD, false, "NextItem");
  131.    }
  132. }
  133.  
  134. function createBullets() {
  135.     tableRows = document.getElementById('ContentTable').childNodes[0].childNodes;
  136.     
  137.     for (j=0;j<tableRows.length;j++) {
  138.         bulletTd = tableRows[j].insertCell(0);
  139.         bulletTd.width = "10";
  140.         bulletTd.vAlign = "Top";
  141.         bulletTd.innerHTML = "<img src='../adpglobal/bullet.gif' ondrag='JavaScript:return false;'>";
  142.     }
  143. }
  144.  
  145. function setTableStyle(td, sign, cssClass) {
  146.     td.className = cssClass;
  147.     td.colspan = 2;
  148.         
  149.     if (sign) {
  150.         td.colspan = 1;   
  151.         signTd = td.parentElement.insertCell();
  152.         signTd.width = "10";
  153.         signTd.innerHTML = "<img src='../adpglobal/v_sign.gif' ondrag='JavaScript:return false;'>";
  154.     }
  155. }
  156.  
  157. function setStepSpan() {
  158.    if (f_spanStep != null)
  159.       setTableStyle(document.getElementById(f_spanStep), false, "CurrentItem");
  160. }
  161.  
  162. function isStepHidden(stepTerm) {
  163.    if (f_hideStep != null) {
  164.       bHideRes = eval(f_hideStep);
  165.  
  166.       if (bHideRes) {
  167.          document.getElementById(f_id).parentElement.removeNode(true);
  168.          return true;
  169.       }
  170.    }
  171.  
  172.    return false;
  173. }
  174.  
  175. //======== AF execute parts =============================================================
  176.  
  177. function goFlow() { 
  178.    setFlowMsgs();
  179.    loadXML(formatFilePath(document.location.pathname, "flow_data.xml")); // loads Xml File
  180.  
  181.    if (g_oAdp.Vars("RunReboot") == "Reboot") {
  182.       if (parseInt(g_oAdp.Vars("nBootStepIndex")) > 0) {
  183.          g_oAdp.Vars("currentStep") = parseInt(g_oAdp.Vars("nBootStepIndex"));
  184.          g_oAdp.Vars("nBootStepIndex") = "" // clears the flow flag
  185.       } else {
  186.             g_oAdp.Vars("currentStep") = flowSequenceXML.childNodes.length;
  187.       }
  188.    }
  189.  
  190.    loadSteps(); // displays Updated AF Location (list style)
  191.  
  192.    // If not at end of flow go to phase; else finish AF
  193.    if (g_oAdp.Vars("currentStep") < flowSequenceXML.childNodes.length) {
  194.       
  195.       loadFlow(g_oAdp.Vars("currentStep")); // sets XML data into variables; 
  196.  
  197.       if (f_objType=="js")
  198.          setTimeout(runFix, 1000);
  199.       else
  200.             runFix();
  201.    } else {
  202.       hideProgBar(true); // ensure no prog_bar in case of restart
  203.       setTimeout(goEndFlow, 2000);
  204.     }
  205. }
  206.  
  207. function runFix() {
  208.    setStepSpan(); // sets joined span visual status
  209.      
  210.    if (f_objType == "acp")
  211.         runAcpFix();
  212.    else
  213.         runJsFix();
  214. }
  215.  
  216. function runAcpFix() { // runs *.atr File
  217.    g_oHideAb3.getObj().Start;
  218.    bGetHide = true;
  219.    g_oIni.getObj().String("AdpData", "error_data", getIniPath()) = "";
  220.    g_oIni.getObj().String("AdpData", "licence", getIniPath()) = "";
  221.    g_oIni.getObj().String("AdpData", "result", getIniPath()) = "StartACP"; // continuously ESC protection
  222.     g_oAdp.RunMeta("SB_CyberCoachWait", "");
  223.    g_oAdp.RunFix(f_obj);
  224. }
  225.  
  226. function runJsFix() { // runs Js Function
  227.    eval(f_obj); // runnnig function from XML by it's full string form
  228.     
  229.     if (f_event != null)
  230.       bAcsWait = true;
  231.          
  232.    if (!getXmlMatch(g_sJsResult)) // checks for Errors / Events
  233.         goStep("next");
  234. }
  235.  
  236. function clearAcsWait(sEventCode) {
  237.    clearTimeout(acsTimeout);
  238.    bAcsWait = false;
  239.  
  240.    if (!getXmlMatch(sEventCode)) // checks for Errors / Events
  241.         goStep("next");
  242. }
  243.  
  244. function goStep(sStep) { // moves Flow 
  245.    if (sStep == "next")  // default - moves Next Action
  246.         g_oAdp.Vars("currentStep")++;
  247.    else                  // goes to Specific Step In Sequence
  248.       g_oAdp.Vars("currentStep") = sStep;
  249.         
  250.     window.location.replace(document.location);
  251. }
  252.  
  253. function hideProgBar(bHide) { // hides the progress bar
  254.     progBar = document.getElementById("ProgressBar");
  255.     progBarContainer = document.getElementById("ProgressBarContainer");
  256.     progBar.attachEvent("ondrag", disableDrag);
  257.     
  258.    if (!bHide) {
  259.       progBar.src = "../adpglobal/progbar.gif";
  260.       progBarContainer.style.visibility = "visible";
  261.    } else {
  262.         progBarContainer.style.visibility = "hidden";
  263.     }
  264. }
  265.  
  266. function disableDrag() { // disables drag event
  267.     return false;
  268. }
  269.  
  270. function setFlowMsgs() { // hides all elements besids steps
  271.     hideChildren(document.body);
  272.     document.getElementById("StepsContainer").style.display = ""; 
  273. }
  274.  
  275. function goEndFlow() {
  276.    hideProgBar(true);
  277.    sendStat("End");
  278.    goEndAF(); // AOL CC AF - no need "Fixed" ADP msg.
  279. }
  280.  
  281. function Window_OnClose() {
  282.    if (bGetHide)
  283.       g_oHideAb3.getObj().Stop;
  284.    
  285.    if (f_objType == "acp")
  286.       g_oIni.getObj().String("AdpData", "licence", getIniPath()) = "FALSE";
  287.       
  288.    if (g_oAdp.Vars("StatWasSent") == "FALSE")
  289.       sendStat("Quit");
  290.  
  291.    completeFix();
  292.    closeAdp();
  293. }
  294.  
  295. //======== ACS API events ===============================================================
  296.  
  297. function OnEnd_Instantiate(sRes) {
  298.    clearAcsWait("OnEnd_Instantiate_" + sRes);
  299. }
  300.  
  301. function OnEnd_RebuildCurrentLocation(sRes) {
  302.    clearAcsWait("OnEnd_RebuildCurrentLocation_" + sRes);
  303. }
  304.  
  305. function OnEnd_FlowIsRunning(sRes) {
  306.    clearAcsWait("OnEnd_FlowIsRunning_" + sRes);
  307. }
  308.  
  309. function OnEnd_StopACS(sRes) {
  310.    clearAcsWait("OnEnd_StopACS_" + sRes);
  311. }
  312.  
  313. function OnEnd_RedetectDevices(sRes) {
  314.    clearAcsWait("OnEnd_RedetectDevices_" + sRes);
  315. }
  316.  
  317. function OnEnd_RebuildAdapter(sRes) {
  318.    g_oAcs.getObj().UnloadAcs();
  319. }
  320.  
  321. function OnEnd_WaitForConnection(sRes) {
  322.    clearAcsWait("OnEnd_WaitForConnection_" + sRes);
  323. }
  324.  
  325. function OnRebuildCurrentLocation(sRes) {
  326.    clearAcsWait("OnRebuildCurrentLocation_" + sRes);
  327. }
  328.  
  329. function OnEnd_UnloadAcs(sRes) {
  330.    clearAcsWait("OnEnd_UnloadAcs_" + sRes);
  331. }