FEATURE: *in progress* working on menu widgets
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
return [
|
||||
'name' => 'Menu',
|
||||
'description' => 'User defined menu'
|
||||
'widgetName' => '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