home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 July / 07_02.iso / software / mdmx / files / DreamweaverMXInstaller.exe / Disk1 / data1.cab / Configuration_En / Commands / InsertConditionalContent.js < prev    next >
Encoding:
JavaScript  |  2002-05-01  |  9.7 KB  |  349 lines

  1. // Copyright 2001-2002 Macromedia, Inc. All rights reserved.
  2.  
  3. //---------------   GLOBAL VARIABLES   ---------------
  4.  
  5. var helpDoc = MM.HELP_insertOptionalContent;
  6. var targetDom = null;
  7. var abortCommand = false; //Set to true if the user cancels out of the 'save as template' dialog
  8.  
  9. var selectedOptionalNode = null;
  10. var currentExpression = "";
  11. var addEditable = false; 
  12.  
  13. var T = null; //Tab Control
  14.  
  15. var paramController = null;
  16.  
  17. //---------------     API FUNCTIONS    ---------------
  18.  
  19. function commandButtons()
  20.     {
  21.       return new Array(
  22.                       MM.BTN_OK,"okClicked()",
  23.                       MM.BTN_Cancel,"window.close()",
  24.                       MM.BTN_Help,"displayHelp()");
  25.     }
  26.  
  27.  
  28. function isDomRequired() {
  29.     return true;
  30. }
  31.  
  32. function receiveArguments()
  33.     {    
  34.     targetDom = arguments[0];
  35.     if (targetDom == null)
  36.         targetDom = dw.getDocumentDOM();
  37.         
  38.     abortCommand = false;
  39.     
  40.     if (!CheckWarnNoTemplate(targetDom))
  41.         abortCommand = true;
  42.     
  43.     var result = new Object();
  44.     
  45.     if (!canMakeTemplateContent("optional", targetDom, result))
  46.         {
  47.         abortCommand = true;
  48.         
  49.         if (result.status == "contained in DW4 edit")
  50.             alert(MM.MSG_SaveDW4First);
  51.         else if (result.status == "locked")
  52.             alert(MSG_cantInsertOptionalHere); 
  53.         else
  54.             alert(MM.MSG_AlreadyEdit);
  55.         }
  56.  
  57.    var curSelNode = null;
  58.    if (arguments.length > 2 && arguments[2] != null)
  59.            curSelNode = arguments[2];
  60.        else
  61.            curSelNode = getUnlockedSelNode(targetDom, false);
  62.  
  63.    if (curSelNode != null && curSelNode.tagName == "MMTEMPLATE:IF" && arguments.length > 1 && arguments[1] == "useSelectedNode")
  64.         selectedOptionalNode = curSelNode;
  65.     
  66.     if (arguments.length > 3 && arguments[3] == "addEditable")
  67.         addEditable = true; 
  68.     else
  69.         addEditable = false; 
  70.                 
  71.     } //receiveArguments
  72.  
  73. function canAcceptCommand()
  74.     {
  75.     targetDom = arguments[0];
  76.     if (targetDom == null)
  77.         targetDom = dw.getDocumentDOM();
  78.         
  79.     return (targetDom != null && dw.getFocus() != 'browser');
  80.     } //canAcceptCommand
  81.  
  82.     
  83. function okClicked()
  84.     {    
  85.     var curDOM = (targetDom == null) ? dw.getDocumentDOM('document') : targetDom;
  86.     
  87.     if (T.getCurPageNum() == 1)
  88.         {
  89.         var newCondName = findObject("condName").value;
  90.         var showByDefault = findObject("showByDefault").checked;
  91.         
  92.         if (stringIsAllDigits(newCondName))
  93.             {
  94.             //parsed as a number - this is not allowed.
  95.             alert(MSG_numberNotAllowed);
  96.             return;
  97.             }
  98.                         
  99.         if (selectedOptionalNode != null)
  100.             {
  101.             curDOM.disableLocking();
  102.             
  103.             if (!checkLegalTemplateName(newCondName))
  104.                 return; //make them enter the name, or cancel the main dialog.
  105.  
  106.             //selectedOptionalNode.cond = dwscripts.minEntityNameEncode(encodeTemplateParam(newCondName, true));
  107.             selectedOptionalNode.cond = encodeTemplateParam(newCondName, true);
  108.  
  109.             //Insert or update the param, if this isn't an expression. Don't encode.
  110.             if (!isExpressionString(newCondName, true))
  111.                 {
  112.                 if (checkInsertTemplateParam(targetDom))
  113.                     insertTemplateParam(newCondName, "boolean", showByDefault ? "true" : "false", targetDom);
  114.                 }
  115.                 
  116.             curDOM.enableLocking();
  117.             window.close();
  118.             }
  119.         else
  120.             {
  121.             var oldParamNode = getTemplateParamTag(newCondName, targetDom);
  122.             if (oldParamNode != null && !RunDSConfirmDialog_YesNo(dwscripts.sprintf(MM.Optional_MSG_ParamExists, newCondName), "showCreateParamWarning", true))
  123.                 return;
  124.  
  125.             if (!doInsertConditional(newCondName,showByDefault, null, targetDom, true, addEditable))
  126.                 return;
  127.                 
  128.             window.close();
  129.             }
  130.         }
  131.     else
  132.         {        
  133.         var isExpression = findObject("expressionRadio").checked;
  134.         var exprString = findObject("expression").value;
  135.  
  136.         var isExistingParam = findObject("existingParamRadio").checked;
  137.         var existingParamToUse = paramController.getValue();
  138.         
  139.         curDOM.synchronizeDocument();
  140.         curDOM.disableLocking();
  141.         var result = false;
  142.                                             
  143.         if (selectedOptionalNode != null)
  144.             {
  145.             if (isExpression && exprString.length > 0)
  146.                 {
  147.                 //selectedOptionalNode.cond = dwscripts.minEntityNameEncode(exprString);
  148.                 selectedOptionalNode.cond = exprString;
  149.                                 
  150.                 result = true;
  151.                 }
  152.             else if (isExistingParam && existingParamToUse != MM.Optional_MSG_None)
  153.                 {
  154.                 //selectedOptionalNode.cond = dwscripts.minEntityNameEncode(encodeTemplateParam(existingParamToUse, true));
  155.                 selectedOptionalNode.cond = encodeTemplateParam(existingParamToUse, true);
  156.                 result = true;
  157.                 }
  158.             else
  159.                 alert(MM.Optional_MSG_MustPick);
  160.             }
  161.         else
  162.             {
  163.             if (isExpression && exprString.length > 0)
  164.                 result = doInsertConditional("",true, exprString, targetDom, false, addEditable);
  165.             else if (isExistingParam && existingParamToUse != MM.Optional_MSG_None)
  166.                 result = doInsertConditional("",true, existingParamToUse, targetDom, true, addEditable);
  167.             else
  168.                 alert(MM.Optional_MSG_MustPick);
  169.             }
  170.         
  171.         curDOM.enableLocking();
  172.     
  173.         if (result)
  174.             {
  175.             curDOM.synchronizeDocument();
  176.             window.close();
  177.             }
  178.         }
  179.     } //okClicked
  180.     
  181.  
  182.     
  183. //---------------    LOCAL FUNCTIONS   ---------------
  184.  
  185.  
  186.  
  187. //Update the selection state on the controls, based on one of them changing.
  188. function updateControls(whichControl)
  189.     {    
  190.     var expressionRadio = findObject("expressionRadio");
  191.     var existingParamRadio = findObject("existingParamRadio");
  192.     
  193.     switch (whichControl)
  194.         {
  195.         case 'expression':
  196.             {
  197.               expressionRadio.checked = true;
  198.               existingParamRadio.checked = false;
  199.               break;
  200.             }
  201.             
  202.         case 'existingParams':
  203.             {
  204.               expressionRadio.checked = false;
  205.               existingParamRadio.checked = true;
  206.               break;
  207.             }
  208.             
  209.         case 'expressionRadio':
  210.             {
  211.               expressionRadio.checked = true;
  212.               existingParamRadio.checked = false;
  213.               break;
  214.             }
  215.             
  216.         case 'existingParamRadio':
  217.             {
  218.               expressionRadio.checked = false;
  219.               existingParamRadio.checked = true;
  220.               break;
  221.             }
  222.         }
  223.     } //updateControls
  224.  
  225.  
  226.  
  227.  
  228. //This is an example of a page class to be used with the TabControl.
  229. //Uncomment the alert() calls to display the various events as they occur.
  230.  
  231. function Pg1(theTabLabel) {
  232.   this.tabLabel = theTabLabel;
  233. }
  234. Pg1.prototype.getTabLabel = Pg1_getTabLabel;
  235.  
  236.  
  237. function Pg1_getTabLabel() {
  238.   return this.tabLabel;
  239. }
  240.  
  241.  
  242. function initializeUI()
  243.     {    
  244.     if (abortCommand)
  245.         {
  246.         window.close();
  247.         return;
  248.         }
  249.  
  250.   var tab0 = findObject("Tab0");
  251.   var tab1 = findObject("Tab1");
  252.  
  253.   //Use appropriate background & tabs for Mac OS X.
  254.   if (dw.isOSX()) {
  255.     findObject("tabBgWin").src = "../Shared/MM/Images/tabBgOSX335x290.gif";    
  256.     var oldMulti = RegExp.multiline;
  257.     RegExp.multiline = true;
  258.     var pat1 = /tabBg\.gif/;
  259.     tab0.innerHTML = tab0.innerHTML.replace(pat1, "tabBgOSX.gif");
  260.       tab1.innerHTML = tab1.innerHTML.replace(pat1, "tabBgOSX.gif");
  261.     var pat2 = /tabBgSel\.gif/;
  262.     tab0.innerHTML = tab0.innerHTML.replace(pat2, "tabBgSelOSX.gif");
  263.     tab1.innerHTML = tab1.innerHTML.replace(pat2, "tabBgSelOSX.gif");
  264.       RegExp.multiline = oldMulti;
  265.   // Use appropriate background & tabs for WinXP with themes  
  266.   } else if (dw.isXPThemed()) {
  267.     findObject("tabBgWin").src = "../Shared/MM/Images/tabBgWinXP335x290.gif";
  268.     var oldMulti = RegExp.multiline;
  269.     RegExp.multiline = true;
  270.     var pat1 = /tabBg\.gif/;
  271.     tab0.innerHTML = tab0.innerHTML.replace(pat1, "tabBgXP.gif");
  272.       tab1.innerHTML = tab1.innerHTML.replace(pat1, "tabBgXP.gif");
  273.     var pat2 = /tabBgSel\.gif/;
  274.     tab0.innerHTML = tab0.innerHTML.replace(pat2, "tabBgSelXP.gif");
  275.     tab1.innerHTML = tab1.innerHTML.replace(pat2, "tabBgSelXP.gif");
  276.     RegExp.multiline = oldMulti;
  277.   // Use standard background  
  278.   } else {    
  279.     findObject("tabBgWin").src = "../Shared/MM/Images/tabBgWin.gif";
  280.   }
  281.  
  282.    T = new TabControl('Tab');
  283.    T.addPage('basic', new Pg1(MM.Optional_LABEL_Basic));
  284.    T.addPage('advanced', new Pg1(MM.Optional_LABEL_Advanced));
  285.   
  286.    var startPage = 'basic';
  287.    currentExpression = "";
  288.           
  289.    if (selectedOptionalNode != null)
  290.            currentExpression = decodeTemplateParam(dwscripts.minEntityNameDecode(selectedOptionalNode.cond));
  291.    else
  292.        {
  293.        //auto-name the optional area. 
  294.        //Count the number of optional areas, add one. 
  295.        currentExpression = getUniqueRegionName(MM.OptionalAutonamePreamble, "MMTemplate:If",  dw.getDocumentDOM('document'));
  296.        }
  297.            
  298.    var isExpression = (selectedOptionalNode != null && isExpressionString(currentExpression, true));
  299.   
  300.    if (isExpression)
  301.       startPage = 'advanced';
  302.        
  303.    T.start(startPage);
  304.  
  305.   
  306.    if (currentExpression != "")
  307.        {
  308.         findObject("condName").value = currentExpression;
  309.         findObject("expression").value = currentExpression;
  310.         }
  311.         
  312.     if (startPage == 'basic')
  313.         {
  314.           findObject("condName").focus(); //set focus on textbox
  315.           findObject("condName").select(); //set insertion point into textbox
  316.           }
  317.           
  318.       findObject("expressionRadio").checked = isExpression;
  319.       findObject("existingParamRadio").checked = !isExpression;
  320.  
  321.       //Setup the popup of existing params.
  322.       paramController = new ListControl("existingParams");
  323.       var boolParams =  getTemplateParams("boolean", null);
  324.       
  325.       var paramNames = new Array();
  326.       paramNames.push(MM.Optional_MSG_None);
  327.       for (i=0;i<boolParams.length;i++)
  328.           paramNames.push(boolParams[i].name);
  329.           
  330.       paramController.setAll(paramNames, paramNames);      
  331.     if (!isExpression && selectedOptionalNode != null && currentExpression.length > 0)
  332.         paramController.pickValue(currentExpression);
  333.     if (selectedOptionalNode != null)
  334.         {
  335.         var curDOM = (targetDom == null) ? dw.getDocumentDOM('document') : targetDom;
  336.         var paramTag = getTemplateParamTag(currentExpression, curDOM);
  337.  
  338.         if (paramTag != null)
  339.             {
  340.             findObject("showByDefault").checked = paramTag.value == "true";
  341.               findObject("existingParamRadio").checked = true;
  342.               findObject("expressionRadio").checked = false;
  343.               paramController.pickValue(paramTag.name);
  344.             }
  345.         }
  346.     } //initializeUI
  347.  
  348.  
  349.