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

  1. //  Copyright 2001 Macromedia, Inc. All rights reserved.
  2.  
  3. //form fields:
  4. //Background - multiple list listing background colors
  5. //Text - multiple list listing text colors. Contents change when new Background item picked.
  6.  
  7. // ******************* GLOBALS **********************
  8.  
  9. var helpDoc = MM.HELP_templateProperties;
  10.  
  11. //This is the data passed into the dialog, and this is used to return data as well. If declared in C, this 
  12. //object would look something like this: 
  13. //struct { 
  14. //        values;                         //Set of all the template parameters that can be changed 
  15. //                                        //in this dialog. This is an object where the attributes
  16. //                                        //are the names of the params, and the values 
  17. //                                        //are the param values.
  18. //        types;                            //The types for all the params in the dialog. This is an
  19. //                                        //object, the attributes are the template attributes, and 
  20. //                                        //the values are either "boolean", "number", "color" , "text", "URL"
  21. //                                        // NOTE: 'CHOICES' IS NOT CURRENTLY SUPPORTED
  22. //        passthrough;                    //object containing a boolean for each attribute, whether it is passthrough or not.
  23. //        returnValue;                    //passed in as -1, set to 1 for success, 0 for cancel. 
  24. //        };
  25.  
  26. var dialogData = null;
  27. var isFake = false; //Used for debugging 
  28.  
  29. var PLATFORM = navigator.platform;
  30.  
  31. //I cache the DOM objects for the layers, so I don't have to search for them all the time. 
  32. var boolControlLayer = null; 
  33. var numberControlLayer = null; 
  34. var colorControlLayer = null; 
  35. var textControlLayer = null; 
  36. var linkControlLayer = null; 
  37. var noControlLayer = null; 
  38. var passthroughSpan = null; 
  39. var passthroughSpanHTML = null; 
  40.  
  41.  
  42. var targetLayer = null; 
  43.  
  44. //This is the currently visible control layer. 
  45. var curVisibleLayer = null;
  46.  
  47. var errorPending = false; 
  48.  
  49. //******************* API **********************
  50.  
  51. function isDomRequired() {return true;} 
  52.  
  53. //Just grab the first argument and stuff it into a global. 
  54. function receiveArguments()
  55.     {        
  56.     dialogData = dw.getDocumentDOM().getTemplateParameters();
  57.     }
  58.  
  59.  
  60. function canAcceptCommand()
  61.     {    
  62.     var curDOM = dw.getDocumentDOM(); 
  63.     
  64.     if (curDOM == null)
  65.         return false; 
  66.         
  67.     return (curDOM.getAttachedTemplate().length > 0);
  68.     } //canAcceptCommand
  69.     
  70. function cmdOK()
  71.     {
  72.     if (!isFake)
  73.         {
  74.         var curDOM = dw.getDocumentDOM();
  75.         curDOM.disableLocking();
  76.         if (!curDOM.setTemplateParameters(dialogData))
  77.             return; 
  78.         }
  79.         
  80.     if (errorPending)
  81.         return; 
  82.         
  83.     dialogData.returnValue = 1; 
  84.     window.close();
  85.     } //cmdOK
  86.  
  87.  
  88. function cmdCancel()
  89.     {
  90.       dialogData.returnValue = 0; 
  91.       window.close();
  92.     } //cmdCancel
  93.  
  94.     
  95.  
  96. //***************** LOCAL FUNCTIONS  ******************
  97.     
  98. function initializeUI()
  99.     {
  100.     errorPending = false; 
  101.     if (dialogData == null)
  102.         {
  103.         window.close(); 
  104.         //alert(MSG_CantRun); 
  105.         return; 
  106.         }
  107.         
  108.     //Find the layer objects. 
  109.     boolControlLayer = findObject("booleanControls", null);     
  110.     numberControlLayer = findObject("numberControls", null); 
  111.     colorControlLayer = findObject("colorControls", null); 
  112.     textControlLayer = findObject("textControls", null); 
  113.     linkControlLayer = findObject("linkControls", null); 
  114.     noControlLayer = findObject("noControls", null); 
  115.  
  116.     passthroughSpan = findObject("passthroughSpan", null); 
  117.     
  118.     if (passthroughSpanHTML == null) 
  119.         passthroughSpanHTML = passthroughSpan.innerHTML; 
  120.     
  121.     targetLayer = findObject("visibleSpan", null);
  122.     curVisibleLayer = noControlLayer; 
  123.     
  124.       SetupTree();
  125.       SetupControls();
  126.       //FixControlLayers(null);
  127.     } //initializeUI
  128.  
  129.  
  130. function adjustButtons()
  131. {
  132.   var theStyle;
  133.   if (PLATFORM=="Win32")
  134.   {
  135.     theStyle=document.okLayer.getAttribute("STYLE");
  136.     theStyle=theStyle.replace(/left:\w*;/,LEFT_LAYER).replace(/top:\w*;/,TOP_LAYER);
  137.     document.okLayer.setAttribute("STYLE", theStyle);
  138.     theStyle=document.cancelLayer.getAttribute("STYLE");
  139.     theStyle=theStyle.replace(/left:\w*;/,RIGHT_LAYER).replace(/top:\w*;/,TOP_LAYER);
  140.     document.cancelLayer.setAttribute("STYLE", theStyle);
  141.   }
  142. }
  143.  
  144. //Add the 'categories' tag to the string stream
  145. function AddCategoriesToTreeStream(theStream)
  146.     {
  147.     theStream.push("<mm:treecolumn name='", LABEL_NameCol, "' value='", LABEL_NameCol, "'  width='200'/>"); 
  148.     theStream.push("<mm:treecolumn name='", LABEL_ValueCol, "' value='", LABEL_ValueCol, "' width='130'/>"); 
  149.     } //AddCategoriesToTreeString
  150.     
  151.     
  152. //Add the treenode for this category to the innerHTML string for the tree node
  153. function OpenCatNode(labelString, theStream)
  154.     {
  155.     theStream.push("<mm:treenode selected value = '",labelString,"' id=-1 state='expanded'>");
  156.     } //AddCatNodeToString
  157.     
  158. function CloseCatNode(theStream)
  159.     {
  160.     theStream.push("</mm:treenode>");
  161.     }
  162.  
  163. function GetVisibleValueString(paramName)
  164.     {
  165.     if (dialogData == null)
  166.         return "";
  167.         
  168.     if (dialogData.passthrough[paramName])
  169.         return LABEL_Passthrough; 
  170.         
  171.     if (dialogData.types[paramName] == "boolean")
  172.         {
  173.         var paramValue = dialogData.values[paramName]; 
  174.         return (paramValue == "true") ? LABEL_TRUE : LABEL_FALSE; 
  175.         }
  176.         
  177.     return dialogData.values[paramName];
  178.     } //GetVisibleValueString
  179.     
  180.     
  181. //Add the string for a single node in the tree. Should look something like: 
  182. //<mm:treenode  value = "Conditional 1|<Not Resolved>" paramName="some name" valueType="number" ></mm:treenode> 
  183. function AddParamNode(paramName, theStream, selected)
  184.     {    
  185.     //var selectedString = selected ? "selected" : ""; 
  186.     var selectedString = ""; 
  187.     
  188.     theStream.push("<mm:treenode  value = '", paramName,  "|", GetVisibleValueString(paramName),  
  189.                       "' paramName='", paramName, "' valueType='", dialogData.types[paramName], "' ", selectedString , " ></mm:treenode>"); 
  190.     } //AddParamNode
  191.     
  192.     
  193. //Build and insert the inner HTML for the tree control
  194. function SetupTree()
  195.     {    
  196.     var theStream = new Array();
  197.     theStream.push("");
  198.      
  199.     AddCategoriesToTreeStream(theStream);
  200.     
  201.     var i; 
  202.     var count = 0; 
  203.     
  204.     //Sort the list of params alphabetically. 
  205.     var paramNames = new Array(); 
  206.     for (i in dialogData.values)
  207.         paramNames.push(i); 
  208.     paramNames.sort();
  209.     
  210.     //Add them to the tree
  211.     for (i=0; i<paramNames.length; i++)
  212.         {
  213.         AddParamNode(paramNames[i], theStream, count==0);    
  214.         count++;
  215.         }
  216.     
  217.     if (count == 0)
  218.         theStream.push("<mm:treenode  value = '" + LABEL_NoParams + " | '     paramName='bar' valueType='none' ></mm:treenode>");
  219.             
  220.     //var theTree = findObject("theTreeControl", null); 
  221.     var theTree = dwscripts.findDOMObject("theTreeControl", null); 
  222.     theTree.innerHTML = theStream.join(""); 
  223.     } //SetupTree
  224.     
  225.  
  226.     
  227. //Everything is off unless on
  228. function FixControlLayers(selectedTreeNode)
  229.     {        
  230.     if (selectedTreeNode == null || selectedTreeNode.valueType == 'none')
  231.         {                    
  232.         targetLayer.innerHTML = noControlLayer.innerHTML; 
  233.         curVisibleLayer = noControlLayer;     
  234.         passthroughSpan.innerHTML = ""; 
  235.         return;     
  236.         }
  237.     
  238.     passthroughSpan.innerHTML = passthroughSpanHTML;
  239.     if (dialogData.passthrough[selectedTreeNode.paramName])
  240.         {
  241.         targetLayer.innerHTML = LABEL_Passthrough; 
  242.         document.theForm.passthroughCheck.checked = true; 
  243.         curVisibleLayer = noControlLayer;
  244.         return;      
  245.         }
  246.         
  247.     var newActiveLayer = noControlLayer; 
  248.     document.theForm.passthroughCheck.checked = false; 
  249.  
  250.     switch (selectedTreeNode.valueType)
  251.         {
  252.         case "boolean":
  253.             newActiveLayer = boolControlLayer;  break;
  254.         case "number":
  255.             newActiveLayer = numberControlLayer;  break;
  256.         case "color":
  257.             newActiveLayer = colorControlLayer; break;
  258.         case "text":
  259.             newActiveLayer = textControlLayer;  break;
  260.         case "link":
  261.         case "URL":
  262.             newActiveLayer = linkControlLayer; break;
  263.         }
  264.         
  265.     if (curVisibleLayer != newActiveLayer)
  266.         {
  267.         targetLayer.innerHTML = newActiveLayer.innerHTML; 
  268.         curVisibleLayer = newActiveLayer; 
  269.         }        
  270.     
  271.     //Customize the string for the selected value
  272.     var showString = selectedTreeNode.paramName; 
  273.     if (selectedTreeNode.valueType == "boolean")
  274.         showString = errMsg(LABEL_Show, selectedTreeNode.paramName);
  275.         
  276.     var labelSpan = findObject("propLabel", null); 
  277.     if (labelSpan != null)
  278.         labelSpan.innerHTML = showString; 
  279. } //FixControlLayers
  280.         
  281.  
  282. //Move the values currently stored in this parameter into the controls for it's type. 
  283. function MoveValuesToControl(selectedNode)
  284.     {
  285.     if (selectedNode == null || selectedNode.valueType == 'none')
  286.         return; 
  287.     
  288.     var attrName = selectedNode.paramName; 
  289.     if (dialogData.passthrough[attrName])
  290.         return; //No controls in this case 
  291.         
  292.     var controlName = ""; 
  293.     var controlObj = null;
  294.     switch (selectedNode.valueType)
  295.         {
  296.         case "boolean": controlName = "booleanCheck";     break;
  297.         case "number":     controlName = "numberField";     break; 
  298.         case "color":     controlName = "colorField";      break;
  299.         case "text":     controlName = "textField";          break;    
  300.         
  301.         case "link":     
  302.         case "URL":     
  303.             controlName = "linkField";      break;
  304.         }
  305.     
  306.     if (controlName == "")
  307.         return; 
  308.         
  309.     //Select the control...
  310.     var controlObj = findObject(controlName, null); 
  311.     
  312.     if (controlObj != null)
  313.         {
  314.         
  315.         //If this is a text control, move the focus into it. 
  316.         if (controlName == "booleanCheck")    
  317.             controlObj.checked = (dialogData.values[attrName] == "true");
  318.         else
  319.             {
  320.             controlObj.value = dialogData.values[attrName];
  321.             if (typeof controlObj["focus"] != "undefined")
  322.                   controlObj.focus(); //set focus on textbox
  323.                   
  324.             if (typeof controlObj["select"] != "undefined")
  325.                   controlObj.select(); //set insertion point into textbox
  326.             }
  327.             
  328.         if (selectedNode.valueType == "color")
  329.             {
  330.             controlObj = findObject("colorPicker", null); 
  331.             if (controlObj != null)
  332.                 controlObj.value = dialogData.values[attrName];
  333.             }
  334.         }
  335.  
  336.     } //MoveValuesToControl
  337.     
  338.         
  339.     
  340. // changes the 'resolve' popup to show the possibilities for the current node
  341. function SetupControls()
  342.     {
  343.     var theTree = findObject("theTreeControl", null); 
  344.     
  345.     var selectedTreeNode = theTree.selectedNodes[0];    
  346.     FixControlLayers(selectedTreeNode);
  347.     MoveValuesToControl(selectedTreeNode);
  348.     
  349.     if (selectedTreeNode)
  350.         selectedTreeNode.selected = true; //some bug in the tree control...
  351.     } //SetupControls
  352.  
  353.  
  354. //Once the user picks an entry from the list, store it back in the dialogData object
  355. function StoreNodeValue()
  356.     {
  357.     var selectedNode = findObject("theTreeControl", null).selectedNodes[0];
  358.     if (selectedNode == null)
  359.         return false; 
  360.         
  361.     var controlObj = null; 
  362.     var attrName = selectedNode.paramName; 
  363.     
  364.     switch (selectedNode.valueType)
  365.         {
  366.         case "boolean":
  367.             {
  368.             controlObj = findObject("booleanCheck", null);         
  369.             var isChecked = false; 
  370.             if (typeof    controlObj.checked == "string")
  371.                 isChecked = (controlObj.checked == "true"); 
  372.             else
  373.                 isChecked = controlObj.checked; 
  374.                 
  375.             if (controlObj != null)
  376.                 dialogData.values[attrName] = isChecked ? "true" :  "false";
  377.             break;
  378.             }
  379.             
  380.         case "number":
  381.             {
  382.             controlObj = findObject("numberField", null); 
  383.             if (controlObj != null)
  384.                 {
  385.                 var controlValue = controlObj.value; 
  386.                 if (isNaN(controlValue))
  387.                     {
  388.                     if (errorPending)
  389.                         return false;  
  390.  
  391.                     alert(MSG_isNAN);
  392.                     errorPending = true; 
  393.  
  394.                     return false; 
  395.                     }
  396.                 dialogData.values[attrName] = controlObj.value;
  397.                 }
  398.                 
  399.             break;
  400.             }
  401.  
  402.         case "color":
  403.             {
  404.             controlObj = findObject("colorField", null); 
  405.             if (controlObj != null)
  406.                 dialogData.values[attrName] = controlObj.value;
  407.             break;
  408.             }
  409.             
  410.         case "text":
  411.             {
  412.             controlObj = findObject("textField", null); 
  413.             if (controlObj != null)
  414.                 dialogData.values[attrName] = controlObj.value;
  415.             break;
  416.             }
  417.             
  418.         case "URL":
  419.         case "link":
  420.             {
  421.             controlObj = findObject("linkField", null); 
  422.             if (controlObj != null)
  423.                 dialogData.values[attrName] = controlObj.value;
  424.             break;
  425.             }
  426.         }
  427.         
  428.     errorPending = false;     
  429.     dialogData.passthrough[attrName] = document.theForm.passthroughCheck.checked;
  430.     
  431.     var newNodeString = attrName + "|" + GetVisibleValueString(attrName); 
  432.     selectedNode.value = newNodeString; 
  433.     return true; 
  434.     } //StoreNodeValue
  435.     
  436.     
  437.     
  438. //Called when one of the controls changes, this either resets the popup menu to reflect the current 
  439. //selected node, or stores the resolution in the tree and data store
  440. function updateUI(itemName)
  441.     {
  442.       switch(itemName)
  443.           {
  444.           case "theTreeControl":
  445.               {
  446.             SetupControls();
  447.  
  448.             break;
  449.               }
  450.               
  451.         case "colorField": 
  452.           case "colorPicker":
  453.               {              
  454.               //If the user types into the color field, move the data into the colorPicker field, 
  455.               //and then store the value. 
  456.             var fieldObj = findObject("colorField", null); 
  457.             var pickerObj = findObject("colorPicker", null); 
  458.             
  459.             if (fieldObj != null && pickerObj != null)
  460.                 {
  461.                 if (itemName == "colorField")
  462.                     pickerObj.value = fieldObj.value; 
  463.                 else
  464.                     {
  465.                     //alert("setting field to " + pickerObj.value);
  466.                     fieldObj.value = pickerObj.value; 
  467.                     }
  468.                 }
  469.                 
  470.             StoreNodeValue();
  471.             break; 
  472.               }
  473.           
  474.           case "boolCheck":
  475.           case "textField":
  476.           case "linkField": 
  477.           case "numberField": 
  478.               {
  479.               StoreNodeValue();
  480.             break;
  481.               }
  482.         
  483.         case "passthroughCheck": 
  484.             {
  485.             var selectedNode = findObject("theTreeControl", null).selectedNodes[0];
  486.             if (selectedNode == null)
  487.                 return; 
  488.                                 
  489.             var attrName = selectedNode.paramName; 
  490.             var isPassthrough = document.theForm.passthroughCheck.checked; 
  491.             dialogData.passthrough[attrName] = isPassthrough;
  492.             
  493.             var newNodeString = attrName + "|" + GetVisibleValueString(attrName); 
  494.             selectedNode.value = newNodeString; 
  495.  
  496.             FixControlLayers(selectedNode);
  497.                         
  498.             //Pull the old values out.
  499.             if (!isPassthrough)
  500.                 MoveValuesToControl(selectedNode);
  501.  
  502.             break; 
  503.             }
  504.                 
  505.           } //switch
  506.     } //updateUI
  507.  
  508.  
  509.