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-RSNavBar.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  10.0 KB  |  383 lines

  1. // Copyright 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3.  
  4. // *************** GLOBALS VARS *****************
  5.  
  6. var helpDoc         = MM.HELP_objRecordsetStatistics;
  7.  
  8. var _RecordsetName  = new EditableRecordsetMenu("RSStatsFirst.htm", "RecordsetName", "");
  9.  
  10. var FIRST_file      = "First.gif"
  11. var PREVIOUS_file   = "Previous.gif"
  12. var NEXT_file       = "Next.gif"
  13. var LAST_file       = "Last.gif"
  14.  
  15. var DISPLAY_TYPE;
  16.  
  17. var LIMIT_RECORDSET = false;
  18.  
  19. //******************* API **********************
  20.  
  21. //--------------------------------------------------------------------
  22. // FUNCTION:
  23. //   canInsertObject
  24. //
  25. // DESCRIPTION:
  26. //   This function is called to determine if this object can be inserted
  27. //   into the current document.  It displays the relevant error messages,
  28. //   and then returns a boolean to indicate if insertion is possible.
  29. //
  30. //   NOTE: this function is called before initializeUI, so it should
  31. //         not rely on internal state.
  32. //
  33. // ARGUMENTS:
  34. //   none
  35. //
  36. // RETURNS:
  37. //   boolean
  38. //--------------------------------------------------------------------
  39. function canInsertObject()
  40. {
  41.   var retVal = false;
  42.   var errMsgStr = "";
  43.   var isServerObject = true;
  44.   
  45.   if (errMsgStr)
  46.   {
  47.     alert (errMsgStr);
  48.     retVal = false;
  49.   }
  50.   
  51.   return retVal;
  52. }
  53.  
  54.  
  55. //--------------------------------------------------------------------
  56. // FUNCTION:
  57. //   commandButtons
  58. //
  59. // DESCRIPTION:
  60. //   Returns the list of buttons which should appear on the right hand
  61. //   side of the dialog
  62. //
  63. // ARGUMENTS:
  64. //   none
  65. //
  66. // RETURNS:
  67. //   Array - pairs of button name and function call
  68. //--------------------------------------------------------------------
  69.  
  70. function commandButtons()
  71. {
  72.    return new Array(MM.BTN_OK,     "clickedOK()",
  73.                     MM.BTN_Cancel, "clickedCancel()",
  74.                     MM.BTN_Help,   "displayHelp()");
  75. }
  76.  
  77.  
  78. //--------------------------------------------------------------------
  79. // FUNCTION:
  80. //   clickedOK
  81. //
  82. // DESCRIPTION:
  83. //   This function is called when the user clicks OK
  84. //
  85. // ARGUMENTS:
  86. //   none
  87. //
  88. // RETURNS:
  89. //   nothing
  90. //--------------------------------------------------------------------
  91.  
  92. function clickedOK()
  93. {
  94.   var rsName = _RecordsetName.getValue();  
  95.   var bUseImages = (DISPLAY_TYPE[1].checked) ? true : false;
  96.   
  97.   if (rsName)
  98.   {
  99.     // check if a page navigation repeat region exists for this recordset
  100.     dwscripts.warnIfNoPageNavDisplay(rsName,true);
  101.     
  102.     // Build up the insertion string, and then apply a doc edit    
  103.     var paramObj = new Object();
  104.     var sbObj = null;
  105.       
  106.     paramObj["RecordsetName"] = rsName;
  107.     paramObj.AddQueryString = "QueryString";
  108.     
  109.     if (!LIMIT_RECORDSET)
  110.     {
  111.       paramObj.MM_familyDefaults = new Object();
  112.       paramObj.MM_familyDefaults.PageSize = 10;
  113.     }
  114.     else
  115.     {
  116.       var sbRecordset = dwscripts.getServerBehaviorByParam("Recordset.htm","RecordsetName",paramObj["RecordsetName"]);
  117.       if (sbRecordset)
  118.       {
  119.         var newRS = sbRecordset.makeEditableCopy();
  120.         newRS.setDefaultPageSize();
  121.         newRS.queueDocEdits();
  122.       }
  123.     }
  124.     
  125.     if(bUseImages)
  126.     {
  127.       if (!copyImageFiles())
  128.       {
  129.         return;
  130.       }
  131.       paramObj.FirstLinkText = '<img src="' + FIRST_file + '" border=0>';
  132.       paramObj.PrevLinkText = '<img src="' + PREVIOUS_file + '" border=0>';
  133.       paramObj.NextLinkText = '<img src="' + NEXT_file + '" border=0>';
  134.       paramObj.LastLinkText = '<img src="' + LAST_file + '" border=0>';
  135.     } 
  136.     else 
  137.     {
  138.       //set parameter values for compound object from localizeable globals file.
  139.       if (dreamweaver.appVersion && ( (dreamweaver.appVersion.indexOf('ja') != -1) ||
  140.                                       (dreamweaver.appVersion.indexOf('ko') != -1) ||
  141.                                       (dreamweaver.appVersion.indexOf('zh') != -1) ) )
  142.       {  
  143.           if (isDoubleByteEncoding()) 
  144.           {
  145.               // Japanese, Korean and Chinese exceptions
  146.               paramObj.FirstLinkText = MM.LABEL_NewMoveToFirstLinkLabel;  
  147.               paramObj.PrevLinkText  = MM.LABEL_NewMoveToPrevLinkLabel;
  148.               paramObj.NextLinkText  = MM.LABEL_NewMoveToNextLinkLabel;
  149.               paramObj.LastLinkText  = MM.LABEL_NewMoveToLastLinkLabel;
  150.           } 
  151.           else 
  152.           {
  153.               // not a JA, KO, or Chinese document so use English to prevent corruption
  154.               paramObj.FirstLinkText = MM.LABEL_EngNewMoveToFirstLinkLabel;  
  155.               paramObj.PrevLinkText  = MM.LABEL_EngNewMoveToPrevLinkLabel;
  156.               paramObj.NextLinkText  = MM.LABEL_EngNewMoveToNextLinkLabel;
  157.               paramObj.LastLinkText  = MM.LABEL_EngNewMoveToLastLinkLabel;
  158.           }
  159.       }
  160.       else 
  161.       {
  162.           paramObj.FirstLinkText = dwscripts.entityNameEncode(MM.LABEL_NewMoveToFirstLinkLabel);  //"First" in English
  163.           paramObj.PrevLinkText  = dwscripts.entityNameEncode(MM.LABEL_NewMoveToPrevLinkLabel);
  164.           paramObj.NextLinkText  = dwscripts.entityNameEncode(MM.LABEL_NewMoveToNextLinkLabel);
  165.           paramObj.LastLinkText  = dwscripts.entityNameEncode(MM.LABEL_NewMoveToLastLinkLabel);
  166.       }
  167.     }
  168.     
  169.     dwscripts.fixUpSelection(dw.getDocumentDOM(), false, true);
  170.     dwscripts.applyGroup("RSNavBar", paramObj);
  171.     
  172.     window.close();
  173.   }
  174.   else
  175.   {
  176.     alert(dwscripts.sprintf(MM.MSG_invalidRS, dwscripts.getRecordsetDisplayName()));
  177.   }
  178. }
  179.  
  180.  
  181. //--------------------------------------------------------------------
  182. // FUNCTION:
  183. //   clickedCancel
  184. //
  185. // DESCRIPTION:
  186. //   This function is called when CANCEL is clicked
  187. //
  188. // ARGUMENTS:
  189. //   none
  190. //
  191. // RETURNS:
  192. //   nothing
  193. //--------------------------------------------------------------------
  194.  
  195. function clickedCancel()
  196. {
  197.   window.close();
  198. }
  199.  
  200.  
  201. //--------------------------------------------------------------------
  202. // FUNCTION:
  203. //   displayHelp
  204. //
  205. // DESCRIPTION:
  206. //   This function is called when the user clicks the HELP button
  207. //
  208. // ARGUMENTS:
  209. //   none
  210. //
  211. // RETURNS:
  212. //   nothing
  213. //--------------------------------------------------------------------
  214.  
  215. function displayHelp()
  216. {
  217.   dwscripts.displayDWHelp(helpDoc);
  218. }
  219.  
  220.  
  221. //***************** LOCAL FUNCTIONS  ******************
  222.  
  223. //--------------------------------------------------------------------
  224. // FUNCTION:
  225. //   initializeUI
  226. //
  227. // DESCRIPTION:
  228. //   This function is called in the onLoad event.  It is responsible
  229. //   for initializing the UI.
  230. //
  231. // ARGUMENTS:
  232. //   none
  233. //
  234. // RETURNS:
  235. //   nothing
  236. //--------------------------------------------------------------------
  237.  
  238. function initializeUI()
  239. {
  240.   var args = dwscripts.getCommandArguments();
  241.   var obj = dwscripts.findDOMObject("RecordsetName");
  242.   if (args && obj)
  243.   {
  244.     if (args.editableRecordset)
  245.     {
  246.       obj.setAttribute("editable","true");
  247.     }
  248.     else
  249.     {
  250.       obj.removeAttribute("editable");
  251.     }
  252.   }
  253.   
  254.   if (args)
  255.   {
  256.     LIMIT_RECORDSET = args.limitRecordset;
  257.   }
  258.   
  259.   // Build Recordset menu
  260.   _RecordsetName.initializeUI();
  261.   
  262.   var rsToPick = dwscripts.getRecordsetNameWithPageNav();
  263.   if (rsToPick)
  264.   {
  265.     _RecordsetName.pickValue(rsToPick);
  266.   }
  267.   
  268.   DISPLAY_TYPE = dwscripts.findDOMObject("DisplayType");
  269.  
  270.   if (obj)
  271.   {
  272.     obj.focus();
  273.   }
  274. }
  275.  
  276. //--------------------------------------------------------------------
  277. // FUNCTION:
  278. //   copyImageFiles
  279. //
  280. // DESCRIPTION:
  281. //   This function is called to copy the image files from the 
  282. //   configuration directory to the document path.  This happens when
  283. //   the user choses Images in the dialog
  284. //
  285. // ARGUMENTS:
  286. //   none
  287. //
  288. // RETURNS:
  289. //   nothing
  290. //--------------------------------------------------------------------
  291. function copyImageFiles()
  292. {
  293.   var bCopyFlag = false;
  294.   
  295.   var dom = dreamweaver.getDocumentDOM();
  296.   var documentPath = dom.URL;
  297.   var lastSlashIndex = documentPath.lastIndexOf('/');
  298.   documentPath = documentPath.substring(0, lastSlashIndex+1);
  299.   
  300.   if(documentPath != "")
  301.   {
  302.     var configPath = dreamweaver.getConfigurationPath();
  303.     configPath += "/Shared/UltraDev/Images/";
  304.   
  305.     bCopyFlag = true;
  306.  
  307.     copyTheFiles(configPath+FIRST_file, documentPath+FIRST_file);
  308.     copyTheFiles(configPath+NEXT_file, documentPath+NEXT_file);
  309.     copyTheFiles(configPath+PREVIOUS_file, documentPath+PREVIOUS_file);
  310.     copyTheFiles(configPath+LAST_file, documentPath+LAST_file);
  311.  
  312.   } 
  313.   
  314.   if(!bCopyFlag)
  315.   {
  316.      alert(MM.MSG_rsNavigationBarSaveDocument);
  317.   }
  318.   
  319.   return bCopyFlag;
  320. }
  321.  
  322. //--------------------------------------------------------------------
  323. // FUNCTION:
  324. //   copyTheFiles
  325. //
  326. // DESCRIPTION:
  327. //   Utility function used for copying a file from source directory
  328. //   to the destination directory
  329. //
  330. // ARGUMENTS:
  331. //   source - the file including the path that needs to be copied
  332. //   destination - the file including the path to where the source
  333. //                 needs to be copied
  334. //
  335. // RETURNS:
  336. //   nothing
  337. //--------------------------------------------------------------------
  338. function copyTheFiles(source, destination)
  339. {
  340.   if(!DWfile.exists(destination))
  341.   {
  342.     if(DWfile.exists(source))
  343.     {
  344.       DWfile.copy(source, destination);
  345.     }
  346.   }
  347. }
  348.  
  349. //--------------------------------------------------------------------
  350. // FUNCTION:
  351. //   isDoubleByteEncoding
  352. //
  353. // DESCRIPTION:
  354. //   Check to avoid entity encoding in double byte languages
  355. //   
  356. // ARGUMENTS:
  357. //   none
  358. //   
  359. // RETURNS:
  360. //   true if charSet and appVersion correspond to a DoubleByte language
  361. //   false otherwise
  362. //
  363. //--------------------------------------------------------------------
  364.  
  365. function isDoubleByteEncoding()
  366. {
  367.     var charSet = dw.getDocumentDOM().getCharSet();
  368.     charSet = charSet.toLowerCase();
  369.     if (   ( (dreamweaver.appVersion.indexOf('ja') != -1) && 
  370.              (charSet == "shift_jis" || charSet == "x-sjis" || charSet == "euc-jp" || charSet == "iso-2022-jp") )
  371.         || ( (dreamweaver.appVersion.indexOf('ko') != -1) && 
  372.              (charSet == "euc-kr") )
  373.         || ( (dreamweaver.appVersion.indexOf('zh') != -1) && 
  374.              (charSet == "big5" || charSet == "gb2312") ) )
  375.     {
  376.         return true;
  377.     }
  378.     else
  379.     {
  380.         return false;
  381.     }
  382. }
  383.