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-InsRecCF.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  11.6 KB  |  418 lines

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