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 / Radio Properties.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  4.9 KB  |  178 lines

  1.  
  2. // Copyright 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved. 
  3.  
  4. //************************GLOBALS**************************
  5.  
  6. var helpDoc = MM.HELP_soFormFieldProps;
  7.  
  8. var EMPTY_LIST = new Array();
  9. var GRID_RADIO;
  10. var TF_RADIO_LABEL;
  11. var TF_RADIO_VALUE;
  12. var TF_DEFAULT_MANUAL;
  13.  
  14.  
  15. //********************API FUNCTIONS**************************
  16.  
  17. function commandButtons(){
  18.  
  19.    return new Array(MM.BTN_OK,    "okClicked()",
  20.                     MM.BTN_Cancel,"cancelClicked()",
  21.                     MM.BTN_Help, "displayHelp()"); 
  22. }
  23.  
  24.  
  25. //--------------------------------------------------------------------
  26. // FUNCTION:
  27. //   displayHelp
  28. //
  29. // DESCRIPTION:
  30. //   This function is called when the user clicks the HELP button
  31. //
  32. // ARGUMENTS:
  33. //   none
  34. //
  35. // RETURNS:
  36. //   nothing
  37. //--------------------------------------------------------------------
  38.  
  39. function displayHelp()
  40. {
  41.   dwscripts.displayDWHelp(helpDoc);
  42. }
  43.  
  44.  
  45. //******************LOCAL FUNCTIONS**************************
  46.  
  47. function okClicked(){
  48.   var allRows = GRID_RADIO.list, nRows = allRows.length, currRowText, dividerInd;
  49.   var labelArr = new Array(),valArr = new Array();
  50.  
  51.   for (i=0;i<nRows;i++){
  52.     currRowText = allRows[i];
  53.     dividerInd = currRowText.indexOf("|");
  54.     labelArr.push(currRowText.substring(0,dividerInd));
  55.     valArr.push(currRowText.substring(dividerInd +1));
  56.   }
  57.  
  58.   MM.commandReturnValue = new eoRadioGroup(labelArr,valArr,TF_DEFAULT_MANUAL.value);
  59.   
  60.   clearUI();
  61.   window.close();
  62. }
  63.  
  64. function cancelClicked(){
  65.   MM.commandReturnValue = "";
  66.   clearUI();
  67.   window.close();
  68. }
  69.  
  70. function clearUI(){
  71.   GRID_RADIO.setAllRows(new Array(),new Array());
  72.   TF_RADIO_LABEL.value = "";
  73.   TF_RADIO_VALUE.value = "";
  74.   TF_DEFAULT_MANUAL.value = "";
  75. }
  76.  
  77.  
  78. function initializeUI(){
  79.  
  80.   GRID_RADIO = new GridWithNavControls("MenuGrid",null,true);
  81.   GRID_RADIO.setColumnNames(MM.LABEL_RadioGrid);
  82.     
  83.   TF_RADIO_LABEL = findObject("MenuText");
  84.   TF_RADIO_VALUE = findObject("MenuValue");
  85.   TF_DEFAULT_MANUAL = findObject("DefaultValueManual");
  86.  
  87.   var radioGroupInfoObj = MM.commandArgument;
  88.   if (radioGroupInfoObj.type == "radioGroup"){ // if a static radio group
  89.     if (GRID_RADIO.list.length == 0){
  90.       TF_DEFAULT_MANUAL.value = "";
  91.       addNewRow();
  92.       GRID_RADIO.setRowIndex(0);
  93.     } else {
  94.       if (GRID_RADIO.list.length == 1 && GRID_RADIO.getRow() == "|"){
  95.         GRID_RADIO.setRow(" |");
  96.         GRID_RADIO.setRowIndex(0);
  97.       }
  98.       TF_RADIO_LABEL.focus();
  99.       TF_RADIO_LABEL.select();
  100.     }
  101.     
  102.     if (radioGroupInfoObj.labelArr != "" || radioGroupInfoObj.defaultChecked != ""){ // if there are prior values
  103.       var nOptions = radioGroupInfoObj.labelArr.length,i;
  104.       var gridDisplayArr = new Array();
  105.       var labelArr = radioGroupInfoObj.labelArr;
  106.       var valArr  = radioGroupInfoObj.valArr;
  107.       for (i=0;i<nOptions;i++){
  108.         gridDisplayArr[i] = labelArr[i] + "|";
  109.         if (valArr[i])
  110.           gridDisplayArr[i] += valArr[i];
  111.       }
  112.  
  113.       if (gridDisplayArr.length && gridDisplayArr.length > 0) {
  114.         GRID_RADIO.setAllRows(gridDisplayArr);
  115.         GRID_RADIO.setRowIndex(0);
  116.         displayGridValues();
  117.       }
  118.     
  119.       TF_RADIO_LABEL.focus();
  120.       if (TF_RADIO_LABEL.value != "")
  121.         TF_RADIO_LABEL.select();
  122.       TF_DEFAULT_MANUAL.value = radioGroupInfoObj.defaultChecked;
  123.     }
  124.   }
  125. }
  126.  
  127. function addNewRow(){
  128.   GRID_RADIO.addRow(MM.LABEL_radioPropLabelPrefix + "|");
  129.   displayGridValues();
  130.   var newLabel = getUniqueLabel(MM.LABEL_radioPropLabelPrefix);
  131.   TF_RADIO_LABEL.value = newLabel;
  132.   updateGridRow();
  133.   TF_RADIO_LABEL.focus();
  134.   TF_RADIO_LABEL.select();
  135. }
  136.  
  137.  
  138.  
  139. function updateGridRow(){
  140.    GRID_RADIO.setRow(TF_RADIO_LABEL.value + "|" + TF_RADIO_VALUE.value);
  141. }
  142.  
  143. function displayGridValues(){
  144.    var currRow = GRID_RADIO.getRow();
  145.    var dividerIndex = currRow.indexOf("|");
  146.    TF_RADIO_LABEL.value = currRow.substring( 0,dividerIndex);
  147.    TF_RADIO_VALUE.value = currRow.substring(dividerIndex+1);
  148. }
  149.  
  150.  
  151. // function: displayDynamicDataDialog
  152. // description: pops up the dialog allowing the user to choose dynamic data
  153. function displayDynamicDataDialog(textFieldObj){
  154.   var serverModel = dw.getDocumentDOM().serverModel.getServerName();
  155.   var expression = dw.showDynamicDataDialog(textFieldObj.value);
  156.   
  157.    if (expression) {
  158.      if (serverModel == "Cold Fusion") {
  159.        expression = stripCFOutput(expression);
  160.      }
  161.      textFieldObj.value = expression;
  162.    }
  163. }
  164.  
  165. function getUniqueLabel(baseName) {
  166.   var label, i, num=1, isUnique,rowText,menuLabel;
  167.  
  168.   for (isUnique=false; !isUnique; num++) {
  169.     label = baseName + num;
  170.     isUnique = true;
  171.     for (i=0; i<GRID_RADIO.list.length && isUnique; i++) {
  172.       rowText = GRID_RADIO.list[i];
  173.       menuLabel = rowText.substring(0,rowText.indexOf("|"));
  174.       if (menuLabel == label) isUnique=false;
  175.     }
  176.   }
  177.   return label;
  178. }