예제 #1
0
 public function render(TreeView $tree)
 {
     if ($this->tree !== $tree) {
         $this->tree = $tree;
     }
     $snippetId = $this->tree->getSnippetId();
     $html = $this->renderNodes($this->tree->getNodes(), 'nodes root');
     if ($this->tree->isControlInvalid() && $this->tree->getPresenter()->isAjax()) {
         $this->tree->getPresenter()->getPayload()->snippets[$snippetId] = (string) $html;
     }
     if (!$this->tree->getPresenter()->isAjax()) {
         $treeContainer = $this->getWrapper('tree container');
         $treeContainer->id = $snippetId;
         $treeContainer->add($html);
         return $treeContainer;
     }
 }
예제 #2
0
 public function render(TreeView $tree)
 {
     if ($this->tree !== $tree) {
         $this->tree = $tree;
     }
     $snippetId = $this->tree->getSnippetId();
     $html = $this->renderNodes($this->tree->getNodes(), 'nodes root');
     $html->add(Html::el('script', array('type' => 'text/javascript', 'charset' => 'utf-8'))->add(sprintf($this->script, $this->getValue('nodes #root'), $this->tree->getPresenter()->link($this->onChange . '!'), $this->getValue('node .item'))));
     if ($this->tree->isControlInvalid() && $this->tree->getPresenter()->isAjax()) {
         $this->tree->getPresenter()->getPayload()->snippets[$snippetId] = (string) $html;
     }
     if (!$this->tree->getPresenter()->isAjax()) {
         $treeContainer = $this->getWrapper('tree container');
         $treeContainer->id = $snippetId;
         $treeContainer->add($html);
         return $treeContainer;
     }
 }
예제 #3
0
 /**
  * @param TreeView
  * @return Nette\Web\Html
  */
 public function render(TreeView $tree)
 {
     if ($this->tree !== $tree) {
         $this->tree = $tree;
     }
     $snippetId = $this->tree->getName();
     $prez = $this->tree->getPresenter();
     $treeContainer = Html::el('div', array('class' => 'etwrap', 'style' => 'border: 1px solid #BBBBBB; padding: 1em 1em 1em 1em;'));
     //TODO: class 'etwrap' nikde nepouzite
     $css = Html::el('style', array('type' => 'text/css'));
     $css->add(sprintf($this->styleItem, $snippetId));
     if ($this->enableAdd) {
         $css->add(".etbtn_add { background-image: url('" . $this->img_add . "'); background-color: transparent; border: none; width: 16px; height: 16px;}");
     }
     if ($this->enableEditName) {
         $css->add(".etbtn_edit { background-image: url('" . $this->img_edit . "'); background-color: transparent; border: none; width: 16px; height: 16px;}");
     }
     if ($this->enableDel) {
         $css->add(".etbtn_del { background-image: url('" . $this->img_cancel . "'); background-color: transparent; border: none; width: 16px; height: 16px;}");
     }
     $treeContainer->add($css);
     if ($this->enableEditName) {
         $treeContainer->add(Html::el('script', array('type' => 'text/javascript', 'charset' => 'utf-8'))->add(sprintf($this->editJS, $snippetId, $prez->link($this->onEdit . '!'))));
     }
     $treeContainer->add($this->renderNodes($this->tree->getNodes(), Html::el('ul', array('id' => $snippetId, 'class' => 'page-list', 'style' => "list-style: none; margin: 0; padding: 0; display: block;"))));
     $treeContainer->add(Html::el('script', array('type' => 'text/javascript', 'charset' => 'utf-8'))->add(sprintf($this->linkingJS, $snippetId, $prez->link($this->onChange . '!'), $snippetId)));
     if ($this->useUI) {
         $treeContainer->add(Html::el('style', array('type' => 'text/css'))->add(".ui-dialog .ui-state-error { padding: .3em;}"));
         $treeContainer->add(Html::el('script', array('type' => 'text/javascript', 'charset' => 'utf-8'))->add("\$(function() {" . "var id=\$('#{$snippetId}-id'),meno=\$('#{$snippetId}-meno'),allFields=\$([]).add(id).add(meno),tips=\$('.validateTips');\n" . "function updateTips(t){ tips.text(t).addClass('ui-state-highlight');setTimeout(function() { tips.removeClass('ui-state-highlight', 1500);}, 500);}\n" . "function checkLength(o,n,min,max){ if ( o.val().length > max || o.val().length < min ) { o.addClass('ui-state-error');updateTips('Length of ' + n + ' must be between '+min+' and '+max+'.');return false;}else return true;}\n" . "function checkRegexp(o,regexp,n){ if (!(regexp.test(o.val()))){ o.addClass('ui-state-error');updateTips(n);return false;}else return true;}\n" . "\$('#{$snippetId}-dform').dialog({" . "autoOpen: false," . "height: 200," . "width: 250," . "modal: true," . "buttons: {" . "'Nastaviť': function() {" . "var bValid=true;" . "allFields.removeClass('ui-state-error');" . "bValid=bValid && checkLength(meno, 'meno', 2, 50);" . "if (bValid) {" . "jQuery.ajax({" . "url: \$(this).dialog('option', 'nop')=='add'? " . TemplateHelpers::escapeJs($prez->link($this->onAdd . '!')) . " : " . TemplateHelpers::escapeJs($prez->link($this->onEdit . '!')) . "," . "type: 'post'," . "data: {" . "id: \$(this).dialog('option', 'idval')," . "value: meno.val()" . "}," . "complete: function(data){ window.location.reload();}" . "});" . "\$(this).dialog('close');" . "}" . "}," . "Cancel: function() {" . "\$(this).dialog('close');" . "}" . "}," . "open: function() {" . "var dlgvals=\$(this).dialog('option', 'dlgvals');" . "id.val(dlgvals['id']);" . "\$(this).dialog('option', 'idval', dlgvals['id']);" . "if (\$(this).dialog('option', 'nop')=='update')" . "meno.val(dlgvals['meno']);" . "}," . "close: function() {" . "allFields.val('').removeClass('ui-state-error');" . "}" . "});\n" . "\$('#{$snippetId}-cnode').button().click(function(){ \$('#{$snippetId}-dform').dialog('option', 'dlgvals', { id: 0, meno: ''});\$('#{$snippetId}-dform').dialog('option', 'nop', 'add');\$('#{$snippetId}-dform').dialog('open');});\n" . "});\n"));
         $fset = Html::el('fieldset', array('style' => 'padding:0; border:0;'));
         $fset->add(Html::el('input', array('type' => 'hidden', 'name' => $snippetId . '-id', 'id' => $snippetId . '-id')));
         $fset->add(Html::el('label', array('for' => $snippetId . '-meno', 'style' => 'display: block;'))->add('Názov'));
         $fset->add(Html::el('input', array('type' => 'text', 'name' => $snippetId . '-meno', 'id' => $snippetId . '-meno', 'class' => 'text ui-widget-content ui-corner-all', 'style' => 'display:block; width:95%;')));
         $treeContainer->add(Html::el('div', array('id' => $snippetId . '-dform', 'title' => $snippetId, 'style' => 'font-size: 62.5%;'))->add(Html::el('p', array('class' => 'validateTips', 'style' => 'border: 1px solid transparent; padding: 0.3em;')))->add(Html::el('form')->add($fset)));
         $treeContainer->add(Html::el('button', array('id' => $snippetId . '-cnode'))->add('Pridať položku'));
     } else {
         if ($this->enableAdd) {
             $treeContainer->add(Html::el('input', array('type' => 'button', 'class' => 'etbtn_add', 'onClick' => "jQuery.ajax({ url: '" . $prez->link($this->onAdd . '!') . "', type: 'POST', complete: function(data){ window.location.reload();}});")));
         }
     }
     return $treeContainer;
 }