home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 July / 07_02.iso / software / mdmx / files / DreamweaverMXInstaller.exe / Disk1 / data1.cab / Configuration_En / Commands / ServerObject-MenuProps.js < prev    next >
Encoding:
JavaScript  |  2002-05-01  |  18.1 KB  |  704 lines

  1.  
  2. // Copyright 2001-2002 Macromedia, Inc. All rights reserved. 
  3.  
  4.  
  5. //************************GLOBALS**************************
  6.  
  7. var helpDoc = MM.HELP_soFormFieldProps;
  8.  
  9. var _MenuGrid;
  10. var _ManualLayer;
  11. var _DatabaseLayer;
  12. var _ColumnText;
  13. var _ColumnValue;
  14. var _DefaultManual;
  15. var _DefaultDatabase;
  16. var _PopulateRadio;
  17. var _ElemUp, _ElemDown, _ElemAdd, _ElemDel;
  18. var _RecordsetName = new RecordsetMenu("InsertRecord.htm","RecordsetName");
  19. var _MenuLabels = new RecordsetFieldMenu("InsertRecord.htm", "MenuLabels", "", "_RecordsetName");
  20. var _MenuValues = new RecordsetFieldMenu("InsertRecord.htm", "MenuValues", "", "_RecordsetName");
  21.  
  22. // The following variable is need by the UI.  Setting here,
  23. //  rather than changing the UI file.
  24. var TF_DEFAULT_DATABASE = "";
  25.  
  26. //********************API FUNCTIONS**************************
  27. //--------------------------------------------------------------------
  28. // FUNCTION:
  29. //   commandButtons
  30. //
  31. // DESCRIPTION:
  32. //   Returns the list of buttons which should appear on the right hand
  33. //   side of the dialog
  34. //
  35. // ARGUMENTS:
  36. //   none
  37. //
  38. // RETURNS:
  39. //   Array - pairs of button name and function call
  40. //--------------------------------------------------------------------
  41. function commandButtons()
  42. {
  43.  
  44.   return new Array(MM.BTN_OK,    "clickedOK()",
  45.                    MM.BTN_Cancel,"clickedCancel()",
  46.                    MM.BTN_Help, "displayHelp()"); 
  47. }
  48.  
  49.  
  50. //--------------------------------------------------------------------
  51. // FUNCTION:
  52. //   displayHelp
  53. //
  54. // DESCRIPTION:
  55. //   This function is called when the user clicks the HELP button
  56. //
  57. // ARGUMENTS:
  58. //   none
  59. //
  60. // RETURNS:
  61. //   nothing
  62. //--------------------------------------------------------------------
  63.  
  64. function displayHelp()
  65. {
  66.   dwscripts.displayDWHelp(helpDoc);
  67. }
  68.  
  69.  
  70. //******************LOCAL FUNCTIONS**************************
  71.  
  72. //--------------------------------------------------------------------
  73. // FUNCTION:
  74. //   clickedOK
  75. //
  76. // DESCRIPTION:
  77. //   This function is called when the user clicks OK
  78. //
  79. // ARGUMENTS:
  80. //   none
  81. //
  82. // RETURNS:
  83. //   nothing
  84. //--------------------------------------------------------------------
  85. function clickedOK()
  86. {
  87.   if (_ManualLayer.visibility == "visible")
  88.   { 
  89.     // static menu object created
  90.     var allRows = _MenuGrid.list, nRows = allRows.length, currRowText, dividerInd;
  91.     var textArr = new Array(),valArr = new Array();
  92.  
  93.     for (i=0;i<nRows;i++)
  94.     {
  95.       currRowText = allRows[i];
  96.       dividerInd = currRowText.indexOf("|");
  97.       textArr.push(currRowText.substring(0,dividerInd));
  98.       valArr.push(currRowText.substring(dividerInd +1));
  99.     }
  100.  
  101.     MM.commandReturnValue = new eoMenu(textArr,valArr,_DefaultManual.value);
  102.   }
  103.   else
  104.   { 
  105.     // dynamic menu object created
  106.     dynMenuObj = new eoDynamicMenu();
  107.     dynMenuObj.recordset = _RecordsetName.getValue();
  108.     dynMenuObj.textCol = _MenuLabels.getValue();
  109.     dynMenuObj.valCol = _MenuValues.getValue();
  110.     dynMenuObj.defaultSelected = _DefaultDatabase.value;
  111.  
  112.     MM.commandReturnValue = dynMenuObj;
  113.   }
  114.  
  115.   clearUI();
  116.   window.close();
  117. }
  118.  
  119.  
  120. function clearUI()
  121. {
  122.   _MenuGrid.setAllRows(new Array(),new Array());
  123.   _ColumnText.value = "";
  124.   _ColumnValue.value = "";
  125.   _DefaultManual.value = ""; 
  126.   _DefaultDatabase.value = "";
  127.  
  128.   _ManualLayer.visibility="hidden";
  129.   _DatabaseLayer.visibility="hidden";
  130. }
  131.  
  132. //--------------------------------------------------------------------
  133. // FUNCTION:
  134. //   clickedCancel
  135. //
  136. // DESCRIPTION:
  137. //   This function is called when CANCEL is clicked
  138. //
  139. // ARGUMENTS:
  140. //   none
  141. //
  142. // RETURNS:
  143. //   nothing
  144. //--------------------------------------------------------------------
  145. function clickedCancel()
  146. {
  147.   MM.commandReturnValue = "";
  148. //  dwscripts.findDOMObject("RecordsetName").selectedIndex = _RecordsetName.listControl.getIndex();
  149. //  dwscripts.findDOMObject("MenuLabels").selectedIndex = _MenuLabels.listControl.getIndex();
  150. //  dwscripts.findDOMObject("MenuValues").selectedIndex = _MenuValues.listControl.getIndex();    
  151.   clearUI();
  152.   window.close();
  153. }
  154.  
  155. //--------------------------------------------------------------------
  156. // FUNCTION:
  157. //   initializeUI
  158. //
  159. // DESCRIPTION:
  160. //   This function is called in the onLoad event.  It is responsible
  161. //   for initializing the UI.
  162. //
  163. // ARGUMENTS:
  164. //   none
  165. //
  166. // RETURNS:
  167. //   nothing
  168. //--------------------------------------------------------------------
  169. function initializeUI()
  170. {
  171.   // Some callers pass just the type, some pass an array w/ type and display name
  172.   var menuInfoObj = MM.commandArgument;
  173.  
  174.   _ManualLayer   = document.layers["manualLayer"];
  175.   _DatabaseLayer = document.layers["databaseLayer"];
  176.  
  177.   _PopulateRadio = new RadioGroup("ServerObject-MenuProps", "Populate", "");
  178.   _PopulateRadio.initializeUI();
  179.   _MenuGrid = new TreeControlWithNavControls("MenuGrid",_ManualLayer,true);
  180.   _MenuGrid.setColumnNames(MM.LABEL_MenuGrid);
  181.  
  182.   _ColumnText = dwscripts.findDOMObject("MenuText",_ManualLayer);
  183.   _ColumnValue = dwscripts.findDOMObject("MenuValue",_ManualLayer);
  184.   _DefaultManual = dwscripts.findDOMObject("DefaultValueManual", _ManualLayer);
  185.  
  186.   var displayNameSpan = dwscripts.findDOMObject("RecordsetDisplayName", _DatabaseLayer);
  187.   displayNameSpan.innerHTML = dwscripts.getRecordsetDisplayName();
  188.  
  189.   _RecordsetName.initializeUI();
  190.   _MenuLabels.initializeUI();
  191.   _MenuValues.initializeUI();
  192.  
  193.   _DefaultDatabase = dwscripts.findDOMObject("DefaultValueDatabase",_DatabaseLayer);
  194.   TF_DEFAULT_DATABASE = _DefaultDatabase;
  195.  
  196.   _ElemUp = dwscripts.findDOMObject("elemUp");
  197.   _ElemDown = dwscripts.findDOMObject("elemDown");
  198.   _ElemAdd = dwscripts.findDOMObject("elemAdd");
  199.   _ElemDel = dwscripts.findDOMObject("elemDel");
  200.  
  201.   if (menuInfoObj.type == "menu" )
  202.   { 
  203.     // if a static menu
  204.     initManualLayer();
  205.     showDifferentLayer("manual");
  206.     _PopulateRadio.setIndex(0);
  207.     if (menuInfoObj.textArr != "" || menuInfoObj.defaultSelected != "")
  208.     { 
  209.       // strip the CFoutput tag...
  210.       menuInfoObj.defaultSelected = dwscripts.stripCFOutputTags(menuInfoObj.defaultSelected);          
  211.       // if there are prior values
  212.       var nOptions = menuInfoObj.textArr.length,i;
  213.       var gridDisplayArr = new Array();
  214.       var textArr = menuInfoObj.textArr;
  215.       var valArr  = menuInfoObj.valArr;
  216.       for (i=0;i<nOptions;i++)
  217.       {
  218.         gridDisplayArr[i] = textArr[i] + "|";
  219.         if (valArr[i])
  220.           gridDisplayArr[i] += valArr[i];
  221.       }
  222.  
  223.       if (gridDisplayArr.length && gridDisplayArr.length > 0)
  224.       {
  225.         _MenuGrid.setAllRows(gridDisplayArr);
  226.         _MenuGrid.setRowIndex(0);
  227.         displayGridValues();
  228.       }
  229.  
  230.       _ColumnText.focus();
  231.       if (_ColumnText.value != "")
  232.         _ColumnText.select();
  233.       _DefaultManual.value = menuInfoObj.defaultSelected;
  234.     }
  235. //    EnableDisableUpDownBtns();
  236. //    EnableDisableAddDelBtns();      
  237.   }
  238.   else
  239.   { 
  240.     // if a dynamic menu
  241.     _PopulateRadio.setIndex(1);
  242.     initDatabaseLayer();
  243.     showDifferentLayer('database');
  244.     if (menuInfoObj.recordset)
  245.     { 
  246.       updateColumns();
  247.       _DefaultDatabase.value = menuInfoObj.defaultSelected;
  248.     }
  249.   }
  250. }
  251.  
  252.  
  253. //--------------------------------------------------------------------
  254. // FUNCTION:
  255. //   initDatabaseLayer
  256. //
  257. // DESCRIPTION:
  258. //   This function is called in the onLoad event.  It is responsible
  259. //   for initializing the UI.
  260. //
  261. // ARGUMENTS:
  262. //   none
  263. //
  264. // RETURNS:
  265. //   nothing
  266. //--------------------------------------------------------------------
  267. function initDatabaseLayer()
  268. {
  269.   updateColumns();
  270.   _DefaultDatabase.value = "";
  271.   if (_DefaultManual.value != "")
  272.   {
  273.     _DefaultDatabase.value = _DefaultManual.value;
  274.   }
  275. }
  276.  
  277.  
  278. //--------------------------------------------------------------------
  279. // FUNCTION:
  280. //   addNewRow
  281. //
  282. // DESCRIPTION:
  283. //   This function is called in the onLoad event.  It is responsible
  284. //   for initializing the UI.
  285. //
  286. // ARGUMENTS:
  287. //   none
  288. //
  289. // RETURNS:
  290. //   nothing
  291. //--------------------------------------------------------------------
  292. function addNewRow()
  293. {
  294.   _MenuGrid.addRow(MM.LABEL_menuPropLabelPrefix + "|");
  295.   displayGridValues();
  296.   var newLabel = getUniqueLabel(MM.LABEL_menuPropLabelPrefix);
  297.   _ColumnText.value = newLabel;
  298.   updateGridRow();
  299.   _ColumnText.focus();
  300.   _ColumnText.select();
  301. //  EnableDisableUpDownBtns();
  302. //  EnableDisableAddDelBtns();   
  303. }
  304.  
  305. //--------------------------------------------------------------------
  306. // FUNCTION:
  307. //   delRow
  308. //
  309. // DESCRIPTION:
  310. //  This function deletes a row in the grid control.
  311. //
  312. // ARGUMENTS:
  313. //   none
  314. //
  315. // RETURNS:
  316. //   nothing
  317. //--------------------------------------------------------------------
  318. function delRow()
  319. {
  320.   _MenuGrid.delRow();
  321.   displayGridValues();
  322.   updateGridRow();  
  323. //  EnableDisableUpDownBtns();
  324. //  EnableDisableAddDelBtns();     
  325. }
  326.  
  327. //--------------------------------------------------------------------
  328. // FUNCTION:
  329. //   moveRowUp
  330. //
  331. // DESCRIPTION:
  332. //  This function moves the selected row up in the grid control.
  333. //
  334. // ARGUMENTS:
  335. //   none
  336. //
  337. // RETURNS:
  338. //   nothing
  339. //--------------------------------------------------------------------
  340. function moveRowUp()
  341. {
  342.   _MenuGrid.moveRowUp();
  343. //  EnableDisableUpDownBtns();
  344. //  EnableDisableAddDelBtns();       
  345. }
  346.  
  347. //--------------------------------------------------------------------
  348. // FUNCTION:
  349. //   moveRowDown
  350. //
  351. // DESCRIPTION:
  352. //  This function moves the selected row down in the grid control.
  353. //
  354. // ARGUMENTS:
  355. //   none
  356. //
  357. // RETURNS:
  358. //   nothing
  359. //--------------------------------------------------------------------
  360. function moveRowDown()
  361. {
  362.   _MenuGrid.moveRowDown();
  363. //  EnableDisableUpDownBtns();
  364. //  EnableDisableAddDelBtns();       
  365. }
  366.  
  367.  
  368. //--------------------------------------------------------------------
  369. // FUNCTION:
  370. //   initManualLayer
  371. //
  372. // DESCRIPTION:
  373. //   This function is called in the onLoad event.  It is responsible
  374. //   for initializing the UI.
  375. //
  376. // ARGUMENTS:
  377. //   none
  378. //
  379. // RETURNS:
  380. //   nothing
  381. //--------------------------------------------------------------------
  382. function initManualLayer()
  383. {
  384.   if (_MenuGrid.list.length == 0)
  385.   {
  386.     _DefaultManual.value = "";
  387.     addNewRow();
  388.     _MenuGrid.setRowIndex(0);
  389. //    EnableDisableUpDownBtns();
  390. //    EnableDisableAddDelBtns();    
  391.   }
  392.   else
  393.   {
  394.     if (_MenuGrid.list.length == 1 && _MenuGrid.getRow() == "|")
  395.     {
  396.       _MenuGrid.setRow(" |");
  397.       _MenuGrid.setRowIndex(0);
  398.     }
  399.     _ColumnText.focus();
  400.     _ColumnText.select();
  401.   }
  402.  
  403.   if (_DefaultDatabase.value !="")
  404.   {
  405.     _DefaultManual.value = _DefaultDatabase.value;
  406.   }
  407. }
  408.  
  409. //--------------------------------------------------------------------
  410. // FUNCTION:
  411. //   showDifferentLayer
  412. //
  413. // DESCRIPTION:
  414. //   This function is called in the onLoad event.  It is responsible
  415. //   for initializing the UI.
  416. //
  417. // ARGUMENTS:
  418. //   none
  419. //
  420. // RETURNS:
  421. //   nothing
  422. //--------------------------------------------------------------------
  423. function showDifferentLayer(whichOne)
  424. {
  425.   if (whichOne == 'database')
  426.   {
  427.     if (dwscripts.getRecordsetNames().length == 0)
  428.     {
  429.       alert (dwscripts.sprintf(MM.MSG_NeedRecordsetForOption, dwscripts.getRecordsetDisplayName()));
  430.       _PopulateRadio.setIndex(0);
  431.       return;
  432.     }
  433.     _ManualLayer.visibility   = "hidden";
  434.     _DatabaseLayer.visibility = "visible";
  435.     initDatabaseLayer();
  436.   }
  437.   else
  438.   {
  439.     _DatabaseLayer.visibility = "hidden";
  440.     _ManualLayer.visibility   = "visible";
  441.     initManualLayer();
  442.   }
  443.  
  444. }
  445.  
  446.  
  447. //--------------------------------------------------------------------
  448. // FUNCTION:
  449. //   updateGridRow
  450. //
  451. // DESCRIPTION:
  452. //   This function is called in the onLoad event.  It is responsible
  453. //   for initializing the UI.
  454. //
  455. // ARGUMENTS:
  456. //   none
  457. //
  458. // RETURNS:
  459. //   nothing
  460. //--------------------------------------------------------------------
  461. function updateGridRow()
  462. {
  463.   _MenuGrid.setRow(_ColumnText.value + "|" + _ColumnValue.value);
  464. }
  465.  
  466.  
  467. //--------------------------------------------------------------------
  468. // FUNCTION:
  469. //   displayGridValues
  470. //
  471. // DESCRIPTION:
  472. //   This function is called in the onLoad event.  It is responsible
  473. //   for initializing the UI.
  474. //
  475. // ARGUMENTS:
  476. //   none
  477. //
  478. // RETURNS:
  479. //   nothing
  480. //--------------------------------------------------------------------
  481. function displayGridValues()
  482. {
  483.   var currRow = _MenuGrid.getRow();
  484.   var dividerIndex = currRow.indexOf("|");
  485.   _ColumnText.value = currRow.substring( 0,dividerIndex);
  486.   _ColumnValue.value = currRow.substring(dividerIndex+1);
  487. //  EnableDisableUpDownBtns();
  488. //  EnableDisableAddDelBtns();   
  489. }
  490.  
  491.  
  492. //--------------------------------------------------------------------
  493. // FUNCTION:
  494. //   displayDynamicDataDialog
  495. //
  496. // DESCRIPTION:
  497. //   This function pops up the dialog allowing the user to choose 
  498. //   dynamic data
  499. //
  500. // ARGUMENTS:
  501. //   none
  502. //
  503. // RETURNS:
  504. //   nothing
  505. //--------------------------------------------------------------------
  506. function displayDynamicDataDialog(textFieldObj)
  507. {
  508.   var serverModel = dw.getDocumentDOM().serverModel.getServerName();
  509.   var expression = dw.showDynamicDataDialog(textFieldObj.value);
  510.  
  511.   if (expression)
  512.   {
  513.     if (serverModel == "Cold Fusion")
  514.     {
  515.       expression = dwscripts.stripCFOutputTags(expression);
  516.     }
  517.     textFieldObj.value = expression;
  518.   }
  519. }
  520.  
  521.  
  522. //--------------------------------------------------------------------
  523. // FUNCTION:
  524. //   updateColumns
  525. //
  526. // DESCRIPTION:
  527. //   This function pops up the dialog allowing the user to choose 
  528. //   dynamic data
  529. //
  530. // ARGUMENTS:
  531. //   none
  532. //
  533. // RETURNS:
  534. //   nothing
  535. //--------------------------------------------------------------------
  536. function updateColumns()
  537. {
  538.   _MenuLabels.updateUI();
  539.   _MenuValues.updateUI();   
  540. }
  541.  
  542.  
  543. //--------------------------------------------------------------------
  544. // FUNCTION:
  545. //   getUniqueLabel
  546. //
  547. // DESCRIPTION:
  548. //   This function pops up the dialog allowing the user to choose 
  549. //   dynamic data
  550. //
  551. // ARGUMENTS:
  552. //   none
  553. //
  554. // RETURNS:
  555. //   nothing
  556. //--------------------------------------------------------------------
  557. function getUniqueLabel()
  558. {
  559.   var label, i, num=1, isUnique;
  560.  
  561.   for (isUnique=false; !isUnique; num++)
  562.   {
  563.     label = TEXT_defaultItemText + num;
  564.     isUnique = true;
  565.     for (i=0; i<GarrMenuOptions.length && isUnique; i++)
  566.       if (GarrMenuOptions[i][0] == label) isUnique=false;
  567.   }
  568.   return label;
  569. }
  570.  
  571.  
  572. //--------------------------------------------------------------------
  573. // FUNCTION:
  574. //   getUniqueLabel
  575. //
  576. // DESCRIPTION:
  577. //   This function pops up the dialog allowing the user to choose 
  578. //   dynamic data
  579. //
  580. // ARGUMENTS:
  581. //   none
  582. //
  583. // RETURNS:
  584. //   nothing
  585. //--------------------------------------------------------------------
  586. function getUniqueLabel(baseName)
  587. {
  588.   var label, i, num=1, isUnique,rowText,menuLabel;
  589.  
  590.   for (isUnique=false; !isUnique; num++)
  591.   {
  592.     label = baseName + num; 
  593.     isUnique = true;
  594.     for (i=0; i<_MenuGrid.list.length && isUnique; i++)
  595.     {
  596.       rowText = _MenuGrid.list[i]; 
  597.       menuLabel = rowText.substring(0,rowText.indexOf("|"));
  598.       if (menuLabel == label) isUnique=false;
  599.     }
  600.   }
  601.   return label;
  602. }
  603.  
  604. //--------------------------------------------------------------------
  605. // FUNCTION:
  606. //   EnableDisableUpDownBtns
  607. //
  608. // DESCRIPTION:
  609. //   Enable/disables the elemUp and elemDown buttons
  610. //
  611. // ARGUMENTS:
  612. //   None
  613. //
  614. // RETURNS:
  615. //   Nothing
  616. //--------------------------------------------------------------------
  617. function EnableDisableUpDownBtns()
  618. {
  619.   // Check if there are any columns
  620.   if (_MenuGrid.list.length == 0 || _MenuGrid.getRowIndex() == -1)
  621.   {
  622.     _ElemUp.setAttribute("disabled", true);
  623.     _ElemUp.src = "../Shared/MM/Images/btnUp_dis.gif";   
  624.  
  625.     _ElemDown.setAttribute("disabled", true);
  626.     _ElemDown.src = "../Shared/MM/Images/btnDown_dis.gif";        
  627.   }
  628.   else
  629.   {
  630.     if(_MenuGrid.list.length == 1)
  631.       {
  632.       // first row, so disable the up and down buttons
  633.       _ElemDown.setAttribute("disabled", true);
  634.       _ElemDown.src = "../Shared/MM/Images/btnDown_dis.gif";
  635.  
  636.       _ElemUp.setAttribute("disabled", true);
  637.       _ElemUp.src = "../Shared/MM/Images/btnUp_dis.gif";
  638.     }
  639.     else if(_MenuGrid.list.length-1 == _MenuGrid.getRowIndex())
  640.     {
  641.       // last row, so disable the down button and enable the up button
  642.       _ElemDown.setAttribute("disabled", true);
  643.       _ElemDown.src = "../Shared/MM/Images/btnDown_dis.gif";
  644.  
  645.       _ElemUp.setAttribute("disabled", false);
  646.       _ElemUp.src = "../Shared/MM/Images/btnUp.gif";
  647.     }    
  648.     // first row, if it is disable up button and enable the down button
  649.     else if (_MenuGrid.getRowIndex() == 0)
  650.     {
  651.       _ElemUp.setAttribute("disabled", true);
  652.       _ElemUp.src = "../Shared/MM/Images/btnUp_dis.gif";
  653.  
  654.       _ElemDown.setAttribute("disabled", false);
  655.       _ElemDown.src = "../Shared/MM/Images/btnDown.gif";      
  656.     }
  657.     else
  658.     {
  659.       //enable both up and down buttons
  660.       _ElemDown.setAttribute("disabled", false);
  661.       _ElemDown.src = "../Shared/MM/Images/btnDown.gif";
  662.  
  663.       _ElemUp.setAttribute("disabled", false);
  664.       _ElemUp.src = "../Shared/MM/Images/btnUp.gif";      
  665.     }
  666.   }
  667. }
  668.  
  669.  
  670. //--------------------------------------------------------------------
  671. // FUNCTION:
  672. //   EnableDisableAddDelBtns
  673. //
  674. // DESCRIPTION:
  675. //   Enable/disables the elemAdd and elemDel buttons
  676. //
  677. // ARGUMENTS:
  678. //   None
  679. //
  680. // RETURNS:
  681. //   Nothing
  682. //--------------------------------------------------------------------
  683. function EnableDisableAddDelBtns()
  684. {
  685.   // if there is no selection, disable the del button and make sure you 
  686.   // enable the add button...
  687.   if (_MenuGrid.getRowIndex() == -1)
  688.   {
  689.     _ElemAdd.setAttribute("disabled", false);
  690.     _ElemAdd.src = "../Shared/MM/Images/btnAdd.gif";   
  691.  
  692.     _ElemDel.setAttribute("disabled", true);
  693.     _ElemDel.src = "../Shared/MM/Images/btnDel_dis.gif";        
  694.   }
  695.   else
  696.   {
  697.     _ElemAdd.setAttribute("disabled", false);
  698.     _ElemAdd.src = "../Shared/MM/Images/btnAdd.gif";   
  699.  
  700.     _ElemDel.setAttribute("disabled", false);
  701.     _ElemDel.src = "../Shared/MM/Images/btnDel.gif";          
  702.   }
  703. }
  704.