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 / DesignNotesMultiFile.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  9.5 KB  |  363 lines

  1. // Copyright 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3. //*************** GLOBALS  *****************
  4.  
  5. var helpDoc = MM.HELP_cmdDesignNotes;
  6.  
  7. var KEY_STATUS = "status";
  8. var KEY_NOTES  = "notes";
  9. var KEY_OPEN   = "showOnOpen";
  10. var PAIR_SEP   = " = ";
  11. var DEFAULT_STATUS = 0;
  12.  
  13. var T = ''; //TabControl object
  14. var DATA;
  15. var FILE_PTR = 0;
  16.  
  17. var FILE_IS_WRITEABLE;
  18.  
  19. //*************** Pg1 Class *****************
  20.  
  21. function Pg1(theTabLabel) {
  22.   this.tabLabel    = theTabLabel;
  23.  
  24.   this.listObj     = new ListControl("statusMenu");
  25.   this.notesObj    = findObject("notesField");
  26.   this.openObj     = findObject("openChbx");
  27. }
  28.  
  29.  
  30. //***** methods *****
  31.  
  32. Pg1.prototype.getTabLabel = Pg1_getTabLabel; //required
  33. Pg1.prototype.canLoad = Pg1_canLoad;
  34. Pg1.prototype.load = Pg1_load;
  35. Pg1.prototype.update = Pg1_update;
  36. Pg1.prototype.unload = Pg1_unload;
  37.  
  38.  
  39. function Pg1_getTabLabel() {
  40.   return this.tabLabel;
  41. }
  42.  
  43.  
  44. //Called to check if a page can be loaded
  45. //
  46. function Pg1_canLoad() {
  47.   return true;
  48. }
  49.  
  50.  
  51. //Called when the layer for this page is displayed.
  52. // Use this call to initialize controls.
  53.  
  54. function Pg1_load() {
  55.   var i;
  56.  
  57.   with (this) {
  58.     listObj.setAll(STATUS_ITEMS); //load select menu
  59.  
  60.     //get status
  61.     temp = stripSpaces(DATA.get(KEY_STATUS));
  62.     if (!temp) listObj.setIndex(DEFAULT_STATUS);
  63.     else {
  64.       for (i=0; i<listObj.getLen(); i++) { //look for status in menu
  65.         if (listObj.get(i) == temp) {
  66.           listObj.setIndex(i);
  67.           break;
  68.       } }
  69.       if (i == listObj.getLen()) listObj.append(temp); //if nonexistent, add it
  70.     }
  71.  
  72.     //get notes
  73.     temp = DATA.get(KEY_NOTES);
  74.     notesObj.value = temp || "";
  75.  
  76.     //get open flag
  77.     temp = DATA.get(KEY_OPEN);
  78.     if (temp != null) openObj.checked = (temp.toString().toLowerCase() == "true");
  79.   }
  80. }
  81.  
  82.  
  83. //Called when another page is about to be shown, or finish() is called on
  84. // the tabControl.  Use this call to perform any finishing tasks.
  85.  
  86. function Pg1_unload() {
  87.   return true;
  88. }
  89.  
  90.  
  91. //Called when one of the page controls calls the tabControl update function.
  92. // Use this call to respond to user input.
  93. function Pg1_update(theItemName) {
  94.  
  95.   with (this) {
  96.       if (theItemName == "insertDate") {
  97.         var theDate = getSimpleDate() + ": \n";
  98.         notesObj.value = theDate + notesObj.value;
  99.         DATA.set(KEY_NOTES,notesObj.value || null); //save notes
  100.  
  101.       } else if (theItemName == "statusMenu") {
  102.         DATA.set(KEY_STATUS,listObj.get() || null); //save status
  103.  
  104.       } else if (theItemName == "notesField") {
  105.         DATA.set(KEY_NOTES,notesObj.value || null); //save notes
  106.  
  107.       } else if (theItemName == "openChbx") {
  108.         DATA.set(KEY_OPEN,openObj.checked || null); //save open flag
  109.       }
  110.   }
  111. }
  112.  
  113.  
  114.  
  115.  
  116. //***************** Pg2 Class ******************
  117.  
  118. function Pg2(theTabLabel) {
  119.   this.tabLabel    = theTabLabel;
  120.  
  121.   this.listObj     = new ListControl("allItems");
  122.   this.nameObj     = findObject("itemName");
  123.   this.valueObj    = findObject("itemValue");
  124.   this.keys        = new Array();
  125. }
  126.  
  127.  
  128. //***** methods *****
  129.  
  130. Pg2.prototype.getTabLabel = Pg2_getTabLabel;
  131. Pg2.prototype.canLoad = Pg2_canLoad;
  132. Pg2.prototype.load = Pg2_load;
  133. Pg2.prototype.update = Pg2_update;
  134. Pg2.prototype.unload = Pg2_unload;
  135. Pg2.prototype.drawList = Pg2_drawList;
  136. Pg2.prototype.drawSelection = Pg2_drawSelection;
  137.  
  138.  
  139.  
  140. function Pg2_getTabLabel() {
  141.   return this.tabLabel;
  142. }
  143.  
  144.  
  145.  
  146. //Called to check if a page can be loaded
  147. //
  148. function Pg2_canLoad() {
  149.   return true;
  150. }
  151.  
  152.  
  153.  
  154. //Called when the layer for this page is displayed.
  155. // Use this call to initialize controls.
  156. //
  157. function Pg2_load() {
  158.   with (this) {
  159.     drawList();
  160.     listObj.setIndex(0); //select first item
  161.     drawSelection()
  162.   }
  163. }
  164.  
  165.  
  166.  
  167. //Called when another page is about to be shown, or finish() is called on
  168. // the tabControl.  Use this call to perform any finishing tasks.
  169. function Pg2_unload() {
  170.   return true;
  171. }
  172.  
  173.  
  174.  
  175. //Called when one of the page controls calls the tabControl update function.
  176. // Use this call to respond to user input.
  177. function Pg2_update(theItemName) {
  178.   var i, temp, temp2;
  179.  
  180.   if (theItemName == "allItems") with (this) {
  181.     drawSelection();
  182.  
  183.   } else {
  184.  
  185.     if (theItemName == "addItem") with (this) {
  186.       listObj.append();
  187.       valueObj.value = "";
  188.       nameObj.value  = "";
  189.       nameObj.focus();
  190.       nameObj.select();
  191.   
  192.     } else if (theItemName == "delItem") with (this) {
  193.       DATA.del(listObj.getIndex());
  194.       listObj.del();
  195.       drawSelection();
  196.   
  197.     } else if (theItemName == "itemName" || theItemName == "itemValue") with (this) {
  198.       temp = nameObj.value;
  199.  
  200.       if (temp.toLowerCase() == "design notes credits") {
  201.         valueObj.value = unescape("%42%72%6F%75%67%68%74 %74%6F %79%6F%75 %62%79...\n%48%65%69%64%69, %4B%65%6E,"+
  202.                                   " %53%74%65%70%68%61%6E%69%65, %61%6E%64 %4A%61%6B%65!\n%59%65%65-%68%61%77!");
  203.       }
  204.  
  205.       temp2 = (valueObj.value);
  206.       if (temp) { //if valid name
  207.         temp = stripSpaces(makeValidKey(temp));
  208.         if (temp) { //if valid name
  209.           if (listObj.get()) { //if selection is not blank (not new item)
  210.             var oldName = DATA.getName(listObj.getIndex()); //get prior name
  211.             if (temp != oldName) DATA.changeName(oldName,temp); //if name changed, update it
  212.           }
  213.           DATA.set(temp,temp2 || null);
  214.           drawList();
  215.         } else {
  216.           alert(MSG_InvalidName);
  217.         }     
  218.       }
  219.     }
  220.   }
  221. }
  222.  
  223.  
  224. //Called when the layer for this page is displayed.
  225. // Use this call to initialize controls.
  226. //
  227. function Pg2_drawList() {
  228.   var i, allItems;
  229.  
  230.   with (this) {
  231.     listObj.setAll(DATA.getAll());       //clear out the old list
  232.     if (listObj.getLen() > 0) {
  233.       drawSelection();                      //display stuff in fields
  234.     }
  235.   }
  236. }
  237.  
  238.  
  239. function Pg2_drawSelection() {
  240.   var name, value;
  241.  
  242.   with (this) {
  243.     name = DATA.getName(listObj.getIndex()); //get the name for the current selection
  244.     name = name || ""; //make blank if null
  245.     nameObj.value = name;
  246.     value = DATA.get(name);
  247.     value = value || ""; //make blank if null
  248.     valueObj.value = value;
  249.   }
  250. }
  251.  
  252.  
  253. //***************** End of Pg2 Class ******************
  254.  
  255. //******************* API **********************
  256.  
  257. function commandButtons(){
  258.   var btns;
  259.  
  260.   btns = new Array(MM.BTN_OK,     "okClicked()", MM.BTN_Cancel, "cancelClicked()", MM.BTN_Help, "displayHelp()");
  261.   return btns
  262. }
  263.  
  264. //***************** LOCAL FUNCTIONS  ******************
  265.  
  266. function initializeUI() {
  267.   var result;
  268.  
  269.   DATA = new NameValuePair();
  270.  
  271.   var tab0 = findObject("Tab0");
  272.   var tab1 = findObject("Tab1");
  273.  
  274.   //Use appropriate background & tabs for Mac OS X.
  275.   if (dw.isOSX()) {
  276.     findObject("tabBgWin").src = "../Shared/MM/Images/tabBgOSX435x334.gif";    
  277.     var oldMulti = RegExp.multiline;
  278.     RegExp.multiline = true;
  279.     var pat1 = /tabBg\.gif/;
  280.     tab0.innerHTML = tab0.innerHTML.replace(pat1, "tabBgOSX.gif");
  281.     tab1.innerHTML = tab1.innerHTML.replace(pat1, "tabBgOSX.gif");
  282.     var pat2 = /tabBgSel\.gif/;
  283.     tab0.innerHTML = tab0.innerHTML.replace(pat2, "tabBgSelOSX.gif");
  284.     tab1.innerHTML = tab1.innerHTML.replace(pat2, "tabBgSelOSX.gif");
  285.       RegExp.multiline = oldMulti;
  286.   // Use appropriate background & tabs for WinXP with themes  
  287.   } else if (dw.isXPThemed()) {
  288.     findObject("tabBgWin").src = "../Shared/MM/Images/tabBgWinXP.gif";
  289.     var oldMulti = RegExp.multiline;
  290.     RegExp.multiline = true;
  291.     var pat1 = /tabBg\.gif/;
  292.     tab0.innerHTML = tab0.innerHTML.replace(pat1, "tabBgXP.gif");
  293.       tab1.innerHTML = tab1.innerHTML.replace(pat1, "tabBgXP.gif");
  294.     var pat2 = /tabBgSel\.gif/;
  295.     tab0.innerHTML = tab0.innerHTML.replace(pat2, "tabBgSelXP.gif");
  296.     tab1.innerHTML = tab1.innerHTML.replace(pat2, "tabBgSelXP.gif");
  297.     RegExp.multiline = oldMulti;
  298.   // Use standard background  
  299.   } else {    
  300.     findObject("tabBgWin").src = "../Shared/MM/Images/tabBgWin.gif";
  301.   }
  302.  
  303.   T = new TabControl('Tab');
  304.   //Add tab pages.   (Pass the layer name, and the page object)
  305.   T.addPage('mainLayer', new Pg1(LABEL_BasicInfo));
  306.   T.addPage('allLayer', new Pg2(LABEL_AllInfo));
  307.   //Initialize and display the tabs.  (Could pass the name of a page to start on)
  308.   T.start();
  309. }
  310.  
  311.  
  312.  
  313. function okClicked() {
  314.   T.finish();
  315.   writeMetafiles();
  316.   window.close();
  317.  
  318.   //update design notes columns in local file list in site window
  319.   if (MMNotes.UpdateSite == true)
  320.     site.refresh("local");
  321. }
  322.  
  323. function cancelClicked() {
  324.   window.close();
  325. }
  326.  
  327.  
  328. function writeMetafiles() {
  329.   var i, names;
  330.  
  331.   site.setFocus("local");
  332.  
  333.   //iterate through each file/folder in the selection
  334.   //and set the access permissions for each
  335.   var localFileList = site.getSelection();
  336.   var numSelected = localFileList.length;
  337.   for (file=0; file<numSelected; file++) {
  338.       //for each file write out new note
  339.       FILE_PTR = MMNotes.open(localFileList[file]);
  340.       names = DATA.getNames();
  341.       for (i=0; i<names.length; i++)  {  //with each local, non-null key
  342.         MMNotes.set(FILE_PTR,names[i],DATA.get(names[i]));  //set it in the file
  343.       }
  344.       MMNotes.close(FILE_PTR);
  345.   }
  346. }
  347.  
  348.  
  349.  
  350. function makeValidKey(theStr) {
  351.   theStr = theStr.replace(/(\")/g,""); //disallow "
  352.   theStr = theStr.replace(/(\')/g,""); //disallow '
  353.   return theStr;
  354. }
  355.  
  356. function getSimpleDate() {
  357.   var today = new Date();
  358.   var dateStr = today.toLocaleString();
  359.   dateStr = dateStr.replace(/\S+\s+(\S+\s+\S+\s+\S+)[^\x00]*/,"$1"); //get 2nd-4th words of date
  360.   return dateStr;
  361. }
  362.  
  363.