home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / code / contr / setup.exe / Disk1 / data1.cab / Configuration_En / Commands / TemplateParams.js < prev    next >
Encoding:
JavaScript  |  2003-07-18  |  15.4 KB  |  596 lines

  1. //  Copyright 2001, 2002, 2003 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.  
  50. // ******************* API **********************
  51.  
  52. //--------------------------------------------------------------------
  53. // FUNCTION:
  54. //   commandButtons
  55. //
  56. // DESCRIPTION:
  57. //   The list of buttons to display on the right of the dialog,
  58. //   along with the functions to call when they are pressed.
  59. //
  60. // ARGUMENTS:
  61. //   none
  62. //
  63. // RETURNS:
  64. //   javascript array
  65. //--------------------------------------------------------------------
  66.  
  67. function commandButtons()
  68. {
  69. /*    return new Array(MM.BTN_OK,     "cmdOK();",
  70.                    MM.BTN_Cancel, "cmdCancel()",
  71.                    MM.BTN_Apply, "cmdApply()",
  72.                    MM.BTN_Help,   "displayHelp();"
  73.                    );
  74. */
  75.  
  76.     return new Array( "PutButtonsOnBottom", "OkButton", MM.BTN_OK, "cmdOK()",
  77.                       "PutButtonOnLeft", MM.BTN_Help,    "displayHelp()",
  78.                       "CancelButton", MM.BTN_Cancel,  "cmdCancel()",
  79.                       "ApplyButton", MM.BTN_Apply, "cmdApply()");
  80.  
  81.  
  82.  
  83.  
  84. }
  85.  
  86.  
  87.  
  88. function isDomRequired() {return true;} 
  89.  
  90. //Just grab the first argument and stuff it into a global. 
  91. function receiveArguments()
  92.     {        
  93.         dialogData = dw.getDocumentDOM().getTemplateParameters();
  94.         if (dialogData == null)
  95.         {
  96.             alert(MSG_CantRun); 
  97.             return "abort";
  98.         }
  99.     }
  100.  
  101.  
  102. function canAcceptCommand()
  103.     {    
  104.         var curDOM = dw.getDocumentDOM();     
  105.         if (curDOM == null)
  106.             return false; 
  107.  
  108.         dialogData = dw.getDocumentDOM().getTemplateParameters();
  109.         if (dialogData == null)
  110.             return false;
  111.             
  112.         return (curDOM.getAttachedTemplate().length > 0);
  113.     } //canAcceptCommand
  114.     
  115. function cmdOK()
  116.     {
  117.     if (!isFake)
  118.         {
  119.         var curDOM = dw.getDocumentDOM();
  120.         curDOM.disableLocking();
  121.         if (!curDOM.setTemplateParameters(dialogData))
  122.             return; 
  123.         }
  124.         
  125.     if (errorPending)
  126.         return; 
  127.         
  128.     dialogData.returnValue = 1; 
  129.     window.close();
  130.     } //cmdOK
  131.  
  132. function cmdApply ()
  133.     {
  134.     if (!isFake)
  135.         {
  136.         var curDOM = dw.getDocumentDOM();
  137.         curDOM.disableLocking();
  138.         if (!curDOM.setTemplateParameters(dialogData))
  139.             return; 
  140.         }
  141.         
  142.     if (errorPending)
  143.         return; 
  144.         
  145.     dialogData.returnValue = 1; 
  146.  
  147. }
  148.  
  149. function cmdCancel()
  150.     {
  151.       dialogData.returnValue = 0; 
  152.       window.close();
  153.     } //cmdCancel
  154.  
  155.     
  156.  
  157. //***************** LOCAL FUNCTIONS  ******************
  158.     
  159. function initializeUI()
  160.     {
  161.     errorPending = false; 
  162.     if (dialogData == null)
  163.         {
  164.         window.close(); 
  165.         //alert(MSG_CantRun); 
  166.         return; 
  167.         }
  168.         
  169.     //Find the layer objects. 
  170.     boolControlLayer = findObject("booleanControls", null);     
  171.     numberControlLayer = findObject("numberControls", null); 
  172.     colorControlLayer = findObject("colorControls", null); 
  173.     textControlLayer = findObject("textControls", null); 
  174.     linkControlLayer = findObject("linkControls", null); 
  175.     noControlLayer = findObject("noControls", null); 
  176.  
  177.     passthroughSpan = findObject("passthroughSpan", null); 
  178.   
  179.   // find the table
  180.   var tableObj = findObject("mainTable");
  181.   if (dw.isOSX()){
  182.     tableObj.setAttribute("height","300");
  183.   }
  184.     
  185.     if (passthroughSpanHTML == null) 
  186.         passthroughSpanHTML = passthroughSpan.innerHTML; 
  187.     
  188.     targetLayer = findObject("visibleSpan", null);
  189.     curVisibleLayer = noControlLayer; 
  190.     
  191.       SetupTree();
  192.       SetupControls();
  193.   window.resizeToContents(); 
  194.       //FixControlLayers(null);
  195.     } //initializeUI
  196.  
  197.  
  198. function adjustButtons()
  199. {
  200.   var theStyle;
  201.   if (PLATFORM=="Win32")
  202.   {
  203.     theStyle=document.okLayer.getAttribute("STYLE");
  204.     theStyle=theStyle.replace(/left:\w*;/,LEFT_LAYER).replace(/top:\w*;/,TOP_LAYER);
  205.     document.okLayer.setAttribute("STYLE", theStyle);
  206.     theStyle=document.cancelLayer.getAttribute("STYLE");
  207.     theStyle=theStyle.replace(/left:\w*;/,RIGHT_LAYER).replace(/top:\w*;/,TOP_LAYER);
  208.     document.cancelLayer.setAttribute("STYLE", theStyle);
  209.   }
  210. }
  211.  
  212. //Add the 'categories' tag to the string stream
  213. function AddCategoriesToTreeStream(theStream)
  214.     {
  215.     theStream.push("<mm:treecolumn name='", LABEL_NameCol, "' value='", LABEL_NameCol, "'  width='200'/>"); 
  216.     theStream.push("<mm:treecolumn name='", LABEL_ValueCol, "' value='", LABEL_ValueCol, "' width='130'/>"); 
  217.     } //AddCategoriesToTreeString
  218.     
  219.     
  220. //Add the treenode for this category to the innerHTML string for the tree node
  221. function OpenCatNode(labelString, theStream)
  222.     {
  223.     theStream.push("<mm:treenode selected value = '",labelString,"' id=-1 state='expanded'>");
  224.     } //AddCatNodeToString
  225.     
  226. function CloseCatNode(theStream)
  227.     {
  228.     theStream.push("</mm:treenode>");
  229.     }
  230.  
  231. function GetVisibleValueString(paramName)
  232.     {
  233.     if (dialogData == null)
  234.         return "";
  235.  
  236.     if (dw.appName != "Contribute")
  237.         {
  238.         if (dialogData.passthrough[paramName])
  239.             return LABEL_Passthrough;
  240.         }
  241.         
  242.     if (dialogData.types[paramName] == "boolean")
  243.         {
  244.         var paramValue = dialogData.values[paramName]; 
  245.         return (paramValue == "true") ? LABEL_TRUE : LABEL_FALSE; 
  246.         }
  247.         
  248.     return dialogData.values[paramName];
  249.     } //GetVisibleValueString
  250.     
  251.     
  252. //Add the string for a single node in the tree. Should look something like: 
  253. //<mm:treenode  value = "Conditional 1|<Not Resolved>" paramName="some name" valueType="number" ></mm:treenode> 
  254. function AddParamNode(paramName, theStream, selected)
  255.     {    
  256.     //var selectedString = selected ? "selected" : ""; 
  257.     var selectedString = ""; 
  258.     
  259.     theStream.push("<mm:treenode  value = '", paramName,  "|", GetVisibleValueString(paramName),  
  260.                       "' paramName='", paramName, "' valueType='", dialogData.types[paramName], "' ", selectedString , " ></mm:treenode>"); 
  261.     } //AddParamNode
  262.     
  263.     
  264. //Build and insert the inner HTML for the tree control
  265. function SetupTree()
  266.     {    
  267.     var theStream = new Array();
  268.     theStream.push("");
  269.      
  270.     AddCategoriesToTreeStream(theStream);
  271.     
  272.     var i; 
  273.     var count = 0; 
  274.     
  275.     //Sort the list of params alphabetically. 
  276.     var paramNames = new Array(); 
  277.     for (i in dialogData.values)
  278.         paramNames.push(i); 
  279.     paramNames.sort();
  280.     
  281.     //Add them to the tree
  282.     for (i=0; i<paramNames.length; i++)
  283.         {
  284.         AddParamNode(paramNames[i], theStream, count==0);    
  285.         count++;
  286.         }
  287.     
  288.     if (count == 0)
  289.         theStream.push("<mm:treenode  value = '" + LABEL_NoParams + " | '     paramName='bar' valueType='none' ></mm:treenode>");
  290.             
  291.     //var theTree = findObject("theTreeControl", null); 
  292.     var theTree = dwscripts.findDOMObject("theTreeControl", null); 
  293.     theTree.innerHTML = theStream.join(""); 
  294.     } //SetupTree
  295.     
  296.  
  297.     
  298. //Everything is off unless on
  299. function FixControlLayers(selectedTreeNode)
  300.     {        
  301.     if (selectedTreeNode == null || selectedTreeNode.valueType == 'none')
  302.         {                    
  303.         targetLayer.innerHTML = noControlLayer.innerHTML; 
  304.         curVisibleLayer = noControlLayer;     
  305.         passthroughSpan.innerHTML = ""; 
  306.         return;     
  307.         }
  308.     
  309.     // In Ringo, don't show the "pass through" checkbox, because it
  310.     // only makes sense when authoring nested templates.
  311.     if (dw.appName == "Contribute")
  312.         {
  313.         passthroughSpan.innerHTML = "";
  314.         }
  315.     else
  316.         {
  317.         passthroughSpan.innerHTML = passthroughSpanHTML;
  318.  
  319.         if (dialogData.passthrough[selectedTreeNode.paramName])
  320.             {
  321.             targetLayer.innerHTML = LABEL_Passthrough; 
  322.             document.theForm.passthroughCheck.checked = true; 
  323.             curVisibleLayer = noControlLayer;
  324.             return;      
  325.             }
  326.         
  327.         document.theForm.passthroughCheck.checked = false;
  328.         }
  329.  
  330.     var newActiveLayer = noControlLayer; 
  331.  
  332.     switch (selectedTreeNode.valueType)
  333.         {
  334.         case "boolean":
  335.             newActiveLayer = boolControlLayer;  break;
  336.         case "number":
  337.             newActiveLayer = numberControlLayer;  break;
  338.         case "color":
  339.             newActiveLayer = colorControlLayer; break;
  340.         case "text":
  341.             newActiveLayer = textControlLayer;  break;
  342.         case "link":
  343.         case "URL":
  344.             newActiveLayer = linkControlLayer; break;
  345.         }
  346.         
  347.     if (curVisibleLayer != newActiveLayer)
  348.         {
  349.         targetLayer.innerHTML = newActiveLayer.innerHTML; 
  350.         curVisibleLayer = newActiveLayer; 
  351.         }        
  352.     
  353.     //Customize the string for the selected value
  354.     var showString = selectedTreeNode.paramName; 
  355.     if (selectedTreeNode.valueType == "boolean")
  356.         showString = errMsg(LABEL_Show, selectedTreeNode.paramName);
  357.         
  358.     var labelSpan = findObject("propLabel", null); 
  359.     if (labelSpan != null)
  360.         labelSpan.innerHTML = showString; 
  361. } //FixControlLayers
  362.         
  363.  
  364. //Move the values currently stored in this parameter into the controls for it's type. 
  365. function MoveValuesToControl(selectedNode)
  366.     {
  367.     if (selectedNode == null || selectedNode.valueType == 'none')
  368.         return; 
  369.     
  370.     var attrName = selectedNode.paramName; 
  371.     if (dialogData.passthrough[attrName])
  372.         return; //No controls in this case 
  373.         
  374.     var controlName = ""; 
  375.     var controlObj = null;
  376.     switch (selectedNode.valueType)
  377.         {
  378.         case "boolean": controlName = "booleanCheck";     break;
  379.         case "number":     controlName = "numberField";     break; 
  380.         case "color":     controlName = "colorField";      break;
  381.         case "text":     controlName = "textField";          break;    
  382.         
  383.         case "link":     
  384.         case "URL":     
  385.             controlName = "linkField";      break;
  386.         }
  387.     
  388.     if (controlName == "")
  389.         return; 
  390.         
  391.     //Select the control...
  392.     var controlObj = findObject(controlName, null); 
  393.     
  394.     if (controlObj != null)
  395.         {
  396.         
  397.         //If this is a text control, move the focus into it. 
  398.         if (controlName == "booleanCheck")    
  399.             controlObj.checked = (dialogData.values[attrName] == "true");
  400.         else
  401.             {
  402.             controlObj.value = dialogData.values[attrName];
  403.             if (typeof controlObj["focus"] != "undefined")
  404.                   controlObj.focus(); //set focus on textbox
  405.                   
  406.             if (typeof controlObj["select"] != "undefined")
  407.                   controlObj.select(); //set insertion point into textbox
  408.             }
  409.             
  410.         if (selectedNode.valueType == "color")
  411.             {
  412.             controlObj = findObject("colorPicker", null); 
  413.             if (controlObj != null)
  414.                 controlObj.value = dialogData.values[attrName];
  415.             }
  416.         }
  417.  
  418.     } //MoveValuesToControl
  419.     
  420.         
  421.     
  422. // changes the 'resolve' popup to show the possibilities for the current node
  423. function SetupControls()
  424.     {
  425.     var theTree = findObject("theTreeControl", null); 
  426.     
  427.     var selectedTreeNode = theTree.selectedNodes[0];    
  428.     FixControlLayers(selectedTreeNode);
  429.     MoveValuesToControl(selectedTreeNode);
  430.     
  431.     if (selectedTreeNode)
  432.         selectedTreeNode.selected = true; //some bug in the tree control...
  433.     } //SetupControls
  434.  
  435.  
  436. //Once the user picks an entry from the list, store it back in the dialogData object
  437. function StoreNodeValue()
  438.     {
  439.     var selectedNode = findObject("theTreeControl", null).selectedNodes[0];
  440.     if (selectedNode == null)
  441.         return false; 
  442.         
  443.     var controlObj = null; 
  444.     var attrName = selectedNode.paramName; 
  445.     
  446.     switch (selectedNode.valueType)
  447.         {
  448.         case "boolean":
  449.             {
  450.             controlObj = findObject("booleanCheck", null);         
  451.             var isChecked = false; 
  452.             if (typeof    controlObj.checked == "string")
  453.                 isChecked = (controlObj.checked == "true"); 
  454.             else
  455.                 isChecked = controlObj.checked; 
  456.                 
  457.             if (controlObj != null)
  458.                 dialogData.values[attrName] = isChecked ? "true" :  "false";
  459.             break;
  460.             }
  461.             
  462.         case "number":
  463.             {
  464.             controlObj = findObject("numberField", null); 
  465.             if (controlObj != null)
  466.                 {
  467.                 var controlValue = controlObj.value; 
  468.                 if (isNaN(controlValue))
  469.                     {
  470.                     if (errorPending)
  471.                         return false;  
  472.  
  473.                     alert(MSG_isNAN);
  474.                     errorPending = true; 
  475.  
  476.                     return false; 
  477.                     }
  478.                 dialogData.values[attrName] = controlObj.value;
  479.                 }
  480.                 
  481.             break;
  482.             }
  483.  
  484.         case "color":
  485.             {
  486.             controlObj = findObject("colorField", null); 
  487.             if (controlObj != null)
  488.                 dialogData.values[attrName] = controlObj.value;
  489.             break;
  490.             }
  491.             
  492.         case "text":
  493.             {
  494.             controlObj = findObject("textField", null); 
  495.             if (controlObj != null)
  496.                 dialogData.values[attrName] = controlObj.value;
  497.             break;
  498.             }
  499.             
  500.         case "URL":
  501.         case "link":
  502.             {
  503.             controlObj = findObject("linkField", null); 
  504.             if (controlObj != null)
  505.                 dialogData.values[attrName] = controlObj.value;
  506.             break;
  507.             }
  508.         }
  509.         
  510.     errorPending = false;
  511.     if (dw.appName == "Contribute")
  512.         dialogData.passthrough[attrName] = false;
  513.     else
  514.         dialogData.passthrough[attrName] = document.theForm.passthroughCheck.checked;
  515.     
  516.     var newNodeString = attrName + "|" + GetVisibleValueString(attrName); 
  517.     selectedNode.value = newNodeString; 
  518.     return true; 
  519.     } //StoreNodeValue
  520.     
  521.     
  522.     
  523. //Called when one of the controls changes, this either resets the popup menu to reflect the current 
  524. //selected node, or stores the resolution in the tree and data store
  525. function updateUI(itemName)
  526.     {
  527.       switch(itemName)
  528.           {
  529.           case "theTreeControl":
  530.               {
  531.             SetupControls();
  532.  
  533.             break;
  534.               }
  535.               
  536.         case "colorField": 
  537.           case "colorPicker":
  538.               {              
  539.               //If the user types into the color field, move the data into the colorPicker field, 
  540.               //and then store the value. 
  541.             var fieldObj = findObject("colorField", null); 
  542.             var pickerObj = findObject("colorPicker", null); 
  543.             
  544.             if (fieldObj != null && pickerObj != null)
  545.                 {
  546.                 if (itemName == "colorField")
  547.                     pickerObj.value = fieldObj.value; 
  548.                 else
  549.                     {
  550.                     //alert("setting field to " + pickerObj.value);
  551.                     fieldObj.value = pickerObj.value; 
  552.                     }
  553.                 }
  554.                 
  555.             StoreNodeValue();
  556.             break; 
  557.               }
  558.           
  559.           case "boolCheck":
  560.           case "textField":
  561.           case "linkField": 
  562.           case "numberField": 
  563.               {
  564.               StoreNodeValue();
  565.             break;
  566.               }
  567.         
  568.         case "passthroughCheck": 
  569.             {
  570.             if (dw.appName != "Contribute")
  571.                 {
  572.                 var selectedNode = findObject("theTreeControl", null).selectedNodes[0];
  573.                 if (selectedNode == null)
  574.                     return; 
  575.                                 
  576.                 var attrName = selectedNode.paramName; 
  577.                 var isPassthrough = document.theForm.passthroughCheck.checked; 
  578.                 dialogData.passthrough[attrName] = isPassthrough;
  579.             
  580.                 var newNodeString = attrName + "|" + GetVisibleValueString(attrName); 
  581.                 selectedNode.value = newNodeString; 
  582.  
  583.                 FixControlLayers(selectedNode);
  584.                         
  585.                 //Pull the old values out.
  586.                 if (!isPassthrough)
  587.                     MoveValuesToControl(selectedNode);
  588.                 }
  589.             break; 
  590.             }
  591.                 
  592.           } //switch
  593.     } //updateUI
  594.  
  595.  
  596.