remove.js
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 13k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. // Functions for the Remove page
  2. /*-------------------------------------------------------------------------
  3. Purpose: Called when ARP switches to the Remove pane
  4. */
  5. function Remove_Activate()
  6. {
  7.     // We need some utility functions
  8.     LoadScriptFile("idScriptUtil", "util.js");
  9.     LoadScriptFile("idScriptBplate", "bplate.js");
  10.     InitBoilerPlateClass();
  11.     
  12.     // Show the relavent rows
  13.     g_docAll.idTrHeadMargin_Remove.style.display = 'block';
  14.     g_docAll.idTrHead_Remove.style.display = 'block';
  15.     g_docAll.idTrBody_Remove.style.display = 'block';
  16.     // Is this an alpha machine?
  17.     if (g_bIsAlpha)
  18.     {
  19.         // Yes; turn on the check box and set the 'force x86' property
  20.         g_docAll.idTrFoot_Remove.style.display = 'block';
  21.         g_docAll.idChkRemoveForcex86.attachEvent("onclick", new Function ("idCtlAppsDso.Forcex86 = idChkRemoveForcex86.checked"));
  22.     }
  23.     // Is this pane being activated for the first time?
  24.     if (false == g_bRemovePageLoaded)
  25.     {
  26.         // Yes
  27.         // Check policies for any restrictions
  28.         if (Dso_IsRestricted("NoSupportInfo"))
  29.             g_bShowSupportInfo = false;
  30.         
  31.         g_docAll.idSelSortBy.onchange = _SortDataSource;
  32.         // Connect the remove listbox to the datasource
  33.         g_docAll.idRemoveListbox.dataSource = "idCtlAppsDso.Remove";
  34.         /* Fake version
  35.         g_docAll.idRemoveListbox.dataSource = "idCtlRemoveApps";
  36.         */
  37.         
  38.         Dso_GetCtl("Remove").attachEvent("ondatasetcomplete", Remove_OnDatasetComplete);
  39.         // Set the initial focus to the listbox, and refresh the listbox 
  40.         // so it gets its data.
  41.         //
  42.         g_docAll.idRemoveListbox.Refresh();
  43.         g_bRemovePageLoaded = true;
  44.     }
  45.     g_bReenumAddList = false;
  46.     
  47.     Remove_SetFocus();
  48. }
  49. /*-------------------------------------------------------------------------
  50. Purpose: Set the initial focus
  51. */
  52. function Remove_SetFocus()
  53. {
  54.     g_docAll.idRemoveListbox.focus();
  55. }
  56. /*-------------------------------------------------------------------------
  57. Purpose: Called when the Remove page is switched away
  58. */
  59. function Remove_Deactivate()
  60. {
  61.     // Hide the relavent rows
  62.     g_docAll.idTrHeadMargin_Remove.style.display = 'none';
  63.     g_docAll.idTrHead_Remove.style.display = 'none';
  64.     g_docAll.idTrFoot_Remove.style.display = 'none';
  65.     g_docAll.idTrBody_Remove.style.display = 'none';
  66.     if (g_bReenumAddList)
  67.     {
  68.         Dso_Refresh("Add");
  69.     }
  70. }
  71. /*-------------------------------------------------------------------------
  72. Purpose: Handler for the 'onSetFocus' listbox event.
  73. */
  74. function Remove_OnSetFocus()
  75. {
  76.     var evt = window.event;
  77.     ApplyExtraStyles(evt.srcChild, evt.bFocus);
  78. }
  79. /*-------------------------------------------------------------------------
  80. Purpose: Handler for the 'onCustomDraw' listbox event.  Fixup the element objects
  81.          as appropriate.
  82.          
  83. */
  84. function Remove_OnCustomDraw()
  85. {
  86.     var evt = window.event;
  87.     var tblElem = evt.srcChild;      // the contents of the row is another table
  88.     if (evt.bSelected)
  89.     {
  90.         // Item is being selected
  91.         var dwCapability = evt.Recordset("capability");
  92.         if ('prepaint' == evt.drawStage)
  93.         {
  94.             // Prepaint stuff
  95.             // alert("Capability=" + dwCapability);
  96.             
  97.             // Show the right set of buttons
  98.             
  99.             // Does this support separate modify/remove buttons?
  100.             if (dwCapability & APPCAP_MODIFYREMOVE)
  101.             {
  102.                 // No
  103.                 evt.srcElement.EnableTemplate('idTrMultiBtns', false);
  104.                 evt.srcElement.EnableTemplate('idTrSingleBtns', true);
  105.             }
  106.             else
  107.             {
  108.                 // Yes; show separate modify/remove buttons
  109.                 evt.srcElement.EnableTemplate('idTrMultiBtns', true);
  110.                 evt.srcElement.EnableTemplate('idTrSingleBtns', false);
  111.             }
  112.         }
  113.         else
  114.         {
  115.             // Postpaint stuff
  116.             var bplate = new BoilerPlate();
  117.             bplate.Parse(evt.Recordset("supportinfo"));
  118.             
  119.             // Does this app have any need for the support info dialog?
  120.             //
  121.             // (Having just the 'displayname' as support info isn't helpful enough
  122.             // to merit showing the dialog)
  123.             //
  124.             // alert("bplate.Length = " + bplate.Length() + "; displayname = " + bplate.Get("displayname"));
  125.             
  126.             if (!g_bShowSupportInfo ||
  127.                 !(dwCapability & APPCAP_REPAIR) && 
  128.                 (1 > bplate.Length() || 
  129.                  1 == bplate.Length() && null != bplate.Get("displayname")))
  130.             {
  131.                 // No; then hide the link to the dialog
  132.                 tblElem.all('idTdInfoDesc').style.visibility = 'hidden';
  133.             }
  134.             
  135.             // Attach events and stuff now that the elements have been added
  136.             // to the document tree.
  137.             
  138.             // Does this support separate modify and remove buttons?
  139.             if (dwCapability & APPCAP_MODIFYREMOVE)
  140.             {
  141.                 // No
  142.                 tblElem.all('idBtnBoth').onclick = _ModifyOrRemove;
  143.                 // Disable buttons according to policy
  144.                 if ( !(dwCapability & APPCAP_UNINSTALL) )
  145.                     tblElem.all('idBtnBoth').disabled = true;
  146.             }
  147.             else
  148.             {
  149.                 // Yes
  150.                 tblElem.all('idBtnModify').onclick = _ModifyOrRemove;
  151.                 tblElem.all('idBtnRemove').onclick = _ModifyOrRemove;
  152.                 // Disable buttons according to policy
  153.                 if ( !(dwCapability & APPCAP_MODIFY) )
  154.                     tblElem.all('idBtnModify').disabled = true;
  155.                     
  156.                 if ( !(dwCapability & APPCAP_UNINSTALL) )
  157.                     tblElem.all('idBtnRemove').disabled = true;
  158.             }
  159.             // Are we sorting by name or size?
  160.             var szSort = g_docAll.idSelSortBy.options(g_docAll.idSelSortBy.selectedIndex).value;
  161.             if ("displayname" == szSort || "size" == szSort || "timesused" == szSort)
  162.             {
  163.                 // Yes; then allow the size field in the properties (the 'index
  164.                 // value') to be an anchor so the user can click it for a 
  165.                 // definition.
  166.                 var spnValue = evt.srcRow.all("idSpnIndexValue");
  167.                 var tdValue = spnValue.parentElement;
  168.                 var tdId = ("timesused" == szSort ? "idAFrequency" : "idASize");
  169.                 
  170.                 tdValue._szInner = tdValue.innerHTML;
  171.                 // If there is nothing to go inside of the 'anchor', then don't create the 
  172.                 // span elements.  We will still replace it with the old _szInner later.
  173.                 if (tdValue.innerText != "")
  174.                 {
  175.                     tdValue.innerHTML = 
  176.                         "<SPAN id=" +
  177.                         tdId +
  178.                         " class='FakeAnchor' tabIndex=0 onKeyDown='_OnKeyDownFakeAnchor()' onClick='_OpenDefinition();'> " +
  179.                         "&nbsp;<U>" +
  180.                         tdValue._szInner + 
  181.                         "</U></SPAN>";
  182.                 }
  183.             }
  184.             // Use the focus state provided by the event
  185.             ApplyExtraStyles(tblElem, evt.bFocus);
  186.         }
  187.     }
  188.     else
  189.     {
  190.         // Item is being deselected
  191.         if ('prepaint' == evt.drawStage)
  192.         {
  193.             // Remove the anchor element from the value field
  194.             var spnValue = evt.srcRow.all("idSpnIndexValue");
  195.             var tdValue = spnValue.parentElement.parentElement.parentElement;
  196.             
  197.             if (null != tdValue._szInner)
  198.             {
  199.                 tdValue.innerHTML = tdValue._szInner;
  200.                 tdValue._szInner = null;
  201.             }
  202.             // Say focus==false so the style reverts to the default setting
  203.             ApplyExtraStyles(tblElem, false);
  204.         }
  205.     }
  206. }
  207. /*-------------------------------------------------------------------------
  208. Purpose: Display the Support Info dialog
  209. */
  210. function _OpenSupportInfo()
  211. {
  212.     // Display the Support Info dialog
  213.     var szFeatures = g_szSupportInfoSize + "; resizable:no; help:no";
  214.     
  215.     window.showModalDialog("support.htm", window, szFeatures);
  216.     
  217.     // Don't let the 'A' elem navigate
  218.     window.event.returnValue = false;
  219.     window.event.cancelBubble = true;
  220. }
  221. /*-------------------------------------------------------------------------
  222. Purpose: Display a definition dialog according to the field that was clicked.
  223. */
  224. function _OpenDefinition()
  225. {
  226.     var elemSrc = window.event.srcElement;
  227.     // We are trying to get the most specific id for looking up a 
  228.     // definition.  We prefer idAFrequency or idASize.  If we
  229.     // get nothing or idSpnIndexValue, check to see if the parent
  230.     // tag is more specific.  It either will be or it will not exist.
  231.     if (("idSpnIndexValue" == elemSrc.id) && ("" != elemSrc.parentElement.parentElement.id))
  232.     {
  233.         elemSrc = elemSrc.parentElement.parentElement;
  234.     }
  235.     
  236.     if ("" == elemSrc.id)
  237.     {
  238.         elemSrc = elemSrc.parentElement;
  239.     }
  240.     if ("idAFrequency" == elemSrc.id)
  241.     {
  242.         var szFeatures = "dialogWidth:20em; dialogHeight:16em; resizable:no; help:no";
  243.         window.showModalDialog("def_freq.htm", window, szFeatures);
  244.     }
  245.     else if ("idASize" == elemSrc.id || "idSpnIndexValue" == elemSrc.id)
  246.     {
  247.         var szFeatures = "dialogWidth:20em; dialogHeight:10.7em; resizable:no; help:no";
  248.         window.showModalDialog("def_size.htm", window, szFeatures);
  249.     }
  250.         
  251.     // Don't let the 'A' elem navigate
  252.     window.event.returnValue = false;
  253.     window.event.cancelBubble = true;
  254. }
  255. /*-------------------------------------------------------------------------
  256. Purpose: Re-sort the given data source object according to the current selection
  257. */
  258. function _SortDataSource()
  259. {
  260.     var selElem = window.event.srcElement;
  261.     var optCur = selElem.options(selElem.selectedIndex);
  262.     Dso_Sort("Remove", optCur.value);
  263. }
  264. /*-------------------------------------------------------------------------
  265. Purpose: Modify or remove the current app (the current recordset)
  266. */
  267. function _ModifyOrRemove()
  268. {
  269.     var rsCur = Dso_GetRecordset("Remove");
  270.     var nRec = rsCur.AbsolutePosition;
  271.     
  272.     switch(event.srcElement.id)
  273.     {
  274.     case "idBtnBoth":
  275.         g_docAll.idCtlAppsDso.Exec("Remove", "uninstall", nRec);
  276.         break;
  277.     case "idBtnModify":
  278.         g_docAll.idCtlAppsDso.Exec("Remove", "modify", nRec);
  279.         break;
  280.     case "idBtnRemove":
  281.         g_docAll.idCtlAppsDso.Exec("Remove", "uninstall", nRec);
  282.         break;
  283.     }
  284.     /* Fake version
  285.     switch(event.srcElement.id)
  286.     {
  287.     case "idBtnBoth":
  288.         alert('Remove ' + rsCur("displayname"));
  289.         break;
  290.     case "idBtnModify":
  291.         alert('Change ' + rsCur("displayname"));
  292.         break;
  293.     case "idBtnRemove":
  294.         alert('Remove ' + rsCur("displayname"));
  295.         break;
  296.     }
  297.     */
  298.     if ("idBtnRemove" == event.srcElement.id)
  299.     {
  300.         // Now cause the 'Add' page to re-enumerate since an app may have been
  301.         // removed.  Ideally we'd only do this when we know an app successfully
  302.         // removed, but I'm lazy about trying to figure that out!
  303.         g_bReenumAddList = true;
  304.     }
  305. }
  306. /*-------------------------------------------------------------------------
  307. Purpose: Called by the Support Info help window.  This repairs the given app.
  308. */
  309. function SupportInfo_Repair(nRecordNumber)
  310. {
  311.     var rsCur = Dso_GetRecordset("Remove");
  312.     var nRecordSav = rsCur.AbsolutePosition;
  313.     window.focus();
  314.     rsCur.AbsolutePosition = nRecordNumber;
  315.     g_docAll.idCtlAppsDso.Exec("Remove", "repair", nRecordNumber);
  316.     /* Fake version
  317.     alert('Repair app ' + rsCur("displayname"));
  318.     */
  319.     
  320.     rsCur.AbsolutePosition = nRecordSav;
  321. }
  322. /*-------------------------------------------------------------------------
  323. Purpose: Called by the Support Info help window.  This returns the structured
  324.          record string containing all info that the Support Info needs.
  325. */
  326. function SupportInfo_Query()
  327. {
  328.     // Compose the record string.  See comments in support.htm for
  329.     // details on the format.
  330.     var rsCur = Dso_GetRecordset("Remove");
  331.     
  332.     var szRecord = "<recordnumber " + rsCur.AbsolutePosition + ">";
  333.     szRecord += rsCur("supportinfo");
  334.     szRecord += "<capability " + rsCur("capability") + ">";
  335.     return szRecord;
  336. }
  337. /*-------------------------------------------------------------------------
  338. Purpose: Called by the Support Info help window.  Returns the string
  339.          specifying the intended size of the window.  This is a hack
  340.          since Trident doesn't provide this for us.
  341. */
  342. function SupportInfo_GetDlgSize()
  343. {
  344.     return g_szSupportInfoSize;
  345. }
  346. /*-------------------------------------------------------------------------
  347. Purpose: Handle 'ondatasetcomplete' event fired from DSO
  348. */
  349. function Remove_OnDatasetComplete()
  350. {
  351.     // Is this dataset complete for Remove?
  352.     if (window.event.qualifier == "Remove")
  353.     {
  354.         // Yes; show this text if the dataset is empty
  355.         var L_RemoveNoneAvailable_Text = "There are no programs installed on this computer";
  356.         
  357.         Dso_FeedbackIfEmpty("Remove", g_docAll.idRemoveListbox, L_RemoveNoneAvailable_Text);
  358.     }
  359. }