home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 September / PCO_0998.ISO / browser / ns405lyc / netcast.z / ncjs10.jar / prefpane.js < prev    next >
Encoding:
JavaScript  |  1998-03-09  |  5.3 KB  |  225 lines

  1. /*
  2.  * prefpane.js
  3.  * 
  4.  * Copyright (c) 1997 Netscape Communications Corporation, All Rights Reserved
  5.  * 
  6.  * Preference panel utilities
  7.  */
  8.  
  9. var        defaultWebtop = 0;
  10. var        editing = 0;
  11. var        applet = null;
  12. var        propID;
  13. var        propContainer;
  14. var        propSelector;
  15. var        previouslySelected = 0;
  16. var        defaultContainer = null;
  17. var        siteList = null;
  18. var        channelArray = null;
  19. var        layoutLoaded = false;
  20.  
  21. function onLoad() {
  22.     siteList = document.layers['channelList'].document.web_form;
  23.     applet = opener.selectorWindow.titlebar.document.demo;
  24.     propSelector = opener;
  25.     fillOptionDialog(siteList, depth.getDefaultContainer(), applet);
  26. }
  27.  
  28.  
  29. /*
  30.  * These methods initializes and populate the options dialog.  It loops through the data
  31.  * model storing pointers to the items, creating the list of channels.
  32.  */
  33. function fillOptionDialog(form, category, applet) {
  34.     var curOption;
  35.     var channelArrayLength;
  36.  
  37.     channelArray = applet.getData(category);
  38.  
  39.     // prevent JavaScript from accessing a null item list
  40.     if ( null == channelArray ) {
  41.         channelArrayLength = 0;
  42.  
  43.         curOption = new Option("------------ none ------------");
  44.         form.sitelist.options[0] = curOption;
  45.  
  46.     } else
  47.         channelArrayLength = channelArray.length;
  48.  
  49.       // Lets loop through all the items storing pointers
  50.     for (i = 0; i < channelArrayLength; i++) 
  51.     {
  52.         // Fill in the channel selection box
  53.         curOption = new Option(channelArray[i].getItemName());
  54.         curOption.prototype = channelArray[i];
  55.         form.sitelist.options[i] = curOption;
  56.  
  57.     }
  58.  
  59.     if (previouslySelected < channelArrayLength) {
  60.         form.sitelist.selectedIndex = previouslySelected
  61.     } else {
  62.         // Mark the first channel as selected
  63.         form.sitelist.selectedIndex = 0;
  64.     }
  65.  
  66.     if (defaultContainer == null) {
  67.         var containerName = depth.getDefaultContainer();
  68.         defaultContainer = applet.findContainerByName(containerName);
  69.     }
  70.  
  71.     adjustButtons();
  72. }
  73.  
  74.  
  75. function PropertiesCallback(propsWindow)
  76. {
  77.     propsWindow.selector  = propSelector;
  78.     propsWindow.container = propContainer;
  79.  
  80.     if (editing == 1)
  81.         propsWindow.editItem(propID);
  82.  
  83.     propsWindow.callback = self;
  84.  
  85. }
  86.  
  87. function EditCallback()
  88. {
  89.   // Fix me, I should pass in a second arg, really I should
  90.     fillOptionDialog(siteList, propContainer, applet);
  91. }
  92.  
  93.  
  94. function adjustButtons() {
  95.     var item = siteList.sitelist.options[siteList.sitelist.selectedIndex].prototype;
  96.     var online = applet.isOnline();
  97.  
  98.     if (defaultContainer.getCanAddItems()) {
  99.         enableButton("new");
  100.     } else {
  101.         disableButton("new");
  102.     }
  103.  
  104.     if ((item!= null) && (item.isDeletable())) {
  105.         enableButton("delete");
  106.     } else {
  107.         disableButton("delete");
  108.     }
  109.  
  110.     if ((item!= null) && (item.getStatus() == 1)) {
  111.         document.layers['stopupdate'].visibility="inherit";
  112.         document.layers['update'].visibility="hide";
  113.     } else {
  114.         document.layers['stopupdate'].visibility="hide";
  115.         document.layers['update'].visibility="inherit";
  116.  
  117.         if (online) {
  118.             enableButton("update");
  119.         } else {
  120.             disableButton("update");
  121.         }
  122.     }
  123. }
  124.  
  125. function goDown(layer) {
  126.     layer.background.src ="images/i_btnbg.gif";
  127.     return false;
  128. }
  129.  
  130. function goUp(layer) {
  131.     layer.background.src ="images/o_btnbg.gif";
  132.     return false;
  133. }
  134.  
  135. function goDownTall(layer) {
  136.     layer.background.src ="images/i_btnbg2.gif";
  137.     return false;
  138. }
  139.  
  140. function goUpTall(layer) {
  141.     layer.background.src ="images/o_btnbg2.gif";
  142.     return false;
  143. }
  144.  
  145. function disableButton(buttonName) {
  146.     document.layers[buttonName+'_d'].visibility="inherit";
  147. }
  148.  
  149. function enableButton(buttonName) {
  150.     document.layers[buttonName+'_d'].visibility="hide";
  151. }
  152.  
  153. function handleAdd()
  154. {
  155.     editing = 0;
  156.  
  157.     var propWin = depth.SecureWindowOpen(window, 'addc.htm', 
  158.                 'prefs', 
  159.                 'left=150,top=200,width=427,height=247,titlebar=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,modal=yes,alwaysRaised=yes,z-lock=no,dependent=yes,hotkeys=no');
  160.  
  161.     propWin.depth = depth;
  162.     propContainer = depth.getDefaultContainer();
  163. }
  164.  
  165. function handleProperties()
  166. {
  167.     previouslySelected = siteList.sitelist.selectedIndex;
  168.     var item = siteList.sitelist.options[previouslySelected].prototype;
  169.  
  170.     if ( null != item ) 
  171.     {
  172.         editing = 1;
  173.         var propWin = depth.SecureWindowOpen (window, 'addc.htm', 
  174.                 'prefs', 
  175.                 'left=150,top=200,width=427,height=247,titlebar=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,modal=yes,alwaysRaised=yes,z-lock=no,dependent=yes,hotkeys=no');
  176.  
  177.         propID = item;
  178.         propWin.depth = depth;
  179.         propContainer = depth.getDefaultContainer();
  180.     }
  181.  
  182. }
  183.  
  184. function stopSelectedUpdate()
  185. {
  186.     var item = siteList.sitelist.options[siteList.sitelist.selectedIndex].prototype;
  187.  
  188.     if (null != item) {
  189.         item.cancelUpdate();
  190.     }
  191. }
  192.  
  193. function deleteSelected()
  194. {
  195.     var item = siteList.sitelist.options[siteList.sitelist.selectedIndex].prototype;
  196.  
  197.     if (null != item) {
  198.         item.deleteMe();
  199.  
  200.         siteList.sitelist.options.length -= 1;
  201.         fillOptionDialog(siteList, depth.getDefaultContainer(), applet);
  202.     }
  203. }
  204.  
  205. function startSelectedUpdate()
  206. {
  207.     var item = siteList.sitelist.options[siteList.sitelist.selectedIndex].prototype;
  208.  
  209.     if ( null != item ) {
  210.         item.update();
  211.     }
  212. }
  213.  
  214. function stopSelectedUpdate()
  215. {
  216.     var item = siteList.sitelist.options[siteList.sitelist.selectedIndex].prototype;
  217.  
  218.     if ( null != item ) {
  219.         item.cancelUpdate();
  220.     }
  221. }
  222.  
  223.  
  224. void(0);
  225.