Commit 3019fa08 authored by Marcello Pivanti's avatar Marcello Pivanti
Browse files

Initial Commit

parents
<?php
/**
* Art-ER Attrattività, ricerca e territorio dell’Emilia-Romagna
* OPEN 2.0
*
* @package Open20Package
* @category CategoryName
* @author Elite Division S.r.l.
*/
/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2017
* @package yii2-tree
* @version 1.0.8
*/
namespace kartik\tree;
use Yii;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
/**
* The tree management module for Yii Framework 2.0.
*
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @since 1.0
*/
class Module extends \kartik\base\Module
{
/**
* The module name for Krajee treeview
*/
const MODULE = 'treemanager';
/**
* Manage node action
*/
const NODE_MANAGE = 'manage';
/**
* Remove node action
*/
const NODE_REMOVE = 'remove';
/**
* Move node action
*/
const NODE_MOVE = 'move';
/**
* Save node action
*/
const NODE_SAVE = 'save';
/**
* Tree details form view - Section Part 1
*/
const VIEW_PART_1 = 1;
/**
* Tree details form view - Section Part 2
*/
const VIEW_PART_2 = 2;
/**
* Tree details form view - Section Part 3
*/
const VIEW_PART_3 = 3;
/**
* Tree details form view - Section Part 4
*/
const VIEW_PART_4 = 4;
/**
* Tree details form view - Section Part 5
*/
const VIEW_PART_5 = 5;
/**
* Session key variable name for storing the tree configuration encryption salt.
*/
const SALT_SESS_KEY = "krajeeTreeConfigSalt";
/**
* @var array the configuration of nested set attributes structure
*/
public $treeStructure = [];
/**
* @var array the configuration of additional data attributes for the tree
*/
public $dataStructure = [];
/**
* @var string the name to identify the nested set behavior name in the [[\kartik\tree\models\Tree]] model.
*/
public $treeBehaviorName = 'tree';
/**
* @var array the default configuration settings for the tree view widget
*/
public $treeViewSettings = [
'nodeView' => '@kvtree/views/_form',
'nodeAddlViews' => [
self::VIEW_PART_1 => '',
self::VIEW_PART_2 => '',
self::VIEW_PART_3 => '',
self::VIEW_PART_4 => '',
self::VIEW_PART_5 => '',
]
];
/**
* @var array the list of asset bundles that would be unset when rendering the node detail form via ajax
*/
public $unsetAjaxBundles = [
'yii\web\YiiAsset',
'yii\web\JqueryAsset',
'yii\widgets\ActiveFormAsset',
'yii\validators\ValidationAsset'
];
/**
* @var string a random salt that will be used to generate a hash signature for tree configuration. If not set, this
* will be generated using [[\yii\base\Security::generateRandomKey()]] to generate a random key. The randomly
* generated salt in the second case will be stored in a session variable identified by [[SALT_SESS_KEY]].
*/
public $treeEncryptSalt;
/**
* @inheritdoc
*/
public function init()
{
$this->_msgCat = 'kvtree';
parent::init();
$app = Yii::$app;
if ($app->has('session') && !isset($this->treeEncryptSalt)) {
$session = $app->session;
if (!$session->get(self::SALT_SESS_KEY)) {
$session->set(self::SALT_SESS_KEY, $app->security->generateRandomKey());
}
$this->treeEncryptSalt = $session->get(self::SALT_SESS_KEY);
} else {
$this->treeEncryptSalt = '<$0ME_R@ND0M_$@LT>';
}
$this->treeStructure += [
'treeAttribute' => 'root',
'leftAttribute' => 'lft',
'rightAttribute' => 'rgt',
'depthAttribute' => 'lvl',
];
$this->dataStructure += [
'keyAttribute' => 'id',
'nameAttribute' => 'name',
'iconAttribute' => 'icon',
'iconTypeAttribute' => 'icon_type'
];
$nodeActions = ArrayHelper::getValue($this->treeViewSettings, 'nodeActions', []);
$nodeActions += [
self::NODE_MANAGE => Url::to(['/treemanager/node/manage']),
self::NODE_SAVE => Url::to(['/treemanager/node/save']),
self::NODE_REMOVE => Url::to(['/treemanager/node/remove']),
self::NODE_MOVE => Url::to(['/treemanager/node/move']),
];
$this->treeViewSettings['nodeActions'] = $nodeActions;
}
}
This diff is collapsed.
<?php
/**
* Art-ER Attrattività, ricerca e territorio dell’Emilia-Romagna
* OPEN 2.0
*
* @package Open20Package
* @category CategoryName
* @author Elite Division S.r.l.
*/
/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2017
* @package yii2-tree-manager
* @version 1.0.8
*/
namespace kartik\tree;
use kartik\base\AssetBundle;
/**
* Asset bundle for TreeView widget.
*
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @since 1.0
*/
class TreeViewAsset extends AssetBundle
{
/**
* @inheritdoc
*/
public $depends = [
'yii\web\JqueryAsset',
'yii\bootstrap\BootstrapAsset',
'yii\widgets\ActiveFormAsset',
'yii\validators\ValidationAsset',
];
/**
* @inheritdoc
*/
public function init()
{
$this->setSourcePath(__DIR__ . '/assets');
$this->setupAssets('js', ['js/kv-tree']);
$this->setupAssets('css', ['css/kv-tree']);
parent::init();
}
}
<?php
/**
* Art-ER Attrattività, ricerca e territorio dell’Emilia-Romagna
* OPEN 2.0
*
* @package Open20Package
* @category CategoryName
* @author Elite Division S.r.l.
*/
/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2017
* @package yii2-tree-manager
* @version 1.0.8
*/
namespace kartik\tree;
use Yii;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use yii\helpers\Json;
use yii\base\Model;
use yii\base\InvalidConfigException;
use yii\web\View;
/**
* An input widget that extends [[TreeView]], and allows one to select records from the tree.
*
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @since 1.0
*/
class TreeViewInput extends TreeView
{
/**
* Caret rendered for the dropdown toggle
*/
const CARET = '<div class="kv-carets"><span class="caret kv-dn"></span><span class="caret kv-up"></span></div>';
/**
* @var Model the data model that this widget is associated with.
*/
public $model;
/**
* @var string the model attribute that this widget is associated with.
*/
public $attribute;
/**
* @var string the input name. This must be set if [[model]] and [[attribute]] are not set.
*/
public $name;
/**
* @var string the input value.
*/
public $value;
/**
* @var boolean whether to show the input as a dropdown select. If set to `false`, it will display directly the tree
* view selector widget. Defaults to `true`. The `BootstrapPluginAsset` will automatically be loaded if this is
* set to `true`. Defaults to `true`.
*/
public $asDropdown = true;
/**
* @var boolean whether to autoclose the dropdown on input selection when `asDropdown` is true. Defaults to `true`.
*/
public $autoCloseOnSelect = true;
/**
* @var boolean whether to show the toolbar in the footer. Defaults to `false`.
*/
public $showToolbar = false;
/**
* @var array the configuration of the tree view dropdown. The following configuration options are available:
* - `input`: _array_, the HTML attributes for the dropdown input container which displays the selected tree items.
* The following special options are available:
* - `placeholder`: string, defaults to `Select...`
* - `dropdown`: _array_, the HTML attributes for the dropdown tree view menu.
* - `options`: _array_, the HTML attributes for the wrapper container
* - `caret`: _string_, the markup for rendering the dropdown indicator for up and down. Defaults to [[CARET]].
*/
public $dropdownConfig = [];
/**
* @var array the HTML attributes for the input that will store the selected nodes for the widget
*/
public $options = ['class' => 'form-control hide'];
/**
* @var string the placeholder for the dropdown input
*/
private $_placeholder;
/**
* @var boolean whether the input is disabled
*/
private $_disabled;
/**
* @inheritdoc
*/
protected function initTreeView()
{
if (!$this->hasModel() && $this->name === null) {
throw new InvalidConfigException("Either 'name', or 'model' and 'attribute' properties must be specified.");
}
$this->showCheckbox = true;
$css = 'kv-tree-input-widget';
if (!$this->showToolbar) {
$css .= ' kv-tree-nofooter';
}
Html::addCssClass($this->treeOptions, $css);
parent::initTreeView();
$this->_hasBootstrap = $this->showTooltips || $this->asDropdown;
}
/**
* @inheritdoc
*/
public function run()
{
if ($this->hasModel()) {
$this->value = Html::getAttributeValue($this->model, $this->attribute);
}
$this->_disabled = ArrayHelper::getValue($this->options, 'disabled', false);
if ($this->asDropdown) {
$this->initDropdown();
}
$this->registerInputAssets();
parent::run();
}
/**
* Initialize tree dropdown menu settings and options
*/
protected function initDropdown()
{
$config = $this->dropdownConfig;
$input = ArrayHelper::getValue($config, 'input', []);
$dropdown = ArrayHelper::getValue($config, 'dropdown', []);
$options = ArrayHelper::getValue($config, 'options', []);
$css = ['form-control', 'dropdown-toggle', 'kv-tree-input'];
if ($this->_disabled) {
$css[] = 'disabled';
}
Html::addCssClass($input, $css);
Html::addCssClass($dropdown, ['dropdown-menu', 'kv-tree-dropdown']);
Html::addCssClass($options, ['dropdown', 'kv-tree-dropdown-container']);
$id = $this->options['id'] . '-tree-input';
$this->_placeholder = ArrayHelper::remove($input, 'placeholder', Yii::t('kvtree', 'Select...'));
$this->_placeholder = Html::tag('span', $this->_placeholder, ['class' => 'kv-placeholder']);
$config['dropdown'] = array_replace_recursive([
'id' => $id . '-menu',
'role' => 'menu',
'aria-labelledby' => $id,
], $dropdown);
$config['input'] = array_replace_recursive([
'id' => $id,
'tabindex' => -1,
'data-toggle' => 'dropdown',
'aria-haspopup' => 'true',
'aria-expanded' => 'false',
], $input);
if (empty($config['caret'])) {
$config['caret'] = self::CARET;
}
$config['options'] = $options;
$this->dropdownConfig = $config;
}
/**
* @inheritdoc
*/
public function renderWidget()
{
if (!$this->showToolbar) {
$this->wrapperTemplate = strtr($this->wrapperTemplate, ['{footer}' => '']);
}
$content = strtr($this->renderWrapper(), [
'{heading}' => $this->renderHeading(),
'{search}' => $this->renderSearch(),
'{toolbar}' => $this->renderToolbar(),
]) . "\n" .
$this->getInput();
if ($this->asDropdown) {
return $this->renderDropdown($content);
}
return $content;
}
/**
* Generates the dropdown tree menu
*
* @param string $content the content to be embedded in the dropdown menu
*
* @return string
*/
protected function renderDropdown($content)
{
$config = $this->dropdownConfig;
$input = Html::tag('div', $config['caret'] . $this->_placeholder, $config['input']);
$dropdown = Html::tag('div', $content, $config['dropdown']);
return Html::tag('div', $input . $dropdown, $config['options']);
}
/**
* Generates the hidden input for storage
*
* @return string
*/
public function getInput()
{
if ($this->hasModel()) {
return Html::activeHiddenInput($this->model, $this->attribute, $this->options);
}
return Html::hiddenInput($this->name, $this->value, $this->options);
}
/**
* Renders the markup for the button actions toolbar
*
* @return string
*/
public function renderToolbar()
{
if (!$this->showToolbar) {
return '';
}
unset($this->toolbar[self::BTN_CREATE], $this->toolbar[self::BTN_CREATE_ROOT], $this->toolbar[self::BTN_REMOVE]);
return parent::renderToolbar();
}
/**
* @return boolean whether this widget is associated with a data model.
*/
protected function hasModel()
{
return $this->model instanceof Model && $this->attribute !== null;
}
/**
* Registers assets for TreeViewInput
*/
public function registerInputAssets()
{
if (!$this->asDropdown) {
return;
}
$view = $this->getView();
TreeViewInputAsset::register($view);
$id = $this->options['id'];
$name = 'treeinput';
$opts = Json::encode([
'treeId' => $this->treeOptions['id'],
'inputId' => $this->dropdownConfig['input']['id'],
'dropdownId' => $this->dropdownConfig['dropdown']['id'],
'placeholder' => $this->_placeholder,
'value' => empty($this->value) ? '' : $this->value,
'caret' => $this->dropdownConfig['caret'],
'autoCloseOnSelect' => $this->autoCloseOnSelect
]);
$var = $name . '_' . hash('crc32', $opts);
$this->options['data-krajee-' . $name] = $var;
$view->registerJs("var {$var}={$opts};", View::POS_HEAD);
$view->registerJs("jQuery('#{$id}').{$name}({$var});");
}
}
<?php
/**
* Art-ER Attrattività, ricerca e territorio dell’Emilia-Romagna
* OPEN 2.0
*
* @package Open20Package
* @category CategoryName
* @author Elite Division S.r.l.
*/
/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2017
* @package yii2-tree-manager
* @version 1.0.8
*/
namespace kartik\tree;
use kartik\base\AssetBundle;
/**
* Asset bundle for TreeViewInput widget.
*
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @since 1.0
*/
class TreeViewInputAsset extends AssetBundle
{
/**
* @inheritdoc
*/
public $depends = [
'kartik\tree\TreeViewAsset'
];
/**
* @inheritdoc
*/
public function init()
{
$this->setSourcePath(__DIR__ . '/assets');
$this->setupAssets('css', ['css/kv-tree-input']);
$this->setupAssets('js', ['js/kv-tree-input']);
parent::init();
}
}
/*!
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2017
* @package yii2-tree-manager
* @version 1.0.8
*
* Tree View Input Widget Style Sheet
*
* Author: Kartik Visweswaran
* Copyright: 2015 - 2017, Kartik Visweswaran, Krajee.com
* For more JQuery plugins visit http://plugins.krajee.com
* For more Yii related demos visit http://demos.krajee.com
*/
.kv-tree-input-widget .kv-focussed {
background-color: #fff;
}
.kv-tree-dropdown-container {
cursor: pointer;
}
.kv-tree-input-widget .kv-disabled > .kv-tree-list .kv-node-checkbox, .kv-tree-input-widget .kv-disabled > .kv-tree-list .kv-node-detail {
cursor: not-allowed;
}
.kv-tree-dropdown {
padding: 0;
}
.kv-tree-dropdown-container .form-control .caret {
float: right;
margin-top: 8px;
}
.kv-placeholder {
color: #999;
}
.kv-tree-input, .kv-tree-input.form-control {
height: auto;
}
.kv-tree-input.disabled {
cursor: not-allowed;
background-color: #eee;
}
.kv-tree-input.has-multi {
padding: 3px 8px 5px 8px;
}
.kv-tree-input-values {
margin: 0;
padding: 0;
overflow: hidden;
white-space: nowrap;
}
.kv-tree-input-values li {
float: left;
list-style: none;
padding: 2px 5px;
margin: 3px 3px 0 0;
position: relative;
background: #f9f9f9;
border: 1px solid #ddd;
border-radius: 3px;
color: #555;
font-size: 12px;
}
.kv-tree-input-values li:focus, .kv-tree-input-values li:hover {
background: #ebebeb;
border-color: #adadad;
color: #333;
}
.kv-tree-dropdown {
width: 100%;
}
.kv-tree-dropdown .kv-header-container,
.kv-tree-dropdown .kv-tree-wrapper.form-control {
border: none;
}
.kv-single-select .kv-root-node-checkbox, .kv-single-select .kv-node-checkbox {
display: none;
}
.kv-single-select .kv-node-indicators {
padding-right: 2px;
margin-right: 2px;
}
.has-multi .kv-tree-input-values {
margin-right: 20px;
}
.kv-carets {
float: right;