RemoteSearchPlugin.js 2.08 KB
/**
  * Project      :  AMDA-NG
  * Name         : RemoteSearchPlug.js
  * @plugin 	  remoteSearchPlugin
  * @extends 	  Ext.AbstractPlugin         
  */


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 reload tree
		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),
				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);	 

			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;	     	  	  
	}
		
});