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 / OrphanedContent.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  12.2 KB  |  451 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_orphanedTemplateContent;
  10.  
  11. //WARNING THESE ARE ALSO DEFINED IN DialogOrphanedContent.cpp
  12. var const_choose = "_MM:choose"; 
  13. var const_nowhere = "_MM:nowhere"; 
  14.  
  15. var orphanNames = null;
  16.  
  17. //This is the data passed into the dialog, and this is used to return data as well. If declared in C, this 
  18. //object would look something like this: 
  19. //struct { 
  20. //        params;                         //Object representing the orphaned params, filled with destination data. 
  21. //                                        //This is an object where the attribute names are the names of the orphaned 
  22. //                                        //fields, and the values are the destination fields ("" to start)
  23. //        editable;                         //same for editable regions
  24. //        repeats;                          //same for repeats; 
  25. //        
  26. //        const destParams;                 //array of field names for destination parameters
  27. //        const destEditable;             //same for editable
  28. //        const destRepeats;                 //same for repeats
  29. //
  30. //        const repeatScope;                 //if non-null, this is the name of the repeat in which we are resolving fields 
  31. //                                        //recursively. This is used in the dialog text only. If null, we're at the root of the 
  32. //                                        //template. 
  33. //        const docFilePath;        //full path of the instance file we are running this dialog for.
  34. //        returnValue;                    //passed in as -1, set to 1 for success, 0 for cancel. 
  35. //        };
  36.  
  37. var dialogData = null;
  38. var PLATFORM = navigator.platform;
  39. var itemListMgr = null; //ListControlClass controlling the 'resolve' control at the bottom of the dialog. 
  40.  
  41. //******************* API **********************
  42.  
  43.  
  44. //Just grab the first argument and stuff it into a global. 
  45. function receiveArguments()
  46.     {    
  47.     if (false)
  48.         {
  49.         dialogData = new Object();
  50.         dialogData.params = new Object();
  51.         dialogData.params.param1 = ""; 
  52.         dialogData.params.param2 = ""; 
  53.         dialogData.params.param3 = ""; 
  54.                     
  55.         dialogData.editable = new Object();
  56.         dialogData.editable.editable1 = ""; 
  57.         dialogData.editable.editable2 = ""; 
  58.         dialogData.editable.editable3 = ""; 
  59.  
  60.         dialogData.repeats = new Object();
  61.         dialogData.repeats.repeats1 = ""; 
  62.         dialogData.repeats.repeats2 = ""; 
  63.         dialogData.repeats.repeats3 = "";
  64.         
  65.         dialogData.destParams = ["paramDest1", "paramDest2", "paramDest3"]; 
  66.         dialogData.destEditable = ["editableDest1", "editableDest2", "editableDest3"]; 
  67.         dialogData.destRepeats = ["repeatDest1", "repeatDest2", "repeatDest3"]; 
  68.         
  69.         dialogData.repeatScope = null; 
  70.         docFilePath.docFilePath = "Some Path"; 
  71.         
  72.         dialogData.returnValue = -1; 
  73.         }    
  74.     else
  75.         {
  76.         dialogData = arguments[0];
  77.         dialogData.destParams.sort();
  78.         dialogData.destEditable.sort();
  79.         dialogData.destRepeats.sort();
  80.         }
  81.     }
  82.  
  83.  
  84. function countOrphans()
  85.     {
  86.     if (dialogData == null)
  87.         receiveArguments();
  88.         
  89.     var myCount = 0; 
  90.     
  91.     for (param in dialogData.params)
  92.         myCount = myCount + 1;
  93.         
  94.     for (editable in dialogData.editable)
  95.         myCount = myCount + 1;
  96.         
  97.     for (repeat in dialogData.repeats)
  98.         myCount = myCount + 1;
  99.     
  100.     return myCount;
  101.     } //countOrphans
  102.  
  103.  
  104. //Called when the 'set all' button is clicked - this places all orphaned content in the currently selected field. 
  105.  
  106. function setAllForNode(node, category)
  107.     {
  108.     if (category == "" || (typeof node["category"] != 'undefined' && node.category == category) )
  109.         StoreCurValuesInNode(node);
  110.  
  111.     for (var i=0;i<node.childNodes.length; i++)
  112.         setAllForNode(node.childNodes[i], category);
  113.     } //setAllForNode
  114.     
  115. function setAll()
  116.     {    
  117.     var selectedTreeNode = findObject("theTreeControl").selectedNodes[0];
  118.     var category = selectedTreeNode.category; 
  119.  
  120.     var curValue = itemListMgr.getValue(); 
  121.     
  122.     if (curValue == const_nowhere || curValue == const_choose ) 
  123.         category = ""; 
  124.  
  125.     setAllForNode(findObject("theTreeControl"), category);
  126.     } //setAll
  127.     
  128.     
  129. function cmdOK()
  130.     {
  131.     if (packageFormData())
  132.         {
  133.         dialogData.returnValue = 1; 
  134.         window.close();
  135.         }
  136.     } //cmdOK
  137.  
  138.  
  139. function cmdCancel()
  140. {
  141.   dialogData.returnValue = 0; 
  142.   window.close();
  143. }
  144.  
  145.     
  146.  
  147. //***************** LOCAL FUNCTIONS  ******************
  148.  
  149. //Load localizable text into the named span object at boot time. 
  150. function LoadLocalizedText(spanName, contentString)
  151.     {
  152.     var theObj = findObject(spanName); 
  153.     if (theObj)
  154.         theObj.innerHTML = contentString; 
  155.     } //LoadLocalizedText
  156.     
  157. function initializeUI()
  158.     {
  159.     if (dialogData == null)
  160.         {
  161.         alert("missing data!"); 
  162.         window.close();
  163.         return; 
  164.         }
  165.  
  166.     LoadLocalizedText("popupLabel", LABEL_Popup);
  167.         
  168.     if (typeof dialogData.repeatScope == 'undefined' || dialogData.repeatScope == null || dialogData.repeatScope == "")
  169.         LoadLocalizedText("dialogMessage", dwscripts.sprintf(LABEL_DialogMessage, dialogData.docFilePath));
  170.     else     
  171.         {
  172.         LoadLocalizedText("dialogMessage", dwscripts.sprintf(LABEL_nestingMessage, dialogData.repeatScope));
  173.         }
  174.         
  175.     if (itemListMgr == null)
  176.         itemListMgr =  new ListControl('itemList', null, false);
  177.  
  178.     itemListMgr.disable();
  179.     
  180.       SetupTree();
  181.       SetResolveControls();
  182.     } //initializeUI
  183.  
  184.  
  185. function adjustButtons()
  186. {
  187.   var theStyle;
  188.   if (PLATFORM=="Win32")
  189.   {
  190.     theStyle=document.okLayer.getAttribute("STYLE");
  191.     theStyle=theStyle.replace(/left:\w*;/,LEFT_LAYER).replace(/top:\w*;/,TOP_LAYER);
  192.     document.okLayer.setAttribute("STYLE", theStyle);
  193.     theStyle=document.cancelLayer.getAttribute("STYLE");
  194.     theStyle=theStyle.replace(/left:\w*;/,RIGHT_LAYER).replace(/top:\w*;/,TOP_LAYER);
  195.     document.cancelLayer.setAttribute("STYLE", theStyle);
  196.   }
  197. }
  198.  
  199. //Add the 'categories' tag to the string stream
  200. function AddCategoriesToTreeStream(theStream)
  201.     {
  202.     theStream.push("<mm:treecolumn name='", LABEL_NameCol, "' value='", LABEL_NameCol, "'  width='200'/>"); 
  203.     theStream.push("<mm:treecolumn name='", LABEL_ResolvedCol, "' value='", LABEL_ResolvedCol, "'  width='230' />"); 
  204.     } //AddCategoriesToTreeString
  205.     
  206.     
  207. //Add the treenode for this category to the innerHTML string for the tree node
  208. function OpenCatNode(labelString, theStream)
  209.     {
  210.     theStream.push("<mm:treenode selected value = '",labelString,"' id=-1 state='expanded'>");
  211.     } //AddCatNodeToString
  212.     
  213. function CloseCatNode(theStream)
  214.     {
  215.     theStream.push("</mm:treenode>");
  216.     }
  217.     
  218. //Add the string for a single node in the tree. Should look something like: 
  219. //<mm:treenode  value = "Conditional 1|<Not Resolved>" id=0 category="params" ></mm:treenode> 
  220. function AddParamNode(paramString, catString, theStream, labelString)
  221.     {    
  222.     var theString = "<mm:treenode  value = '" + paramString + "|" + labelString + "' id='" + paramString  + "' category='" + catString + "' ></mm:treenode>"; 
  223.     theStream.push(theString); 
  224.     } //AddParamNode
  225.     
  226.         
  227.     
  228. //Build and insert the inner HTML for the tree control
  229. function SetupTree()
  230.     {    
  231.     var theStream = new Array();
  232.     theStream.push("");
  233.      
  234.     AddCategoriesToTreeStream(theStream);
  235.     
  236.     var labelString; 
  237.     
  238.     var i; 
  239.     var count = 0; 
  240.     var temp = new Array(); 
  241.     for (i in dialogData.params)
  242.         {        
  243.         temp.push(i);
  244.         } 
  245.     temp.sort(); 
  246.     
  247.     var tempValue; 
  248.     
  249.     for (i in temp)    
  250.         {
  251.         if (count == 0)
  252.             OpenCatNode(LABEL_OptionalContent, theStream); 
  253.         
  254.         tempValue = dialogData.params[temp[i]]; 
  255.         labelString = (tempValue == null || tempValue == "") ? LABEL_NotResolved : tempValue;
  256.         
  257.         AddParamNode(temp[i], "params", theStream, labelString);    
  258.         count++;
  259.         }
  260.     if (count > 0)
  261.         CloseCatNode(theStream);
  262.     
  263.     count = 0;
  264.     temp = new Array(); 
  265.     for (i in dialogData.repeats)
  266.         temp.push(i); 
  267.     temp.sort(); 
  268.     
  269.     for (i in temp)    
  270.         {
  271.         if (count == 0)
  272.             OpenCatNode(LABEL_RepeatingContent, theStream); 
  273.  
  274.         tempValue = dialogData.repeats[temp[i]]; 
  275.         labelString = (tempValue == null || tempValue == "") ? LABEL_NotResolved : tempValue;
  276.         AddParamNode(temp[i], "repeats", theStream, labelString);    
  277.         count++;
  278.         }
  279.     if (count > 0)
  280.         CloseCatNode(theStream);
  281.     
  282.     count = 0; 
  283.     count = 0;
  284.     temp = new Array(); 
  285.     
  286.     for (i in dialogData.editable)
  287.         temp.push(i); 
  288.     temp.sort(); 
  289.     
  290.     for (i in temp)    
  291.         {
  292.         if (count == 0)
  293.             OpenCatNode(LABEL_EditableRegions, theStream); 
  294.             
  295.         tempValue = dialogData.editable[temp[i]]; 
  296.         labelString = (tempValue == null || tempValue == "") ? LABEL_NotResolved : tempValue;
  297.  
  298.         AddParamNode(temp[i], "editable", theStream, labelString);    
  299.         count++;
  300.         }
  301.     if (count > 0)
  302.         CloseCatNode(theStream);
  303.             
  304.     findObject("theTreeControl").innerHTML = theStream.join("");     
  305.     } //SetupTree
  306.     
  307.  
  308. function PopulatePopup(destNames)
  309.     {
  310.     var defaultNames = [MSG_choose, MSG_delete]; 
  311.     var defaultValues = [const_choose, const_nowhere]; 
  312.  
  313.     var popupNames = defaultNames.concat(destNames); 
  314.     var popupValues = defaultValues.concat(destNames); 
  315.     itemListMgr.setAll(popupNames, popupValues);
  316.     } //SetResolveOptionForField
  317.     
  318.     
  319. // changes the 'resolve' popup to show the possibilities for the current node
  320. function SetResolveControls()
  321.     {
  322.     var selectedNodes = findObject("theTreeControl").selectedNodes; 
  323.     var selectedTreeNode = null; 
  324.     if (selectedNodes && selectedNodes.length > 0)
  325.          selectedTreeNode = selectedNodes[0];
  326.     
  327.     if (!selectedTreeNode || selectedTreeNode.id == -1)
  328.         {
  329.         //DISABLE THE SELECT
  330.         itemListMgr.disable();
  331.  
  332.         return; 
  333.         }
  334.             
  335.     //POPULATE THE SELECT POPUP
  336.     var destNames = null; 
  337.     if (selectedTreeNode.category == "params")
  338.         destNames = dialogData.destParams; 
  339.     else if (selectedTreeNode.category == "repeats")
  340.         destNames = dialogData.destRepeats; 
  341.     else if (selectedTreeNode.category == "editable")
  342.         destNames = dialogData.destEditable; 
  343.     
  344.     PopulatePopup(destNames);    
  345.     itemListMgr.enable();
  346.     
  347.     //Code here for setting the control to the selected value. 
  348.     var theSplit = selectedTreeNode.getAttribute("value").split("|"); 
  349.     
  350.     itemListMgr.setIndex(0);
  351.     
  352.     //Select the item with the same visible value as this tree node. 
  353.     var len = itemListMgr.getLen(); 
  354.     for (var i=0;i<len;i++)
  355.         if (itemListMgr.get(i) == theSplit[1])
  356.             {
  357.             itemListMgr.setIndex(i); 
  358.             break; 
  359.             }
  360.     } //SetResolveControls
  361.  
  362.  
  363. //Once the user picks an entry from the list, store it back in the dialogData object
  364. function StoreNodeValue(nodeID, nodeCategory, resolveString)
  365.     {
  366.     dialogData[nodeCategory][nodeID] = resolveString; 
  367.     } //StoreNodeValue
  368.     
  369.  
  370. function StoreCurValuesInNode(node)
  371.     {
  372.     if (!node || node.id == -1)
  373.         return; 
  374.     
  375.     if (node.tagName != "MM:TREENODE")
  376.         return; 
  377.         
  378.     //Store the value selected
  379.     StoreNodeValue(node.id, node.category, itemListMgr.getValue());
  380.     
  381.     //Show the visible value in the tree control.
  382.     var resolvedString = itemListMgr.get(); //Get the visible value here, so it's clear to the user. 
  383.     
  384.     //Update the visible string of this item. 
  385.     var splitArray = node.getAttribute("value").split("|"); 
  386.     var newString = splitArray[0] + "|" + resolvedString; 
  387.     node.setAttribute("value",newString);
  388.     }
  389.         
  390. // store the current setting of the popup in the selected tree control 
  391. function ResolveCurrentNode()
  392.     {
  393.     var selectedTreeNode = findObject("theTreeControl").selectedNodes[0];
  394.  
  395.     StoreCurValuesInNode(selectedTreeNode);
  396.     } //ResolveCurrentNode
  397.  
  398.  
  399. //Called when one of the controls changes, this either resets the popup menu to reflect the current 
  400. //selected node, or stores the resolution in the tree and data store
  401. function updateUI(itemName)
  402.     {
  403.       switch(itemName)
  404.           {
  405.           case "theTreeControl":
  406.               {
  407.             SetResolveControls();
  408.  
  409.             break;
  410.               }
  411.               
  412.           case "itemList":
  413.               {
  414.               ResolveCurrentNode();
  415.             break;
  416.               }
  417.               
  418.           } //switch
  419.     } //updateUI
  420.  
  421.  
  422. //Check to see if any of the attributes of this object contain an empty 
  423. //string, if so, return false (we're not ready to return) otherwise return true. 
  424. function CheckResultObj(theObject)
  425.     {
  426.     var i; 
  427.     
  428.     for (i in theObject)
  429.         {
  430.         if (theObject[i] == null || theObject[i] == "" || theObject[i] == const_choose )
  431.             {
  432.             alert(MSG_mustChoose);
  433.             return false;
  434.             }
  435.         }
  436.         
  437.     return true; 
  438.     } //CheckResultObj
  439.     
  440.     
  441. //Check to see if we can exit. 
  442. function packageFormData()
  443.     {
  444.     return (    CheckResultObj(dialogData.params) && 
  445.                  CheckResultObj(dialogData.editable) &&
  446.                  CheckResultObj(dialogData.repeats));         
  447.     } //packageFormData
  448.     
  449.  
  450.  
  451.