<?php 

include_once("_dirinfo.php");
include_once(PATH_TO_ROOT."init.php");
include_once(PATH_TO_ROOT."_class/class.Extjs_grid.php");
include_once(PATH_TO_ROOT."_class/class.Extjs_tree.php");


$tabId = $_POST['uniqueTabId'];
$tableNameTree = '_QueryMachineTemplates';

$tree = new MakeTree($tabId.'_tree');
$treeName = $tree->getName();

$tree->SetTable($tableNameTree,DB_WARPIT_USERSPOOL);
$tree->SetRootVisible('true')
	->setWidth('250')
;
$tree->setTextPadding('1px');
$tree
	->addConfig('region',"'west'")
	->activateDD()
	->setContAddItem()
	->setContAddGroup()
	->setContDelete()
;	 



$grid = new MakeGrid($tabId.'_grid');
$grid->setMainTable('_QueryMachineConstruction',DB_WARPIT_USERSPOOL)
//	->setTitle('QueryMachine')
;
// create the combo instance
echo "//combo box for condition choise
var andOrCombo = new Ext.form.ComboBox({
    typeAhead: true,
    triggerAction: 'all',
    lazyRender:true,
    mode: 'local',
    store: new Ext.data.ArrayStore({
        id: 0,
        fields: [
            'myId',
            'displayText'
        ],
        data: [['AND', 'AND'], ['OR', 'OR']]
    }),
    valueField: 'myId',
    displayField: 'displayText'
	});
	//combobox for operation choises
	var wupOperationCombo = new Ext.form.ComboBox({
    typeAhead: true,
    triggerAction: 'all',
    lazyRender:true,
    mode: 'local',
    store: new Ext.data.ArrayStore({
        id: 0,
        fields: [
            'myId',
            'displayText'
        ],
        data: [['=', '='], ['!=', '!='], ['<', '<'], ['>', '>'], ['LIKE', 'LIKE']]
    }),
    valueField: 'myId',
    displayField: 'displayText'
	});
	//combobox (tree) for all possible fields
	var wupQueryFieldCombo = new Ext.ux.TreeCombo({autoHeight:true,loader : new Ext.tree.TreeLoader({
 dataUrl   	:'webuserspool/_ajax/ajax.queryMachine.php', preloadChildren:true,
 baseParams	: {RMtable:'_QueryMachineFields',database:'".DB_WARPIT_USERSPOOL."',action:'selectAll',RMcomp:'tree', boldRoots : true} 
,listeners: { load : function(a,b,resp){ var r = Ext.decode(resp.responseText); if(r!= null && r.success === false){ alert('Tree load error: '+r.error,'Error'); }  }
				} }
				) //eo treeLoader
				});
				
	wupQueryFieldCombo.treePanel.expandAll();	
var treeComboToRenderer = function(combo) 
	{ return function(value) { 
		var idx = combo.treePanel.getRootNode().findChild('id' , value,true);
		if(idx==null)	return 'Select';
		return idx.attributes.text;
		}
	}
	
	
";

echo $tree->CreateTree();

echo "
	$treeName.on('dblclick',function(node) {
		if(node.attributes.leaf)
		{
			var tmp = Ext.getCmp('wupQueryMachineGrid_'+node.id );
			if( tmp )
			{
				tmp.show();
				return;
			}
			CallScript('webuserspool/_forms/SQLmachine/forms.queryMachine.php',{node_id: node.id,name:node.text});
		}
	 });
	
	var $tabId = new Ext.Panel({
		id:'$tabId',
		title:'QueryMachine',
		defaults:{split:true,border:false},
	
		layout:'border',
		border: false,
		closable:true,
		items:[$treeName, { xtype:'tabpanel',id:'queryMachineTabPanel',region:'center'  }   ]
	});
mainTabPanel.add( $tabId ).show();  "

?>