⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 perspectives.js

📁 Hippo CMS是一个以信息为中心的开源内容管理系统。Hippo CMS目标是供中,大型企业来管理其发布在互连网
💻 JS
字号:
//////////////////////////////////////////////////////////////////////////////
// PerspectiveManager class
//  (c) 2004 - abogaart@hippo.nl
//
// Description:
//  class that manages perspectives
//////////////////////////////////////////////////////////////////////////////

function PerspectiveManager() {
  if(!Cfx.Class.IsDefined(PerspectiveManager)) {
    Cfx.Class.New(PerspectiveManager, baseComponent);
  
    if(Cfx.Class.IsInitializing(PerspectiveManager)) {
       PerspectiveManager.Method(init);
       PerspectiveManager.Method(initialized);
       PerspectiveManager.Method(showPerspective);
       PerspectiveManager.Method(getActivePerspective);
       PerspectiveManager.Method(getPerspectiveById);

       return;
    }
  }
  
  // Setup instance data.
  this.InitInstance();

  this.activePerspective = null;
  this.persperspectives = null;
  this.perspectivesRefId = new Array();

  // Return instance.
  return this;
   
   
  //////////////////////////////////////////////////////////////////////////
  // init()
  //////////////////////////////////////////////////////////////////////////
  
  function init() {
    if (this.log.debugging()) {
       this.log.debug("initializing"); 
    }
    this.perspectives = new Array(this.config.list.length);
    try{
      for(var i=0; i<this.config.list.length;i++)
      {
        this.perspectives[i] = this.sm.lookup("framework.componentFactory").createComponent
              ( this.config.list[i]
                ,this.log
                ,this.context
                ,this.sm);
      }
      if (this.log.debugging()) {
        this.log.debug("perspectives succesfully created");
      }
      for(var i=0;i<this.perspectives.length;i++) {
        this.perspectives[i].init();
        this.perspectives[this.perspectives[i].getId()] = this.perspectives[i];
      }
      if (this.log.debugging()) {
        this.log.debug("perspectives succesfully initialized");
      }
    }
    catch (ex) {
      this.log.error(ex, "init: Error!");
      throw ex;
    }
  }
  
  function initialized(){
  	 var _res=true;
  	 var i;
  	 for (i=0; i<this.perspectives.length; i++){
  	 	_res=_res && this.perspectives[i].initialized();
  	 }
  	 return _res;
  }
  
  function showPerspective (id, args) {
  	if (this.log.debugging()) {
		  this.log.debug("showPerspective id: " + id);
  	}
		  		
    if(this.activePerspective != null)
    {
      this.perspectives[this.activePerspective].hide();
    }

    this.perspectives[id].show();
    this.activePerspective = id;  
  }  
  
  function getPerspectiveById(id){
    for(var i = 0 ; i < this.perspectives.length; i++) {
      if (id == this.perspectives[i].getId())
        return this.perspectives[i];
    }
    return null;   
  }
  
  function getActivePerspective() {
    if(this.activePerspective != null)
      return this.perspectives[this.activePerspective];
    
    return null;  
  }
}  

//////////////////////////////////////////////////////////////////////////////
// Abstract Perspective class
//  (c) 2004 - abogaart@hippo.nl
//
// Description:
//  Class acting as Eclipse perspective
//////////////////////////////////////////////////////////////////////////////

function Perspective() {
  if(!Cfx.Class.IsDefined(Perspective)) {
    Cfx.Class.New(Perspective, baseComponent);
  
    if(Cfx.Class.IsInitializing(Perspective)) {
       Perspective.Method(init);
       Perspective.Method(initialized);
       Perspective.Method(show);
       Perspective.Method(hide);
       Perspective.Method(onLoad);
       Perspective.Method(onUnload);
       Perspective.Method(contextualize);
       Perspective.Method(refresh);
       Perspective.Method(refreshView);
       Perspective.Method(getBreadcrumb);
       
       this.vm = null;
       this.shown = false;
       
       return;
    }
  }
  
  // Setup instance data.
  this.InitInstance();
 
  // Return instance.
  return this;
  
  function contextualize(parentContext) {
     this.context = new DefaultContext(parentContext);
  }

  function init() {

    if (this.log.debugging()) {
      this.log.debug("initializing " + this.config.id);
    }
    
    this.sm.lookup("framework.eventmanager").addEventListener(this);
    
    this.container = this.sm.lookup("framework.componentFactory").createComponent
              ( {className: 'PerspectiveContainer'
                 ,frameName: this.config.container
                 ,frameUrl: this.config.frameUrl
                 ,id: this.config.id+'Container'}
                 ,this.log
                 ,this.context
                 ,this.sm);

    if (this.log.debugging()) {
      this.log.debug("before initializing PerspectiveContainer: " +this.config.id);
    }
                 
    this.container.init();

    if (this.log.debugging()) {
      this.log.debug("after initializing PerspectiveContainer: " +this.config.id);
    }
    
    this.context.put("pcontainer", this.container);
    this.vm = this.sm.lookup("framework.componentFactory").createComponent(
              this.config.views
              ,this.log
              ,this.context
              ,this.sm);
  
    this.vm.init();
    
    this.shown = false;

  }  
  
  function initialized(){
 	 	var _res=this.vm.initialized() && this.container.initialized();
    return _res;
  }

  function show() {
    if (!this.shown) this.shown = true;
    this.vm.showViews();
    this.container.setVisibility(true);
    
    var ieh =  window.top.document.globalInputEventHandler;
    var containerFrame = this.context.get(this.context.get("pcontainer").config.frameName);
    this.sm.lookup("cms.workbench").globalKeyBoardHandler.propagateHandlers(containerFrame.frames);
    this.onLoad();
  }
  
  function hide() {
    this.container.setVisibility(false);
    this.onUnload();
  }

  function onLoad() {
    // perspective - specific code goes here
  }

  function onUnload() {
    // perspective - specific code goes here
  }

  function refresh() {
    this.vm.refreshAll();    
  }
  
  function refreshView(strId) {
    this.vm.refreshSingle(strId);
  }

  function getBreadcrumb() {
    var bc = this.vm.getBreadcrumb();
    var arr = [this.config.label];
    var i;

    if (bc != null)
      for (i=0; i<bc.length; i++)
        arr.push(bc[i]);
        
    return arr;
  }
  
}

function DashboardPerspective() {
  if (Cfx.Class.IsDefined(DashboardPerspective) == false) {
    Cfx.Class.New(DashboardPerspective, Perspective);
    if( Cfx.Class.IsInitializing( DashboardPerspective)) {
      // Initialize class methods
      DashboardPerspective.Method(onLoad);
      return;
    }
  }
 
  // Setup instance data.
  this.InitInstance();
  this.firstHitHandled = false;
  // Return instance.
  return this;
  
  function onLoad() {
    
    this.baseClass.onLoad.apply(this); //super call

    if(this.firstHitHandled)
      return;
      
    var defaultStartupView = 'welcome';
    var subMenu = this.vm.getViewById('submenu');
    var id = subMenu.config.defaultView != null ? subMenu.config.defaultView : defaultStartupView;
    var lastActive = 'welcome';
    
    if(id == lastActive)
      return;
     
    var myV = this.vm.getViewById(id);
    if(myV != null && isInstanceOf(myV, 'LazyView') && !myV.isActivatable()) {
      myV.setActivatable();  //refactor
    }
    
    var dom = this.container.getDOM();
    if (dom.getById(lastActive)) {
  	  dom.getById(lastActive).style.display = 'none';
    }
    if (dom.getById(id)) {
		  dom.getById(id).style.display = 'block';
    }
    subMenu.setLastActive(id);
    this.firstHitHandled = true;	
  }
}

function DocumentPerspective() {
  if (Cfx.Class.IsDefined(DocumentPerspective) == false ) {
    Cfx.Class.New(DocumentPerspective, Perspective);
    if( Cfx.Class.IsInitializing(DocumentPerspective)) {
      // Initialize class methods
      DocumentPerspective.Method(show);
      DocumentPerspective.Method(selectSource);
      return;
    }
  }
  this.InitInstance();
  return this;

  function show() {
    var firstTime = !this.shown;
    if (!this.shown) this.shown = true;
    this.vm.showViews();
    this.container.setVisibility(true);

    var ep = this.sm.lookup("cms.workbench").perspectiveManager.getPerspectiveById("editing");
    var openedDocument = ep.getDocument();
    if (firstTime && openedDocument != ""){
       var p = "[{key:'url',val:'"+openedDocument+"'}]";      
       window.setTimeout("window.top.window.frames['topframe'].workbench.perspectiveManager.getPerspectiveById('documents').selectSource("+p+")",2000);
    } 
  }

  function selectSource(srcPath) 
  {
    var fileName = "";
    var filePath = "";
    var perspectiveId = "";

    var url = "";
    for (var i = 0; i < srcPath.length; i++)
    {
      if (srcPath[i].key == "url")
      {
        url = srcPath[i].val;
      }
    }

    var folders = url.split("/");
    for (var i = 0; i < folders.length; i++) 
    {
    	//perspectiveId
    	if(i==1)
    	  perspectiveId = "/" + folders[i];

    	if(i < folders.length-1 && folders[i] != '')
        filePath += "/" + folders[i];  //folderpath
      else if(folders[i] != '')
        fileName = folders[i];  //filename
    }
    
    // if resource is in root (perspectiveId) 
    // than add a trailing slash to path
    if(filePath == perspectiveId)
      filePath += '/';

    // parameters for expandfolder and openfolder events
    var folderParams = new Array(3);
    folderParams[0] = {key: 'url', val: filePath};
    folderParams[1] = {key: 'currentPath', val: filePath};
    folderParams[2] = {key: 'perspectiveId', val: perspectiveId};
    folderParams[3] = {key: 'refresh', val: perspectiveId};

    // open folder containing resource    
    this.sm.lookup('framework.eventmanager').fireEvent('expandfolder', folderParams);
    this.sm.lookup('framework.eventmanager').fireEvent('openfolder', folderParams);
    
    // parameters for newDocument event    
    var fileParams = new Array(2);
    fileParams[0] = {key: 'url', val: filePath};
    fileParams[1] = {key: 'selectedResourceName', val: fileName};

    // select resource by firing newDocument event
    this.sm.lookup('framework.eventmanager').fireEvent('newDocument', fileParams);
        
  }
}

function AssetPerspective() {
  if ( Cfx.Class.IsDefined( AssetPerspective) == false ) {
    Cfx.Class.New( AssetPerspective, Perspective);
    if( Cfx.Class.IsInitializing( AssetPerspective)) {
      // Declare class methods
      AssetPerspective.Method(assetselectSource);
      return;
    }
  }
  this.InitInstance();
  return this;

  function assetselectSource(srcPath) 
  {
    var fileName = "";
    var filePath = "";
    var perspectiveId = "";
    var url = "";

    for (var i = 0; i < srcPath.length; i++)
    {
      if (srcPath[i].key == "url")
      {
        url = srcPath[i].val;
      }
    }

    var folders = url.split("/");
    for (var i = 0; i < folders.length; i++) 
    {
    	//perspectiveId
    	if (i == 1)
    	{
    	  perspectiveId = "/" + folders[i];
      }
    	if (i != (folders.length - 1) && folders[i] != '')
    	{
        filePath += "/" + folders[i];  //folderpath
      }
      else if (folders[i] != '')
      {
        fileName = folders[i];  //filename
      }
    }
    this.log.debug("--- filePath: " + filePath);
    this.log.debug("--- fileName: " + fileName);
    
    //if resource is in root (perspectiveId) 
    //than add a trailing slash to path
    if(filePath == perspectiveId)
    {
      filePath += '/';
    }

    var folderParams = new Array(3);
    folderParams[0] = {key: 'url', val: filePath};
    folderParams[1] = {key: 'currentPath', val: filePath};
    folderParams[2] = {key: 'perspectiveId', val: perspectiveId};

    //expand the tree following the filePath
    this.vm.views['assetfolders'].expandassetfolder( folderParams );
    this.vm.views['assetfolders'].openassetfolder(folderParams);
    this.vm.views['assetfolderactions'].openassetfolder(folderParams);

    var fileParams = new Array(2);
    fileParams[0] = {key: 'url', val: filePath};
    fileParams[1] = {key: 'selectedResourceName', val: fileName};

    // fire upload event so all view's will focus on the file
    this.vm.views['assetdocs'].assetupload( fileParams );    
  }

}


function SourcePerspective() {
  if (Cfx.Class.IsDefined(SourcePerspective) == false) {
    Cfx.Class.New( SourcePerspective, Perspective);
    if(Cfx.Class.IsInitializing( SourcePerspective )) {
      // Initialize class methods
      return;
    }
  }
  this.InitInstance();
  return this;
}

function SlidePerspective() {
  if (Cfx.Class.IsDefined(SlidePerspective) == false) {
    Cfx.Class.New( SlidePerspective, Perspective);
    if(Cfx.Class.IsInitializing( SlidePerspective )) {
      // Initialize class methods
      return;
    }
  }
  this.InitInstance();
  return this;
}



function SearchPerspective() {
  if (Cfx.Class.IsDefined(SearchPerspective) == false) {
    Cfx.Class.New( SearchPerspective, Perspective);
    if(Cfx.Class.IsInitializing( SearchPerspective )) {
      // Initialize class methods
      return;
    }
  }
  this.InitInstance();
  return this;
}

function SearchEnginePerspective() {
  if (Cfx.Class.IsDefined(SearchEnginePerspective) == false) {
    Cfx.Class.New( SearchEnginePerspective, Perspective);
    if(Cfx.Class.IsInitializing( SearchEnginePerspective )) {
      // Initialize class methods
      SearchEnginePerspective.Method( doSavedReportSearch );
      SearchEnginePerspective.Method( onLoad );
      SearchEnginePerspective.Method( onUnload );
      return;
    }
  }
  this.InitInstance();
  
 function doSavedReportSearch(params){
    if (!this.shown) this.shown = true;
    this.container.setVisibility(true);
 }
 
 function onLoad(){
   try{
     var summary = window.top.frames["topframe"].document.getElementById('search_result_summary');
     summary.innerHTML = '';
     summary.style.display='inline';
   } catch (e){};
   try{
     var extended_summary = window.top.frames["topframe"].document.getElementById('search_result_extended_summary');
     extended_summary.innerHTML = '';
     extended_summary.style.display='inline';
   } catch(e){};
 }

 function onUnload(){
   try{
     var summary = window.top.frames["topframe"].document.getElementById('search_result_summary');
     summary.style.display='none';
   } catch (e){};
   try{
     var extended_summary = window.top.frames["topframe"].document.getElementById('search_result_extended_summary');
     extended_summary.style.display='none';
   } catch(e){};
 }
 
   
  
  return this;
}





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -