Closed buttflattery closed 6 years ago
The sequence seems to be wrong. You have to set allowNewRoots before initializing the TreeView widget. Are you trying to modify the tree view JS plugin and it's options at runtime?
No, I am not modifying the js plugin, but I don't quite get the statement
You have to set
allowNewRoots
before initializing theTreeView
widget
what do you mean by before initializing the TreeView
i am using it in the following way
<?=
TreeView::widget([
// single query fetch to render the tree
// use the Campaign model you have in the previous step
'query' => Campaign::find()->addOrderBy('root, lft'),
'headingOptions' => ['label' => 'Campaign List'],
'mainTemplate' => '
<div class="wrapper">
<nav id="sidebar" class="col-sm-4">
<div class="card">
{wrapper}
</div>
</nav>
<div id="content">
<div class="card">
{detail}
</div>
</div>
</div>',
'rootOptions' => ['label' => '<span class="text-primary">All Campaigns</span>'],
'emptyNodeMsg' => 'No campaigns selected',
'breadcrumbs' => [
'activeCss' => 'active',
],
'fontAwesome' => true, // optional
'isAdmin' => Yii::$app->user->can($route), // optional (toggle to enable admin mode)
'allowNewRoots' => Yii::$app->user->can($route),
'displayValue' => 1, // initial display value
'softDelete' => false, // defaults to true
'iconEditSettings' => [
'show' => 'none',
'type' => TreeView::ICON_RAW,
'listData' => [
'Root' => '<i class="material-icons">widgets</i>',
'Child' => '<i class="material-icons">folder</i>',
]
],
'toolbar' => [
TreeView::BTN_CREATE => [
'options' => ['title' => Yii::t('kvtree', 'Add New'), 'class' => 'btn btn-default waves-effect']
],
TreeView::BTN_CREATE_ROOT => [
'options' => ['title' => Yii::t('kvtree', 'Add Root'), 'class' => 'btn btn-default waves-effect']
],
TreeView::BTN_REMOVE => [
'options' => ['title' => Yii::t('kvtree', 'Remove'), 'class' => 'btn btn-default waves-effect']
],
TreeView::BTN_SEPARATOR,
TreeView::BTN_MOVE_UP => [
'options' => ['title' => Yii::t('kvtree', 'Move UP'), 'class' => 'btn btn-default waves-effect']
],
TreeView::BTN_MOVE_DOWN => [
'options' => ['title' => Yii::t('kvtree', 'Move DOWN'), 'class' => 'btn btn-default waves-effect']
],
TreeView::BTN_MOVE_LEFT => [
'options' => ['title' => Yii::t('kvtree', 'Move LEFT'), 'class' => 'btn btn-default waves-effect']
],
TreeView::BTN_MOVE_RIGHT => [
'options' => ['title' => Yii::t('kvtree', 'Move RIGHT'), 'class' => 'btn btn-default waves-effect']
],
TreeView::BTN_REFRESH => [
'options' => ['title' => Yii::t('kvtree', 'Refresh'), 'class' => 'btn btn-default waves-effect']
],
],
'clientMessages' => [
'invalidCreateNode' => Yii::t('kvtree', 'Cannot create Campaign. Parent Campaign is not saved or is invalid.'),
'emptyNode' => Yii::t('kvtree', '(new)'),
'removeNode' => Yii::t('kvtree', 'Are you sure you want to remove this Campaign?'),
'nodeRemoved' => Yii::t('kvtree', 'The Campaign was removed successfully.'),
'nodeRemoveError' => Yii::t('kvtree', 'Error while removing the Campaign. Please try again later.'),
'nodeNewMove' => Yii::t('kvtree', 'Cannot move this Campaign as the node details are not saved yet.'),
'nodeTop' => Yii::t('kvtree', 'Already at top-most Campaign in the hierarchy.'),
'nodeBottom' => Yii::t('kvtree', 'Already at bottom-most Campaign in the hierarchy.'),
'nodeLeft' => Yii::t('kvtree', 'Already at left-most Campaign in the hierarchy.'),
'nodeRight' => Yii::t('kvtree', 'Already at right-most Campaign in the hierarchy.'),
'emptyNodeRemoved' => Yii::t('kvtree', 'The untitled Campaign was removed.'),
'selectNode' => Yii::t('kvtree', 'Select a Campaign by clicking on one of the tree items.'),
],
'nodeView' => '@backend/views/campaign/_form',
'nodeActions' => [
Module::NODE_MANAGE => Url::to(['/node/manage']),
Module::NODE_SAVE => Url::to(['/node/save']),
Module::NODE_REMOVE => Url::to(['/node/remove']),
Module::NODE_MOVE => Url::to(['/node/move']),
],
'showIDAttribute' => false,
'cacheSettings' => [
'enableCache' => true // defaults to true
],
]);
?>
i am using the customized view though if you want me to add it here i will, maybe i didnt change something accordingly?
Ok I see. I will provide a fix for this.
This should be resolved with the above fix. Let know.
Awesome, it is fixed in the latest version now. thanks again @kartik-v .
Prerequisites
master
branch of yii2-tree-manager.Steps to reproduce the issue
1.Install Tree-Manager 2.initialize the TreeView Widget 3.Disable creation of new root Nodes by using the option
'allowNewRoots'=>false
Expected behavior and actual behavior
When I follow those steps, I see...![image](https://user-images.githubusercontent.com/1536454/42813077-3160234e-89d9-11e8-82d6-870164e8f38a.png)
I was expecting...![image](https://user-images.githubusercontent.com/1536454/42813105-4875da60-89d9-11e8-8b2a-5a83eb303a18.png)
The problem seems to be that the button element is still populated in the html when
allowdNewRoots
is disabled or false the html for the button is belowWhich may be because the left nav is populated via javascript? if i am not wrong. In case of
allowNewRoots
is false we can use acss
class withdisplay:none
property that would fix the issue.Environment
Ubuntu 14.04 Php 5.6
Browsers
Operating System
Libraries
Isolating the problem