kartik-v / yii2-tree-manager

An advanced tree management module using nested sets for Yii 2.
http://demos.krajee.com/tree-manager
Other
150 stars 107 forks source link

Layout disturbed for the left nav footer toolbar buttons #200

Closed buttflattery closed 6 years ago

buttflattery commented 6 years ago

Prerequisites

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

I was expecting... image

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 below

<div class="btn-group-sm btn-group" role="group">
    <a class="btn btn-default waves-effect kv-toolbar-btn kv-refresh" href="/manage-campaigns" title="" data-original-title="Refresh">
        <span class="kv-icon-10 fa fa-refresh"></span>
    </a>
    <button type="button" class="btn btn-default waves-effect kv-toolbar-btn kv-create-root" title="" data-original-title="Add Root"></button>
</div>

Which may be because the left nav is populated via javascript? if i am not wrong. In case of allowNewRoots is false we can use a css class with display:none property that would fix the issue.

Environment

Ubuntu 14.04 Php 5.6

Browsers

Operating System

Libraries

Isolating the problem

kartik-v commented 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?

buttflattery commented 6 years ago

No, I am not modifying the js plugin, but I don't quite get the statement

You have to set allowNewRoots before initializing the TreeView 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?

kartik-v commented 6 years ago

Ok I see. I will provide a fix for this.

kartik-v commented 6 years ago

This should be resolved with the above fix. Let know.

buttflattery commented 6 years ago

Awesome, it is fixed in the latest version now. thanks again @kartik-v .