RemoteSearchPlugin.js 2.83 KB
/**
  * Project      :  AMDA-NG
  * Name         : RemoteSearchPlug.js
  * @plugin 	  amdaUI.InteractiveIntervalPlug
  * @extends 	  Ext.AbstractPlugin 
  * @ptype 	 	  interactiveIntervalPlugin
  * @brief		 Plot interactive session UI (View)
  * @author Myriam
  * @version $Id: RemoteSearchPlugin.js 1130 2012-12-18 16:45:54Z elena $
  ********************************************************************************
  *    FT Id     :   Date   : Name - Description
  *******************************************************************************
  *  :          
  */


Ext.define('amdaUI.RemoteSearchPlugin', {
	extend: 'Ext.AbstractPlugin',
	alias: 'plugin.remoteSearchPlugin',
	 	
	moduleId : 'up-win',
 
	win : null,
	
 	constructor: function(config) { 	  
        Ext.apply(this, config);  
        this.callParent(arguments);
	},
 	
	
	init: function(cmp) {
	    this.hostCmp = cmp;   
	    this.hostCmp.on({
		open: this.onOpen, 	
		scope: this});
	},
		 	
	onDestroy : function() {
	     this.win = null;
	},
			
	onOpen: function(url) {
	  //TODO just reloa dtree
	        if (this.win) this.win.destroy();
	   
		if (!this.win) {
		  this.win = new Ext.Window({			
			  id: 'remoteSearch-win',  
			  width: 310, 
			  height: 500,			 	 
			  title: url,
			  layout: 'fit',
			  constrain: true,
			  ghost: false,			 
			  items: this.getTree(url),
			  listeners: {
			      scope: this,			    
			      beforeclose: function(){			      				 
	//			  Ext.PluginManager.unregister(this);
			      }
			  },
			  getConstrainVector: function(constrainTo){
					var me = this;
			        if (me.constrain || me.constrainHeader) {
			            constrainTo = constrainTo || (me.floatParent && me.floatParent.getTargetEl()) || me.container || me.el.getScopeParent();
			            return (me.constrainHeader ? me.header.el : me.el).getConstrainVector(constrainTo);
			        }
			    }
		  });
		  this.win.on('destroy', this.onDestroy, this);
		
		//  Ext.PluginManager.register(this);		 
	
		  this.win.show();		 		 		 		 
	  }
	},
	
	getTree : function(url) {
	  
	  var store = Ext.create('Ext.data.TreeStore', {
	  model: 'amdaModel.AmdaNode',		     
	  root: {			  			  
	      text: url,	   
	      nodeType : 'url',
	      expanded: true
	  } ,
	  listeners: {
	    scope : this,
	    beforeload: function(store, operation){
	      store.proxy.extraParams = {
		   nodeType: 'url',
		   baseId: url
	      }}	     
	    }
	  
	  });
	  
	  var tree = Ext.create('Ext.tree.Panel', {
	    store: store,
	    listeners : {
	        scope : this,
		itemdblclick: function(view, record, item, index, event){
                    event.stopEvent();
		    var form = this.hostCmp.down('form').next().getForm();
		    form.getFields().getAt(1).setValue(record.internalId);	// internalId ??			
		    this.win.destroy();
		}
	      }
	    });
	  
	  return tree;	     	  	  
	}
		
});