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-MastDetailPHP.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  21.1 KB  |  749 lines

  1. // Copyright 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3. var HELP_DOC = MM.HELP_objMasterDetail;
  4.  
  5. var _RecordsetName = new RecordsetMenu("","RecordsetName");
  6. var _MasterPageFields = new RecordsetFieldsOrderedList("MasterDetail.htm", "MasterPageFields", "");
  7. var _LinkField = new RecordsetFieldMenu("MasterDetail.htm", "LinkField", "");
  8. var _UniqueKeyField = new RecordsetFieldMenu("MasterDetail.htm", "UniqueKeyField", "");
  9. var _NumRecs = new NumRecButtons("MasterDetail.htm", "NumRecs", "");
  10. var _DetailPageName = new URLTextField("MasterDetail.htm", "DetailPageName", "");
  11. var _DetailPageFields = new RecordsetFieldsOrderedList("MasterDetail.htm", "DetailPageFields", "");
  12.  
  13.  
  14. var _documentTypeID = "";
  15.  
  16. //--------------------------------------------------------------------
  17. // FUNCTION:
  18. //   commandButtons
  19. //
  20. // DESCRIPTION:
  21. //   API function for commands. Controls dialog buttons.
  22. //
  23. // ARGUMENTS:
  24. //   none
  25. //
  26. // RETURNS:
  27. //   an array of button names and function calls
  28. //--------------------------------------------------------------------
  29. function commandButtons()
  30. {
  31.   return new Array(MM.BTN_OK,      "clickedOK()",
  32.                    MM.BTN_Cancel,  "window.close()",
  33.                    MM.BTN_Help,    "displayHelp()");
  34. }
  35.  
  36.  
  37.  
  38. //--------------------------------------------------------------------
  39. // FUNCTION:
  40. //   createMasterDetailSet
  41. //
  42. // DESCRIPTION:
  43. //   Inserts the content into the master and detail pages.
  44. //
  45. //   In this implementation, this function is responsible for all
  46. //   insertion work.
  47. //
  48. // ARGUMENTS:
  49. //   paramObj. Contains properties:
  50. //     RecordsetName -- string
  51. //     MasterPageFields -- array
  52. //     DetailPageFields -- array
  53. //     LinkToField -- string
  54. //     UniqueIDField -- string
  55. //     DetailPagePath -- string, relative path from master page
  56. //     DetailPageName -- string, file name only
  57. //     PageSize -- string or number, "all" or positive integer
  58. //
  59. // RETURNS:
  60. //   string - empty upon success, or an error message
  61. //--------------------------------------------------------------------
  62. function createMasterDetailSet(paramObj)
  63. {
  64.   var docURL = dw.getDocumentPath('document');
  65.   var siteURL = dw.getSiteRoot();
  66.   var detailPageName = paramObj.DetailPageName;
  67.   var detailPageAbsURL = dwscripts.getAbsoluteURL(detailPageName,docURL,siteURL);
  68.   var uniqueIDField = paramObj.UniqueIDField;
  69.   _documentTypeID = dw.getDocumentDOM().documentType;
  70.  
  71.   // add recordset parameters. Looks for the recordset paramObj.RecordsetName,
  72.   // and adds its parameters to paramObj
  73.   getRecordsetParameters(paramObj);
  74.   
  75.   paramObj.AddQueryString = "QueryString";
  76.  
  77.   // hava: genericize this so that it is not platform-specific...
  78.   //for retrieving the tabelname in order to get the columntype"
  79.   
  80.   var sqlStatement=paramObj.SQLStatement.toLowerCase();
  81.   var index=sqlStatement.indexOf("from");
  82.   var index=sqlStatement.indexOf(" ",index+3);
  83.   var endIndex=sqlStatement.indexOf(" ",index+1);
  84.   if(endIndex==-1)
  85.       var tableName=sqlStatement.substring(index);
  86.   else    
  87.       var tableName=sqlStatement.substring(index,endIndex);
  88.   var colsAndTypes = dwscripts.getColumnValueList(paramObj.ConnectionName,tableName);
  89.   var columnType="";
  90.   for(var i=0;i<colsAndTypes.length;++i) {
  91.     if(colsAndTypes[i].getColumnName() == uniqueIDField) {
  92.       columnType=colsAndTypes[i].getColumnType();
  93.       break;
  94.     } 
  95.   }
  96.   var urlVar = (!dwscripts.isStringDBColumnType(columnType))?"$recordID":"'" + "$recordID" + "'";
  97.   var conditionStr = paramObj.UniqueIDField + " = " + urlVar;
  98.  
  99.   // new SQL statement used in detail page recordset
  100.   paramObj.SQLStatement = editWhereClause(paramObj.SQLStatement,conditionStr);
  101.  
  102.   // add navigation bar parameters
  103.   paramObj.FirstLinkText = MM.LABEL_NewMoveToFirstLinkLabel;
  104.   paramObj.PrevLinkText  = MM.LABEL_NewMoveToPrevLinkLabel;
  105.   paramObj.NextLinkText  = MM.LABEL_NewMoveToNextLinkLabel;
  106.   paramObj.LastLinkText  = MM.LABEL_NewMoveToLastLinkLabel;
  107.  
  108.   // add navigation statistic parameters
  109.   paramObj.beforeFirst = MM.LABEL_RSNavBeforeFirst;
  110.   paramObj.beforeLast  = MM.LABEL_RSNavBeforeLast;
  111.   paramObj.beforeTotal = MM.LABEL_RSNavBeforeTotal;
  112.   paramObj.afterTotal  = MM.LABEL_RSNavAfterTotal;
  113.   paramObj.total = MM.LABEL_RSNavTotal;
  114.   
  115.   if (!dwscripts.selectionIsInBody())
  116.   {
  117.     dwscripts.setCursorToEndOfBody();
  118.   }
  119.  
  120.   // insert content into master page, which is the currently open page
  121.   if (paramObj.PageSize) 
  122.     extGroup.queueDocEdits("MasterPageNumRecs",paramObj,null);
  123.   else
  124.     extGroup.queueDocEdits("MasterPageAllRecs",paramObj,null);
  125.   dwscripts.applyDocEdits();
  126.  
  127.  
  128.   // create new or open existing detail page, and prep for insertion
  129.   createAndPrepDetailPage(detailPageName,detailPageAbsURL);
  130.  
  131.   // create unique name for the detail page recordset
  132.   // Note: the below line of code  *must* be placed at a point
  133.   // in the workflow where the Detail Page already has the focus.
  134.   paramObj.RecordsetName = getUniqueRecordsetName();
  135.  
  136.   // insert detail page content into detail page, which is currently open
  137.   extGroup.queueDocEdits("DetailPage",paramObj,null);
  138.   dwscripts.applyDocEdits();
  139.   createLiveDataSettings(); // allow detail page to be viewed with Live Data
  140.  
  141.   // switch focus back to Master Page
  142.   dw.openDocument(docURL);
  143.  
  144.  
  145.   return "";
  146.  
  147. }
  148.  
  149. //--------------------------------------------------------------------
  150. // FUNCTION:
  151. //   createLiveDataSettings
  152. //
  153. // DESCRIPTION:
  154. //   sets the recordID variable to 1 so that page can be previewed
  155. //   from within the application
  156. //
  157. // ARGUMENTS:
  158. //   none
  159. //
  160. // RETURNS:
  161. //   nothing
  162. //--------------------------------------------------------------------
  163. function createLiveDataSettings(detailPageObj)
  164. {
  165.   // NOTE: This is currently Cold Fusion specific
  166.   var str =  "recordID=1";
  167.   dw.setLiveDataParameters(str);
  168. }
  169.  
  170. //--------------------------------------------------------------------
  171. // FUNCTION:
  172. //   clickedOK
  173. //
  174. // DESCRIPTION:
  175. //   verifies data and alerts err msg if invalid.
  176. //   if valid, sets value of MM.cmdReturnValue to parameters and
  177. //   closes dialog
  178. //
  179. // ARGUMENTS:
  180. //   none
  181. //
  182. // RETURNS:
  183. //   an array of button names and function calls
  184. //--------------------------------------------------------------------
  185. function clickedOK()
  186. {
  187.  
  188.   var errMsg = "";
  189.   var detailPageName = _DetailPageName.getValue();
  190.   var masterPageName = dwscripts.getFileName(dw.getDocumentPath("document"));
  191.   var rsName = _RecordsetName.getValue();
  192.   var numRecs = _NumRecs.getValue();
  193.  
  194.   // check that all parameter values are valid
  195.  
  196.   // check detail page name
  197.   if (   !detailPageName || detailPageName.charAt(0) == " "
  198.       || detailPageName.indexOf("/") != -1 
  199.       || (detailPageName.indexOf(".") == 0) 
  200.       || (detailPageName.indexOf(".") == detailPageName.length - 1)
  201.      )
  202.   {
  203.     errMsg = MM.MSG_invalidDetailPageName;
  204.   }
  205.   
  206.   if (!errMsg)
  207.   {
  208.     if (   (detailPageName == masterPageName) 
  209.         || (masterPageName.indexOf(detailPageName + ".") == 0)
  210.        )
  211.     {
  212.       errMsg = MM.MSG_NeedUniqueDetailPageName;
  213.     }
  214.   }
  215.  
  216.   if (!errMsg) // check number of records validity
  217.   {
  218.     errMsg = _NumRecs.applyServerBehavior();
  219.   }
  220.   
  221.   if (!errMsg)
  222.   {
  223.     if (numRecs != "3")
  224.     {
  225.       var sbObj = sbUtils.getRepeatRegionWithPageNav(rsName, true);
  226.       if (sbObj != null)
  227.       {
  228.         errMsg = MM.MSG_RepeatRegionWithPageNavExists;
  229.       }
  230.     }
  231.   }
  232.  
  233.   if (!errMsg) // check that valid columns exist
  234.   {
  235.     var masterFields = _MasterPageFields.getValue();
  236.  
  237.     if((masterFields.length == 0) ||
  238.        (masterFields.length == 1 && masterFields[0].indexOf("MM_ERROR")!=-1))
  239.     {
  240.       errMsg = MM.MSG_columnsEmpty;
  241.     }
  242.   }
  243.   if (!errMsg) 
  244.   {
  245.     // PHP requires that we modify the recordset code when using 
  246.     // PHP repeat region, the following code modifies the recordset 
  247.     // so that it contains a new SQL statement that has limit functionality.  
  248.     var sbRecordset = dwscripts.getServerBehaviorByParam("Recordset.htm","RecordsetName",_RecordsetName.getValue());
  249.     if (sbRecordset)
  250.     {
  251.       var newRS = sbRecordset.makeEditableCopy() ;
  252.  
  253.       if (_NumRecs.getValue() != "all")
  254.       {
  255.         newRS.setPageSize(_NumRecs.getValue());
  256.         newRS.queueDocEdits();
  257.       }
  258.       else
  259.       {
  260.         newRS.updatePageSize(sbObj);
  261.         newRS.queueDocEdits();
  262.       }
  263.     }
  264.   }
  265.  
  266.   if (errMsg)
  267.   {
  268.     alert(errMsg);
  269.     var urlField = dwscripts.findDOMObject('DetailPageName');
  270.       urlField.focus();
  271.   }
  272.   else
  273.   {
  274.     paramObj = new Object();
  275.     paramObj.RecordsetName = _RecordsetName.getValue();
  276.     paramObj.MasterPageFields = _MasterPageFields.getValue();
  277.     paramObj.DetailPageFields = _DetailPageFields.getValue();
  278.     paramObj.LinkToField = _LinkField.getValue();
  279.     paramObj.UniqueIDField = _UniqueKeyField.getValue();
  280.     paramObj.DetailPageName = addExtensionToFileName(detailPageName);
  281.     paramObj.PageSize = (_NumRecs.getValue() =="all") ? "":_NumRecs.getValue();
  282.     //paramObj.Numeric = _Numeric.getCheckedState();
  283.  
  284.     MM.cmdReturnValue.push(paramObj);
  285.  
  286.     window.close();
  287.   }
  288. }
  289.  
  290.  
  291.  
  292. //--------------------------------------------------------------------
  293. // FUNCTION:
  294. //   initializeUI
  295. //
  296. // DESCRIPTION:
  297. //   Prepare the dialog and controls for user input
  298. //
  299. // ARGUMENTS:
  300. //   none
  301. //
  302. // RETURNS:
  303. //   nothing
  304. //--------------------------------------------------------------------
  305. function initializeUI()
  306. {
  307.   var elts;
  308.  
  309.   _RecordsetName.initializeUI();
  310.   _MasterPageFields.initializeUI();
  311.   _LinkField.initializeUI();
  312.   _UniqueKeyField.initializeUI();
  313.   _NumRecs.initializeUI();
  314.   _DetailPageName.initializeUI();
  315.   _DetailPageFields.initializeUI();
  316.   
  317.  
  318.   elts = document.forms[0].elements;
  319.   if (elts && elts.length)
  320.     elts[0].focus();
  321. }
  322.  
  323.  
  324.  
  325. //-------------------------------------------------------------------
  326. // FUNCTION:
  327. //   displayHelp
  328. //
  329. // DESCRIPTION:
  330. //   displays appropriate help file
  331. //
  332. // ARGUMENTS:
  333. //   none
  334. //
  335. // RETURNS:
  336. //   nothing
  337. //--------------------------------------------------------------------
  338. function displayHelp()
  339. {
  340.   dwscripts.displayDWHelp(HELP_DOC);
  341. }
  342.  
  343.  
  344.  
  345. //--------------------------------------------------------------------
  346. // FUNCTION:
  347. //   updateUI
  348. //
  349. // DESCRIPTION:
  350. //   Called from controls to update the dialog based on user input
  351. //
  352. // ARGUMENTS:
  353. //   whatChanged -- string -- key for which UI element has been updated
  354. //
  355. // RETURNS:
  356. //   nothing
  357. //--------------------------------------------------------------------
  358. function updateUI(whatChanged)
  359. {
  360.   switch (whatChanged)
  361.   {
  362.  
  363.     case "masterFieldsLength":
  364.       var masterFieldsArr = _MasterPageFields.getValue();
  365.       var linkFieldsArr = _LinkField.listControl.list;
  366.  
  367.       if (masterFieldsArr.length != linkFieldsArr.length)
  368.       {
  369.         _LinkField.listControl.setAll(masterFieldsArr,masterFieldsArr);
  370.       }
  371.       break;
  372.  
  373.     default:
  374.       break;
  375.   }
  376. }
  377.  
  378.  
  379. //--------------------------------------------------------------------
  380. // FUNCTION:
  381. //   getUniqueRecordsetName
  382. //
  383. // DESCRIPTION:
  384. //   Returns a unique recordset name for the current document
  385. //
  386. // ARGUMENTS:
  387. //   none
  388. //
  389. // RETURNS:
  390. //   unique recordset name
  391. //--------------------------------------------------------------------
  392. function getUniqueRecordsetName()
  393. {
  394.   var dsNames = dwscripts.getRecordsetNames();
  395.   var nNames = dsNames.length;
  396.   var num = -1;
  397.   var uniqueName = false;
  398.   var rsName = ""
  399.  
  400.   while(!uniqueName)
  401.   {
  402.     num++;
  403.     if(num==0)
  404.         rsName = "DetailRS";
  405.     else
  406.         rsName= "DetailRS" + num;     
  407.     uniqueName = true;
  408.     for (var i=0;i<nNames;i++)
  409.     {
  410.       if (dsNames.toLowerCase() == rsName.toLowerCase())
  411.       {
  412.         uniqueName = false;
  413.         break;
  414.       }
  415.     }
  416.   }
  417.  
  418.   return rsName;
  419. }
  420.  
  421.  
  422.  
  423. //-------------------------------------------------------------------
  424. // FUNCTION:
  425. //   addExtensionToFileName
  426. //
  427. // DESCRIPTION:
  428. //   Given a file name, check for a file extension, and add a
  429. //   file extension (server-specific) if one does not exist
  430. //
  431. // ARGUMENTS:
  432. //   fileName -- string, file name
  433. //
  434. // RETURNS:
  435. //   file name
  436. //--------------------------------------------------------------------
  437. function addExtensionToFileName(fileName)
  438. {
  439.   var retVal = fileName;
  440.   var hasExtension = (fileName.search(/\.\w+$/) != -1);
  441.  
  442.   if (!hasExtension)
  443.   {
  444.     var fileExtension = dwscripts.getFileExtension(dw.getDocumentDOM().URL)
  445.     retVal = fileName +"." + fileExtension;
  446.   }
  447.  
  448.   return retVal;
  449. }
  450.  
  451. // HE Note: This is modified from the original in Sam's file because I'm passing
  452. // in the entire filter; this makes it generic and easier to copy for multiple users.
  453. // function: editWhereClause -- would better be part of the SQL class
  454.  
  455. // SQL RELATED FUNCTIONS BELOW, should be moved
  456. // They belong in the main SQL function
  457.  
  458. var CONST_where = "WHERE";
  459. var CONST_and = "AND";
  460. var CONST_orderBy = "ORDER BY";
  461. var CONST_groupBy = "GROUP BY";
  462.  
  463. function buildNewSQLSource(sourceStr, index, clause, filter)
  464. {
  465.   var newSource;
  466.  
  467.   newSource = sourceStr.substr(0, index - 1) + " " + clause + " " + filter + " " + sourceStr.substr(index, sourceStr.length - index);
  468.  
  469.   return newSource;
  470.  
  471. }
  472.  
  473. function editWhereClause(SQLStatement,newFilter)
  474. {
  475.  
  476.    //var part = new Participant("recordset_sqlVar");
  477.    var sourceStr = SQLStatement
  478.    var filter = "";
  479.    var newSource = "";
  480.  
  481.    var paramObj = new Object();
  482.    // paramObj.rsName = rsName;
  483.    // paramObj.varName = varName;
  484.  
  485.    // filter = part.getInsertString(paramObj);
  486.  
  487.    // filter = colId + " = " + enclosingToken + filter + enclosingToken;
  488.  
  489.    filter = newFilter;
  490.    var re = new RegExp("\\bwhere\\b","gi");
  491.  
  492.    var index = sourceStr.search(re);
  493.  
  494.    if (index == -1) {
  495.      //The where clause was not found in the sql
  496.  
  497.        var reOrderBy = new RegExp("\\border\\sby\\b","gi");
  498.      var reGroupBy = new RegExp("\\bgroup\\sby\\b","gi");
  499.      var orderIndex = sourceStr.search(reOrderBy);
  500.      var groupIndex = sourceStr.search(reGroupBy);
  501.      if(groupIndex == orderIndex)
  502.      {
  503.          //This can only mean that the group by and order by clause both don't exist (index returns -1).
  504.          newSource = sourceStr + " " + CONST_where + " " + filter;
  505.      } else {
  506.  
  507.          var groupBoolean = new Boolean(false);
  508.  
  509.          // Either group by or order by or both clauses exist in the sql.
  510.        if((groupIndex > -1) && (orderIndex > -1)) {
  511.            // both clause's exist. Check which one has the least index value and insert the filter before it.
  512.          groupBoolean = (groupIndex < orderIndex);
  513.        } else {
  514.            //only one clause exists. Check which one has the greater index value and insert the filter before it.
  515.              groupBoolean = (groupIndex > orderIndex);
  516.        }
  517.        if(groupBoolean)
  518.           newSource = buildNewSQLSource(sourceStr, groupIndex, CONST_where, filter);
  519.        else
  520.           newSource = buildNewSQLSource(sourceStr, orderIndex, CONST_where, filter);
  521.      }
  522.    } else {
  523.        //The sql contains a where clause. We need to find out where it is and insert our filter just after it.
  524.      //The clause generated here will be the only where clause that is used.
  525.      newSource = sourceStr.substr(0, index) + " " + CONST_where + " " + filter;
  526.    }
  527.  
  528.    return newSource;
  529. }
  530.  
  531. //--------------------------------------------------------------------
  532. // FUNCTION:
  533. //   getUniqueRecordsetName
  534. //
  535. // DESCRIPTION:
  536. //   Returns a unique recordset name for the current document
  537. //
  538. // ARGUMENTS:
  539. //   none
  540. //
  541. // RETURNS:
  542. //   unique recordset name
  543. //--------------------------------------------------------------------
  544. function getUniqueRecordsetName()
  545. {
  546.   var dsNames = dwscripts.getRecordsetNames();
  547.   var nNames = dsNames.length;
  548.   var num = 0;
  549.   var uniqueName = false;
  550.   var rsName = ""
  551.  
  552.   while(!uniqueName)
  553.   {
  554.     num++;
  555.     rsName = "DetailRS" + num;
  556.     uniqueName = true;
  557.     for (var i=0;i<nNames;i++)
  558.     {
  559.       if (dsNames[i].toLowerCase() == rsName.toLowerCase())
  560.       {
  561.         uniqueName = false;
  562.         break;
  563.       }
  564.     }
  565.   }
  566.  
  567.   return rsName;
  568. }
  569.  
  570. //--------------------------------------------------------------------
  571. // FUNCTION:
  572. //   getSQLStringForURLVariable
  573. //
  574. // DESCRIPTION:
  575. //   Returns url variable surrounded by appropriate delimiters
  576. //
  577. // ARGUMENTS:
  578. //   connName -- string, name of connection. Note: in CF, this is the data source name
  579. //   tableName -- string, name of table
  580. //   colName -- string, name of column
  581. //   varStr -- string, url variable for sql statement, e.g.: #URL.recordID#
  582. //
  583. //
  584. //
  585. // RETURNS:
  586. //   unique recordset name
  587. //--------------------------------------------------------------------
  588. function getSQLStringForURLVariable(connName,tableName,colName,varStr)
  589. {
  590.     var colAndTypes = MMDB.getColumnAndTypeOfTable(connectionName, tableName);
  591.     var nItems = colAndTypes.length;
  592.     var i;
  593.     var colType = "";
  594.     var retVal = colName;
  595.  
  596.     // find colName in colAndTypesArr
  597.     // note that colAndTypes is single dimensional array in form of
  598.     // column name, column type, etc.
  599.  
  600.     for (i=0;i<nItems;i+=2)
  601.     {
  602.       if (colAndTypes[i] == colName)
  603.       {
  604.         colType = colAndTypes[i+1];
  605.       }
  606.     }
  607.  
  608.     // hava: is colType number or string type? Will next clause work?
  609.     if (colType)
  610.     {
  611.       retVal = dwscripts.getSQLStringForDBColumnType(varStr,colType);
  612.     }
  613.     else
  614.     {
  615.       // this case should not be hit, but if it is, use no delimiters
  616.       retVal = varStr;
  617.     }
  618.  
  619.     return retVal;
  620.  
  621.  
  622. }
  623.  
  624. //--------------------------------------------------------------------
  625. // FUNCTION:
  626. //   getRecordsetParameters
  627. //
  628. // DESCRIPTION:
  629. //   Finds paramObj.RecordsetName in the current document, and adds all
  630. //   recordset related parameters to paramObj
  631. //   NOTE: Another way to do this would be use an explicit recordset
  632. //   copying method. hava: is one way preferable over another?
  633. //
  634. // ARGUMENTS:
  635. //   paramObj -- object to store parameters. Must include a property
  636. //   named "RecordsetName" with a valid recordset name.
  637. //   The recordset properties are added to paramObj. Note: this
  638. //   function will override existing paramObj properties of the same
  639. //   name.
  640. //
  641. // RETURNS:
  642. //   nothing. paramObj is passed by reference; return value not needed.
  643. //--------------------------------------------------------------------
  644. function getRecordsetParameters(paramObj)
  645. {
  646.  
  647.   var sbRecs = dw.sbi.getServerBehaviors();
  648.   var nRecs = sbRecs.length;
  649.   var rsName = paramObj.RecordsetName;
  650.   var i;
  651.   var currRec = "";
  652.  
  653.   for (i=0;i<nRecs;i++)
  654.   {
  655.     currRec = sbRecs[i];
  656.     if (currRec.getName() == "Recordset" && currRec.getParameter("RecordsetName") == rsName)
  657.     {
  658.       rsParamObj = currRec.getParameters();
  659.       break;
  660.     }
  661.   }
  662.  
  663.   // add recordset parameters to paramObj
  664.   for (var i in rsParamObj)
  665.   {
  666.     if(i=="PageSize")
  667.       continue;
  668.     paramObj[i] = rsParamObj[i];
  669.   }
  670. }
  671.  
  672.  
  673.  
  674.  
  675. // shamelessly copied -- only temporary to focus on major issues first
  676. // add to common dwscripts file? or at least to server behavior file
  677. // in any case, move it!
  678.  
  679. //Invokes dialog to allow user to select filename. Puts value in text input.
  680. // The optional flag stripParameters will remove anything after a question
  681. // mark if it is set to true
  682.  
  683. function browseFile(fieldToStoreURL, stripParameters)
  684. {
  685.   var fileName = "";
  686.   fileName = browseForFileURL();  //returns a local filename
  687.   if (stripParameters) {
  688.     var index = fileName.indexOf("?");
  689.     if (index != -1) {
  690.       fileName = fileName.substring(0,index);
  691.     }
  692.   }
  693.   if (fileName) fieldToStoreURL.value = fileName;
  694. }
  695.  
  696.  
  697. //--------------------------------------------------------------------
  698. // FUNCTION:
  699. //   createAndPrepDetailPage
  700. //
  701. // DESCRIPTION:
  702. //   Looks at detail page name to determine if it exists. Creates
  703. //   file for detail page if it does not already exist. Preps file
  704. //   in either case to ensure that future html insertion will not
  705. //   cause invalid html markup.
  706. //
  707. //
  708. // ARGUMENTS:
  709. //   detailPageName -- string
  710. //   detailPageAbsURL -- string -- detail page absolute path
  711. //   dom (optional) -- document object model for current document
  712. //
  713. //
  714. // RETURNS:
  715. //   nothing
  716. //--------------------------------------------------------------------
  717. function createAndPrepDetailPage(detailPageName,detailPageAbsURL,theDom)
  718. {
  719.   var detailPageExists = dwscripts.fileExists(detailPageAbsURL);
  720.   var detailPageIsOpen = detailPageExists && dwscripts.fileIsCurrentlyOpen(detailPageAbsURL);
  721.   var detailPageIsOpen = false;
  722.   var dom = (theDom)?theDom:dw.getDocumentDOM();
  723.  
  724.   if (detailPageExists)
  725.   {
  726.     dw.openDocument(detailPageAbsURL);
  727.     dom = dw.getDocumentDOM();
  728.  
  729.     if (detailPageIsOpen)
  730.     {
  731.       // move cursor from head, move outside of block tags
  732.       dwscripts.fixUpSelection(dom,false,false);
  733.     }
  734.       else
  735.     {
  736.       // if it was closed, move cursor to the end of the just-opened document
  737.       dwscripts.setCursorToEndOfBody(dom);
  738.     }
  739.   }
  740.  
  741.   else // create a new page to use as the detail page
  742.   {
  743.     dw.createDocument(false, _documentTypeID);
  744.     dom = dw.getDocumentDOM();
  745.     dw.saveDocument(dom,detailPageAbsURL);
  746.   }
  747. }
  748.  
  749.