Commit ebd4adfc authored by Tobias Munk's avatar Tobias Munk

updated UI

parent 353ca2ff
<?php
/**
* @link http://www.diemeisterei.de/
* @copyright Copyright (c) 2016 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace hrzg\widget\assets;
use yii\web\AssetBundle;
class WidgetAsset extends AssetBundle
{
public $sourcePath = __DIR__.'/web';
public $css = [
'widgets.less'
];
}
\ No newline at end of file
.hrzg-widget-widget-container {
min-height: 32px;
&:hover {
outline: 2px dashed #ccc;
}
.hrzg-widget-widget-controls {
opacity: 0.3;
position: absolute;
&:hover {
opacity: 1;
}
}
.hrzg-widget-container-controls {
opacity: 0.3;
&:hover {
opacity: 1;
}
}
.hrzg-widget-widget {
&:hover {
outline: 4px solid gray;
}
}
}
......@@ -10,11 +10,13 @@
namespace hrzg\widget\widgets;
use hrzg\widget\models\crud\WidgetContent;
use hrzg\widget\assets\WidgetAsset;
use rmrevin\yii\fontawesome\AssetBundle;
use rmrevin\yii\fontawesome\component\Icon;
use rmrevin\yii\fontawesome\FA;
use yii\base\Event;
use yii\base\Widget;
use yii\helpers\Html;
use yii\helpers\Json;
class WidgetContainer extends Widget
......@@ -22,6 +24,9 @@ class WidgetContainer extends Widget
public function init()
{
\Yii::$app->trigger('registerMenuItems', new Event(['sender' => $this]));
if (\Yii::$app->user->can('widgets')) {
WidgetAsset::register(\Yii::$app->view);
}
}
public function run()
......@@ -47,7 +52,12 @@ class WidgetContainer extends Widget
private function renderWidgets()
{
$html = '';
$html = Html::beginTag('div',['class'=>'hrzg-widget-widget-container']);
if (\Yii::$app->user->can('widgets')) {
$html .= $this->generateContainerControls();
}
foreach ($this->queryWidgets() as $widget) {
$properties = Json::decode($widget->default_properties_json);
$class = \Yii::createObject($widget->template->php_class);
......@@ -56,10 +66,14 @@ class WidgetContainer extends Widget
if ($properties) {
$class->setProperties($properties);
}
$html .= Html::beginTag('div',['class'=>'hrzg-widget-widget']);
if (\Yii::$app->user->can('widgets')) {
$html .= $this->generateWidgetControls($widget);
}
$html .= $class->run();
$html .= Html::endTag('div');
}
$html .= Html::endTag('div');
return $html;
}
......@@ -67,6 +81,26 @@ class WidgetContainer extends Widget
{
}
private function generateContainerControls(){
$html = Html::beginTag('div',['class'=>'hrzg-widget-container-controls pull-right']);
$html .= Html::a('Add', ['/widgets/crud/widget/create',
'WidgetContent' => [
'route' => \Yii::$app->requestedRoute,
'container_id' => $this->id,
'request_param' => \Yii::$app->request->get('id'),
'access_domain' => \Yii::$app->language,
]], ['class'=>'btn btn-default']);
$html .= Html::endTag('div');
return $html;
}
private function generateWidgetControls($widget){
$html = Html::beginTag('div',['class'=>'hrzg-widget-widget-controls']);
$html .= Html::a('Edit', ['/widgets/crud/widget/update', 'id'=>$widget->id], ['class'=>'btn btn-default']);
$html .= Html::endTag('div');
return $html;
}
public function getMenuItems()
{
// todo, register FA-asset from asset bundle
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment