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

📄 views.js

📁 Hippo CMS是一个以信息为中心的开源内容管理系统。Hippo CMS目标是供中,大型企业来管理其发布在互连网
💻 JS
📖 第 1 页 / 共 5 页
字号:
// free function to toggle a specific view
function toggleView(ele)
{
  var element = ele;
  var string = "";
  while(element.parentNode!=null)
  {
    //alert("element id = "+element.id);
    if(element.view && element.view.indexOf("framework.")>-1)
    {
      string = element.view;
      break;
    }
    else
      element=element.parentNode; 
  }
  if(string=="")
  {
    //alert("parent view not found!");
    return;
  }
  
  var view = window.top.window.frames['topframe'].workbench.sm.lookup(string);
  if(view)
    view.togglePause();
 // else
    //alert("Parent view empty!");
}


//////////////////////////////////////////////////////////////////////////////
// ViewManager class
//  (c) 2004 - abogaart@hippo.nl
//
// Description:
//
//
// [BS] Added b.s. by b.s. Do not initialize view if view has accessRights set
// and user doesn't have accessRights. (Do create view, or looping through 
// views creates errors) Furthermore, showViews doesn't activate these views.  
//////////////////////////////////////////////////////////////////////////////
function ViewManager() {
  if(!Cfx.Class.IsDefined(ViewManager)) {
    Cfx.Class.New(ViewManager, baseComponent);
    if(Cfx.Class.IsInitializing(ViewManager)) {
       ViewManager.Method(init);
       ViewManager.Method(initialized);
       ViewManager.Method(showViews);
       ViewManager.Method(hideViews);
       ViewManager.Method(refreshAll);
       ViewManager.Method(refreshSingle);
       ViewManager.Method(getViewById);
       ViewManager.Method(getBreadcrumb);       
      
       return;
    }
  }
  
  // Setup instance data.
  this.InitInstance();
  
  this.views = null;
  this.perspective = null;
  
  // Return instance.
  return this;
  
  function init() {
  var hiddenViewsInitialized = 0;
  var hiddenViewsCreated = 0;  
  
  if (this.log.debugging) {
    this.log.debug("Initializing ViewManager");
  }

  this.views = new Array(this.config.list.length);
  try {
    for (var i=0; i<this.config.list.length; i++) {
      var cf = this.sm.lookup("framework.componentFactory");
      this.views[i] = cf.createComponent(this.config.list[i],this.log,this.context,this.sm);
    }
    if (this.log.debugging) {
      this.log.debug((this.views.length - hiddenViewsCreated) + " views succesfully created");
    }
    for(var i = 0; i < this.views.length; i++) {
      //accessRights for views
      if (this.views[i].config.accessRights) {
        if (CMS_userName != this.views[i].config.accessRights && this.views[i].requirementsSatisfied()) {
          this.views[i].init();
          this.views[this.views[i].getId()] = this.views[i];
        } 
        else {
          hiddenViewsInitialized++;        
        }
      } 
      else {
      	if (this.views[i].requirementsSatisfied()){
          this.views[i].init();
          this.views[this.views[i].getId()] = this.views[i];
      	} else hiddenViewsInitialized++;
      }
    }
    if (this.log.debugging) {
      this.log.debug((this.views.length - hiddenViewsInitialized) + " visible views succesfully initialized");
      this.log.debug(hiddenViewsInitialized + " hidden views succesfully initialized");
    }
  } 
  catch (ex) {
    this.log.error(ex, "init:");
  }
}

function initialized(){
  	 var _res=true;
  	 var i;
  	 for (i=0; i<this.views.length; i++){
  	 	_res=_res && this.views[i].initialized();
  	 }
  	 return _res;
}

  function showViews() 
  {
    if (this.context.get("browser") == 'MOZ') 
    {
      this.views.reverse();
    }
    for(i=0;i<this.views.length;i++) {
    //[BS] do not activate if not user within accessRights
    //[DD] do not activate if requirements are not met
      if ( ( (!this.views[i].config.accessRights) || 
      							(CMS_userName == this.views[i].config.accessRights) )  && 
      					 this.views[i].requirementsSatisfied())
      {
        // [NvK] put while loop around activate to retry on failure
        var r = 0;
        while (!this.views[i].loaded && r < 3)
        {
          this.views[i].activate();
          r++;
        }
      };
    }
  }

  function getViewById(id) {
    for(i=0;i<this.views.length;i++) {
      if (this.views[i].getId() == id) return this.views[i];
    }
    return null; 
  }

  function hideViews() {
    for(i=0;i<this.views.length;i++) {
      this.views[i].deactivate();
    } 
  }
  
  function refreshAll() {
    for(i=0;i<this.views.length;i++) {
      this.views[i].refresh();
    } 
  }
  function refreshSingle(strID) {
    for(i=0;i<this.views.length;i++) {
        if(this.views[i].getId() == strID){
          this.views[i].refresh();
          break;
      }     
    } 
  }
  
  function getBreadcrumb(){
    var arr = new Array();
    var bc;
    var i;
    var j;
    
    for(i=0;i<this.views.length;i++) {
      if(this.views[i].activated){
        bc = this.views[i].getBreadcrumb();
        if (bc != null){
          for (j=0; j<bc.length; j++)
            arr.push(bc[j]);
        }
      }     
    } 
    return arr;
  }
}

