home *** CD-ROM | disk | FTP | other *** search
/ Practical Internet Web Designer 86 / PIWD86.iso / pc / contents / dreamweaver / software / dwmx2004.exe / Disk1 / data1.cab / Configuration_En / Commands / ServerObject-RadioProps.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  8.0 KB  |  338 lines

  1.  
  2. // Copyright 2001, 2002, 2003 Macromedia, Inc. All rights reserved. 
  3.  
  4. //************************GLOBALS**************************
  5.  
  6. var helpDoc = MM.HELP_soFormFieldProps;
  7.  
  8. var _MenuGrid;
  9. var _ColumnText;
  10. var _ColumnValue;
  11. var _DefaultManual;
  12.  
  13. //********************API FUNCTIONS**************************
  14.  
  15. //--------------------------------------------------------------------
  16. // FUNCTION:
  17. //   commandButtons
  18. //
  19. // DESCRIPTION:
  20. //   Returns the list of buttons which should appear on the right hand
  21. //   side of the dialog
  22. //
  23. // ARGUMENTS:
  24. //   none
  25. //
  26. // RETURNS:
  27. //   Array - pairs of button name and function call
  28. //--------------------------------------------------------------------
  29. function commandButtons()
  30. {
  31.  
  32.   return new Array(MM.BTN_OK,    "clickedOK()",
  33.                    MM.BTN_Cancel,"clickedCancel()",
  34.                    MM.BTN_Help,  "displayHelp()"); 
  35. }
  36.  
  37.  
  38. //--------------------------------------------------------------------
  39. // FUNCTION:
  40. //   displayHelp
  41. //
  42. // DESCRIPTION:
  43. //   This function is called when the user clicks the HELP button
  44. //
  45. // ARGUMENTS:
  46. //   none
  47. //
  48. // RETURNS:
  49. //   nothing
  50. //--------------------------------------------------------------------
  51.  
  52. function displayHelp()
  53. {
  54.   dwscripts.displayDWHelp(helpDoc);
  55. }
  56.  
  57.  
  58. //******************LOCAL FUNCTIONS**************************
  59.  
  60. //--------------------------------------------------------------------
  61. // FUNCTION:
  62. //   clickedOK
  63. //
  64. // DESCRIPTION:
  65. //   This function is called when the user clicks OK
  66. //
  67. // ARGUMENTS:
  68. //   none
  69. //
  70. // RETURNS:
  71. //   nothing
  72. //--------------------------------------------------------------------
  73. function clickedOK()
  74. {
  75.   // static radio object created
  76.   var allRows = _MenuGrid.list, nRows = allRows.length, currRowText, dividerInd;
  77.   var labelArr = new Array(),valArr = new Array();
  78.  
  79.   for (i=0;i<nRows;i++)
  80.   {
  81.     currRowText = allRows[i];
  82.     dividerInd = currRowText.indexOf("|");
  83.     labelArr.push(currRowText.substring(0,dividerInd));
  84.     valArr.push(currRowText.substring(dividerInd +1));
  85.   }
  86.  
  87.   MM.commandReturnValue = new eoRadioGroup(labelArr,valArr,_DefaultManual.value);
  88.   
  89.   clearUI();
  90.   window.close();
  91. }
  92.  
  93. //--------------------------------------------------------------------
  94. // FUNCTION:
  95. //   clickedCancel
  96. //
  97. // DESCRIPTION:
  98. //   This function is called when CANCEL is clicked
  99. //
  100. // ARGUMENTS:
  101. //   none
  102. //
  103. // RETURNS:
  104. //   nothing
  105. //--------------------------------------------------------------------
  106. function clickedCancel()
  107. {
  108.   MM.commandReturnValue = "";
  109.   clearUI();
  110.   window.close();
  111. }
  112.  
  113. function clearUI()
  114. {
  115.   _MenuGrid.setAllRows(new Array(),new Array());
  116.   _ColumnText.value = "";
  117.   _ColumnValue.value = "";
  118.   _DefaultManual.value = "";
  119. }
  120.  
  121. //--------------------------------------------------------------------
  122. // FUNCTION:
  123. //   initializeUI
  124. //
  125. // DESCRIPTION:
  126. //   This function is called in the onLoad event.  It is responsible
  127. //   for initializing the UI.
  128. //
  129. // ARGUMENTS:
  130. //   none
  131. //
  132. // RETURNS:
  133. //   nothing
  134. //--------------------------------------------------------------------
  135. function initializeUI()
  136. {
  137.   // Some callers pass just the type, some pass an array w/ type and display name
  138.   var radioGroupInfoObj = MM.commandArgument;
  139.  
  140.   _MenuGrid = new TreeControlWithNavControls("MenuGrid",null,true);
  141.   _MenuGrid.setColumnNames(MM.LABEL_RadioGrid);
  142.  
  143.   _ColumnText = dwscripts.findDOMObject("MenuText");
  144.   _ColumnValue = dwscripts.findDOMObject("MenuValue");
  145.   _DefaultManual = dwscripts.findDOMObject("DefaultValueManual");
  146.   
  147.  
  148.   if (radioGroupInfoObj.type == "radioGroup")
  149.   { 
  150.     // if a static radio group
  151.     if (_MenuGrid.list.length == 0)
  152.     {
  153.       _DefaultManual.value = "";
  154.       addNewRow();
  155.       _MenuGrid.setRowIndex(0);
  156.     }
  157.     else
  158.     {
  159.       if (_MenuGrid.list.length == 1 && _MenuGrid.getRow() == "|")
  160.       {
  161.         _MenuGrid.setRow(" |");
  162.         _MenuGrid.setRowIndex(0);
  163.       }
  164.       _ColumnText.focus();
  165.       _ColumnText.select();
  166.     }
  167.     
  168.     if (radioGroupInfoObj.labelArr != "" || radioGroupInfoObj.defaultChecked != "")
  169.     {
  170.        // strip the CFoutput tag...
  171.       radioGroupInfoObj.defaultChecked = dwscripts.stripCFOutputTags(radioGroupInfoObj.defaultChecked);      
  172.       // if there are prior values
  173.       var nOptions = radioGroupInfoObj.labelArr.length,i;
  174.       var gridDisplayArr = new Array();
  175.       var labelArr = radioGroupInfoObj.labelArr;
  176.       var valArr  = radioGroupInfoObj.valArr;
  177.       for (i=0;i<nOptions;i++)
  178.       {
  179.         gridDisplayArr[i] = labelArr[i] + "|";
  180.         if (valArr[i])
  181.           gridDisplayArr[i] += valArr[i];
  182.       }
  183.  
  184.       if (gridDisplayArr.length && gridDisplayArr.length > 0)
  185.       {
  186.         _MenuGrid.setAllRows(gridDisplayArr);
  187.         _MenuGrid.setRowIndex(0);
  188.         displayGridValues();
  189.       }
  190.  
  191.       _ColumnText.focus();
  192.       if (_ColumnText.value != "")
  193.         _ColumnText.select();
  194.       _DefaultManual.value = radioGroupInfoObj.defaultChecked;
  195.     }
  196.   }
  197. }
  198.  
  199. //--------------------------------------------------------------------
  200. // FUNCTION:
  201. //   addNewRow
  202. //
  203. // DESCRIPTION:
  204. //  This function adds a new row to the grid control
  205. //
  206. // ARGUMENTS:
  207. //   none
  208. //
  209. // RETURNS:
  210. //   nothing
  211. //--------------------------------------------------------------------
  212. function addNewRow()
  213. {
  214.   _MenuGrid.addRow(MM.LABEL_radioPropLabelPrefix + "|");
  215.   displayGridValues();
  216.   var newLabel = getUniqueLabel(MM.LABEL_radioPropLabelPrefix);
  217.   _ColumnText.value = newLabel;
  218.   updateGridRow();
  219.   _ColumnText.focus();
  220.   _ColumnText.select();
  221. }
  222.  
  223. //--------------------------------------------------------------------
  224. // FUNCTION:
  225. //   delRow
  226. //
  227. // DESCRIPTION:
  228. //  This function deletes a row in the grid control.
  229. //
  230. // ARGUMENTS:
  231. //   none
  232. //
  233. // RETURNS:
  234. //   nothing
  235. //--------------------------------------------------------------------
  236. function delRow()
  237. {
  238.   _MenuGrid.delRow();
  239.   displayGridValues();
  240.   updateGridRow();   
  241. }
  242.  
  243. //--------------------------------------------------------------------
  244. // FUNCTION:
  245. //   moveRowUp
  246. //
  247. // DESCRIPTION:
  248. //  This function moves the selected row up in the grid control.
  249. //
  250. // ARGUMENTS:
  251. //   none
  252. //
  253. // RETURNS:
  254. //   nothing
  255. //--------------------------------------------------------------------
  256. function moveRowUp()
  257. {
  258.   _MenuGrid.moveRowUp();
  259. }
  260.  
  261. //--------------------------------------------------------------------
  262. // FUNCTION:
  263. //   moveRowDown
  264. //
  265. // DESCRIPTION:
  266. //  This function moves the selected row down in the grid control.
  267. //
  268. // ARGUMENTS:
  269. //   none
  270. //
  271. // RETURNS:
  272. //   nothing
  273. //--------------------------------------------------------------------
  274. function moveRowDown()
  275. {
  276.   _MenuGrid.moveRowDown();
  277. }
  278.  
  279.  
  280. function updateGridRow()
  281. {
  282.   _MenuGrid.setRow(_ColumnText.value + "|" + _ColumnValue.value);
  283. }
  284.  
  285. function displayGridValues()
  286. {
  287.   var currRow = _MenuGrid.getRow();
  288.   var dividerIndex = currRow.indexOf("|");
  289.   _ColumnText.value = currRow.substring( 0,dividerIndex);
  290.   _ColumnValue.value = currRow.substring(dividerIndex+1);
  291. }
  292.  
  293.  
  294. // function: displayDynamicDataDialog
  295. // description: pops up the dialog allowing the user to choose dynamic data
  296. function displayDynamicDataDialog(textFieldObj)
  297. {
  298.   var serverModel = dw.getDocumentDOM().serverModel.getServerName();
  299.   var expression = dw.showDynamicDataDialog(textFieldObj.value);
  300.  
  301.   if (expression)
  302.   {
  303.     if (serverModel == "Cold Fusion")
  304.     {
  305.       expression = dwscripts.stripCFOutputTags(expression);
  306.     }
  307.     textFieldObj.value = expression;
  308.   }
  309. }
  310.  
  311. function updateColumns()
  312. {
  313.   _MenuLabels.updateUI();
  314.   _MenuValues.updateUI();   
  315.  
  316. }
  317.  
  318.  
  319.  
  320. function getUniqueLabel(baseName)
  321. {
  322.   var label, i, num=1, isUnique,rowText,menuLabel;
  323.  
  324.   for (isUnique=false; !isUnique; num++)
  325.   {
  326.     label = baseName + num;
  327.     isUnique = true;
  328.     for (i=0; i<_MenuGrid.list.length && isUnique; i++)
  329.     {
  330.       rowText = _MenuGrid.list[i];
  331.       menuLabel = rowText.substring(0,rowText.indexOf("|"));
  332.       if (menuLabel == label) isUnique=false;
  333.     }
  334.   }
  335.   return label;
  336. }
  337.  
  338.