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

  1. // Copyright 2002 Macromedia, Inc. All rights reserved.
  2.  
  3. //---------------   GLOBAL VARIABLES   ---------------
  4.  
  5. var helpDoc = MM.HELP_objRepeatingTable;
  6. var gDialogShown = false;
  7. var gReturnTag;
  8.  
  9. var nextEditRegionInd = -1; 
  10. var haveCalledCanInsert = false; 
  11.  
  12. //---------------     API FUNCTIONS    ---------------
  13.  
  14. function isDOMRequired() {
  15.     return false;
  16. }
  17.     
  18. function commandButtons(){
  19.    return new Array(MM.BTN_OK,         "onOK()",
  20.                     MM.BTN_Cancel,     "window.close()",
  21.                     MM.BTN_Help,       "displayHelp()" );
  22. }
  23.  
  24. function onOK()
  25.     {
  26.     //Make sure the rows make sense. 
  27.     var Rows = document.theForm.Rows.value;
  28.     var repeatStart = document.theForm.startingRow.value; 
  29.     var repeatEnd = document.theForm.endingRow.value;
  30.     
  31.     if (repeatStart > Rows || repeatEnd < repeatStart || repeatEnd > Rows)
  32.         {
  33.         alert(MM.RepeatTableRowsWarning);
  34.         return;
  35.         }
  36.     
  37.      var regionName = document.theForm.repeatName.value; 
  38.      if (findNamedRepeatingRegion(regionName, dw.getDocumentDOM("document")) != null)    
  39.         {
  40.         alert(MSG_alreadyExists_Repeat);
  41.         return; 
  42.         }
  43.     
  44.     setTableStr();
  45.         
  46.     simpleBlockInsert( gReturnTag, "", dw.getDocumentDOM("document"), false );
  47.     gReturnTag = "";
  48.     
  49.     window.close();
  50.     }
  51.  
  52.  
  53.  
  54. //Get a row of a table that has edit regions in each cell. 
  55. function getEditTableRow(columnCount)
  56.     {
  57.     var tableRow = ""; 
  58.       for (var i=0; i< columnCount; i++)
  59.           {
  60.           var curCellName = MM.EditAutonamePreamble + nextEditRegionInd;
  61.           nextEditRegionInd++; 
  62.           
  63.           var curCell; 
  64.           
  65.           
  66.           if (dw.generateTemplateTagSyntax())
  67.               curCell = "<TD><MMTemplate:Editable name=\"" + curCellName + "\">" + dw.getDocumentDOM("document").getNBSPChar() + "</MMTemplate:Editable></TD>";
  68.         else    
  69.               curCell = "<TD><!-- TemplateBeginEditable name=\"" + curCellName + "\" -->" + dw.getDocumentDOM("document").getNBSPChar() + "<!-- TemplateEndEditable --></TD>";
  70.         
  71.         tableRow += curCell;
  72.            }
  73.            
  74.      return tableRow = "<"+"TR>" + tableRow + "<"+"/TR>";
  75.     }
  76.                     
  77. function canInsert()
  78.     {    
  79.     haveCalledCanInsert = true; 
  80.     
  81.     targetDom = arguments[0];
  82.     if (targetDom == null)
  83.         targetDom = dw.getDocumentDOM();
  84.             
  85.     if (!CheckWarnNoTemplate(targetDom))
  86.         return false;
  87.     
  88.     var result = new Object();
  89.     if (!canMakeTemplateContent("repeatingTable", targetDom, result))
  90.         {        
  91.         if (result.status == "contained in DW4 edit")
  92.             alert(MM.MSG_SaveDW4First);
  93.         else if (result.status == "locked")
  94.             alert(MSG_cantInsertRepeatHere)
  95.         else
  96.             alert(MM.MSG_AlreadyEdit);
  97.             
  98.         return false; 
  99.         }            
  100.             
  101.     return true; 
  102.     } //canInsert
  103.  
  104.  
  105.  
  106. function setTableStr(){
  107.  
  108.   var Columns = document.theForm.Cols.value;
  109.   var Rows = document.theForm.Rows.value;
  110.   var Border = document.theForm.Border.value;
  111.   var Width = document.theForm.Width.value;
  112.   var cellSpacing = document.theForm.Cellspace.value;
  113.   var cellPadding = document.theForm.Cellpad.value;
  114.   var unitChoice = document.forms[0].Units.selectedIndex;
  115.  
  116.   var repeatEnd = document.theForm.endingRow.value;
  117.   var repeatStart = document.theForm.startingRow.value;
  118.  
  119.   var regionName = document.theForm.repeatName.value; 
  120.   
  121.   if (regionName == "")
  122.       regionName = getUniqueRegionName(MM.RepeatAutonamePreamble, "MMTemplate:Repeat", dw.getDocumentDOM("document"));
  123.  
  124.   var repeatStartContent;
  125.   var repeatEndContent; 
  126.  
  127.   if (dw.generateTemplateTagSyntax())
  128.       {
  129.       repeatStartContent = "<MMTemplate:Repeat name=\"" + regionName + "\">"; 
  130.       repeatEndContent = "</MMTemplate:Repeat>";
  131.       }
  132.   else
  133.       {
  134.      repeatStartContent = "<!-- TemplateBeginRepeat name=\"" + regionName + "\" -->";
  135.      repeatEndContent = "<!-- TemplateEndRepeat -->";
  136.       }
  137.       
  138.   var tableCells='<'+'TD>' + dw.getDocumentDOM("document").getNBSPChar() + '<'+'/TD>\n';
  139.   var tableRow='',tableContent='';
  140.   var openTag= '<' + 'table ', spaceIndex;
  141.   var widthAttr;
  142.  
  143.   //change any negative or non-numeric row or column value into 1
  144.   if (Columns <= 0)
  145.       Columns = 1; 
  146.   if (Rows <= 0)
  147.       Rows = 1; 
  148.   if (repeatEnd <= 0)
  149.       repeatEnd = 1; 
  150.   if (repeatStart <= 0)
  151.       repeatStart = 1; 
  152.  
  153.   //CREATE TABLE
  154.   //determine contents of 1 table row
  155.   for (i=0; i< Columns; i++)
  156.     tableRow+=tableCells;
  157.   tableRow = "<"+"TR>\n" + tableRow + "<"+"/TR>\n";
  158.   
  159.   nextEditRegionInd = getUniqueRegionCount(MM.EditAutonamePreamble, "MMTemplate:Editable", dw.getDocumentDOM("document"));
  160.  
  161.   //determine number of table rows & concatanate rows together
  162.   for (var i=0; i< Rows; i++)
  163.       {     
  164.     if (i == repeatStart-1)
  165.         tableContent += repeatStartContent; 
  166.         
  167.     if (i >= repeatStart-1 && i <= repeatEnd -1)
  168.         tableContent += getEditTableRow(Columns); 
  169.     else
  170.         tableContent += tableRow;
  171.     
  172.     if (i == repeatEnd - 1)
  173.         tableContent += repeatEndContent; 
  174.     
  175.     }
  176.     
  177.     
  178.   //add percent or pixel values to opening tag, if applicable
  179.   if (Width)
  180.     openTag += 'width="'+Width + ((unitChoice == 0)? '%" ' : '" ');
  181.   //add border value, if applicable
  182.   if (Border)
  183.     openTag+='border="' + Border + '" ';
  184.   //add cellspacing value, if applicable
  185.   if (cellSpacing)
  186.     openTag+='cellspacing="' + cellSpacing + '" ';
  187.   //add cellpadding value, if applicable
  188.   if (cellPadding)
  189.     openTag+='cellpadding="' + cellPadding + '" ';
  190.  
  191.   //strip extra space from openTag, if it exists
  192.   spaceIndex = openTag.length-1
  193.   if (escape(openTag.charAt(spaceIndex))=='%20')
  194.     openTag = openTag.substring(0,spaceIndex);
  195.  
  196.   openTag += '>' + tableContent;
  197.  
  198.   if (gDialogShown) {
  199.     saveExtension(document)
  200.   }
  201.   gDialogShown = false; // Reset show dialog global.
  202.   
  203.   openTag += '<'+'/table'+'>';
  204.   gReturnTag= openTag;    
  205.    dw.getDocumentDOM("document").disableLocking();
  206. }
  207.  
  208.  
  209. function objectTag(){
  210.     
  211.     alert(gReturnTag);
  212.     return gReturnTag; 
  213.     }
  214.     
  215.  
  216.  
  217. function createTableStr() {
  218.  
  219.     return gReturnTag;
  220.  
  221. }
  222. //---------------    LOCAL FUNCTIONS   ---------------
  223.  
  224. function saveExtension(curDOM) {
  225.   var curHTML = DWfile.read(curDOM.URL);
  226.   var tempFilename = dw.getConfigurationPath() + '/Shared/MM/Cache/empty.htm';
  227.   if (DWfile.exists(tempFilename)) {
  228.     var tempDOM = dw.getDocumentDOM(tempFilename);
  229.     tempDOM.documentElement.outerHTML = curHTML;
  230.     var atrStr = DWfile.getAttributes(curDOM.URL);
  231.     if (tempDOM.body.outerHTML != curDOM.body.outerHTML && (atrStr.indexOf('R') == -1)){
  232.       tempDOM.body.outerHTML = curDOM.body.outerHTML;
  233.       DWfile.write(curDOM.URL, tempDOM.documentElement.outerHTML);
  234.     }
  235.   }
  236. }
  237.  
  238. function initializeUI()
  239. {
  240. if (!haveCalledCanInsert && !canInsert())
  241.     {
  242.     haveCalledCanInsert = false; 
  243.     window.close();
  244.     return;
  245.     }
  246.     
  247.   document.theForm.repeatName.value =  getUniqueRegionName(MM.RepeatAutonamePreamble, "MMTemplate:Repeat", dw.getDocumentDOM("document"));
  248.  
  249.   document.theForm.Rows.focus(); //set focus on textbox
  250.   document.theForm.Rows.select(); //set insertion point into textbox
  251.   gDialogShown = true;
  252.   gReturnTag = '';
  253.   haveCalledCanInsert = false; 
  254. }
  255.  
  256.  
  257.  
  258.  
  259.     
  260.