function LazyViewManager() {
  if ( Cfx.Class.IsDefined( LazyViewManager ) == false ) {
    Cfx.Class.New( LazyViewManager, ViewManager );
    if( Cfx.Class.IsInitializing( LazyViewManager, ViewManager )) {

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

  return this;
  
  function showViews() {
    
    if (this.context.get("browser") == 'MOZ') 
    	this.views.reverse();
    
    for(i=0;i<this.views.length;i++) {
      
      var aView = this.views[i];
    
      if ((!aView.config.accessRights || CMS_userName == aView.config.accessRights)  
         && aView.requirementsSatisfied()) {
        
        var r = 0;
        while (!aView.loaded && r < 3)
        {
          if(Cfx.Class.InstanceOf(aView, LazyView)){
            if(aView.isActivatable()) {
              aView.activate();  
            }  
          }else {
            aView.activate();
          }  
          r++;
        }
      };
    }
  }
}

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

function View() {
  if(!Cfx.Class.IsDefined(View)) {
    Cfx.Class.New(View, baseComponent);
  
    if(Cfx.Class.IsInitializing(View)) {
      View.Method(init);
      View.Method(initialized);
      View.Method(create);
      View.Method(activate);
      View.Method(deactivate);
      View.Method(load);
      View.Method(refresh);
      View.Method(doRPC);
      View.Method(saveRPC);
      View.Method(pause);
      View.Method(unpause);
      View.Method(togglePause);
      View.Method(requirementsSatisfied);
      View.Method(getBreadcrumb);
      
      //MP: added delay methods and stuff
      View.Method(callWithDelay);
      View.Method(cancelDelay);
      View.Method(timeoutPassed);
      
      //MP: members for delay methods
      this.timestamps=new Array();
      this.intervals=new Array();
      this.shortDelay = 0;
      this.longDelay = 0;
      this.timeout = 0;
             
      //view ID for array lookup   
      this.id = null;
      //view label for HTML/user presentation
      this.label = null;
      //div element
      this.ele = null;
      //base url for application used in view
      this.appUrl = null;
      //startup location for app
      this.bootParam = '';
      //flag indicating load state, for future use in 'lazy-load'
      this.loaded = false;
      // the ID of the resource currently shown in this view
      this.resourceID = null;
      //flag that helps events to choose execution if visible
      this.activated = false;
      //flat to see if this view is paused
      this.paused = false;
      // requirements for a specific view to be shown ( array of functions )
      this.requirements = null;
      return;
    }
  }

  // Setup instance data.
  this.InitInstance();
        
  // Return instance.
  return this;
 
  function init () {
    if(this.log.debugging()) {
      this.log.debug("Initializing view");
    }
    this.sm.lookup("framework.eventmanager").addEventListener(this);
    
    if(this.log.debugging()) {
    this.log.debug("Got a perspectiveContainer from context: ");
    }  

    this.rpcid=null;

    // set delay members    
    this.timeout = (this.config.timeout!=undefined || this.config.timeout!=null) ? parseInt(this.config.timeout) : 0;
    this.shortDelay = (this.config.shortDelay!=undefined || this.config.shortDelay!=null) ? parseInt(this.config.shortDelay) : 0;
    this.longDelay = (this.config.longDelay!=undefined || this.config.longDelay!=null) ? parseInt(this.config.longDelay) : 0;
    
    //this.log.debug("%%%%%% read config: timeout="+this.timeout+" shortDelay="+this.shortDelay+" longDelay="+this.longDelay);
    
    // register the views with the service manager so we can resolve them to do callbacks
    this.sm.put(this.log.category,this);
    
  }
  
  function initialized(){
     return true;	
  }
  
  // strfunction: string to evaluate after delay
  // delay: delay time in millisecs
  // index: interval id index in array
  function callWithDelay(strfunction, delay, index)
  {
    if(this.intervals==undefined)
      this.intervals=new Array();
  
    var id = this.intervals[index];
    
    var objname = this.log.category;
    
    if(id!=undefined && id!=null) //its running
      this.cancelDelay(index);
    
    // start it
    if(objname)
      this.intervals[index]= window.setInterval('workbench.sm.lookup("'+objname+'").'+strfunction+'; workbench.sm.lookup("'+objname+'").cancelDelay('+index+');',delay);
    
    //this.log.info("*************** callWithDelay calling: "+'workbench.sm.lookup("'+objname+'").'+strfunction+'; workbench.sm.lookup("'+objname+'").cancelDelay('+index+');');
    this.log.debug("***** callWithDelay! call: "+strfunction);
  }

  function cancelDelay(index)
  {
    if(this.intervals==undefined)
      this.intervals=new Array();
  
    this.log.debug("********************* cancelDelay("+index+")!");
    var id = this.intervals[index];
    if(id!=undefined && id!=null)
    {
      window.clearInterval(id);
      this.intervals[index] = null;
    }
  }
  // index: timestamp index to timestamp array (may be shared between functions)
  // timeout: time difference to check for (in milliseconds)
  function timeoutPassed(index)
  {
    if(this.timeout==0) //no timeout
      return true;
  
    if(this.timestamps==undefined)
      this.timestamps=new Array();
    
    var time = this.timestamps[index];
    var d = new Date();
    
    this.log.debug("******* timestamps length: "+this.timestamps.length);
    
    this.log.debug("###### timestamp["+index+"]: "+time);
    
    if( (time==undefined && time==null) || (time!=undefined && time!=null && time+this.timeout <= d.getTime()) ) // timestamp not set or timeout passed 
    {
      this.timestamps[index] = d.getTime();
      this.log.debug("###### new timestamp["+index+"]: "+this.timestamps[index]);
      this.log.debug("###### timestamp "+index+" passed threshold "+this.timeout+"!");
      return true;
    }
    else
    {
      this.log.debug("###### timestamp "+index+" did not pass threshold "+this.timeout+"!");
      return false;
    }
  }
  
  function deleteChildren(node)
  {
    while(node.hasChildNodes())
      node.removeChild(node.firstChild);
      
    node.parentNode.removeChild(node);
  }
  
  function togglePause()
  {
    if(this.paused)
      this.unpause();
    else
      this.pause();
  }
  
  /**
   * "pauses", i.e. collapses a view to just its title bar. This view should not be updated while it is paused
   * name is a prefix to the id of the table cell which has to be cleared
   */
  function pause()
  {
    this.paused = true;
    
    var queue = new Array();
    var doneCell=false;
    var doneToggler=false;
    var doneHeader=false;
    
    //enqueue all child nodes
    for(var i=0; i<this.ele.childNodes.length; i++)
      queue.push(this.ele.childNodes[i]);
    
    if(this.log.debugging()) {
    this.log.debug("starting breath-first, queuelength: "+queue.length);
    }
    
    while(queue.length>0  ) // && ( !doneCell || !doneToggler || !doneHeader)
    {
      var el = queue.shift();
      //this.log.debug("doing breath-first, queuelength: "+queue.length);
      
      if(this.log.debugging() && (el.nodeName=="TD" || el.nodeName=="IMG")) {
        this.log.debug("traverse: name="+el.name+" nodeName="+el.nodeName+" content="+el.nodeValue+" done");
      }
        
      if(el.nodeName=="TD" && el.className!=undefined && el.className=="sidePanelHeader" && !doneHeader)
      {
        this.log.debug("header done");
        var str = el.innerHTML;
        //el.innerHTML = str.replace(/\([^\)]*\)/gi,'');
        var index = str.lastIndexOf("(");
        if(index!=str.indexOf("("))
          el.innerHTML = str.substring(0,index);
        this.log.debug("header: SWITCHED --> "+str+" <-- TO --> "+el.innerHTML+" <--");
      }
      if(el.nodeName=="TD" && el.className!=undefined && el.className=="sidePanelBody" && !doneCell)
      {
        doneCell=true;
        deleteChildren(el);
        this.log.debug("did cell");
      }
      if(el.nodeName=="IMG" && el.className!=undefined && el.className=="toggler" && !doneToggler)
      {
        doneToggler=true;
        el.src="/skin/images/open.gif";
        this.log.debug("did toggler");
      }
      
      //enqueue all children
      for(var i=0; i<el.childNodes.length; i++)
        queue.push(el.childNodes[i]);
        
      //this.log.debug("doing breath-first, enqueued "+el.childNodes.length+" children, queuelength: "+queue.length);
    }
    
    this.log.debug("traverse done: queuelength="+queue.length);
    
  }
  
  function unpause()
  {
    this.paused = false;
    this.refresh();
  }

⌨️ 快捷键说明

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