Skip to content

Commit

Permalink
🐛 #216 alterando TTreeView para permitir expand
Browse files Browse the repository at this point in the history
  • Loading branch information
bjverde committed Feb 29, 2020
1 parent 3519a40 commit 8a2ee1f
Showing 1 changed file with 94 additions and 43 deletions.
137 changes: 94 additions & 43 deletions base/classes/webform/TTreeView.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class TTreeView extends TControl
private $childFieldName;
private $descFieldName;
private $tableName;
private $mixData;

/**
* Implementa Tree View
Expand Down Expand Up @@ -116,35 +117,42 @@ class TTreeView extends TControl
* @param mixed $strParentFieldName - 4: id do campo chave do pai
* @param mixed $strChildFieldName - 5: id do campo chave dos filhos
* @param mixed $strDescFieldName - 6: Texto da descrição dos nos da arvore
* @param mixed $strInitialParentKey
* @param mixed $mixUserDataFieldNames - campos separados por virgula ou array normal ex: array('nome','telefone');
* @param mixed $strHeight - 9: altura
* @param mixed $strInitialParentKey -07:
* @param mixed $mixUserDataFieldNames -08: campos separados por virgula ou array normal ex: array('nome','telefone');
* @param mixed $strHeight -09: altura
* @param mixed $strWidth -10: largura
* @param mixed $jsOnClick
* @param mixed $jsOnDblClick
* @param mixed $jsOnCheck
* @param mixed $jsOnDrag
* @param mixed $boolEnableCheckBoxes
* @param mixed $boolEnableRadioButtons
* @param mixed $boolEnableTreeLines
* @param mixed $mixFormSearchFields
* @param mixed $jsOnClick -11:
* @param mixed $jsOnDblClick -12:
* @param mixed $jsOnCheck -13:
* @param mixed $jsOnDrag -14:
* @param mixed $boolEnableCheckBoxes -15:
* @param mixed $boolEnableRadioButtons-16:
* @param mixed $boolEnableTreeLines -17:
* @param mixed $mixFormSearchFields -18:
* @param mixed $boolShowToolBar -19:
* @param mixed $startExpanded -20: Se o treeView deve aparecer expandido ou não.
* @return TTreeView
*/
public function __construct( $strName=null, $strRootLabel = null, $mixData = null
, $strParentFieldName = null, $strChildFieldName = null
, $strDescFieldName = null, $strInitialParentKey = null
, $mixUserDataFieldNames = null, $strHeight = null, $strWidth = null
, $jsOnClick = null, $jsOnDblClick = null, $jsOnCheck = null, $jsOnDrag = null
, $jsOnClick = null
, $jsOnDblClick = null
, $jsOnCheck = null
, $jsOnDrag = null
, $boolEnableCheckBoxes = null
, $boolEnableRadioButtons = null
, $boolEnableTreeLines = null
, $mixFormSearchFields = null
, $boolShowToolBar = null )
, $boolShowToolBar = null
, $startExpanded = null)
{
$strName = is_null($strName) ? 'tree_'.$this->getRandomChars(3):$strName;
parent::__construct( 'div', $strName );
$this->setFieldType( 'treeview' );
$this->setClass( 'fwTreeView' );
$this->setStartExpanded($startExpanded);
$this->setOnClick( $jsOnClick );
$this->setOnDblClick( $jsOnDblClick );
$this->setOnCheck( $jsOnCheck );
Expand All @@ -160,6 +168,7 @@ public function __construct( $strName=null, $strRootLabel = null, $mixData = nul
//$this->enableRadio($boolEnableRadioButtons);
$this->addFormSearchFields( $mixFormSearchFields );
$this->enableLines( $boolEnableTreeLines );
//$this->setMixData($mixData);
$this->setData( $mixData, $strParentFieldName, $strChildFieldName, $strDescFieldName, $mixUserDataFieldNames );
$this->setParentFieldName($strParentFieldName);
$this->SetChildFieldName($strChildFieldName);
Expand Down Expand Up @@ -196,28 +205,45 @@ public function setXmlFile( $strFileName = null )

public function getXmlFile()
{
if( !$this->itens )
{
if( !$this->itens ) {
$xmlFile = is_null($this->xmlFile) ? $this->getBase().'callbacks/treeView.php' : $this->xmlFile;
if( file_exists($xmlFile) )
{
return 'index.php?modulo='
. $xmlFile .'&ajax=1&fwTreeview=1&parentField='
. $this->getParentFieldName(). '&childField='
. $this->getChildFieldName() . '&descField='
. $this->getDescFieldName() . '&tableName='
. $this->getTableName() . '&userDataFields=' . $this->getUserDataFieldNames();
if( file_exists($xmlFile) ) {
$parentFieldName = $this->getParentFieldName();
$childFieldName = $this->getChildFieldName();
$descFieldName = $this->getDescFieldName();
$tableName = $this->getTableName();
$userDataFieldNames = $this->getUserDataFieldNames();
$url = 'index.php?modulo='.$xmlFile
.'&ajax=1&fwTreeview=1&parentField='.$parentFieldName
.'&childField='.$childFieldName
.'&descField='.$descFieldName
.'&tableName='.$tableName
.'&userDataFields='.$userDataFieldNames;
return $url;
//return $this->xmlFile;
}
else
{
} else {
$this->addItem(0,1,'Arquivo '.$xmlFile.' não encontrado!', true, '' );
}
}
}

protected function showData()
{
$mixData = $this->getMixData();
$strParentFieldName = $this->getParentFieldName();
$strChildFieldName = $this->getChildFieldName();
$strDescFieldName = $this->getDescFieldName();
$mixUserDataFieldNames = $this->getUserDataFieldNames();
$this->setData( $mixData
, $strParentFieldName
, $strChildFieldName
, $strDescFieldName
, $mixUserDataFieldNames );
}

public function show( $print = true )
{
//$this->showData();
$this->setToolBar();
return parent::show( $print );
}
Expand Down Expand Up @@ -361,24 +387,19 @@ public function setData( $arrData, $strParentField, $strChildField, $strDescFiel
{
$arrUserData = null;

if ( is_array( $mixUserDataFields ) )
{
foreach( $mixUserDataFields as $kData => $vData )
{
if ( isset( $arrData[ trim( $vData )] ) )
{
if ( is_array( $mixUserDataFields ) ) {
foreach( $mixUserDataFields as $kData => $vData ) {
if ( isset( $arrData[ trim( $vData )] ) ) {
$arrUserData[ trim( $vData )] = $arrData[ trim( $vData )][ $k ];
}
}
}

if ( ( string ) $v == '' )
{
if ( ( string ) $v == '' ){
$this->addItem( 0, $arrData[ $strChildField ][ $k ], $arrData[ $strDescField ][ $k ], null, null, $arrUserData );
}
else
{
$this->addItem( $v, $arrData[ $strChildField ][ $k ], $arrData[ $strDescField ][ $k ], null, null, $arrUserData );
}else{
$expand = $this->getItemIsOpen(null, null, null, null);
$this->addItem( $v, $arrData[ $strChildField ][ $k ], $arrData[ $strDescField ][ $k ], $expand, null, $arrUserData );
}
}
}
Expand Down Expand Up @@ -505,16 +526,36 @@ public function getRootLabel()
}

//---------------------------------------------------------------------------
function setStartExpanded( $boolNewValue = null )
public function setStartExpanded( $boolNewValue = null )
{
//echo '<hr>';
//echo '$boolNewValue:'.$boolNewValue;
//var_dump($boolNewValue);
//echo '<hr>';
$boolNewValue = is_null( $boolNewValue ) ? false : $boolNewValue;
$this->startExpanded = $boolNewValue;
}

function getStartExpanded()
public function getStartExpanded()
{
return $this->startExpanded;
}


protected function getItemIsOpen( $open = null, $idParent, $id, $text )
{
$expand = false;
if ( !is_null($open) ){
$expand = $open;
}else{
$expand = is_null( $this->getStartExpanded() ) ? true : $this->getStartExpanded();
}
//echo '<hr>';
//echo 'id:'.$id.', idParent:'.$idParent.', text:'.$text.', $open: '.$open.', $expand: '.$expand.', $expandObj: '.$this->getStartExpanded();
//var_dump($id,$idParent,$text,$open,$expand,$this->getStartExpanded());
return $expand;
}

//---------------------------------------------------------------------------
/**
* Adicionar ítem na árvore
Expand All @@ -533,7 +574,7 @@ public function addItem( $idParent = null, $id, $text, $open = null, $hint = nul
$idParent = is_null($idParent) ? '' : $idParent.'';
if ( !$this->itens ) {

$expand = is_null( $this->getStartExpanded() ) ? true : $this->getStartExpanded();
$expand = $this->getItemIsOpen($open, $idParent, $id, $text);
if( $idParent == $this->initialParentKey && ! isset($_REQUEST['id'] ) ) {
if ( $this->getRootLabel() ) {
$this->itens = new TTreeViewData( '0', 'root', true, '' ); // nivel obrigatório
Expand All @@ -550,7 +591,8 @@ public function addItem( $idParent = null, $id, $text, $open = null, $hint = nul
$parent = ( is_null($idParent) || $idParent=="" || $idParent == '0') ? $this->rootNode : $this->itens->getElementById( $idParent );
if ( !$parent )
{
$item = New TTreeViewData( $id, $text, $open, $hint, $arrUserData, $boolSelect );
$expand = $this->getItemIsOpen($open, $idParent, $id, $text);
$item = New TTreeViewData( $id, $text, $expand, $hint, $arrUserData, $boolSelect );
$item->setParent( $idParent );
$this->addOrphan( $item );
return;
Expand All @@ -563,7 +605,8 @@ public function addItem( $idParent = null, $id, $text, $open = null, $hint = nul
// adicionar filho somente se não existir
if ( !$item = $this->itens->getElementById( $id ) )
{
$parent->addItem( new TTreeViewData( $id, $text, $open, $hint, $arrUserData, $boolSelect, $boolChecked ) );
$expand = $this->getItemIsOpen($open, $idParent, $id, $text);
$parent->addItem( new TTreeViewData( $id, $text, $expand, $hint, $arrUserData, $boolSelect, $boolChecked ) );
}
}
//---------------------------------------------------------------------------
Expand Down Expand Up @@ -819,6 +862,14 @@ public function getTableName()
{
return $this->tableName;
}
public function setMixData($strNewValue=null)
{
$this->mixData = $strNewValue;
}
public function getMixData()
{
return $this->mixData;
}
public function setUserDataFieldNames($mixNewValue=null)
{
$this->userDataFieldNames = $mixNewValue;
Expand Down

0 comments on commit 8a2ee1f

Please sign in to comment.