Source code of Windows XP (NT5)
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.

490 lines
14 KiB

  1. // Code for the Add pane
  2. /*-------------------------------------------------------------------------
  3. Purpose: Called by the containing document when the page is 'loaded'.
  4. */
  5. function Add_Activate()
  6. {
  7. // We need some utility functions
  8. LoadScriptFile("idScriptUtil", "util.js");
  9. if (false == g_bAddPageLoaded)
  10. {
  11. g_bIsOnDomain = g_docAll.idCtlAppsDso.OnDomain;
  12. /* Fake version
  13. g_bIsOnDomain = true;
  14. */
  15. }
  16. // We need to first set the display style to indicate the active page
  17. // has changed.
  18. g_docAll.idTrHeadMargin_Add.style.display = 'block';
  19. g_docAll.idTrHeadCDROM1_Add.style.display = 'block';
  20. g_docAll.idTrHeadCDROM2_Add.style.display = 'block';
  21. g_docAll.idTrHeadInternet1_Add.style.display = 'block';
  22. g_docAll.idTrHeadInternet2_Add.style.display = 'block';
  23. g_docAll.idTrHeadPub_Add.style.display = 'block';
  24. g_docAll.idTrBody2_Add.style.display = 'block';
  25. if (false == g_bAddPageLoaded)
  26. {
  27. // Check policy restrictions to show the right sections. Use the visibility
  28. // style to maintain text flow.
  29. if (Dso_IsRestricted("NoAddFromCDorFloppy"))
  30. {
  31. g_docAll.idTrHeadCDROM1_Add.style.visibility = 'hidden';
  32. g_docAll.idTrHeadCDROM2_Add.style.visibility = 'hidden';
  33. }
  34. if (Dso_IsRestricted("NoAddFromInternet"))
  35. {
  36. g_docAll.idTrHeadInternet1_Add.style.visibility = 'hidden';
  37. g_docAll.idTrHeadInternet2_Add.style.visibility = 'hidden';
  38. }
  39. // Is this machine on a domain at all?
  40. if (false == g_bIsOnDomain || Dso_IsRestricted("NoAddFromNetwork"))
  41. {
  42. // No; don't bother showing the published list
  43. g_docAll.idTrHeadPub_Add.style.visibility = 'hidden';
  44. g_docAll.idTrBody2_Add.style.visibility = 'hidden';
  45. g_bIsOnDomain = false; // override to persist restriction across panes
  46. }
  47. // Check the GPO policy for the default category selection.
  48. g_bSelectDefault = true;
  49. }
  50. if (false == g_bIsOnDomain)
  51. {
  52. // To maintain the Places Bar column, we turn on idTrBody1_Add in place
  53. // of idTrBody2_Add for this case.
  54. g_docAll.idTrBody1_Add.style.display = 'block';
  55. }
  56. g_bReenumInstalledList = false; // Reset this each time we activate this pane
  57. // Is this an alpha machine?
  58. if (g_bIsAlpha)
  59. {
  60. // Yes; turn on the check box and set the 'force x86' property
  61. g_docAll.idTrFoot_Add.style.display = 'block';
  62. g_docAll.idChkAddForcex86.attachEvent("onclick", new Function("idCtlAppsDso.Forcex86 = idChkAddForcex86.checked"));
  63. }
  64. // Is this being loaded for the first time?
  65. if (false == g_bAddPageLoaded)
  66. {
  67. // Yes; apply some one-time settings
  68. // Handle button clicks
  69. g_docAll.idBtnCDFloppy.onclick = _AddApp;
  70. g_docAll.idBtnInternet.onclick = _AddApp;
  71. if (g_bIsOnDomain)
  72. {
  73. _SetPubWaitingFeedback();
  74. g_docAll.idSelCategory.onchange = _OnChangeCategories;
  75. // Bind our stub span element so the categories are enumerated
  76. g_docAll.idBindCategories.dataFld = 'displayname';
  77. g_docAll.idBindCategories.dataSrc = '#idCtlAppsDso.Categories';
  78. g_docAll.idSpnAddLaterSchedule.dataSrc = "#idCtlAppsDso.Add";
  79. g_docAll.idAddListbox.dataSource = "idCtlAppsDso.Add";
  80. /* Fake version
  81. g_docAll.idBindCategories.dataSrc = '#idCtlCategory';
  82. g_docAll.idSpnAddLaterSchedule.dataSrc = "#idCtlAddApps";
  83. g_docAll.idAddListbox.dataSource = "idCtlAddApps";
  84. */
  85. // Attach to the categories DSO so we know when to populate the dropdown
  86. Dso_GetCtl("Categories").attachEvent("ondatasetcomplete", Cat_OnDatasetComplete);
  87. Dso_GetCtl("Add").attachEvent("ondatasetcomplete", Add_OnDatasetComplete);
  88. // Set the initial focus to the listbox, and refresh the listbox
  89. // so it gets its data.
  90. //
  91. g_docAll.idAddListbox.Refresh();
  92. }
  93. g_bAddPageLoaded = true;
  94. }
  95. Add_SetFocus();
  96. }
  97. /*-------------------------------------------------------------------------
  98. Purpose: Set the initial focus
  99. */
  100. function Add_SetFocus()
  101. {
  102. g_docAll.idAddListbox.focus();
  103. }
  104. /*-------------------------------------------------------------------------
  105. Purpose: Called by the containing document when the page is switched away.
  106. */
  107. function Add_Deactivate()
  108. {
  109. g_docAll.idTrHeadMargin_Add.style.display = 'none';
  110. g_docAll.idTrHeadCDROM1_Add.style.display = 'none';
  111. g_docAll.idTrHeadCDROM2_Add.style.display = 'none';
  112. g_docAll.idTrHeadInternet1_Add.style.display = 'none';
  113. g_docAll.idTrHeadInternet2_Add.style.display = 'none';
  114. g_docAll.idTrHeadPub_Add.style.display = 'none';
  115. g_docAll.idTrFoot_Add.style.display = 'none';
  116. g_docAll.idTrBody1_Add.style.display = 'none';
  117. g_docAll.idTrBody2_Add.style.display = 'none';
  118. // Reenumerate the list of installed apps (since we might be
  119. // navigating to that page)?
  120. if (g_bReenumInstalledList)
  121. {
  122. // Yes; force a refresh of the installed apps
  123. Dso_Refresh("Remove");
  124. }
  125. }
  126. /*-------------------------------------------------------------------------
  127. Purpose: Handler for the 'onSetFocus' listbox event.
  128. */
  129. function Add_OnSetFocus()
  130. {
  131. var evt = window.event;
  132. ApplyExtraStyles(evt.srcChild, evt.bFocus);
  133. }
  134. /*-------------------------------------------------------------------------
  135. Purpose: Handler for the 'onCustomDraw' listbox event. Fixup the element objects
  136. as appropriate.
  137. */
  138. function Add_OnCustomDraw()
  139. {
  140. var evt = window.event;
  141. var tblElem = evt.srcChild; // the contents of the row is another table
  142. if (evt.bSelected)
  143. {
  144. // Item is selected
  145. var dwCapability = evt.Recordset("capability");
  146. if ('prepaint' == evt.drawStage)
  147. {
  148. // Prepaint stuff
  149. // Show the right set of buttons
  150. // Does this support 'add later'?
  151. if (dwCapability & APPCAP_ADDLATER)
  152. {
  153. // Yes
  154. evt.srcElement.EnableTemplate('idTrMultiBtns', true);
  155. evt.srcElement.EnableTemplate('idTrSingleBtns', false);
  156. }
  157. else
  158. {
  159. // No
  160. evt.srcElement.EnableTemplate('idTrMultiBtns', false);
  161. evt.srcElement.EnableTemplate('idTrSingleBtns', true);
  162. }
  163. }
  164. else
  165. {
  166. // Postpaint stuff
  167. // Attach events and stuff now that the elements have been added
  168. // to the document tree.
  169. // Does this support 'add later'?
  170. if (dwCapability & APPCAP_ADDLATER)
  171. {
  172. // Yes
  173. tblElem.all("idBtnAdd").onclick = _AddApp;
  174. tblElem.all("idBtnAddLater").onclick = _AddLater;
  175. }
  176. else
  177. {
  178. // No
  179. tblElem.all("idBtnAdd").onclick = _AddApp;
  180. }
  181. // Does this app have a support URL?
  182. var szSupportUrl = evt.Recordset("supporturl");
  183. if ("" != szSupportUrl)
  184. {
  185. // Yes; show the "more info" string
  186. var spnMoreInfo = tblElem.all("idSpnMoreInfo");
  187. spnMoreInfo.all("idAMoreInfo").href = szSupportUrl;
  188. spnMoreInfo.style.display = 'block';
  189. }
  190. ApplyExtraStyles(evt.srcChild, evt.bFocus);
  191. }
  192. }
  193. }
  194. /*-------------------------------------------------------------------------
  195. Purpose: Display the More Info dialog
  196. */
  197. function _OpenMoreInfo()
  198. {
  199. var url = event.srcElement.parentElement.href;
  200. window.open(url, "", "");
  201. // Don't let it navigate
  202. event.returnValue = false;
  203. }
  204. /*-------------------------------------------------------------------------
  205. Purpose: Filter the categories according to the selection list
  206. */
  207. function _FilterCategories(optElem)
  208. {
  209. var szFilter;
  210. _SetPubWaitingFeedback();
  211. if (optElem.value == "all")
  212. szFilter = "";
  213. else
  214. szFilter = optElem.value;
  215. Dso_Filter("Add", szFilter);
  216. }
  217. /*-------------------------------------------------------------------------
  218. Purpose: Handle the onchange event for the categories drop down
  219. */
  220. function _OnChangeCategories()
  221. {
  222. var elem = window.event.srcElement;
  223. var optElem = elem.options(elem.selectedIndex);
  224. _FilterCategories(optElem);
  225. }
  226. /*-------------------------------------------------------------------------
  227. Purpose: Add the app
  228. */
  229. function _AddApp()
  230. {
  231. var rsCur = Dso_GetRecordset("Add");
  232. switch(event.srcElement.id)
  233. {
  234. case "idBtnAdd":
  235. g_docAll.idCtlAppsDso.Exec("Add", "install", rsCur.AbsolutePosition);
  236. break;
  237. case "idBtnCDFloppy":
  238. g_docAll.idCtlAppsDso.Exec("Add", "generic install", 0);
  239. break;
  240. case "idBtnInternet":
  241. g_docAll.idCtlAppsDso.Exec("Add", "winupdate", 0);
  242. break;
  243. }
  244. /* Fake version
  245. switch(event.srcElement.id)
  246. {
  247. case "idBtnAdd":
  248. alert('Add ' + rsCur("displayname"));
  249. break;
  250. case "idBtnCDFloppy":
  251. alert('Add from CD or Floppy');
  252. break;
  253. case "idBtnInternet":
  254. alert('Add from Windows Update');
  255. break;
  256. }
  257. */
  258. if ("idBtnAdd" == event.srcElement.id || "idBtnInternet" == event.srcElement.id)
  259. {
  260. // Now cause the 'Remove' page to re-enumerate since an app may have been
  261. // installed. Ideally we'd only do this when we know an app successfully
  262. // installed, but I'm lazy about trying to figure that out!
  263. g_bReenumInstalledList = true;
  264. }
  265. }
  266. /*-------------------------------------------------------------------------
  267. Purpose: Add the app later on a schedule
  268. */
  269. function _AddLater()
  270. {
  271. var rsCur = Dso_GetRecordset("Add");
  272. g_docAll.idCtlAppsDso.Exec("Add", "addlater", rsCur.AbsolutePosition);
  273. /* Fake version
  274. alert('Add ' + rsCur("displayname") + ' later');
  275. */
  276. // Don't let the 'A' elem navigate
  277. window.event.returnValue = false;
  278. window.event.cancelBubble = true;
  279. }
  280. /*-------------------------------------------------------------------------
  281. Purpose: Change the schedule of the scheduled app.
  282. */
  283. function _Schedule()
  284. {
  285. var elemSrc = window.event.srcElement;
  286. if ("idASchedule" == elemSrc.id)
  287. {
  288. var rsCur = Dso_GetRecordset("Add");
  289. g_docAll.idCtlAppsDso.Exec("Add", "addlater", rsCur.AbsolutePosition);
  290. /* Fake version
  291. alert('Change schedule for ' + rsCur("displayname"));
  292. */
  293. }
  294. // Don't let the 'A' elem navigate
  295. window.event.returnValue = false;
  296. window.event.cancelBubble = true;
  297. }
  298. /*-------------------------------------------------------------------------
  299. Purpose: Reset the category list by removing all but the orginal "All" category
  300. */
  301. function _ResetCategoryList()
  302. {
  303. var i;
  304. var optElem;
  305. var colOptions = g_docAll.idSelCategory.options;
  306. for (i = 0; i < colOptions.length;)
  307. {
  308. optElem = colOptions[i];
  309. if (optElem.value != "all") // this does not need to be localized
  310. optElem.removeNode();
  311. else
  312. i++;
  313. }
  314. }
  315. /*-------------------------------------------------------------------------
  316. Purpose: Initialize the category selection list
  317. */
  318. function _InitCategoryList()
  319. {
  320. var rsCur = Dso_GetRecordset("Categories");
  321. if (rsCur.RecordCount > 0)
  322. {
  323. var i;
  324. var szDefault;
  325. var optElemSel = null;
  326. // Determine what the default category should be according
  327. // to the GPO policy.
  328. szDefault = g_docAll.idCtlAppsDso.DefaultCategory;
  329. /* Fake version
  330. szDefault = "{C}";
  331. */
  332. // Is there a default category?
  333. if ("" == szDefault)
  334. {
  335. // No; select the "All" category
  336. szDefault = "all"; // This does not need to be localized
  337. }
  338. // Now add the items to the dropdown
  339. rsCur.MoveFirst();
  340. for (i = 1; i <= rsCur.RecordCount; i++)
  341. {
  342. var optElem = document.createElement("option");
  343. // Right now we use the displayname as the id
  344. optElem.value = rsCur("displayname");
  345. /* Fake version
  346. optElem.value = rsCur("id");
  347. */
  348. optElem.text = rsCur("displayname");
  349. // Do we select this item?
  350. if (g_bSelectDefault && optElem.value == szDefault)
  351. {
  352. optElem.selected = true; // Yes
  353. optElemSel = optElem;
  354. }
  355. g_docAll.idSelCategory.add(optElem); // add it
  356. rsCur.MoveNext();
  357. }
  358. if (optElemSel)
  359. _FilterCategories(optElemSel);
  360. g_bSelectDefault = false; // Reset this so we don't always reselect the default
  361. }
  362. }
  363. /*-------------------------------------------------------------------------
  364. Purpose: Handle 'ondatasetcomplete' event fired from DSO
  365. */
  366. function Cat_OnDatasetComplete()
  367. {
  368. // Is this dataset complete for categories
  369. if (window.event.qualifier == "Categories")
  370. {
  371. _ResetCategoryList();
  372. _InitCategoryList();
  373. }
  374. }
  375. /*-------------------------------------------------------------------------
  376. Purpose: Handle 'ondatasetcomplete' event fired from DSO
  377. */
  378. function Add_OnDatasetComplete()
  379. {
  380. // Is this dataset complete for add?
  381. if (window.event.qualifier == "Add")
  382. {
  383. // Yes; show this text if the dataset is empty
  384. var L_AddNoneAvailable_Text = "No programs are available on the network";
  385. Dso_FeedbackIfEmpty("Add", g_docAll.idAddListbox, L_AddNoneAvailable_Text);
  386. }
  387. }