public function menuWidget($view = 'node', $attributes = array(), $return = false) { $items = $this->childrenTree($attributes); $behavior = $this; $widget = new ARTreeMenuWidget(compact('view', 'items', 'behavior'), $return); return $widget->run(); }
/** * Generates jstree menu from owner children. * @param array $data data for widget * @param bool|string $callback $this method name for data processing * - define it for variable options and bind functions attaching. * @return Widget menu widget */ public function menuWidget($data = [], $callback = false) { $data = array_merge(['items' => [$this->owner], 'behavior' => $this, 'view' => 'node'], $data); if ($callback) { $data = $this->{$callback}($data); } $widget = new ARTreeMenuWidget($data); return $widget->run(); }
public function getMenu() { $moduleName = AbstractModel::moduleName(static::className()); $model = $this->findModel(); $uniqueKey = 0; $items = $model::find()->orderBy(['lft' => SORT_ASC])->asArray()->all(); foreach ($items as &$item) { $uniqueKey++; $nodeId = $uniqueKey . '-id-' . $item['id']; $item['nodeAttributes'] = ['id' => $nodeId, 'text' => $item['name'], 'type' => 'folder', 'active' => \Yii::$app->request->get('id') == $item['id'], 'a_attr' => ['data-id' => $nodeId, 'href' => ["/{$moduleName}/category/update", 'id' => $item['id']]]]; } $treeWidget = new ARTreeMenuWidget(['items' => $items, 'view' => 'nested']); return $treeWidget->run(); }
/** * Callback for $this->menuWidget() method. * @param array $data data to process. * @return array processed data. */ public function menuCallback($data) { $contextMenu = ARTreeMenuWidget::this()->commonOptions()['contextmenu']; $contextMenu['items'] = ['create' => $contextMenu['items']['create'], 'delete' => $contextMenu['items']['delete']]; $data['options'] = ['types' => $this->types, 'contextmenu' => $contextMenu]; $items = AuthItem::find()->where(['type' => \yii\rbac\Item::TYPE_ROLE])->indexBy('name')->all(); $relations = AuthItemChild::find()->all(); $data['items'] = $this->generateTree($items, $relations); return $data; }
public function treeWidget($callback, $force = false) { $options = ['view' => 'simple', 'behavior' => $this, 'items' => $this->{$callback}(), 'id' => $callback, 'options' => ["core" => $callback == 'classEventTree' ? ["animation" => 0, "check_callback" => true, 'data' => ['url' => Url::toRoute(['tree', 'type' => $callback, 'model_id' => $this->owner->id]), 'data' => 'function(node) {return { "id" : node.id };}']] : (new ARTreeMenuWidget())->commonOptions()['core'], 'plugins' => ["search", "types"]], 'binds' => ['select_node.jstree' => 'function(event, data){ var el = $(data.event.currentTarget); if (data.node.children_d.length) { return jstree.jstree(true).deselect_node(data.node); } var className = []; el.parents("#' . $callback . ' ul li").each(function(){ className.unshift($(this).find("a").eq(0).text().replace(/\\s/, "")); }); var methodName = className.pop(); className = className.join(\'\\\\\'); $("input.owner.' . $callback . '").val(className); $("input.method.' . $callback . '").val(methodName); }']]; return ARTreeMenuWidget::widget($options); }
public function run() { $treeWidget = new ARTreeMenuWidget(['items' => $this->generateItems(), 'view' => 'nested']); return $treeWidget->run(); }