home *** CD-ROM | disk | FTP | other *** search
/ Flash MX Savvy / FlashMX Savvy.iso / pc / WIN / UltraDev / UltraDev_Trial.exe / Disk1 / data1.cab / Configuration_En / Commands / EditOpsCmn.js < prev    next >
Encoding:
JavaScript  |  2000-12-11  |  32.7 KB  |  1,007 lines

  1.  
  2. // Copyright 2000 Macromedia, Inc. All rights reserved.
  3.  
  4.     
  5. //**********************GLOBAL VARS********************
  6.  
  7. var PREFIX = "editOps_";
  8.  
  9. // participants -- stored as globals because the overhead of getting them can be high, and
  10. // some may be re-used
  11. var PART_TEXT, PART_TF,PART_TA, PART_CB, PART_DYN_CB, PART_RG,PART_DYN_RG;     
  12. var PART_SELECT,PART_OPTION,PART_DYN_MENU,PART_TR,PART_TR_RG,PART_TR_RB;     
  13. var PART_TR_TA,PART_TABLE,PART_BEGIN_LOOP,PART_END_LOOP,PART_CHECKED_ATTR;
  14. var PART_SELECTED_ATTR,PART_DYN_OPTION,PART_DYN_OP_NOSEL
  15.  
  16. var TEXTFIELD     =  MM.LABEL_TextField;
  17. var TEXTAREA      =  MM.LABEL_TextArea;
  18. var MENU          =  MM.LABEL_Menu;
  19. var CHECKBOX      =  MM.LABEL_CheckBox;
  20. var RADIOGROUP    =  MM.LABEL_RadioGroup;
  21. var TEXT          =  MM.LABEL_Text;
  22. var NUMERIC       =  MM.LABEL_Numeric;
  23. var DATE          =  MM.LABEL_Date;
  24. var DATEMSACCESS  =  MM.LABEL_DateMSAccess;
  25. var CHECKBOXYN    =  MM.LABEL_CheckBoxYN;
  26. var CHECKBOX10    =  MM.LABEL_CheckBox10;
  27. var CHECKBOXNEG10 =  MM.LABEL_CheckBoxNeg10;
  28. var CHECKBOXACCESS=  MM.LABEL_CheckBoxAccess;
  29.  
  30. var STR_DIVIDER = "* *";
  31. var STR_ELEMENT_NAMES = STR_DIVIDER;
  32.  
  33. var STR_CURR_RS = "";
  34.  
  35.  
  36. // stores separate file dom needed for dynamic UI
  37. var DOM_UI_PIECES = dw.getDocumentDOM("EditOpsAltHTML.htm"); 
  38.  
  39.  
  40. // global form widget variables
  41. var MENU_CONN, MENU_TABLES, MENU_DISPLAY, MENU_SUBMIT;
  42. var MENU_RS, MENU_COLS; // only for Update
  43. var TF_REDIRECT_URL, TF_LABEL, GRID_COLS, CB_NUMERIC;
  44.  
  45. var ARR_COLS_TO_ADD = new Array();
  46. var ARR_COL_TYPES = new Array();
  47. var EMPTY_LIST = new Array();
  48. var EDIT_OP_TYPE;
  49. var SUBMIT_BTN_TEXT = (EDIT_OP_TYPE == "Insert")?MM.BTN_InsertRecord:MM.BTN_UpdateRecord;
  50. var GROUP_DYN_DATA;
  51.  
  52. //********************API FUNCTIONS******************************    
  53.  
  54.  
  55. function commandButtons(){
  56.   return new Array(BTN_OK,       "okayClicked()",
  57.                    BTN_Cancel,   "cancelClicked()",
  58.                    BTN_Help,     "displayHelp()");
  59.  
  60. }
  61.  
  62.  
  63.  
  64. //********************LOCAL FUNCTIONS******************************    
  65.  
  66. function getCommandTitle(){
  67.   var titleStr = dw.getDocumentDOM().getElementsByTagName("TITLE").item(0).innerHTML;
  68.   
  69.   // strip starting white space
  70.   while ( titleStr[0] == " " )  titleStr = titleStr.substring(1); 
  71.   
  72.   return titleStr;
  73. }
  74.  
  75.  
  76.  
  77. function okayClicked(){
  78.   var conn = MMDB.getConnectionString(MENU_CONN.get());
  79.   var editOpTypeIsInsert = ( EDIT_OP_TYPE == "Insert" );
  80.   var rs = "",col="", colQuote, dom = dw.getDocumentDOM();
  81.   var table = MENU_TABLES.getValue();
  82.   var redirectURL   = (TF_REDIRECT_URL.value)?TF_REDIRECT_URL.value:"";
  83.   if ( !editOpTypeIsInsert ) {
  84.     rs  = MENU_RS.getValue();
  85.     col = MENU_COLS.getValue();
  86.     colQuote = (CB_NUMERIC.checked.toString() == "true")?"":"'";
  87.   }
  88.   
  89.   // check for error conditions
  90.   var errMsgStr = "";
  91.   if (!conn) {
  92.     errMsgStr = MM.MSG_NoConnection;
  93.   } else if (!table) {
  94.     errMsgStr = MM.MSG_NoTables;
  95.   } else if ( !editOpTypeIsInsert && !col) {
  96.     errMsgStr = MM.MSG_NoColumn;
  97.   }
  98.   if ( !editOpTypeIsInsert && !errMsgStr) {
  99.     // check that the selected column exists in the recordset
  100.     var colList = findAllColumnNames(MENU_RS.getValue()),i, found=true;
  101.     for (i=0, found=false; !found && i < colList.length; i++)
  102.       found = (colList[i].toLowerCase() == col.toLowerCase());  
  103.     if (!found) errMsgStr = MM.MSG_NoColumnInRS;
  104.   }
  105.  
  106.   // if error condition, alert it and return
  107.   if (errMsgStr){
  108.     alert (errMsgStr);
  109.     return;
  110.   }
  111.   
  112.   // if no error conditions, build the edits to apply to the document
  113.   MM.setBusyCursor();
  114.   // if cursor is inside of a form, set the selection so that the cursor is just outside
  115.   // of the form
  116.   checkThatCursorIsNotInsideOfAForm();
  117.   // call generic selection handling for non-object insertion
  118.   fixUpInsertionPoint();
  119.   
  120.   // create participant group to apply/insert into document
  121.   var formContent = createFormContent(GRID_COLS.valueList,rs,col);
  122.   var editOpsGroup = new Group( (editOpTypeIsInsert)?"insertRecord":"updateRecord" ); 
  123.   var customGroup = new Group();
  124.   var formActionPart = new Participant("editOps_formAttr"); 
  125.   var formPart = new Participant("editOps_form");
  126.   
  127.   customGroup.addParticipants(editOpsGroup.getParticipants("aboveHTML"));
  128.   
  129.   // comment out below line if using insertHTML
  130.   customGroup.addParticipants(Array(formPart));
  131.  
  132.  
  133.   // create parameter object used to provide variables for this edit op
  134.   // server behavior
  135.   var paramObj = new Object();
  136.   paramObj.table   = wrapNamesWithSpaces(table);
  137.   //paramObj.elemStr = determineElementsString();
  138.   setFieldsAndColumns(paramObj);
  139.   paramObj.redirect__url     = redirectURL;
  140.   paramObj.conn    = conn;
  141.   paramObj.username = (MENU_CONN.object) ? MMDB.getUserName(MENU_CONN.get()) : '';
  142.   paramObj.password = (MENU_CONN.object) ? MMDB.getPassword(MENU_CONN.get()) : '';
  143.   paramObj.driver   = (MENU_CONN.object) ? MMDB.getDriverName(MENU_CONN.get()) : '';  
  144.   if (!editOpTypeIsInsert){
  145.     paramObj.rs  = rs;
  146.     paramObj.col = col;
  147.     paramObj.colQuote = colQuote;
  148.   }
  149.   
  150.   paramObj.formContent = formContent;
  151.   paramObj.formAction  = killEndingWhiteSpace(formActionPart.getInsertString());
  152.   paramObj.formName    = makeUniqueName("FORM","form");
  153.   
  154.   // needed for connection participant
  155.   paramObj.cname   = (MENU_CONN.object) ? MENU_CONN.get() : '';
  156.   paramObj.relpath = getConnectionsPath(paramObj.cname);
  157.   paramObj.ext = getServerExtension();
  158.   
  159.   
  160.   // H: uncomment out below to use dw.insertHTML
  161.   //var formStr = formPart.getInsertString(paramObj);
  162.   //dom.insertHTML(formStr);
  163.   customGroup.apply(paramObj);
  164.   
  165.   MM.clearBusyCursor();
  166.   window.close();
  167.   
  168. }
  169.  
  170.  
  171. function cancelClicked(){
  172.   MM.commandReturnValue = "";
  173.   window.close();
  174. }
  175.  
  176. function initializeUI(){ 
  177.  
  178.    defineGlobalsBasedOnServerModel();
  179.    
  180.    // define global form elements
  181.    MENU_CONN   = new ListControl("Connection")
  182.    MENU_TABLES = new ListControl("TableToUpdate");
  183.    MENU_DISPLAY = new ListControl("DisplayAs");
  184.    MENU_SUBMIT = new ListControl("SubmitAs");
  185.    if (EDIT_OP_TYPE == "Update"){
  186.      MENU_RS = new ListControl("SelectRecordFrom");
  187.      MENU_COLS = new ListControl("UniqueKeyColumn");
  188.      CB_NUMERIC  = findObject("Numeric");
  189.    } 
  190.    TF_REDIRECT_URL  = findObject("GoToURL");
  191.    TF_LABEL    = findObject("ElementLabel");
  192.    GRID_COLS   = new GridWithNavControls("ColumnNames");
  193.    GRID_COLS.setColumnNames(MM.LABEL_ColGrid);
  194.  
  195.    // populate menus
  196.    var displayAsArr = new Array(TEXTFIELD,TEXTAREA,MENU,CHECKBOX,RADIOGROUP,TEXT);
  197.    var submitAsArr  = new Array(TEXT,NUMERIC,DATE,DATEMSACCESS,CHECKBOXYN,CHECKBOX10,CHECKBOXNEG10,CHECKBOXACCESS);
  198.    MENU_DISPLAY.setAll(displayAsArr,displayAsArr);
  199.    MENU_SUBMIT.setAll(submitAsArr,submitAsArr);
  200.    updateUI("populateConnectionList");
  201.  
  202.    // if "Update Record", then populate recordset list
  203.    if (EDIT_OP_TYPE == "Update"){ 
  204.      var rsNames = findAllRecordsetNames();
  205.      if (rsNames) {
  206.        MENU_RS.setAll(rsNames,rsNames);
  207.        STR_CURR_RS = MENU_RS.get();
  208.      } else {
  209.        MENU_RS.setAll(new Array(MM.LABEL_NoRecordsets), EMPTY_LIST);
  210.      }
  211.    }
  212.  
  213. }
  214.  
  215.  
  216. function updateUI(whichSection){ 
  217.   
  218.    switch (whichSection){
  219.      case "defineConnection":
  220.        var pickedValue = MENU_CONN.getValue();
  221.        MMDB.showConnectionMgrDialog()
  222.        updateUI("populateConnectionList");
  223.        break;
  224.          
  225.      case "populateConnectionList":
  226.        var connNames = MMDB.getConnectionList();
  227.        connNames.unshift(MM.LABEL_None);
  228.        if (connNames.length > 0) 
  229.          MENU_CONN.setAll(connNames,connNames);
  230.        else
  231.          MENU_CONN.setAll(new Array(MM.LABEL_NoConnections), EMPTY_LIST);
  232.        if (pickedValue)
  233.          MENU_CONN.pickValue(pickedValue);
  234.        updateUI("tableMenu");
  235.        break;
  236.       
  237.      case "tableMenu":
  238.        var tableNames = new Array(), tableName,i;
  239.        if (MENU_CONN.get() != MM.LABEL_None) {
  240.          var tableObjects = MMDB.getTables(MENU_CONN.get());
  241.          for (var i = 0; i < tableObjects.length; i++) {
  242.            var tableName = "";
  243.            if (tableObjects[i].schema != "") {
  244.              tableName = Trim(tableObjects[i].schema) + ".";
  245.            } else if (tableObjects[i].catalog != "") {
  246.              tableName = Trim(tableObjects[i].catalog) + ".";
  247.            }
  248.            tableName += tableObjects[i].table;
  249.            if (tableName) {
  250.              tableNames.push(tableName);
  251.            }
  252.          }
  253.        }
  254.        if (tableNames.length > 0) {
  255.          MENU_TABLES.setAll(tableNames,tableNames);
  256.          MENU_TABLES.setIndex(0);
  257.        }
  258.        else {
  259.          MENU_TABLES.setAll(new Array(MM.LABEL_NoTables), EMPTY_LIST);
  260.        }
  261.        updateUI('columnGrid');
  262.        break;
  263.         
  264.       case "RSHasChanged":
  265.         if (STR_CURR_RS != ""){
  266.           updateDefaultFormFieldValues(STR_CURR_RS,MENU_RS.getValue());
  267.           displayGridFieldValues();
  268.           STR_CURR_RS = MENU_RS.getValue();
  269.         }
  270.         break;
  271.         
  272.         
  273.       case "tableColList":
  274.         // check for checking numeric box here
  275.         var column = MENU_COLS.get();
  276.         if (ARR_COL_TYPES[column] != null) {
  277.           if (colTypeIsNumeric(ARR_COL_TYPES[column])) {
  278.             CB_NUMERIC.setAttribute("checked","true");
  279.           } else {
  280.             CB_NUMERIC.removeAttribute("checked");
  281.           }
  282.         }
  283.         break;
  284.         
  285.       case "columnGrid": 
  286.         // populate grid, and populate UI according to first grid item
  287.         populateColumnGrid();
  288.         displayGridFieldValues();
  289.         
  290.         // if Update, populate uniqueID menu
  291.        if (EDIT_OP_TYPE == "Update") {
  292.          var i, colArr = new Array();
  293.          for (i in ARR_COL_TYPES){
  294.            colArr.push(i);
  295.        }
  296.        if (colArr.length > 0)
  297.          MENU_COLS.setAll(colArr, colArr);
  298.        else
  299.          MENU_COLS.setAll(new Array(MM.LABEL_NoColumns), EMPTY_LIST); 
  300.        updateUI("tableColList");
  301.   }
  302.         break;     
  303.    
  304.       default:
  305.         break;
  306.  
  307.    }
  308. }
  309.  
  310.  
  311. function populateColumnGrid(){
  312.   // clear additional column list
  313.   // it lists columns that don't get populated in the grid, and needs to be cleared
  314.   updateAdditionalColumnList('clear'); 
  315.   
  316.   // if there are no tables, then clear grid, and return
  317.   if ( !connectionHasBeenChosen() ){
  318.     GRID_COLS.setAllRows(new Array(),new Array());
  319.     return;
  320.   }
  321.   
  322.   var colsAndTypes = MMDB.getColumnAndTypeOfTable(MENU_CONN.get(),MENU_TABLES.getValue())
  323.   var nColumns = colsAndTypes.length/2, rowInfo, i;
  324.   var rowTextArr = new Array();
  325.   var rowValArr  = new Array();
  326.   ARR_COL_TYPES = new Array();
  327.   
  328.   for (var i=0; i < colsAndTypes.length; i+=2) {
  329.      ARR_COL_TYPES[colsAndTypes[i]] = colsAndTypes[i+1];
  330.      if (EDIT_OP_TYPE == "Update") {
  331.        rowInfo = getRowTextAndValue(colsAndTypes[i],colsAndTypes[i+1],MENU_RS.get());
  332.      } else {  // if Insert (and recordset menu does not exist)
  333.        rowInfo = getRowTextAndValue(colsAndTypes[i],colsAndTypes[i+1]);
  334.      }
  335.      rowTextArr.push(rowInfo[0]);
  336.      rowValArr.push(rowInfo[1]);
  337.   }
  338.   
  339.   GRID_COLS.setAllRows(rowTextArr,rowValArr);
  340.   
  341.   // clear global field names array (used to check for dupe field names)
  342.   STR_ELEMENT_NAMES = STR_DIVIDER;
  343.   
  344.   
  345. }
  346.  
  347.  
  348. // Note: rsName is last parameter because it is only used for Update
  349. function getRowTextAndValue(colName,colType,rsName){
  350.   var rowValObj = new Object();
  351.   var rowText = "";
  352.  
  353.   
  354.   colLabel = getLabelFromColumnName(colName);
  355.   colFieldType = getFieldTypeFromColumnType(colType);
  356.   colSubmitType = getSubmitTypeFromColumnType(colType);
  357.   rowText = colName + "|" + colLabel + "|" + colFieldType + "|" + colSubmitType;
  358.       
  359.   rowValObj.column = colName;
  360.   rowValObj.label = colLabel;
  361.   rowValObj.displayAs = getFormFieldStorageObjectFromFormFieldType(colFieldType);
  362.   rowValObj.submitAs = colSubmitType;
  363.   rowValObj.fieldName = getElementNameFromColumnName(colName);
  364.   rowValObj.defaultStr = "";
  365.  
  366.   // populate storage object with any default values
  367.   if (EDIT_OP_TYPE == "Update"){
  368.     var rs = (rsName)?rsName:MENU_RS.getValue();
  369.     rowValObj = populateFormFieldStorageType(rowValObj,rs,colName);
  370.   }
  371.           
  372.   return new Array(rowText,rowValObj);
  373. }
  374.  
  375.  
  376. // note: this fn is only called when the row is first created, which is why
  377. // it only lists some of the available form types
  378. function populateFormFieldStorageType(rowValObj,rsName,colName){
  379.   var displayType = rowValObj.displayAs.type;
  380.   var dynDataVal = createDynamicData(rsName,colName);
  381.   rowValObj.defaultStr = dynDataVal;
  382.   
  383.   if  (displayType == "textField" || displayType  == "textArea") {
  384.     rowValObj.displayAs.value = dynDataVal;
  385.   } else if (displayType == "text" ){
  386.     rowValObj.displayAs.text = dynDataVal;
  387.   } else if (displayType == "dynamicCheckBox"){
  388.     rowValObj.displayAs.checkIf = dynDataVal;
  389.   }
  390.  
  391.   return rowValObj;
  392. }
  393.  
  394.  
  395. function getFormFieldStorageObjectFromFormFieldType(fieldType){
  396.   var retObj = "";
  397.     
  398.   if (fieldType == TEXT){
  399.     retObj = new eoText();
  400.   } else if (fieldType == TEXTFIELD){
  401.     retObj = new eoTextField();
  402.   } else if (fieldType == TEXTAREA){
  403.     retObj = new eoTextArea();
  404.   } else if (fieldType == MENU){
  405.     retObj = new eoMenu();
  406.   } else if (fieldType == RADIOGROUP){
  407.     retObj = new eoRadioGroup();
  408.   } else if (fieldType == CHECKBOX){
  409.     retObj = (EDIT_OP_TYPE == "Insert")?new eoCheckBox():new eoDynamicCheckBox();
  410.   } 
  411.  
  412.   return retObj;
  413. }
  414.  
  415.  
  416.  
  417. // function: showDifferentParams
  418. // description: shows form field specific parameters at the bottom of the dialog
  419. // for instance, shows "Menu Properties" button for menu, value field for textfield, etc.
  420.  
  421. function showDifferentParams(displayDefaultStr){
  422.   
  423.    // don't bother if connection has not been chosen
  424.    if ( !connectionHasBeenChosen() ){
  425.      return;
  426.    }
  427.    var displayAs = MENU_DISPLAY.getValue()?MENU_DISPLAY.getValue():"none";
  428.    var tables = DOM_UI_PIECES.getElementsByTagName("TABLE"), param, i;
  429.    var mmParamsTag = findObject("contentLayer").getElementsByTagName("mmParams").item(0);
  430.    
  431.    toggleSubmitAsVisibility(displayAs); // enable or disable Submit As Menu
  432.  
  433.    if (displayAs == TEXTFIELD || displayAs == TEXTAREA ) {
  434.      param = "textField";
  435.    } else if (displayAs == TEXT){
  436.      param = "text";
  437.    } else if (displayAs == RADIOGROUP){
  438.      param = "radio";
  439.    } else if (displayAs == MENU){
  440.      param = "menu";
  441.    } else if (displayAs == CHECKBOX){
  442.      param = (EDIT_OP_TYPE == "Insert") ? "checkBox" : "dynamicCheckBox";
  443.    } else if (displayAs == "none"){
  444.      param = "none";
  445.    }
  446.    
  447.    for (i=0;i<tables.length;i++){
  448.       if (tables[i].name && tables[i].name == param){
  449.          mmParamsTag.innerHTML = tables[i].innerHTML;
  450.          break;
  451.       }
  452.    }
  453.    // if display as equals text, text area, or text field, and the display as menu has
  454.    // just been changed, then display the default text for this column
  455.    if (displayDefaultStr) {
  456.      var rowInfoObj = GRID_COLS.getRowValue();
  457.      var defaultStr = GRID_COLS.getRowValue().defaultStr;
  458.      
  459.      if ( displayAs == TEXTFIELD || displayAs == TEXTAREA ) {
  460.          findObject("SetValueTo").value = rowInfoObj.displayAs.value = defaultStr;  // set UI
  461.      } else if ( displayAs == TEXT ) {
  462.          findObject("Text").value = rowInfoObj.displayAs.text = defaultStr;    // set UI
  463.      } else if ( param == "dynamicCheckBox" ){
  464.          findObject("CheckIf").value = rowInfoObj.displayAs.checkIf = defaultStr;
  465.      }
  466.    }
  467.     
  468. }
  469.  
  470. // function: updateGridRow
  471. // description: called whenever the label, submitAs, or displayAs fields are edited
  472. // updates both the actual text display in the grid, 
  473. // and the object that stores the information about the display
  474. // whichColumn: the parameter which has been edited -- displayAs, submitAs, or label
  475.  
  476. function updateGridRow(whichColumn){
  477.   // check that connection has been chosen before proceeding
  478.   if ( !connectionHasBeenChosen() ){
  479.     alert( MM.MSG_NoConnectionSelected );
  480.     // MENU_DISPLAY.setIndex(0); // set display menu back to first item
  481.     return;
  482.   }
  483.   
  484.   var currRowObj  = GRID_COLS.getRowValue();
  485.   var currRowText = GRID_COLS.getRow();
  486.   var currColName = currRowText.substring(  0,currRowText.indexOf("|")  );
  487.   
  488.   // update grid row text
  489.   var newRowText = currColName + "|" + TF_LABEL.value + "|" + MENU_DISPLAY.get() + "|"; 
  490.   newRowText += (findObject("SubmitAs")) ? MENU_SUBMIT.get() : "";
  491.   GRID_COLS.setRow(newRowText);
  492.   
  493.   // update object that stores information about grid row
  494.   // this object is stored in a value attribute of the Grid object
  495.   // these objects are stored in an array: GridObj.valueList
  496.   
  497.   switch (whichColumn){
  498.     case "label":
  499.       currRowObj.label = TF_LABEL.value;
  500.       break;
  501.       
  502.     case "submitAs":
  503.       currRowObj.submitAs = MENU_SUBMIT.get();
  504.       break;
  505.       
  506.     case "displayAs": 
  507.       currRowObj.displayAs = getFormFieldStorageObjectFromFormFieldType(MENU_DISPLAY.getValue());
  508.       // need to update submit property, because changing displayAs menu can
  509.       // auto-change submit type
  510.       if ( findObject("SubmitAs") ) {
  511.         currRowObj.submitAs = MENU_SUBMIT.getValue();
  512.       }
  513.       
  514.       var defaultStr = currRowObj.defaultStr;
  515.       var fieldType = currRowObj.displayAs.type
  516.       if ( fieldType == "textField" ||
  517.            fieldType == "textArea"){
  518.            currRowObj.displayAs.value = defaultStr;
  519.       } else if ( fieldType == "text"){
  520.            currRowObj.displayAs.text = defaultStr;
  521.       } else if ( fieldType == "menu"){
  522.            currRowObj.displayAs.defaultSelected = defaultStr;
  523.       } else if ( fieldType == "radioGroup"){
  524.            currRowObj.displayAs.defaultChecked = defaultStr;
  525.       } else if (fieldType == "dynamicCheckBox"){
  526.            currRowObj.displayAs.checkIf = defaultStr;
  527.       }
  528.       break;
  529.       
  530.     default:
  531.       break;
  532.   }
  533. }
  534.  
  535.  
  536. // function: displayGridFieldValues
  537. // description: called when the user clicks on a new row in the grid,
  538. // changes the values of the UI fields to display the correct information
  539.  
  540. function displayGridFieldValues(){ 
  541.   // don't bother if grid is empty -- needed because this fn is also
  542.   // called when the connection or table changes
  543.   if (GRID_COLS.list.length == 0){
  544.     TF_LABEL.value = "";
  545.     return;
  546.   }
  547.     
  548.    var currRowText = GRID_COLS.getRow();
  549.    var currRowVal  = GRID_COLS.getRowValue();
  550.    var rowTextTokens = getTokens(currRowText,"|");
  551.    
  552.    
  553.    TF_LABEL.value = rowTextTokens[1]; // update label field
  554.    MENU_DISPLAY.pickValue(rowTextTokens[2]); // update display menu
  555.    
  556.    // change UI at bottom of dialog, if relevent
  557.    // for instance, if prior row had displayAs = Text, but this row has displayAs = Menu
  558.    showDifferentParams(); 
  559.    
  560.    if (  findObject("SubmitAs")  ) 
  561.      MENU_SUBMIT.pickValue(rowTextTokens[3]); // update submit menu
  562.    
  563.    // fill in form parameters at bottom of UI
  564.    // note that in the case of radio or menu, there is nothing to fill in
  565.    switch (currRowVal.displayAs.type){
  566.      case "text":
  567.        findObject("Text").value = currRowVal.displayAs.text = currRowVal.defaultStr;
  568.        break;
  569.        
  570.      case "textArea":
  571.      case "textField":
  572.        findObject("SetValueTo").value = currRowVal.displayAs.value = currRowVal.defaultStr;
  573.        break;
  574.        
  575.      case "checkBox": 
  576.        // note: findObject doesn't work with radios, so manual references are needed
  577.        var InitialStateRadios = findObject("contentLayer").document.forms[0].InitialState;
  578.        if ( currRowVal.displayAs.checked.toString() == "true"){
  579.          InitialStateRadios[0].checked = true; InitialStateRadios[1].checked = false;
  580.        } else {
  581.          InitialStateRadios[0].checked = false; InitialStateRadios[1].checked = true;
  582.        }
  583.        break;
  584.        
  585.      case "dynamicCheckBox":
  586.        findObject("CheckIf").value = currRowVal.displayAs.checkIf;
  587.        findObject("EqualTo").value = currRowVal.displayAs.equalTo;
  588.        break;
  589.        
  590.      case "default":
  591.        break; 
  592.    }
  593.   
  594.    GRID_COLS.setRowIndex(GRID_COLS.getRowIndex());
  595. }
  596.  
  597.  
  598. // function: deleteGridRow
  599. // description: called when the user clicks the "--" image button
  600.  
  601. function deleteGridRow(){
  602.   var currRow = GRID_COLS.getRow();
  603.   var currCol = currRow.substring(0,currRow.indexOf("|") );
  604.   var nRows = GRID_COLS.list.length;
  605.   
  606.   if (nRows > 1){
  607.     updateAdditionalColumnList('add',currCol);
  608.     GRID_COLS.delRow();
  609.     displayGridFieldValues(); 
  610.   } else {
  611.     alert(MM.MSG_NeedOneColumnInList);
  612.   }
  613. }
  614.  
  615.  
  616. // function: addGridRow
  617. // description: if there are columns not already displayed in the grid
  618. // pop up the "Add Columns" dialog, and allow the user to add them
  619.  
  620. function addGridRow(){
  621.   // check to see if there are columns to add first
  622.   if (ARR_COLS_TO_ADD.length == 0){
  623.     alert(MM.MSG_NoMoreColumnsToAdd);
  624.     return;
  625.   }
  626.   
  627.   var colsToAdd = callCommand('Add Column.htm',ARR_COLS_TO_ADD);
  628.   if (!colsToAdd) return; // user clicked Cancel
  629.   var nCols = colsToAdd.length,i, currCol, rowInfoArr;
  630.   
  631.   for (i=0;i<nCols;i++){
  632.     currCol = colsToAdd[i];
  633.     rowInfoArr = getRowTextAndValue(currCol,ARR_COL_TYPES[currCol]);
  634.     GRID_COLS.addRow(rowInfoArr[0],rowInfoArr[1]);
  635.     updateAdditionalColumnList('del',currCol);
  636.   }
  637. }
  638.  
  639.  
  640. // function: updateAdditionalColumnList
  641. // description: the + button calls up an Add Columns dialog, allowing
  642. // the user to add additional columns to the list. When the Add Columns
  643. // dialog is called, it is populated with the "additional columns list".
  644. // This list is updated when a user adds or deletes a column from the UI.
  645. // The action argument can be add, del, or clear
  646.  
  647. function updateAdditionalColumnList(action,col){
  648.    var addColArr = ARR_COLS_TO_ADD; 
  649.    if (action == 'add'){
  650.       addColArr.push(col);
  651.    } else if ( action == 'clear'){
  652.       // addColArr.length = 0;
  653.       ARR_COLS_TO_ADD = new Array();
  654.    } else { // delete an item from additional column list
  655.      var nItems = addColArr.length,i;
  656.      
  657.      for (i=0;i<nItems;i++){
  658.        if (addColArr[i] == col){
  659.          addColArr.splice(i,1);
  660.          break;
  661.        }
  662.      }
  663.    }
  664. }
  665.  
  666.  
  667. // function: popUpFormFieldPropertiesDialog
  668. // description: pops up the Radio or Menu Properties dialog,
  669. // and passes in the current menu/radio storage object
  670. // so that the dialog can be initialized correctly
  671. // "whichOne" argument can be "Radio" or "Menu";
  672.  
  673. function popUpFormFieldPropertiesDialog(whichOne){
  674.   var commandFileName = whichOne + " Properties.htm";
  675.   var rowObj = GRID_COLS.getRowValue();
  676.   var fieldInfoObj = callCommand(commandFileName,rowObj.displayAs)
  677.  
  678.  
  679.   // note: use the "type" property on the menuInfoObj to see which
  680.   // type of object was returned
  681.   if (fieldInfoObj) {
  682.     rowObj.displayAs = fieldInfoObj;
  683.   }
  684. }
  685.  
  686.  
  687. function getFieldTypeFromColumnType(colType){
  688.   return ( colTypeIsBoolean(colType)) ? CHECKBOX : TEXTFIELD;
  689. }
  690.  
  691.  
  692. function getLabelFromColumnName(colName){
  693.   return colName.charAt(0).toUpperCase() + colName.substring(1) + MM.LABEL_Delimiter;      
  694. }
  695.  
  696. // function: getSubmitTypeFromColumnType
  697. // description: called when the grid is populated, to choose a submit type based
  698. // on the column type
  699. // Note: this function is used during initial population only.
  700. // changeSubmitTypeBasedOnElementType() is used when the element type is changed
  701.  
  702. function getSubmitTypeFromColumnType(colType){
  703.   var retVal = "";
  704.   var colIsNumeric = colTypeIsNumeric(colType);
  705.   var colIsDate    = colTypeIsDate(colType);
  706.   var colIsBoolean = colTypeIsBoolean(colType);
  707.   
  708.   if ( colIsNumeric ){
  709.     retVal = (colIsBoolean) ? CHECKBOX10 : NUMERIC;
  710.   } else if ( colIsDate ){
  711.     retVal = DATE;
  712.   } else { // if text-based
  713.     retVal = (colIsBoolean) ? CHECKBOXYN : TEXT;
  714.   }
  715.   return retVal;
  716.  
  717. }
  718.  
  719. function connectionHasBeenChosen(){
  720.   return ( MENU_CONN.getIndex() != 0 );
  721. }
  722.  
  723.  
  724. function setFieldsAndColumns(paramObj) {
  725.   var colInfoObjs = GRID_COLS.valueList, nCols = colInfoObjs.length, i, currObj;
  726.   var fieldsStr = "",columnsStr = "", submitType;
  727.   
  728.   // create mini-lookup table
  729.   var lookupTable = new Object();
  730.   lookupTable[TEXT]          = "',none,''";
  731.   lookupTable[NUMERIC]       = "none,none,NULL";
  732.   lookupTable[DATE]          = "',none,NULL";
  733.   lookupTable[DATEMSACCESS]  = "#,none,NULL";
  734.   lookupTable[CHECKBOXYN]    = "none,'Y','N'";
  735.   lookupTable[CHECKBOX10]    = "none,1,0";
  736.   lookupTable[CHECKBOXNEG10] = "none,-1,0";
  737.   lookupTable[CHECKBOXACCESS]= "none,Yes,No";
  738.   
  739.   for (i=0;i<nCols;i++){
  740.     currObj = colInfoObjs[i];
  741.     if (currObj.displayAs.type != "text"){ // if a form element
  742.       submitType = currObj.submitAs;  
  743.       fieldsStr += currObj.fieldName + "|value|";
  744.       columnsStr += wrapNamesWithSpaces(currObj.column) + "|" + lookupTable[submitType] + "|";
  745.     }
  746.   }
  747.   
  748.   // remove last separators
  749.   fieldsStr = fieldsStr.substring(0,fieldsStr.length-1);
  750.   columnsStr = columnsStr.substring(0,columnsStr.length-1);
  751.   
  752.   if (dw.getDocumentDOM() != null && 
  753.       dw.getDocumentDOM().serverModel.getServerName() == "Cold Fusion") {
  754.     fieldsStr = fieldsStr.replace(/#/g,"##");
  755.     columnsStr = columnsStr.replace(/#/g,"##");      
  756.   }
  757.   
  758.   paramObj.fieldsStr = fieldsStr;
  759.   paramObj.columnsStr = columnsStr;
  760. }
  761.  
  762.  
  763. // function: checkThatCursorIsNotInsideOfAForm
  764. // description: before inserting a form, check that cursor is not inside of 
  765. // an existing form. If it is, set IP location to be just after the form
  766.  
  767. function checkThatCursorIsNotInsideOfAForm(){
  768.   var dom = dw.getDocumentDOM();
  769.   var formNode = findForm(dom);
  770.   
  771.   if (formNode){ // if inside of a form tag
  772.     formArr = dom.nodeToOffsets(formNode);
  773.     dom.setSelection(formArr[1]+1,formArr[1]+1);
  774.   }
  775. }
  776.  
  777. function findForm(dom){
  778.   var formObj="";
  779.   var selArr = dom.getSelection();
  780.   var selObj = dom.offsetsToNode(selArr[0],selArr[1]);
  781.  
  782.   while (formObj=="" && selObj.parentNode){
  783.     if (selObj.nodeType == Node.ELEMENT_NODE && selObj.tagName=="FORM")
  784.     formObj=selObj;
  785.   else
  786.     selObj = selObj.parentNode;
  787.   }
  788.   
  789.   return formObj;
  790. }
  791.  
  792.  
  793. function changeSubmitTypeBasedOnElementType(){
  794.   
  795.   // don't bother if conection hasn't been chosen
  796.   if ( !connectionHasBeenChosen() ){
  797.     return;
  798.   }
  799.   
  800.   var elemType = MENU_DISPLAY.get();
  801.   var submitType = MENU_SUBMIT.get();
  802.   var newSubmitType = "";
  803.   var colType = ARR_COL_TYPES[ GRID_COLS.getRowValue().column ];
  804.   var colIsNumeric = colTypeIsNumeric(colType);
  805.   var colIsDate    = colTypeIsDate(colType);
  806.   
  807.   if ( elemType == CHECKBOX ) { // if display element is a checkbox
  808.     if (colIsNumeric)       
  809.       newSubmitType = CHECKBOX10;
  810.     else
  811.       newSubmitType = CHECKBOXYN;
  812.   } else { // display type does not equal checkbox
  813.   
  814.     // if submit type is currently a checkbox type,
  815.     // then change it back to the most appropriate
  816.     // non-checkbox type
  817.     
  818.     if (submitType==CHECKBOXYN    || submitType==CHECKBOX10 ||
  819.         submitType==CHECKBOXNEG10 || submitType == CHECKBOXACCESS) {
  820.         if (colIsNumeric) {
  821.           newSubmitType = NUMERIC;
  822.         } else if (colIsDate) {
  823.           newSubmitType = DATE;
  824.         } else {
  825.           newSubmitType = TEXT;
  826.         }
  827.     }
  828.   }
  829.   
  830.   if (newSubmitType)
  831.     MENU_SUBMIT.pickValue(newSubmitType);
  832.  
  833. }
  834.  
  835.  
  836.  
  837.  
  838. // function: toggleSubmitAsVisibility 
  839. // description: toggles the visibility of "Submit As: [menu]" that appears
  840. // on the UI.
  841. // This menu should be visible for all items except text
  842.  
  843. function toggleSubmitAsVisibility(displayAs){
  844.   var currentVal = MENU_SUBMIT.getValue();
  845.   if ( displayAs != TEXT && (currentVal == " " || !currentVal)) { // if any form field is chosen in displayAs menu
  846.       MENU_SUBMIT.enable();
  847.       MENU_SUBMIT.del();
  848.       var submitType = getSubmitTypeFromColumnType(ARR_COL_TYPES[GRID_COLS.getRowValue().column]);
  849.       MENU_SUBMIT.pickValue(submitType);
  850.   } else if (displayAs == TEXT)  { // if plain text was chosen in displayAs menu
  851.       MENU_SUBMIT.append(" ");
  852.       MENU_SUBMIT.disable();
  853.   }
  854. }
  855.  
  856. function updateUIBasedOnDisplayAsMenuChange(){
  857.   showDifferentParams(true);
  858.   changeSubmitTypeBasedOnElementType();
  859.   updateGridRow('displayAs')
  860. }
  861.  
  862.  
  863.  
  864. function getElementNameFromColumnName(col){
  865.   var elemName = col;
  866.   var counter = 2;
  867.   var divider = STR_DIVIDER;
  868.   
  869.   // replace spaces with underscores
  870.   var regExp = / /g;
  871.   elemName = elemName.replace(regExp,"_");
  872.   // strip out all characters that are not alpha-numeric, or underscores
  873.   regExp = /[^a-zA-Z_0-9]/g;
  874.   elemName = elemName.replace(regExp,"");
  875.   // don't allow the first character to be numeric
  876.   while (parseInt(elemName.charAt(0)) &&
  877.          parseInt(elemName.charAt(0) ) == elemName.charAt(0) ){
  878.      elemName = elemName.substring(1);
  879.   }
  880.  
  881.   // in the unlikely case that no characters are left after the above,
  882.   // then name element generically as "element"
  883.   if (elemName.length == 0) {
  884.     elemName = MM.LABEL_Element;
  885.   }
  886.  
  887.   // ensure that name is not a dupe
  888.   var tempName = elemName; 
  889.   while (STR_ELEMENT_NAMES.indexOf(divider + elemName + divider) != -1){
  890.     elemName = tempName + counter++;
  891.   }
  892.  
  893.   // add name to global names list
  894.   STR_ELEMENT_NAMES += elemName + divider;
  895.   
  896.   return elemName;
  897. }
  898.  
  899.  
  900.  
  901. // function: displayDynamicDataDialog
  902. // description: pops up the dialog allowing the user to choose dynamic data
  903. function displayDynamicDataDialog(textFieldObj){
  904.   var serverModel = dw.getDocumentDOM().serverModel.getServerName();
  905.   var expression = dw.showDynamicDataDialog(textFieldObj.value);
  906.   
  907.    if (expression) {
  908.      if (serverModel == "Cold Fusion") {
  909.        expression = stripCFOutput(expression);
  910.      }
  911.      textFieldObj.value = expression;
  912.    }
  913. }
  914.  
  915.  
  916. function createDynamicData(rs,col){
  917.   var paramObj = new Object();
  918.   paramObj.rsName = rs;
  919.   paramObj.bindingName = col;
  920.   
  921.   return ( GROUP_DYN_DATA.getInsertStrings(paramObj,"replaceSelection") );
  922. }
  923.  
  924. // go through the default values, and replace references to the old
  925. // recordset with the new recordset
  926. function updateDefaultFormFieldValues(oldRS,newRS){
  927.   var rowObjs = GRID_COLS.valueList;
  928.   var nRows = rowObjs.length, i, fieldType, currRowObj, regExp;
  929.   
  930.   for (i=0;i<nRows;i++){
  931.     currRowObj = rowObjs[i];
  932.     regExp = new RegExp(oldRS,"g");
  933.     currRowObj.defaultStr = currRowObj.defaultStr.toString().replace(regExp,newRS);
  934.  
  935.     // update the current display
  936.     switch(currRowObj.displayAs.type){
  937.       case "textField":
  938.       case "textArea":
  939.         currRowObj.displayAs.value = currRowObj.defaultStr;
  940.         break;
  941.       case "text":
  942.         currRowObj.displayAs.text = currRowObj.defaultStr;
  943.       case "radioGroup":
  944.       case "dynamicRadioGroup":
  945.         currRowObj.displayAs.defaultChecked = currRowObj.defaultStr;
  946.         break;
  947.       case "menu":
  948.       case "dynamicMenu":
  949.         currRowObj.displayAs.defaultSelected = currRowObj.defaultStr;
  950.         break;
  951.       case "dynamicCheckBox":
  952.         currRowObj.displayAs.checkIf = currRowObj.defaultStr;
  953.         break;
  954.       case "default":
  955.         break;  
  956.     }
  957.   } 
  958.  
  959. }
  960.  
  961.  
  962. function killEndingWhiteSpace(textStr){
  963.   var str = textStr;
  964.   while (  str.length > 0 &&
  965.            ( str.charAt( str.length - 1 ) == "\n" ||
  966.              str.charAt( str.length - 1 ) == "\r" ||
  967.              str.charAt( str.length - 1 ) == " " )) {    
  968.        
  969.                str = str.substring(0,str.length-1);  
  970.   }
  971.   
  972.   return str;
  973. }
  974.  
  975.  
  976. // function: defineGlobalsBasedOnServerModel
  977. // description: define global variables that depend on the server model
  978. function defineGlobalsBasedOnServerModel(){
  979.   PART_TEXT       =   new Participant(PREFIX + "text");   
  980.   PART_TF         =   new Participant(PREFIX + "textField");
  981.   PART_TA         =   new Participant(PREFIX + "textArea");  
  982.   PART_CB         =   new Participant(PREFIX + "checkBox");  
  983.   PART_DYN_CB     =   new Participant(PREFIX + "dynamicCheckBox");
  984.   PART_RG         =   new Participant(PREFIX + "radioGroup"); 
  985.   PART_DYN_RG     =   new Participant(PREFIX + "dynamicRadioGroup"); 
  986.   PART_SELECT     =   new Participant(PREFIX + "select");      
  987.   PART_OPTION     =   new Participant(PREFIX + "option");    
  988.   PART_DYN_OPTION =   new Participant("dynamicList_option");
  989.   PART_DYN_OP_NOSEL = new Participant("dynamicListNoSel_option");
  990.   PART_DYN_MENU   =   new Participant(PREFIX + "dynamicMenu"); 
  991.   PART_TR         =   new Participant(PREFIX + "tableRow");  
  992.   PART_TR_RG      =   new Participant(PREFIX + "radioGroupTableRow"); 
  993.   PART_TR_RB      =   new Participant(PREFIX + "radioButtonTableRow"); 
  994.   PART_TR_TA      =   new Participant(PREFIX + "textAreaTableRow"); 
  995.   PART_TABLE      =   new Participant(PREFIX + "table");    
  996.   PART_BEGIN_LOOP =   new Participant("dynamicList_begin");
  997.   PART_END_LOOP   =   new Participant("dynamicList_end");
  998.   PART_CHECKED_ATTR = new Participant("dynamicRadioButtons_attrib");
  999.   PART_SELECTED_ATTR = new Participant("dynamicList_attrib");
  1000.  
  1001.   GROUP_DYN_DATA = new Group("dynamicData");
  1002.  
  1003. }
  1004.  
  1005.  
  1006.  
  1007.