home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 August / PCpro_2005_08.ISO / files / firefox / ScrapBook.xpi / chrome / scrapbook.jar / content / detail.js < prev    next >
Encoding:
JavaScript  |  2005-06-04  |  6.6 KB  |  214 lines

  1. /**************************************************
  2. // detail.js
  3. // Implementation file for detail.xul
  4. // 
  5. // Description: 
  6. // Author: Gomita
  7. // Contributors: 
  8. // 
  9. // Version: 
  10. // License: see LICENSE.txt
  11. **************************************************/
  12.  
  13.  
  14.  
  15. var SBstring;
  16. var SBarguments = {};
  17. var SBcustom;
  18. var gLinkedExpanding = false;
  19.  
  20.  
  21.  
  22.  
  23. function SB_initDetail()
  24. {
  25.     try {
  26.         SBarguments = window.arguments[0];
  27.     } catch(ex) {
  28.         alert("ScrapBook ERROR: No Arguments.");
  29.     }
  30.     SBcustom = document.getElementById("ScrapBookDetailLinkedCustom");
  31.     SB_toggleLinkedCustom();
  32.     SBcustom.nextSibling.value = nsPreferences.copyUnicharPref("scrapbook.detail.custom", "pdf, doc");
  33.     SBstring = document.getElementById("ScrapBookString");
  34.     document.documentElement.getButton("accept").label = SBstring.getString("CAPTURE_OK_BUTTON");
  35.     document.documentElement.getButton("accept").accesskey = "C";
  36.     SB_fillTitleList();
  37.     setTimeout(SB_initFolderWithDelay, 100);
  38. }
  39.  
  40.  
  41. function SB_initFolderWithDelay()
  42. {
  43.     SBRDF.init();
  44.     SBfolderList.init();
  45. }
  46.  
  47.  
  48. function SB_toggleLinkedCustom()
  49. {
  50.     SBcustom.nextSibling.disabled = !SBcustom.checked;
  51. }
  52.  
  53.  
  54. function SB_toggleLinkedExpanding()
  55. {
  56.     gLinkedExpanding = !gLinkedExpanding;
  57.     document.getElementById("ScrapBookDetailExpander").setAttribute("image", gLinkedExpanding ? "chrome://scrapbook/skin/expander_up.png" : "chrome://scrapbook/skin/expander_down.png");
  58.     document.getElementById("ScrapBookDetailLinkedGroupbox").setAttribute("orient", gLinkedExpanding ? "vertical" : "horizontal");
  59.     var flags = new Array("I","S","M","A");
  60.     for ( var i = 0; i < flags.length; i++ )
  61.     {
  62.         var checkbox = document.getElementById("ScrapBookDetailLinked" + flags[i]);
  63.         if ( gLinkedExpanding ) {
  64.             checkbox.label = checkbox.getAttribute("tooltiptext");
  65.             checkbox.setAttribute("tmpsrc", checkbox.getAttribute("src"));
  66.             checkbox.removeAttribute("src");
  67.         } else {
  68.             checkbox.setAttribute("tooltiptext", checkbox.label);
  69.             checkbox.removeAttribute("label");
  70.             checkbox.setAttribute("src", checkbox.getAttribute("tmpsrc"));
  71.         }
  72.     }
  73.     document.getElementById("ScrapBookDetailLinkedU").nextSibling.hidden = !gLinkedExpanding;
  74.     window.sizeToContent();
  75. }
  76.  
  77.  
  78.  
  79.  
  80. var SBfolderList = {
  81.  
  82.     listXUL  : null,
  83.     popupXUL : null,
  84.     depth : 0,
  85.  
  86.     init : function()
  87.     {
  88.         this.listXUL  = document.getElementById("ScrapBookDetailFolder");
  89.         this.popupXUL = document.getElementById("ScrapBookDetailFolderPopup");
  90.         this.depth = 0;
  91.         this.fillRecursively("urn:scrapbook:root");
  92.         if ( !SBarguments.resName ) SBarguments.resName = "urn:scrapbook:root";
  93.         this.listXUL.selectedItem = document.getElementById(SBarguments.resName);
  94.         this.listXUL.disabled = false;
  95.     },
  96.  
  97.     clear : function()
  98.     {
  99.         var oldItems = this.popupXUL.childNodes;
  100.         for ( var i = oldItems.length - 1; i > 1 ; i-- )
  101.         {
  102.             this.popupXUL.removeChild(oldItems[i]);
  103.         }
  104.     },
  105.  
  106.     fillRecursively : function(aResName)
  107.     {
  108.         this.depth++;
  109.         SBservice.RDFC.Init(SBRDF.data, SBservice.RDF.GetResource(aResName));
  110.         var ResList = SBservice.RDFC.GetElements();
  111.         while ( ResList.hasMoreElements() )
  112.         {
  113.             var aRes = ResList.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
  114.             var aID  = SBRDF.getProperty("id", aRes);
  115.             if ( !SBservice.RDFCU.IsContainer(SBRDF.data, aRes) ) continue;
  116.             var SBmenuitem = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "menuitem");
  117.             SBmenuitem.setAttribute("id",    aRes.Value);
  118.             SBmenuitem.setAttribute("label", SBRDF.getProperty("title", aRes));
  119.             SBmenuitem.setAttribute("class", "menuitem-iconic folder-icon");
  120.             SBmenuitem.setAttribute("style", "padding-left:" + 20 * this.depth + "px;");
  121.             this.popupXUL.appendChild(SBmenuitem);
  122.             this.fillRecursively(aRes.Value);
  123.         }
  124.         this.depth--;
  125.     },
  126.  
  127.     createFolder : function()
  128.     {
  129.         var newID = SBRDF.identify(SBcommon.getTimeStamp());
  130.         var newSBitem = new ScrapBookItem(newID);
  131.         newSBitem.title = SBstring.getString("DEFAULT_FOLDER");
  132.         newSBitem.type = "folder";
  133.         var tarResName = SBarguments.resName;
  134.         var newRes = SBRDF.addItem(newSBitem, tarResName, 0);
  135.         SBRDF.createEmptySeq(newRes.Value);
  136.         var result = {};
  137.         window.openDialog("chrome://scrapbook/content/property.xul", "", "modal,centerscreen,chrome", newSBitem.id, result);
  138.         if ( !result.accept ) {
  139.             SBRDF.deleteItemDescending(newRes, SBservice.RDF.GetResource(tarResName));
  140.             SBRDF.flush();
  141.         } else {
  142.             this.reset(newRes.Value, true);
  143.         }
  144.     },
  145.  
  146.     reset : function(aResID, shouldUpdate)
  147.     {
  148.         if ( shouldUpdate )
  149.         {
  150.             SBfolderList.clear();
  151.             SBfolderList.fillRecursively("urn:scrapbook:root");
  152.         }
  153.         this.listXUL.selectedItem = document.getElementById(aResID);
  154.         this.onselect(aResID);
  155.     },
  156.  
  157.     onselect : function(aResID)
  158.     {
  159.         SBarguments.resName = aResID;
  160.         SBarguments.change  = true;
  161.     },
  162.  
  163.     openFolderPicker : function()
  164.     {
  165.         var result = {};
  166.         window.openDialog('chrome://scrapbook/content/folderPicker.xul','','modal,chrome,centerscreen,resizable=yes',result);
  167.         if ( result.target )
  168.         {
  169.             this.reset(result.target.Value, result.shouldUpdate);
  170.         }
  171.     },
  172.  
  173. };
  174.  
  175.  
  176.  
  177.  
  178. function SB_fillTitleList()
  179. {
  180.     var listXUL = document.getElementById("ScrapBookDetailTitle");
  181.     for ( var i = 0; i < SBarguments.titleList.length; i++ )
  182.     {
  183.         listXUL.appendItem(SBarguments.titleList[i]);
  184.         if ( i == 0 && SBarguments.titleList.length > 1 ) listXUL.firstChild.appendChild(document.createElement("menuseparator"));
  185.     }
  186.     listXUL.selectedIndex = (SBarguments.titleList.length > 1) ? 2 : 0;
  187. }
  188.  
  189.  
  190. function SB_acceptDetail()
  191. {
  192.     window.opener.SBcapture.item.title   = document.getElementById("ScrapBookDetailTitle").value;
  193.     window.opener.SBcapture.item.comment = document.getElementById("ScrapBookDetailComment").value.replace(/\r|\n/g, " __BR__ ");
  194.     window.opener.SBcapture.linked.img   = document.getElementById("ScrapBookDetailLinkedI").checked;
  195.     window.opener.SBcapture.linked.snd   = document.getElementById("ScrapBookDetailLinkedS").checked;
  196.     window.opener.SBcapture.linked.mov   = document.getElementById("ScrapBookDetailLinkedM").checked;
  197.     window.opener.SBcapture.linked.arc   = document.getElementById("ScrapBookDetailLinkedA").checked;
  198.     window.opener.SBcapture.linked.seq   = document.getElementById("ScrapBookDetailLinkSeq").checked;
  199.     window.opener.SBcapture.linked.custom = "";
  200.     if ( SBcustom.checked )
  201.     {
  202.         window.opener.SBcapture.linked.custom = SBcustom.nextSibling.value.replace(/[^0-9a-zA-Z,\|]/g, "").replace(/[,\|]/g, ", ");
  203.         nsPreferences.setUnicharPref("scrapbook.detail.custom", window.opener.SBcapture.linked.custom);
  204.     }
  205. }
  206.  
  207.  
  208. function SB_cancelDetail()
  209. {
  210.     SBarguments.cancel = true;
  211. }
  212.  
  213.  
  214.