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

  1. /**************************************************
  2. // manage.js
  3. // Implementation file for manage.xul
  4. // 
  5. // Description: 
  6. // Author: Gomita
  7. // Contributors: 
  8. // 
  9. // Version: 
  10. // License: see LICENSE.txt
  11. **************************************************/
  12.  
  13.  
  14.  
  15. function SB_initManage()
  16. {
  17.     SBstring = document.getElementById("ScrapBookString");
  18.     SBRDF.init();
  19.     SBstatus.init();
  20.     SBtreeUtil.init("ScrapBookManageTree", false);
  21.     SB_initObservers();
  22.     SBpref.init();
  23.     SBtree.ref = window.arguments[0];
  24.     var popupKeys = ['C','M','E'];
  25.     for ( var i = 0; i < popupKeys.length; i++ )
  26.     {
  27.         document.getElementById("ScrapBookTreePopup" + popupKeys[i]).setAttribute("disabled", true);
  28.     }
  29.     var winTitle = SBRDF.getProperty("title", SBservice.RDF.GetResource(SBtree.ref));
  30.     if ( winTitle )
  31.     {
  32.         document.getElementById("ScrapBookManageWindow").setAttribute("title", winTitle);
  33.         document.title = winTitle;
  34.     }
  35. }
  36.  
  37.  
  38. function SB_openDblClick(aEvent)
  39. {
  40.     if ( aEvent.originalTarget.localName != "treechildren" ) return;
  41.     var tabbed = (aEvent.ctrlKey || aEvent.shiftKey);
  42.     var curIdx = SBtree.currentIndex;
  43.     var curRes = SBtree.builderView.getResourceAtIndex(curIdx);
  44.     if ( SBtree.view.isContainer(curIdx) )
  45.     {
  46.         if ( SBpref.folderclick ) SBtreeUtil.collapseOtherFolders(curIdx);
  47.         return;
  48.     }
  49.     var myID   = SBRDF.getProperty("id", curRes);
  50.     var myType = SBRDF.getProperty("type", curRes);
  51.     SBcommon.loadURL(SBcommon.getURL(myID, myType), tabbed);
  52. }
  53.  
  54.  
  55. function SB_moveIntoFolder()
  56. {
  57.     var idxList = SBtreeUtil.getSelection(false, 2);
  58.     if ( idxList.length < 1 ) return;
  59.     if ( SB_validateMultipleSelection(idxList) == false ) return;
  60.     var i = 0;
  61.     var curResList = [];
  62.     var curParList = [];
  63.     for ( i = 0; i < idxList.length; i++ )
  64.     {
  65.         curResList.push( SBtree.builderView.getResourceAtIndex(idxList[i]) );
  66.         curParList.push( SB_getParentResourceAtIndex(idxList[i]) );
  67.     }
  68.     var result = {};
  69.     window.openDialog('chrome://scrapbook/content/folderPicker.xul','','modal,chrome,centerscreen,resizable=yes',result);
  70.     if ( !result.target ) return;
  71.     var tarPar = result.target;
  72.     for ( i = 0; i < idxList.length; i++ )
  73.     {
  74.         SBRDF.moveItem(curResList[i], curParList[i], tarPar, -1);
  75.     }
  76.     SBRDF.flush();
  77. }
  78.  
  79.  
  80. function SB_deleteMultiple()
  81. {
  82.     var idxList = SBtreeUtil.getSelection(false, 2);
  83.     if ( idxList.length < 1 ) return;
  84.     if ( SB_validateMultipleSelection(idxList) == false ) return;
  85.     if ( !SBpref.quickDelete )
  86.     {
  87.         if ( !window.confirm( SBstring.getString("CONFIRM_DELETE") ) ) return;
  88.     }
  89.     var i = 0;
  90.     var curResList = [];
  91.     var curParList = [];
  92.     for ( i = 0; i < idxList.length; i++ )
  93.     {
  94.         curResList.push( SBtree.builderView.getResourceAtIndex(idxList[i]) );
  95.         curParList.push( SB_getParentResourceAtIndex(idxList[i]) );
  96.     }
  97.     var rmIDs = [];
  98.     for ( var i = 0; i < idxList.length; i++ )
  99.     {
  100.         rmIDs = rmIDs.concat ( SBRDF.deleteItemDescending(curResList[i], curParList[i]) );
  101.     }
  102.     SBRDF.flush();
  103.     for ( var i = 0; i < rmIDs.length; i++ )
  104.     {
  105.         if ( rmIDs[i].length == 14 ) SBcommon.removeDirSafety( SBcommon.getContentDir(rmIDs[i]) );
  106.     }
  107.     SBstatus.trace(rmIDs.length + " items removed");
  108. }
  109.  
  110.  
  111. function SB_validateMultipleSelection(aIdxList)
  112. {
  113.     if ( aIdxList.length != SBtree.view.selection.count )
  114.     {
  115.         alert("ScrapBook ERROR: Can't move/delete multiple items including folders.");
  116.         return false;
  117.     }
  118.     return true;
  119. }
  120.  
  121.  
  122.  
  123. SBdropUtil.moveMultiple = function()
  124. {
  125.     var idxList = SBtreeUtil.getSelection(false, 2);
  126.     if ( SB_validateMultipleSelection(idxList) == false ) return;
  127.     var i = 0;
  128.     var curResList = []; var curParList = [];
  129.     var tarResList = []; var tarParList = [];
  130.     for ( i = 0; i < idxList.length; i++ )
  131.     {
  132.         curResList.push( SBtree.builderView.getResourceAtIndex(idxList[i]) );
  133.         curParList.push( SB_getParentResourceAtIndex(idxList[i]) );
  134.         tarResList.push( SBtree.builderView.getResourceAtIndex(this.row) );
  135.         tarParList.push( ( this.orient == this.DROP_ON ) ? tarResList[i] : SB_getParentResourceAtIndex(this.row) );
  136.     }
  137.     if ( this.orient == this.DROP_AFTER )
  138.     {
  139.         for ( i = idxList.length - 1; i >= 0 ; i-- )
  140.         {
  141.             this.moveCurrentToTarget(curResList[i], curParList[i], tarResList[i], tarParList[i]);
  142.         }
  143.     }
  144.     else
  145.     {
  146.         for ( i = 0; i < idxList.length; i++ )
  147.         {
  148.             this.moveCurrentToTarget(curResList[i], curParList[i], tarResList[i], tarParList[i]);
  149.         }
  150.     }
  151.     SBRDF.flush();
  152. }
  153.  
  154.  
  155.