Exemplo n.º 1
0
use gilek\gtreetable\assets\UrlAsset;
use gilek\gtreetable\assets\BrowserAsset;
use yii\jui\JuiAsset;
use yii\helpers\Url;
use yii\web\JsExpression;
use yii\helpers\ArrayHelper;
UrlAsset::register($this);
if (isset($title)) {
    $this->title = $title;
}
if (!isset($routes)) {
    $routes = [];
}
$controller = !isset($controller) ? '' : $controller . '/';
$routes = array_merge(['nodeChildren' => $controller . 'nodeChildren', 'nodeCreate' => $controller . 'nodeCreate', 'nodeUpdate' => $controller . 'nodeUpdate', 'nodeDelete' => $controller . 'nodeDelete', 'nodeMove' => $controller . 'nodeMove'], $routes);
$defaultOptions = ['source' => new JsExpression("function (id) {\n        return {\n            type: 'GET',\n            url: URI('" . Url::to([$routes['nodeChildren']]) . "').addSearch({'id':id}).toString(),\n            dataType: 'json',\n            error: function(XMLHttpRequest) {\n                alert(XMLHttpRequest.status+': '+XMLHttpRequest.responseText);\n            }\n        }; \n    }"), 'onSave' => new JsExpression("function (oNode) {\n        return {\n            type: 'POST',\n            url: !oNode.isSaved() ? '" . Url::to([$routes['nodeCreate']]) . "' : URI('" . Url::to([$routes['nodeUpdate']]) . "').addSearch({'id':oNode.getId()}).toString(),\n            data: {\n                parent: oNode.getParent(),\n                name: oNode.getName(),\n                position: oNode.getInsertPosition(),\n                related: oNode.getRelatedNodeId()\n            },\n            dataType: 'json',\n            error: function(XMLHttpRequest) {\n                alert(XMLHttpRequest.status+': '+XMLHttpRequest.responseText);\n            }\n        };        \n    }"), 'onDelete' => new JsExpression("function(oNode) {\n        return {\n            type: 'POST',\n            url: URI('" . Url::to([$routes['nodeDelete']]) . "').addSearch({'id':oNode.getId()}).toString(),\n            dataType: 'json',\n            error: function(XMLHttpRequest) {\n                alert(XMLHttpRequest.status+': '+XMLHttpRequest.responseText);\n            }\n        };        \n    }"), 'onMove' => new JsExpression("function(oSource, oDestination, position) {\n        return {\n            type: 'POST',\n            url: URI('" . Url::to([$routes['nodeMove']]) . "').addSearch({'id':oSource.getId()}).toString(),\n            data: {\n                related: oDestination.getId(),\n                position: position\n            },\n            dataType: 'json',\n            error: function(XMLHttpRequest) {\n                alert(XMLHttpRequest.status+': '+XMLHttpRequest.responseText);\n            }\n        };        \n    }"), 'language' => Yii::$app->language];
$options = !isset($options) ? $defaultOptions : ArrayHelper::merge($defaultOptions, $options);
if (array_key_exists('draggable', $options) && $options['draggable'] === true) {
    BrowserAsset::register($this);
    JuiAsset::register($this);
}
$params = [];
$reflector = new ReflectionClass(Widget::className());
foreach ($reflector->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
    $name = $property->name;
    if (isset(${$name})) {
        $params[$name] = ${$name};
    }
}
echo Widget::widget($params);
Exemplo n.º 2
0
<?php

use gilek\gtreetable\Widget;
use gilek\gtreetable\assets\UrlAsset;
use gilek\gtreetable\assets\BrowserAsset;
use yii\jui\JuiAsset;
use yii\helpers\Url;
use yii\web\JsExpression;
use yii\helpers\ArrayHelper;
UrlAsset::register($this);
if (isset($title)) {
    $this->title = $title;
}
if (!isset($routes)) {
    $routes = [];
}
$controller = !isset($controller) ? '' : $controller . '/';
$routes = array_merge(['nodeChildren' => $controller . 'nodeChildren', 'nodeCreate' => $controller . 'nodeCreate', 'nodeUpdate' => $controller . 'nodeUpdate', 'nodeDelete' => $controller . 'nodeDelete', 'nodeMove' => $controller . 'nodeMove'], $routes);
$defaultOptions = ['source' => new JsExpression("function (id) {  \n        return URI('" . Url::to([$routes['nodeChildren']]) . "').addSearch({'id':id});\n    }"), 'onSave' => new JsExpression("function (oNode) {\n        return jQuery.ajax({\n            type: 'POST',\n            url: !oNode.isSaved() ? '" . Url::to([$routes['nodeCreate']]) . "' : URI('" . Url::to([$routes['nodeUpdate']]) . "').addSearch({'id':oNode.getId()}),\n            data: {\n                parent: oNode.getParent(),\n                name: oNode.getName(),\n                position: oNode.getInsertPosition(),\n                related: oNode.getRelatedNodeId()\n            },\n            dataType: 'json',\n            error: function(XMLHttpRequest) {\n                alert(XMLHttpRequest.status+': '+XMLHttpRequest.responseText);\n            }\n        });        \n    }"), 'onDelete' => new JsExpression("function(oNode) {\n        return jQuery.ajax({\n            type: 'POST',\n            url: URI('" . Url::to([$routes['nodeDelete']]) . "').addSearch({'id':oNode.getId()}),\n            dataType: 'json',\n            error: function(XMLHttpRequest) {\n                alert(XMLHttpRequest.status+': '+XMLHttpRequest.responseText);\n            }\n        });        \n    }"), 'onMove' => new JsExpression("function(oSource, oDestination, position) {\n        return jQuery.ajax({\n            type: 'POST',\n            url: URI('" . Url::to([$routes['nodeMove']]) . "').addSearch({'id':oSource.getId()}),\n            data: {\n                related: oDestination.getId(),\n                position: position\n            },\n            dataType: 'json',\n            error: function(XMLHttpRequest) {\n                alert(XMLHttpRequest.status+': '+XMLHttpRequest.responseText);\n            }\n        });        \n    }")];
$options = !isset($options) ? $defaultOptions : ArrayHelper::merge($defaultOptions, $options);
if (array_key_exists('draggable', $options) && $options['draggable'] === true) {
    BrowserAsset::register($this);
    JuiAsset::register($this);
}
echo Widget::widget(['options' => $options]);