FEATURE: *in progress* working on menu widgets
This commit is contained in:
@@ -3,5 +3,13 @@ namespace App\Widgets\Contracts;
|
|||||||
|
|
||||||
interface MenuExtensionHandler {
|
interface MenuExtensionHandler {
|
||||||
|
|
||||||
public static function getPossibleValues();
|
public function getName();
|
||||||
|
public function getDescription();
|
||||||
|
public function getId();
|
||||||
|
|
||||||
|
public function getPossibleValues();
|
||||||
|
|
||||||
|
public function getFormExtensionTemplate();
|
||||||
|
|
||||||
|
public function save();
|
||||||
}
|
}
|
||||||
@@ -4,8 +4,33 @@ namespace App\Widgets\Menu\Extensions;
|
|||||||
use App\Widgets\Contracts\MenuExtensionHandler;
|
use App\Widgets\Contracts\MenuExtensionHandler;
|
||||||
|
|
||||||
class URL implements MenuExtensionHandler {
|
class URL implements MenuExtensionHandler {
|
||||||
public static function getPossibleValues()
|
public function getPossibleValues()
|
||||||
{
|
{
|
||||||
// TODO: Implement getPossibleValues() method.
|
return '*';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return 'url';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return trans('widgets/menu.extensionURL');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription()
|
||||||
|
{
|
||||||
|
return trans('widgets/menu.extensionURLDescription');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFormExtensionTemplate()
|
||||||
|
{
|
||||||
|
return 'admin.widgets.menu.extensions.url';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
// TODO: Implement save() method.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,9 +3,9 @@ namespace App\Widgets\Menu;
|
|||||||
|
|
||||||
use App\Http\Requests\Request;
|
use App\Http\Requests\Request;
|
||||||
use App\Widgets\Contracts\WidgetRenderer;
|
use App\Widgets\Contracts\WidgetRenderer;
|
||||||
use App\Widgets\Widget;
|
use App\Widgets\NonInstallableWidget;
|
||||||
|
|
||||||
class Menu extends Widget
|
class Menu extends NonInstallableWidget
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Name getter
|
* Name getter
|
||||||
@@ -14,7 +14,7 @@ class Menu extends Widget
|
|||||||
*/
|
*/
|
||||||
public static function getName()
|
public static function getName()
|
||||||
{
|
{
|
||||||
return 'widgets/menu.name';
|
return 'widgets/menu.widgetName';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,7 +24,7 @@ class Menu extends Widget
|
|||||||
*/
|
*/
|
||||||
public static function getDescription()
|
public static function getDescription()
|
||||||
{
|
{
|
||||||
return 'widgets/menu.description';
|
return 'widgets/menu.widgetDescription';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,24 +45,6 @@ class Menu extends Widget
|
|||||||
*/
|
*/
|
||||||
public static function save(\App\Models\Widget $widget, Request $request)
|
public static function save(\App\Models\Widget $widget, Request $request)
|
||||||
{
|
{
|
||||||
// TODO: Implement save() method.
|
return $widget;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function for installing given widget
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function install()
|
|
||||||
{
|
|
||||||
// TODO: Implement install() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function for uninstalling widget
|
|
||||||
*/
|
|
||||||
public static function uninstall()
|
|
||||||
{
|
|
||||||
// TODO: Implement uninstall() method.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ namespace App\Widgets\Menu\Presenters;
|
|||||||
use App\Models\Widget;
|
use App\Models\Widget;
|
||||||
use App\Models\WidgetType;
|
use App\Models\WidgetType;
|
||||||
use App\Widgets\Contracts\WidgetRenderer;
|
use App\Widgets\Contracts\WidgetRenderer;
|
||||||
|
use Illuminate\Support\Facades\App;
|
||||||
|
|
||||||
class Menu implements WidgetRenderer
|
class Menu implements WidgetRenderer
|
||||||
{
|
{
|
||||||
@@ -18,7 +19,7 @@ class Menu implements WidgetRenderer
|
|||||||
*/
|
*/
|
||||||
public static function render($settings)
|
public static function render($settings)
|
||||||
{
|
{
|
||||||
// TODO: Implement render() method.
|
return json_encode($settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,7 +31,16 @@ class Menu implements WidgetRenderer
|
|||||||
*/
|
*/
|
||||||
public static function renderAddForm(WidgetType $type)
|
public static function renderAddForm(WidgetType $type)
|
||||||
{
|
{
|
||||||
// TODO: Implement renderAddForm() method.
|
$extensions = App::make('registerMenuExtension')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$widget = new Widget();
|
||||||
|
|
||||||
|
return view('admin.widgets.menu.new', [
|
||||||
|
'type' => $type,
|
||||||
|
'widget' => $widget,
|
||||||
|
'extensions' => $extensions
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,6 +52,9 @@ class Menu implements WidgetRenderer
|
|||||||
*/
|
*/
|
||||||
public static function renderEditForm(Widget $widget)
|
public static function renderEditForm(Widget $widget)
|
||||||
{
|
{
|
||||||
// TODO: Implement renderEditForm() method.
|
$extensions = App::make('registerMenuExtension')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
return view('admin.widgets.menu.edit', ['widget' => $widget]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
return [
|
return [
|
||||||
'name' => 'Menu',
|
'widgetName' => 'Menu',
|
||||||
'description' => 'User defined menu'
|
'widgetDescription' => 'User defined menu'
|
||||||
];
|
];
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title></title>
|
||||||
|
<style>
|
||||||
|
label { display: inline-block; margin-right: 10px; }
|
||||||
|
|
||||||
|
a { display: inline-block; margin-right: 10px; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="zoznampoloziek">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="jednapolozka" id="hlavnanovapolozka">
|
||||||
|
<input type="text" class="polozkamenu" data-id="0" data-parent="0">
|
||||||
|
<a href="javascript:void(0);" onclick="pridajPolozku(this.parentNode.getElementsByClassName('polozkamenu')[0])">pridaj
|
||||||
|
polozku</a>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
<a href="javascript:console.info(model)">printni model do conosoly</a>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var model = {};
|
||||||
|
var counter = 0;
|
||||||
|
var zoznam = document.getElementById ('zoznampoloziek');
|
||||||
|
var hlavnapolozka = document.getElementById ('hlavnanovapolozka');
|
||||||
|
|
||||||
|
function pridajPolozku(element) {
|
||||||
|
if (element.value == '') {
|
||||||
|
alert ('prazdnu polozku nepridas');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
counter++;
|
||||||
|
element.setAttribute ('data-id', counter);
|
||||||
|
model[element.getAttribute ('data-id')] = {
|
||||||
|
'name': element.value,
|
||||||
|
'parent': element.getAttribute ('data-parent'),
|
||||||
|
};
|
||||||
|
|
||||||
|
element.value = '';
|
||||||
|
|
||||||
|
aktualizujZoznam ();
|
||||||
|
}
|
||||||
|
function zmazat(element) {
|
||||||
|
var polozka = element.parentNode.getElementsByTagName ('LABEL')[0];
|
||||||
|
if (confirm ('naozaj zmazat id: ' + polozka.getAttribute ('data-id') + ' : "' + polozka.textContent + '" ?')) {
|
||||||
|
delete model[polozka.getAttribute ('data-id')];
|
||||||
|
aktualizujZoznam ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function novePridajPolozku(element) {
|
||||||
|
var polozka = element.parentNode.getElementsByTagName ('LABEL')[0],
|
||||||
|
subpolozkainput = hlavnapolozka.cloneNode (true),
|
||||||
|
subinput = subpolozkainput.getElementsByClassName ('polozkamenu')[0];
|
||||||
|
|
||||||
|
counter++;
|
||||||
|
subpolozkainput.removeAttribute ('id');
|
||||||
|
subinput.setAttribute ('data-id', counter.toString ());
|
||||||
|
subinput.setAttribute ('data-parent', polozka.getAttribute ('data-id'));
|
||||||
|
|
||||||
|
element.parentNode.appendChild (subpolozkainput);
|
||||||
|
}
|
||||||
|
|
||||||
|
function novyDomPrePolozky(id, parent, name) {
|
||||||
|
var div = document.createElement ('div'),
|
||||||
|
popis = document.createElement ('label'),
|
||||||
|
zmaz = document.createElement ('a'),
|
||||||
|
sub = document.createElement ('a');
|
||||||
|
|
||||||
|
popis.textContent = name;
|
||||||
|
popis.setAttribute ('data-id', id);
|
||||||
|
popis.setAttribute ('data-parent', parent);
|
||||||
|
|
||||||
|
zmaz.textContent = 'zmaz';
|
||||||
|
zmaz.href = 'javascript:void(0);';
|
||||||
|
zmaz.setAttribute ('onclick', 'zmazat(this);');
|
||||||
|
|
||||||
|
sub.textContent = 'pridaj sub';
|
||||||
|
sub.href = 'javascript:void(0)';
|
||||||
|
sub.setAttribute ('onclick', 'novePridajPolozku(this);');
|
||||||
|
div.appendChild (popis);
|
||||||
|
div.appendChild (zmaz);
|
||||||
|
div.appendChild (sub);
|
||||||
|
|
||||||
|
return div;
|
||||||
|
}
|
||||||
|
function aktualizujZoznam() {
|
||||||
|
var key,
|
||||||
|
novydom,
|
||||||
|
zoznamitems = zoznam.childNodes,
|
||||||
|
zoznamitems_i = zoznamitems.length;
|
||||||
|
while (zoznamitems_i--) {
|
||||||
|
zoznam.removeChild (zoznamitems[zoznamitems_i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (key in model) {
|
||||||
|
if (model.hasOwnProperty (key)) {
|
||||||
|
novydom = novyDomPrePolozky (key, model[key].parent, model[key].name);
|
||||||
|
if (model[key].parent == 0) {
|
||||||
|
zoznam.appendChild (novydom);
|
||||||
|
} else {
|
||||||
|
zoznam.insertBefore (novydom, zoznam.querySelector ('[data-id="' + model[key].parent + '"]').parentNode.nextSibling);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
zoznam.appendChild (document.createElement ('div'));
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
@extends('admin.layout')
|
||||||
|
|
||||||
|
@section('pageName', @trans('widgets/menu.edit', ['name' => $widget->name]))
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<h1>@lang('widgets/menu.edit', ['name' => $widget->name])</h1>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="column large-8">
|
||||||
|
@include('admin.widgets.menu.form', ['formAction' => route('widgets.postEdit', ['id' => $widget->id])])
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="column large-4">
|
||||||
|
<h3>@lang('widgets/menu.preview')</h3>
|
||||||
|
|
||||||
|
@widgetPreview($widget)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@stop
|
||||||
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<label>
|
||||||
|
@lang('widgets.url')
|
||||||
|
|
||||||
|
<input type="text" name="url" id="urlField"/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
@lang('widgets.anchor')
|
||||||
|
|
||||||
|
<input type="text" name="anchor" id="anchorField"/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
@lang('widgets.openInNewWindow')
|
||||||
|
|
||||||
|
<input type="checkbox" checked="checked" name="openInNewWindow" id="openInNewWindowField"/>
|
||||||
|
</label>
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
@if (!isset($hideMessages))
|
||||||
|
@if (session('success'))
|
||||||
|
<div class="callout success">
|
||||||
|
{{ session('success') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@if (session('error'))
|
||||||
|
<div class="callout alert">
|
||||||
|
{{ session('error') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<form action="{{$formAction}}" method="POST">
|
||||||
|
{!! csrf_field() !!}
|
||||||
|
<label>
|
||||||
|
@lang('widgets/menu.name')
|
||||||
|
|
||||||
|
<input type="text" name="name" value="{{old("name", $widget->name)}}" placeholder="@lang('widgets/menu.name')" />
|
||||||
|
|
||||||
|
@if (isset($errors) && $errors->has('name'))
|
||||||
|
<div class="callout alert">
|
||||||
|
{{ $errors->first('name') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
@lang('widgets/menu.description')
|
||||||
|
|
||||||
|
<input type="text" name="description" placeholder="@lang('widgets/menu.description')"
|
||||||
|
value="{{old("description", $widget->description)}}" />
|
||||||
|
|
||||||
|
@if (isset($errors) && $errors->has('description'))
|
||||||
|
<div class="callout alert">
|
||||||
|
{{ $errors->first('description') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<textarea name="moduleSettings" id="menuConfig">{}</textarea>
|
||||||
|
|
||||||
|
<button type="submit" class="button success">@lang('widgets/menu.createNew')</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
<ul class="tabs" data-tabs id="createMenu">
|
||||||
|
@foreach($extensions as $extension)
|
||||||
|
<li class="tabs-title @if($extension->getId() == reset($extensions)->getId()) is-active @endif">
|
||||||
|
<a href="#{{$extension->getId()}}" @if($extension->getId() == reset($extensions)->getId()) aria-selected="true" @endif>
|
||||||
|
{{trans($extension->getName())}}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
@endforeach
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div class="tabs-content" data-tabs-content="createMenu">
|
||||||
|
@foreach($extensions as $extension)
|
||||||
|
<div class="tabs-panel @if($extension->getId() == reset($extensions)->getId()) is-active @endif" id="{{$extension->getId()}}">
|
||||||
|
<h4>{{$extension->getName()}}</h4>
|
||||||
|
<p>{{$extension->getDescription()}}</p>
|
||||||
|
|
||||||
|
<form action="#" id="menuItem-{{$extension->getId()}}" class="menuItems" data-extension="{{$extension->getId()}}">
|
||||||
|
@include($extension->getFormExtensionTemplate())
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<button class="button" type="submit"><i class="fa fa-plus"></i></button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section('javascripts')
|
||||||
|
<script type="text/javascript">
|
||||||
|
$('.menuItems').submit(function () {
|
||||||
|
var id = $(this).data('extension');
|
||||||
|
var existingSettings = {};
|
||||||
|
|
||||||
|
try {
|
||||||
|
existingSettings = JSON.parse ($ ('#menuConfig').val ());
|
||||||
|
} catch (err) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
$(this).find(':input').each(function () {
|
||||||
|
var name = $(this).attr('name');
|
||||||
|
var value = $(this).val();
|
||||||
|
|
||||||
|
alert('name: '+name+", value: "+value);
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@stop
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
@extends('admin.layout')
|
||||||
|
|
||||||
|
@section('pageName', @trans('widgets/menu.new'))
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<h1>@lang('widgets/menu.new')</h1>
|
||||||
|
|
||||||
|
@include('admin.widgets.menu.form', ['formAction' => route('widgets.postNew', ['type' => $type])])
|
||||||
|
@stop
|
||||||
|
|
||||||
Reference in New Issue
Block a user