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-InsRecPHP.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  11.2 KB  |  407 lines

  1. // Copyright 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3.     
  4. //**********************GLOBAL VARS********************
  5.  
  6. var helpDoc = MM.HELP_objInsertRecord;
  7.  
  8. // stores separate file dom needed for dynamic UI
  9. var domUIPieces = dw.getDocumentDOM("ServerObject-FormEditHTML.htm"); 
  10.  
  11. // global form widget variables
  12. var _DisplayAs, _SubmitAs, _ElemUp, _ElemDown, _ElemAdd, _ElemDel;
  13. var _GoToURL, _ElementLabel, _ColumnNames;
  14.  
  15. var _ConnectionName = new ConnectionMenu("ServerObject-InsRecPHP.htm", "ConnectionName"); 
  16. var _TableName = new ConnectionTableMenu("ServerObject-InsRecPHP.htm", "TableName");
  17.  
  18. var ColumnsToAdd = new Array();  // the list of columns available for adding
  19. var ColumnTypes = new Array();
  20.  
  21. //********************API FUNCTIONS******************************
  22.  
  23. //--------------------------------------------------------------------
  24. // FUNCTION:
  25. //   commandButtons
  26. //
  27. // DESCRIPTION:
  28. //   Returns the list of buttons which should appear on the right hand
  29. //   side of the dialog
  30. //
  31. // ARGUMENTS:
  32. //   none
  33. //
  34. // RETURNS:
  35. //   Array - pairs of button name and function call
  36. //--------------------------------------------------------------------
  37. function commandButtons()
  38. {
  39.   return new Array(MM.BTN_OK,     "clickedOK()", 
  40.                    MM.BTN_Cancel, "clickedCancel()", 
  41.                    MM.BTN_Help,   "displayHelp()"); 
  42. }
  43.  
  44.  
  45. //--------------------------------------------------------------------
  46. // FUNCTION:
  47. //   canInsertObject
  48. //
  49. // DESCRIPTION:
  50. //   This function is called to determine if this object can be inserted
  51. //   into the current document.  It displays the relevant error messages,
  52. //   and then returns a boolean to indicate if insertion is possible.
  53. //
  54. //   NOTE: this function is called before initializeUI, so it should
  55. //         not rely on internal state.
  56. //
  57. // ARGUMENTS:
  58. //   none
  59. //
  60. // RETURNS:
  61. //   boolean
  62. //--------------------------------------------------------------------
  63. function canInsertObject()
  64. {
  65.   var retVal = true;
  66.  
  67.   var errMsgStr = "";
  68.  
  69.   if (errMsgStr)
  70.   {
  71.     alert (errMsgStr);
  72.     retVal = false;
  73.   }
  74.  
  75.   return retVal;
  76. }
  77.  
  78.  
  79.  
  80. //********************LOCAL FUNCTIONS****************************** 
  81.  
  82. //--------------------------------------------------------------------
  83. // FUNCTION:
  84. //   clickedOK
  85. //
  86. // DESCRIPTION:
  87. //   This function is called when the user clicks OK
  88. //
  89. // ARGUMENTS:
  90. //   none
  91. //
  92. // RETURNS:
  93. //   nothing
  94. //--------------------------------------------------------------------
  95. function clickedOK()
  96. {
  97.   var conn = _ConnectionName.getValue();
  98.   var table = _TableName.getValue();
  99.   var redirectURL   = (_GoToURL.value)?_GoToURL.value:"";
  100.   var nRows, i, currRowInfoObj, fieldInfoObj;
  101.   var sqlObj = new SQLStatement("");
  102.   var columnInfoList = new Array(), columnInfoNode, ElementStrArr = new Array();
  103.   var hiddenFieldNamesArr = new Array(), hiddenFieldValuesArr = new Array();
  104.  
  105.   rowInfoArr = _ColumnNames.valueList;
  106.   nRows = rowInfoArr.length;
  107.  
  108.   // check for error conditions
  109.   var errMsgStr = "";
  110.   if (!conn)
  111.   {
  112.     errMsgStr = MM.MSG_NoConnection;
  113.   }
  114.   else if (!table)
  115.   {
  116.     errMsgStr = MM.MSG_NoTables;
  117.   }
  118.   else if (!nRows)
  119.   {
  120.     errMsgStr = MM.Msg_NoColumnsInTable;
  121.   }   
  122.  
  123.   // if error condition, alert it and return
  124.   if (errMsgStr)
  125.   {
  126.     alert (errMsgStr);
  127.     return;
  128.   }
  129.     
  130.   // if no error conditions, build the edits to apply to the document
  131.   MM.setBusyCursor();
  132.  
  133.   // create parameter object used to provide variables for this edit op
  134.   // server behavior
  135.   var paramObj = new Object(); 
  136.  
  137.   paramObj.TableAlign   = "center";
  138.   // Get a unique form name...
  139.   var formName = dwscripts.getUniqueNameForTag("FORM","form");
  140.   paramObj.FormName = formName;
  141.     
  142.   for (i = 0; i < nRows; i++)
  143.   {
  144.     currRowInfoObj = rowInfoArr[i];
  145.     fieldInfoObj = currRowInfoObj.displayAs; 
  146.     var columnName = currRowInfoObj.column;
  147.     fieldInfoObj.fieldName = currRowInfoObj.fieldName;
  148.     if (currRowInfoObj.submitAs && columnName)
  149.     {
  150.       columnInfoNode = dwscripts.getColumnValueNode(); // get platform specific ColumnValueNode
  151.       columnInfoNode.setColumnName(columnName);
  152.       columnInfoNode.setColumnType(fieldInfoObj.type);
  153.       columnInfoNode.setVariableName(getVarNameFromFormField(fieldInfoObj.fieldName));
  154.       columnInfoNode.setSubmitAs(currRowInfoObj.submitAs);
  155.       columnInfoList.push(columnInfoNode);
  156.     }
  157.         
  158.     // handle the hidden fields
  159.     if (fieldInfoObj.type == "hiddenField")
  160.     {
  161.       hiddenFieldNamesArr.push(fieldInfoObj.fieldName);
  162.       hiddenFieldValuesArr.push(fieldInfoObj.value);
  163.     }  
  164.   }
  165.   
  166.   // Also push the Insert hidden field into the array...
  167.   hiddenFieldNamesArr.push("MM_insert");
  168.   hiddenFieldValuesArr.push(formName);
  169.   
  170.   paramObj.HiddenFieldName = hiddenFieldNamesArr;
  171.   paramObj.HiddenFieldValue = hiddenFieldValuesArr;
  172.   
  173.   // this will go through all the form elements and returns a string array...
  174.   ElementStrArr = createFormElementStrings(rowInfoArr);
  175.   
  176.   paramObj.ElementString = ElementStrArr;
  177.   paramObj.ButtonText = MM.BTN_InsertRecord;
  178.   
  179.   paramObj.Redirect_url = redirectURL;
  180.   paramObj.ConnectionName = conn;
  181.   paramObj.ConnectionPath = dwscripts.getConnectionURL(conn);
  182.    
  183.   var sqlVarList = sqlObj.createInsertStatement(table, columnInfoList);    
  184.   var sqlString = sqlObj.getStatement(true);
  185.   paramObj.SQLStatement = sqlString;
  186.   paramObj.SQLVariableList = sqlVarList.join(",\n                       ");
  187.  
  188.   // correct the selection
  189.   checkThatCursorIsNotInsideOfAForm();
  190.   dwscripts.setCursorOutsideParagraph();
  191.   dwscripts.fixUpSelection(dw.getDocumentDOM(), false, true);
  192.   
  193.   dwscripts.applyGroup("RecordInsertForm", paramObj);
  194.  
  195.   MM.clearBusyCursor();
  196.   window.close();
  197. }
  198.  
  199. //--------------------------------------------------------------------
  200. // FUNCTION:
  201. //   clickedCancel
  202. //
  203. // DESCRIPTION:
  204. //   This function is called when CANCEL is clicked
  205. //
  206. // ARGUMENTS:
  207. //   none
  208. //
  209. // RETURNS:
  210. //   nothing
  211. //--------------------------------------------------------------------
  212. function clickedCancel()
  213. {
  214.   MM.commandReturnValue = "";
  215.   window.close();
  216. }
  217.  
  218.  
  219. //--------------------------------------------------------------------
  220. // FUNCTION:
  221. //   displayHelp
  222. //
  223. // DESCRIPTION:
  224. //   Displays the built-in Dreamweaver help.
  225. //
  226. // ARGUMENTS:
  227. //   none
  228. //
  229. // RETURNS:
  230. //   nothing
  231. //--------------------------------------------------------------------
  232. function displayHelp()
  233. {
  234.   // Replace the following call if you are modifying this file for your own use.
  235.   dwscripts.displayDWHelp(helpDoc);
  236. }
  237.  
  238.  
  239.  
  240. //--------------------------------------------------------------------
  241. // FUNCTION:
  242. //   initializeUI
  243. //
  244. // DESCRIPTION:
  245. //   This function is called in the onLoad event.  It is responsible
  246. //   for initializing the UI.
  247. //
  248. // ARGUMENTS:
  249. //   none
  250. //
  251. // RETURNS:
  252. //   nothing
  253. //--------------------------------------------------------------------
  254. function initializeUI()
  255.   // define global form elements
  256.   _DisplayAs = new ListControl("DisplayAs");
  257.   _SubmitAs = new ListControl("SubmitAs");
  258.   _GoToURL  = dwscripts.findDOMObject("GoToURL");
  259.   _ElementLabel    = dwscripts.findDOMObject("ElementLabel");
  260.   _ColumnNames = new TreeControlWithNavControls("ColumnNames");
  261.   _ElemUp = dwscripts.findDOMObject("elemUp");
  262.   _ElemDown = dwscripts.findDOMObject("elemDown");
  263.   _ElemAdd = dwscripts.findDOMObject("elemAdd");
  264.   _ElemDel = dwscripts.findDOMObject("elemDel");
  265.   
  266.   
  267.   // initialize the form elements
  268.   _ConnectionName.initializeUI();
  269.   _TableName.initializeUI();
  270.  
  271.   _ColumnNames.setColumnNames(MM.LABEL_ColGrid);
  272.  
  273.   //EnableDisableUpDownBtns();
  274.   //EnableDisableAddDelBtns();
  275.   
  276.   var displayAsArr = new Array(TEXTFIELD,TEXTAREA,MENU,HIDDENFIELD,CHECKBOX,RADIOGROUP,PASSWORDFIELD,STATICTEXT);
  277.   _DisplayAs.setAll(displayAsArr,displayAsArr);
  278.   
  279.   _SubmitAs.init();  // get the values from the HTML
  280.  
  281.   elts = document.forms[0].elements;
  282.   if (elts && elts.length)
  283.   {
  284.     elts[0].focus();
  285.   }
  286. }
  287.  
  288.  
  289. //--------------------------------------------------------------------
  290. // FUNCTION:
  291. //   updateUI
  292. //
  293. // DESCRIPTION:
  294. //   This function is called by the UI controls to handle UI updates
  295. //
  296. // ARGUMENTS:
  297. //   control - string - the name of the control sending the event
  298. //   event - string - the event which is being sent
  299. //
  300. // RETURNS:
  301. //   nothing
  302. //--------------------------------------------------------------------
  303. function updateUI(control, event)
  304. {
  305.   if (control == "ConnectionName")
  306.   {
  307.     _TableName.updateUI(_ConnectionName, event); // this will trigger a recursive call to this function
  308.   }
  309.   else if (control == "TableName")
  310.   {
  311.     // clear additional column list
  312.     // it lists columns that don't get populated in the grid, and needs to be cleared
  313.     updateAdditionalColumnList('clear'); 
  314.  
  315.     // populate grid
  316.     populateColumnGrid();
  317.     
  318.     // clear global field names array (used to check for dupe field names)
  319.     STR_ELEMENT_NAMES = STR_DIVIDER;
  320.     
  321.     // populate UI according to first grid item
  322.     displayGridFieldValues();
  323.   }
  324.   else if (control == "AddRow")
  325.   {
  326.     addGridRow();
  327.     //EnableDisableUpDownBtns();
  328.     //EnableDisableAddDelBtns();
  329.   }
  330.   else if (control == "DeleteRow")
  331.   {
  332.     deleteGridRow();
  333.     //EnableDisableUpDownBtns();
  334.     //EnableDisableAddDelBtns();
  335.   }
  336.   else if (control == "MoveRowUp")
  337.   {
  338.     _ColumnNames.moveRowUp();
  339.     //EnableDisableUpDownBtns();
  340.   }
  341.   else if (control == "MoveRowDown")
  342.   {
  343.     _ColumnNames.moveRowDown();
  344.     //EnableDisableUpDownBtns();
  345.   }
  346.   else if (control == "ColumnNames")
  347.   {
  348.     displayGridFieldValues();
  349.   }
  350.   else if (control == "ElementLabel")
  351.   {
  352.     updateGridRow('label');
  353.   }
  354.   else if (control == "SubmitAs")
  355.   {
  356.     updateGridRow('submitAs');
  357.   }
  358.   else if (control == "DisplayAs")
  359.   {
  360.     showDifferentParams(true);
  361.  
  362.     var newSubmitType = getSubmitTypeBasedOnElementType
  363.       (_SubmitAs.getValue(),_DisplayAs.get(),ColumnTypes[ _ColumnNames.getRowValue().column ]);
  364.     _SubmitAs.pickValue(newSubmitType);
  365.  
  366.     updateGridRow('displayAs')
  367.   }
  368.   else if (control == "GoToURL")
  369.   {
  370.     var theRedirect_url = dw.browseForFileURL("select", MM.LABEL_FileRedirect,0,0); 
  371.     
  372.     if (theRedirect_url.length > 0)
  373.     {
  374.       // convert any script blocks to concat values
  375.       theRedirect_url = theRedirect_url.replace(/<\?php\s+(?:echo\s+)?/gi, "\" . ");
  376.       theRedirect_url = theRedirect_url.replace(/;?\s*\?>/gi, " . \"");
  377.       
  378.       _GoToURL.value = theRedirect_url;
  379.     }
  380.   }
  381. }
  382.  
  383. //--------------------------------------------------------------------
  384. // FUNCTION:
  385. //   getVarNameFromFormField
  386. //
  387. // DESCRIPTION:
  388. //   Prepare the php columnValueNode variable name based on form field name.
  389. //
  390. // ARGUMENTS:
  391. //   value - formFieldName
  392. //
  393. // RETURNS:
  394. //   string - php columnValueNode variable name
  395. //--------------------------------------------------------------------
  396. function getVarNameFromFormField(value)
  397. {
  398.   var varName = "";
  399.   if (value)
  400.   {
  401.     var paramInfo = dwscripts.getParameterCodeFromType(MM.LABEL_PHP_Param_Types[1], value);
  402.     varName = ((paramInfo) ? paramInfo.nameVal : "");
  403.   }
  404.   return varName;
  405. }
  406.