home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 September / Australian PC User - September 2003 (CD1).iso / magstuff / web / files / dwmx61.exe / Disk1 / data1.cab / Configuration_En / Objects / Server / serverObjectsCommon.js < prev    next >
Encoding:
JavaScript  |  2002-11-25  |  9.1 KB  |  352 lines

  1. // Copyright 2002 Macromedia, Inc. All rights reserved.
  2.  
  3. // This file manages the behavior of the error dialog that appears when the
  4. // prerequisites are not met for applying a server object into the document.
  5. // The error dialog contains links to the appropriate dialogs in order to
  6. // meet the prerequisite conditions.
  7.  
  8.  
  9. //--------------------------------------------------------------------
  10. // FUNCTION:
  11. //   getSetupStepsForServerObject
  12. //
  13. // DESCRIPTION:
  14. //   Returns a javascript array, which represents the steps that
  15. //   need to be completed before a server object can be inserted
  16. //   into the document.
  17. //
  18. // ARGUMENTS:
  19. //   excludeRecordsetCreationStep - boolean - (optional) set to
  20. //     true to elimnate the recordset creation step
  21. //
  22. // RETURNS:
  23. //   Array of strings
  24. //--------------------------------------------------------------------
  25.  
  26. function getSetupStepsForServerObject(excludeRecordsetCreationStep)
  27. {
  28.   var steps = new Array();
  29.   var dom = null;
  30.   var documentType = "";
  31.   var serverModel = "";
  32.  
  33.   // Try to get the server model of the currently open document.
  34.   // If there's no currently open document, get the default server
  35.   // model for the current site.
  36.   dom = dw.getDocumentDOM();
  37.   if (dom == null)
  38.   {
  39.     dom = dw.getNewDocumentDOM();
  40.   }
  41.   
  42.   if (dom)
  43.   {
  44.     if (dom.documentType)
  45.     {
  46.       documentType = dom.documentType;
  47.     }
  48.     if (dom.serverModel)
  49.     {
  50.       serverModel = dom.serverModel.getFolderName();
  51.     }
  52.   }
  53.  
  54.   steps.push(MM.MSG_BeforeInsertingServerObject);
  55.   steps.push(dwscripts.sprintf(MM.MSG_CreateSite,'<a href="#" onMouseDown="event:CreateSite">','</a>'));
  56.   steps.push(dwscripts.sprintf(MM.MSG_ChooseDynamicDocType,'<a href="#" onMouseDown="event:SetDocType">','</a>'));
  57.   steps.push(dwscripts.sprintf(MM.MSG_SetAppServer,'<a href="#" onMouseDown="event:SetAppServer">','</a>'));
  58.  
  59.   if (documentType == "ColdFusion" && serverModel != "UD4-ColdFusion")
  60.   {
  61.     // ColdFusion specific steps are only for the DWMX version.
  62.     steps.push(dwscripts.sprintf(MM.MSG_SetRDSPassword,'<a href="#" onMouseDown="event:SetRDSPassword">','</a>'));
  63.     steps.push(dwscripts.sprintf(MM.MSG_CreateCFDataSource,'<a href="#" onMouseDown="event:CreateCFDataSource">','</a>'));
  64.   }
  65.   
  66.   if (!excludeRecordsetCreationStep)
  67.   {
  68.     var fmt = MM.MSG_CreateRecordset;
  69.       var before = '<a href="#" onMouseDown="onCreateRecordset()">';
  70.       var after = '</a>';
  71.       var recordsetDisplayName = dwscripts.getRecordsetDisplayName();
  72.     
  73.       steps.push(dwscripts.sprintf(fmt, before, recordsetDisplayName, after));
  74.   }
  75.  
  76.   if (documentType == "ASP.NET_CSharp" || documentType == "ASP.NET_VB")
  77.   {
  78.     // For ASP.NET, add an optional step specifying to deploy to the testing server bin.
  79.     steps[steps.length-1] += "<br><br>"
  80.                           + dwscripts.sprintf(MM.MSG_DeployToTestingServerBin,
  81.                                               '<a href="#" onMouseDown="site.showTestingServerBinDeployDialog()">','</a>'
  82.                                              );
  83.   }
  84.  
  85.   // The Instruction steps dialog has very little vertical space between the
  86.   //   last instruction and the bottom of the dialog. As a simple workaround, 
  87.   //   we add a <br> at the end of the last instructions text.
  88.   steps[steps.length - 1] += "<br>";
  89.   
  90.   return steps;
  91. }
  92.  
  93.  
  94. //--------------------------------------------------------------------
  95. // FUNCTION:
  96. //   setupStepsCompletedForServerObject
  97. //
  98. // DESCRIPTION:
  99. //   Returns an integer indication how many of the steps have been 
  100. //   completed.  A value of -1 indicates that all of the steps
  101. //   are complete.
  102. //
  103. // ARGUMENTS:
  104. //   excludeRecordsetCreationStep - boolean - (optional) set to
  105. //     true to elimnate the recordset creation step
  106. //
  107. // RETURNS:
  108. //   integer
  109. //--------------------------------------------------------------------
  110.  
  111. function setupStepsCompletedForServerObject(excludeRecordsetCreationStep)
  112. {
  113.   var dom = null;
  114.   var cfDsnList = null;
  115.   var connList = null;
  116.   var documentType = "";
  117.   var serverModel = "";
  118.   var url = "";
  119.   var curSite = null;
  120.   
  121.   // Try to get the site for the currently selected document
  122.   dom = dw.getDocumentDOM();
  123.   if (dom != null)
  124.   {
  125.     url = dom.URL;
  126.   }
  127.   
  128.   if (url.length > 0)
  129.   {
  130.     curSite = site.getSiteForURL(url);
  131.   }
  132.   else
  133.   {
  134.     curSite = site.getCurrentSite();
  135.   }
  136.  
  137.   // If no site defined, prompt user to create one
  138.   if (curSite.length == 0)
  139.   {
  140.     return 0;
  141.   }
  142.  
  143.   // Try to get the server model of the currently selected document
  144.   if (dom == null)
  145.   {
  146.     dom = dw.getNewDocumentDOM();
  147.   }
  148.   if (dom)
  149.   {
  150.     if (dom.documentType)
  151.     {
  152.       documentType = dom.documentType;
  153.     }
  154.     if (dom.serverModel)
  155.     {
  156.       serverModel = dom.serverModel.getFolderName();
  157.     }
  158.   }
  159.  
  160.   // If doc type does not support server markup, prompt user
  161.   // to choose dynamic doc type
  162.   if (serverModel.length == 0)
  163.   {
  164.     return 1;
  165.   }
  166.  
  167.   // If no app server is defined, prompt user to specify one
  168.   if (dom.serverModel.testAppServer() == false)
  169.   {
  170.     return 2;
  171.   }
  172.  
  173.   if (documentType == "ColdFusion" && serverModel != "UD4-ColdFusion")
  174.   {
  175.     // ColdFusion specific steps are only for the DWMX version.
  176.  
  177.     // Getting the DSN list updates the flag indicating whether we
  178.       // need to prompt for RDS info.
  179.     cfDsnList = MMDB.getColdFusionDsnList();
  180.  
  181.     // If RDS password is empty, prompt user to supply one
  182.     if (MMDB.needToPromptForRdsInfo(true))
  183.     {
  184.       return 3;
  185.     }
  186.  
  187.     // If no CF data sources are defined, send user to CF Administrator
  188.     if (cfDsnList == null || cfDsnList.length == 0)
  189.     {
  190.       return 4;
  191.     }
  192.     
  193.     // If no recordsets are defined, then send user to recordset sb
  194.     if (!excludeRecordsetCreationStep && !recordsetIsDefined())
  195.     {
  196.       return 5;
  197.     }
  198.   }
  199. /*//The deploy instruction for asp.net is optional...
  200.   else if (documentType == "ASP.NET_CSharp" || documentType == "ASP.NET_VB")
  201.   {
  202.     // If ASCX files have not yet been deployed, send user to deploy dialog
  203.     if (site.getNeedToDeployTestingServerBin())
  204.     {
  205.       return 3;
  206.     }
  207.  
  208.     // If no recordsets are defined, then send user to recordset sb
  209.     if (!excludeRecordsetCreationStep && !recordsetIsDefined())
  210.     {
  211.       return 4;
  212.     }
  213.   }
  214. */
  215.   else
  216.   {   
  217.     // If no recordsets are defined, then send user to recordset sb
  218.     if (!excludeRecordsetCreationStep && !recordsetIsDefined())
  219.     {
  220.       return 3;
  221.     }
  222.   }
  223.  
  224.   // All setup steps have been completed
  225.   return -1;
  226. }
  227.  
  228.  
  229.  
  230. //--------------------------------------------------------------------
  231. // FUNCTION:
  232. //   onCreateRecordset
  233. //
  234. // DESCRIPTION:
  235. //   Handles event that user clicked the create recordset instruction step.
  236. //
  237. // ARGUMENTS:
  238. //   none
  239. //
  240. // RETURNS:
  241. //   boolean
  242. //--------------------------------------------------------------------
  243.  
  244. function onCreateRecordset()
  245. {
  246.   // Only popup the recordset dialog if the document has a server model.
  247.   if (dwscripts.hasServerModel())
  248.   {
  249.     saveBodyRelativeSelection();
  250.     dw.popupServerBehavior("Recordset.htm");
  251.     restoreBodyRelativeSelection();
  252.   }
  253. }
  254.  
  255.  
  256. //--------------------------------------------------------------------
  257. // FUNCTION:
  258. //   recordsetIsDefined
  259. //
  260. // DESCRIPTION:
  261. //   Returns true if a recordset is currently defined on the page
  262. //
  263. // ARGUMENTS:
  264. //   none
  265. //
  266. // RETURNS:
  267. //   boolean
  268. //--------------------------------------------------------------------
  269.  
  270. function recordsetIsDefined()
  271. {
  272.   var retVal = false;
  273.   
  274.   var rsList = dwscripts.getRecordsetNames();
  275.   if (rsList && rsList.length > 0)
  276.   {
  277.     retVal = true;
  278.   }
  279.   
  280.   return retVal;
  281. }
  282.  
  283.  
  284.  
  285. //--------------------------------------------------------------------
  286. // FUNCTION:
  287. //   saveBodyRelativeSelection
  288. //
  289. // DESCRIPTION:
  290. //   Stores the body tag relative location of the current selection
  291. //   in the global variable CURRENT_SEL.
  292. //
  293. // ARGUMENTS:
  294. //   none
  295. //
  296. // RETURNS:
  297. //   nothing
  298. //--------------------------------------------------------------------
  299.  
  300. var CURRENT_SEL = null;
  301.  
  302. function saveBodyRelativeSelection()
  303. {
  304.   var dom = dw.getDocumentDOM();
  305.   
  306.   var sel = dom.getSelection();
  307.   
  308.   if (sel && sel.length > 1)
  309.   {
  310.     var bodyOffset = dom.nodeToOffsets(dom.body);
  311.  
  312.     sel[0] = sel[0] - bodyOffset[0];
  313.     sel[1] = sel[1] - bodyOffset[0];
  314.     
  315.     CURRENT_SEL = sel;
  316.   }  
  317. }
  318.  
  319.  
  320. //--------------------------------------------------------------------
  321. // FUNCTION:
  322. //   restoreBodyRelativeSelection
  323. //
  324. // DESCRIPTION:
  325. //   Sets the selection back to it's original location, before the
  326. //   recordset was inserted.
  327. //
  328. // ARGUMENTS:
  329. //   none
  330. //
  331. // RETURNS:
  332. //   nothing
  333. //--------------------------------------------------------------------
  334.  
  335. function restoreBodyRelativeSelection()
  336. {
  337.   var sel = CURRENT_SEL;
  338.   CURRENT_SEL = null;
  339.   
  340.   if (sel)
  341.   {
  342.     var dom = dw.getDocumentDOM();
  343.     
  344.     var bodyOffset = dom.nodeToOffsets(dom.body);
  345.     
  346.     sel[0] = sel[0] + bodyOffset[0];
  347.     sel[1] = sel[1] + bodyOffset[0];
  348.     
  349.     dom.setSelection(sel[0], sel[1]);
  350.   }
  351. }
  352.