public function renderNode(TreeViewNode $node) { $nodes = $node->getNodes(); $snippetId = $node->getSnippetId(); $nodeContainer = $this->getWrapper('node container'); $nodeContainer->id = $snippetId; if (count($nodes) > 0) { switch ($node->getState()) { case TreeViewNode::EXPANDED: $stateLink = $this->renderLink($node, 'stateLink', 'link collapse'); break; case TreeViewNode::COLLAPSED: $stateLink = $this->renderLink($node, 'stateLink', 'link expand'); break; } if (null !== $stateLink) { $nodeContainer->add($stateLink); } } else { $icon = $this->getWrapper('node icon'); if (null !== $icon) { $nodeContainer->add($icon); } } $link = $this->renderLink($node, 'nodeLink'); if (null !== $link) { $nodeContainer->add($link); } if ($this->tree->sortable) { foreach (array('up', 'down', 'left', 'right') as $direction) { $nodeContainer->add($this->renderSortableLink($node, $direction)); } } //$up = $this->renderLink($node, 'moveUpLink', 'sorting up'); //$down = $this->renderLink($node, 'moveDownLink', 'sorting down'); //$left = $this->renderLink($node, 'moveLeftLink', 'sorting left'); //$right = $this->renderLink($node, 'moveRightLink', 'sorting right'); $this->tree->onNodeRender($this->tree, $node, $nodeContainer); if (TreeViewNode::EXPANDED === $node->getState() && count($nodes) > 0) { $nodesContainer = $this->renderNodes($nodes); if (null !== $nodesContainer) { $nodeContainer->add($nodesContainer); } } $html = isset($nodeContainer) ? $nodeContainer : $nodesContainer; if ($node->isInvalid()) { $this->tree->getPresenter()->getPayload()->snippets[$snippetId] = (string) $html; } return $html; }
protected function load() { if (!$this->loaded) { $this->loaded = true; $dataRows = TreeView::EXPANDED !== $this->treeView->mode ? $this->getDataRows() : $this->treeView->getDataRows(); foreach ($dataRows as $dataRow) { if (empty($this->dataRow) && empty($dataRow->parentId) || !empty($this->dataRow) && $this->dataRow->id === $dataRow->parentId) { $name = $dataRow[$this->treeView->primaryKey]; $node = new TreeViewNode($this, $name, $dataRow); $node['nodeLink'] = clone $this['nodeLink']; if (TreeView::EXPANDED === $this->treeView->mode && ($this->treeView->rememberState && !$node->isSessionState() || !$this->treeView->rememberState)) { $node->expand(); } } } } }
public function renderNode(TreeViewNode $node) { $nodes = $node->getNodes(); $snippetId = $node->getSnippetId(); $nodeContainer = $this->getWrapper('node container'); $nodeContainer->id = $snippetId; if ($this->tree->getSelected() == $node->name) { $nodeContainer->addClass($this->getValue('node .selected')); } if ($node->getState() == TreeViewNode::EXPANDED && count($nodes) > 0) { $nodeContainer->addClass($this->getValue('node .expanded')); } if (count($nodes) > 0) { switch ($node->getState()) { case TreeViewNode::EXPANDED: $stateLink = $this->renderLink($node, 'stateLink', 'link collapse'); break; case TreeViewNode::COLLAPSED: $stateLink = $this->renderLink($node, 'stateLink', 'link expand'); break; } if (NULL !== $stateLink) { $nodeContainer->add($stateLink); } } else { $icon = $this->getWrapper('node icon'); if (NULL !== $icon) { $nodeContainer->add($icon); } } $link = $this->renderLink($node, 'nodeLink'); if (NULL !== $link) { $nodeContainer->add($link); } $this->tree->onNodeRender($this->tree, $node, $nodeContainer); if (TreeViewNode::EXPANDED === $node->getState() && count($nodes) > 0) { $nodesContainer = $this->renderNodes($nodes); if (NULL !== $nodesContainer) { $nodeContainer->add($nodesContainer); } } $html = isset($nodeContainer) ? $nodeContainer : $nodesContainer; if ($node->isInvalid()) { $this->tree->getPresenter()->getPayload()->snippets[$snippetId] = (string) $html; } return $html; }
protected function getDataRows() { if (TreeView::EXPANDED === $this->mode) { if (NULL === $this->dataRows) { $this->dataRows = $this->dataSource->fetchAssoc($this->primaryKey); } return $this->dataRows; } return parent::getDataRows(); }
public function renderLink(TreeViewNode $node, $name, $wrapper = 'link node') { $el = $this->getWrapper($wrapper); if (NULL === $el) { return NULL; } $link = $node[$name]; if ($link->useAjax) { $class = $el->class; $ajaxClass = $this->getValue('link .ajax'); if (!empty($class) && !empty($ajaxClass)) { $ajaxClass = $class . ' ' . $ajaxClass; } $el->class = $ajaxClass; } $el->setText($link->getLabel()); $el->href($link->getUrl()); if ($name != 'nodeLink') { $span = Html::el('span'); $span->class = 'collapsable'; $span->add($el); return $span; } else { $sub = $this->getWrapper('node subcontainer'); $sub->class = $this->getValue('node .subcontainer'); $sub->add($el); $move = $this->getWrapper('move container'); $move->addClass($this->getValue('move .class')); //TODO: nefunguje v nove verzi jquery? //$move->addClass('handler'); $delete = $this->getWrapper('delete container'); $delete->href = $this->tree->getPresenter()->link($this->onDelete . '!', $node->getDataRow()->id); $delete->class = $this->getValue('delete .ajax'); $delete->addClass($this->getValue('delete .class')); $deleteSpan = $this->getWrapper('delete subcontainer'); $deleteSpan->add('delete'); $delete->add($deleteSpan); $edit = Html::el('a'); $edit->href = $this->tree->getPresenter()->link($this->onEdit, $node->getDataRow()->id); $edit->addClass('edit'); $editSpan = Html::el('span'); $editSpan->add('edit'); $edit->add($editSpan); $sub->add($move); $sub->add($delete); $sub->add($edit); return $sub; } return $el; }
/** * Render 1 node (+ subnodes) * @param TreeViewNode node * @param control * @param label * @return Nette\Web\Html */ private function renderNode(TreeViewNode $node, $control, $label) { $pcontrol = clone $control; $li = NHtml::el('li'); $nid = $node->getDataRow()->id; $control->id = $label->for = $control->id . '-' . $nid; $ck = $this->checkColumn; /* * Pridal som ze ak neezistuje stlpec, aby nedavalo notice */ if (isset($node->getDataRow()->{$ck}) and $node->getDataRow()->{$ck}) { $control->checked = 'checked'; } else { $control->checked = null; } $control->value = $nid; $nc = $this->nameColumn; $label->setText($node->getDataRow()->{$nc}); $li->add((string) $control . (string) $label); $nodes = $node->getNodes(); if (count($nodes)) { $ul = NHtml::el('ul'); $li->add($ul); foreach ($nodes as $n) { $ul->add($this->renderNode($n, $pcontrol, $label)); } } return $li; }
/** * @param TreeViewNode * @param string name * @return Nette\Web\Html */ public function renderLink(TreeViewNode $node, $name) { $pres = $this->tree->getPresenter(); $id = $node->getDataRow()->id; $nname = $this->tree->getName(); $link = $node[$name]; $label = $link->getLabel(); $el = Html::el('div'); $el->add(Html::el('img', array('src' => $this->img_move, 'height' => '16', 'class' => 'handler', 'alt' => 'move', 'style' => 'cursor: move;'))); if ($this->useCB) { $cbx = Html::el('input', array('type' => 'checkbox', 'name' => $nname . '[]', 'id' => 'cbx-' . $id, 'style' => 'cursor: default;')); $ck = $this->checkColumn; if ($node->getDataRow()->{$ck}) { $cbx->checked = 'checked'; } $url = $pres->link($this->onCB . '!'); $cbx->onChange = "jQuery.ajax({ url: '{$url}', type: 'POST', data: { tid: {$id}, vis: this.checked}})"; $el->add($cbx); } if (!$this->enableEditName) { $el->add($label); } else { if ($this->useUI) { // $el->add($label); $el->add(Html::el('span', array('style' => 'cursor: text;', 'onClick' => "\$('#{$nname}-dform').dialog('option', 'dlgvals', { id: {$id}, meno: '{$label}'}); \$('#{$nname}-dform').dialog('option', 'nop', 'update'); \$('#{$nname}-dform').dialog('open');"))->add($label)); } else { $el->add(Html::el('span', array('class' => $nname . '_click', 'id' => $id))->add($label)); } } if ($this->enableDel) { $el->add(Html::el('input', array('type' => 'button', 'class' => 'etbtn_del', 'onClick' => "jQuery.ajax({ url: '" . $pres->link($this->onDel . '!', array('id' => $id)) . "', type: 'post', complete: function(data){ window.location.reload();}});"))); } if ($this->useUI) { if ($this->enableEditName) { /* editBTN $el->add(Html::el('input', array( 'type' => 'button', 'class' => 'etbtn_edit', 'onClick' => "$('#$nname-dform').dialog('option', 'dlgvals', { id: $id, meno: '$label'}); $('#$nname-dform').dialog('option', 'nop', 'update'); $('#$nname-dform').dialog('open');" ))); */ $el->add(Html::el('input', array('type' => 'button', 'class' => 'etbtn_add', 'onClick' => "\$('#{$nname}-dform').dialog('option', 'dlgvals', { id: {$id}, meno: '{$label}'}); \$('#{$nname}-dform').dialog('option', 'nop', 'add'); \$('#{$nname}-dform').dialog('open');"))); } } elseif ($this->enableAdd) { $el->add(Html::el('input', array('type' => 'button', 'class' => 'etbtn_add', 'onClick' => "jQuery.ajax({ url: '" . $pres->link($this->onAdd . '!', array('id' => $id)) . "', type: 'post', complete: function(data){ window.location.reload();}});"))); } return $el; }