Enabled adding new attributes to a DN

This commit is contained in:
Deon George 2023-09-02 20:50:54 +10:00
parent 6d900d0964
commit 652cdee034
22 changed files with 403 additions and 105 deletions

View File

@ -97,6 +97,7 @@ class Attribute
$this->name = $name; $this->name = $name;
$this->values = collect($values); $this->values = collect($values);
$this->lang_tags = collect(); $this->lang_tags = collect();
$this->required_by = collect();
// No need to load our schema for internal attributes // No need to load our schema for internal attributes
if (! $this->is_internal) if (! $this->is_internal)
@ -182,9 +183,10 @@ class Attribute
* Display the attribute value * Display the attribute value
* *
* @param bool $edit * @param bool $edit
* @param bool $blank
* @return View * @return View
*/ */
public function render(bool $edit=FALSE): View public function render(bool $edit=FALSE,bool $blank=FALSE): View
{ {
return view('components.attribute') return view('components.attribute')
->with('edit',$edit) ->with('edit',$edit)

View File

@ -18,10 +18,11 @@ final class JpegPhoto extends Binary
$this->internal = FALSE; $this->internal = FALSE;
} }
public function render(bool $edit=FALSE): View public function render(bool $edit=FALSE,bool $blank=FALSE): View
{ {
return view('components.attribute.binary.jpegphoto') return view('components.attribute.binary.jpegphoto')
->with('edit',$edit) ->with('edit',$edit)
->with('blank',$blank)
->with('o',$this) ->with('o',$this)
->with('f',new \finfo); ->with('f',new \finfo);
} }

View File

@ -13,7 +13,7 @@ abstract class Internal extends Attribute
{ {
protected bool $is_internal = TRUE; protected bool $is_internal = TRUE;
public function render(bool $edit=FALSE): View public function render(bool $edit=FALSE,bool $blank=FALSE): View
{ {
// @note Internal attributes cannot be edited // @note Internal attributes cannot be edited
return view('components.attribute.internal') return view('components.attribute.internal')

View File

@ -11,7 +11,7 @@ use App\Classes\LDAP\Attribute\Internal;
*/ */
final class Timestamp extends Internal final class Timestamp extends Internal
{ {
public function render(bool $edit=FALSE): View public function render(bool $edit=FALSE,bool $blank=FALSE): View
{ {
// @note Internal attributes cannot be edited // @note Internal attributes cannot be edited
return view('components.attribute.internal.timestamp') return view('components.attribute.internal.timestamp')

View File

@ -39,7 +39,7 @@ final class ObjectClass extends Attribute
return $this->structural->search($value) !== FALSE; return $this->structural->search($value) !== FALSE;
} }
public function render(bool $edit=FALSE): View public function render(bool $edit=FALSE,bool $blank=FALSE): View
{ {
return view('components.attribute.objectclass') return view('components.attribute.objectclass')
->with('edit',$edit) ->with('edit',$edit)

View File

@ -11,10 +11,11 @@ use App\Classes\LDAP\Attribute;
*/ */
final class Password extends Attribute final class Password extends Attribute
{ {
public function render(bool $edit=FALSE): View public function render(bool $edit=FALSE,bool $blank=FALSE): View
{ {
return view('components.attribute.password') return view('components.attribute.password')
->with('edit',$edit) ->with('edit',$edit)
->with('blank',$blank)
->with('o',$this); ->with('o',$this);
} }
} }

View File

@ -49,7 +49,7 @@ abstract class Schema extends Attribute
return Arr::get(($array ? $array->get($string) : []),$key); return Arr::get(($array ? $array->get($string) : []),$key);
} }
public function render(bool $edit=FALSE): View public function render(bool $edit=FALSE,bool $blank=FALSE): View
{ {
// @note Schema attributes cannot be edited // @note Schema attributes cannot be edited
return view('components.attribute.internal') return view('components.attribute.internal')

View File

@ -33,7 +33,7 @@ final class Mechanisms extends Schema
return parent::_get(config_path('ldap_supported_saslmechanisms.txt'),$string,$key); return parent::_get(config_path('ldap_supported_saslmechanisms.txt'),$string,$key);
} }
public function render(bool $edit=FALSE): View public function render(bool $edit=FALSE,bool $blank=FALSE): View
{ {
// @note Schema attributes cannot be edited // @note Schema attributes cannot be edited
return view('components.attribute.schema.mechanisms') return view('components.attribute.schema.mechanisms')

View File

@ -34,7 +34,7 @@ final class OID extends Schema
return parent::_get(config_path('ldap_supported_oids.txt'),$string,$key); return parent::_get(config_path('ldap_supported_oids.txt'),$string,$key);
} }
public function render(bool $edit=FALSE): View public function render(bool $edit=FALSE,bool $blank=FALSE): View
{ {
// @note Schema attributes cannot be edited // @note Schema attributes cannot be edited
return view('components.attribute.schema.oid') return view('components.attribute.schema.oid')

View File

@ -8,14 +8,16 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redirect;
use LdapRecord\Exceptions\InsufficientAccessException; use LdapRecord\Exceptions\InsufficientAccessException;
use LdapRecord\LdapRecordException; use LdapRecord\LdapRecordException;
use LdapRecord\Query\ObjectNotFoundException; use LdapRecord\Query\ObjectNotFoundException;
use App\Classes\LDAP\Server; use App\Classes\LDAP\{Attribute,Server};
use App\Exceptions\InvalidUsage; use App\Exceptions\InvalidUsage;
use App\Http\Requests\EntryRequest; use App\Http\Requests\EntryRequest;
use App\View\Components\AttributeType;
class HomeController extends Controller class HomeController extends Controller
{ {
@ -47,7 +49,20 @@ class HomeController extends Controller
->with('page_actions',$page_actions); ->with('page_actions',$page_actions);
} }
public function entry_update(EntryRequest $request) public function entry_newattr(string $id)
{
$x = new AttributeType(new Attribute($id,[]),TRUE);
return $x->render();
}
/**
* Show a confirmation to update a DN
*
* @param EntryRequest $request
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse
* @throws ObjectNotFoundException
*/
public function entry_pending_update(EntryRequest $request)
{ {
$dn = Crypt::decryptString($request->dn); $dn = Crypt::decryptString($request->dn);
@ -56,10 +71,60 @@ class HomeController extends Controller
foreach ($request->except(['_token','dn']) as $key => $value) foreach ($request->except(['_token','dn']) as $key => $value)
$o->{$key} = array_filter($value); $o->{$key} = array_filter($value);
Session::put('dn',$request->dn); if (! $o->getDirty())
return back()
->withInput()
->with('note',__('No attributes changed'));
$base = Server::baseDNs() ?: collect();
$bases = $base->transform(function($item) {
return [
'title'=>$item->getRdn(),
'item'=>$item->getDNSecure(),
'lazy'=>TRUE,
'icon'=>'fa-fw fas fa-sitemap',
'tooltip'=>$item->getDn(),
];
});
return view('frames.update')
->with('bases',$bases)
->with('dn',$dn)
->with('o',$o);
}
/**
* Update a DN entry
*
* @param EntryRequest $request
* @return \Illuminate\Http\RedirectResponse
* @throws ObjectNotFoundException
*/
public function entry_update(EntryRequest $request)
{
$base = Server::baseDNs() ?: collect();
$bases = $base->transform(function($item) {
return [
'title'=>$item->getRdn(),
'item'=>$item->getDNSecure(),
'lazy'=>TRUE,
'icon'=>'fa-fw fas fa-sitemap',
'tooltip'=>$item->getDn(),
];
});
$dn = Crypt::decryptString($request->dn);
$o = config('server')->fetch($dn);
foreach ($request->except(['_token','dn']) as $key => $value)
$o->{$key} = array_filter($value);
if (! $dirty=$o->getDirty()) if (! $dirty=$o->getDirty())
return back() return back()
->withInput()
->with('note',__('No attributes changed')); ->with('note',__('No attributes changed'));
try { try {
@ -70,7 +135,8 @@ class HomeController extends Controller
switch ($x=$e->getDetailedError()->getErrorCode()) { switch ($x=$e->getDetailedError()->getErrorCode()) {
case 50: case 50:
return back() return Redirect::to('/')
->withInput()
->withErrors(sprintf('%s: %s (%s)',__('LDAP Server Error Code'),$x,__($e->getDetailedError()->getErrorMessage()))); ->withErrors(sprintf('%s: %s (%s)',__('LDAP Server Error Code'),$x,__($e->getDetailedError()->getErrorMessage())));
default: default:
@ -82,7 +148,8 @@ class HomeController extends Controller
switch ($x=$e->getDetailedError()->getErrorCode()) { switch ($x=$e->getDetailedError()->getErrorCode()) {
case 8: case 8:
return back() return Redirect::to('/')
->withInput()
->withErrors(sprintf('%s: %s (%s)',__('LDAP Server Error Code'),$x,__($e->getDetailedError()->getErrorMessage()))); ->withErrors(sprintf('%s: %s (%s)',__('LDAP Server Error Code'),$x,__($e->getDetailedError()->getErrorMessage())));
default: default:
@ -90,7 +157,8 @@ class HomeController extends Controller
} }
} }
return back() return Redirect::to('/')
->withInput()
->with('success',__('Entry updated')) ->with('success',__('Entry updated'))
->with('updated',$dirty); ->with('updated',$dirty);
} }

View File

@ -10,16 +10,18 @@ class Attribute extends Component
{ {
public LDAPAttribute $o; public LDAPAttribute $o;
public bool $edit; public bool $edit;
public bool $new;
/** /**
* Create a new component instance. * Create a new component instance.
* *
* @return void * @return void
*/ */
public function __construct(bool $edit,LDAPAttribute $o) public function __construct(bool $edit,LDAPAttribute $o,bool $new=FALSE)
{ {
$this->edit = $edit; $this->edit = $edit;
$this->o = $o; $this->o = $o;
$this->new = $new;
} }
/** /**
@ -29,6 +31,6 @@ class Attribute extends Component
*/ */
public function render() public function render()
{ {
return $this->o->render($this->edit); return $this->o->render($this->edit,$this->new);
} }
} }

View File

@ -0,0 +1,34 @@
<?php
namespace App\View\Components;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
use App\Classes\LDAP\Attribute as LDAPAttribute;
class AttributeType extends Component
{
public LDAPAttribute $o;
public bool $new;
/**
* Create a new component instance.
*/
public function __construct(LDAPAttribute $o,bool $new=FALSE)
{
$this->o = $o;
$this->new = $new;
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.attribute-type')
->with('o',$this->o)
->with('new',$this->new);
}
}

View File

@ -123,7 +123,7 @@ return [
'validation' => [ 'validation' => [
'objectclass' => ['objectclass'=>['array','min:1']], 'objectclass' => ['objectclass'=>['array','min:1']],
'gidnumber' => ['gidnumber'=>['sometimes','array','max:1'],'gidnumber.*'=>['integer','max:65535']], 'gidnumber' => ['gidnumber'=>['sometimes','array','max:1'],'gidnumber.*'=>['integer','max:65535']],
'mail' => ['mail'=>['sometimes','array','min:1'],'mail.*'=>['email']], 'mail' => ['mail'=>['sometimes','array','min:1'],'mail.*'=>['nullable','email']],
'uidnumber' => ['uidnumber'=>['sometimes','array','max:1'],'uidnumber.*'=>['integer','max:65535']], 'uidnumber' => ['uidnumber'=>['sometimes','array','max:1'],'uidnumber.*'=>['integer','max:65535']],
], ],
]; ];

2
public/js/custom.js vendored
View File

@ -13,7 +13,7 @@ function expandChildren(node) {
function getNode(item) { function getNode(item) {
$.ajax({ $.ajax({
url: 'dn', url: '/dn',
method: 'POST', method: 'POST',
data: { key: item }, data: { key: item },
dataType: 'html', dataType: 'html',

View File

@ -0,0 +1,20 @@
<!-- $o=AttributeType::class -->
<div class="row pb-3">
<div class="col-12 col-sm-1 col-md-2"></div>
<div class="col-12 col-sm-10 col-md-8">
<div class="row">
<div class="col-12 bg-light text-dark p-2">
<strong><abbr title="{{ $o->description }}">{{ $o->name }}</abbr></strong>
<!-- Attribute Hints -->
<span class="float-end small">
@foreach($o->hints as $name => $description)
@if ($loop->index),@endif
<abbr title="{{ $description }}">{{ $name }}</abbr>
@endforeach
</span>
</div>
</div>
<x-attribute :edit="true" :new="$new" :o="$o"/>
</div>
</div>

View File

@ -1,31 +1,26 @@
<!-- $o=Attribute::class --> <!-- $o=Attribute::class -->
<div class="row"> <div class="row pt-2">
<div class="col-12"> <div class="col-1"></div>
<div class="col-10 p-2">
<div id="{{ $o->name_lc }}"> <div id="{{ $o->name_lc }}">
@foreach (old($o->name_lc,$o->values) as $value) @foreach (old($o->name_lc,$new ? [NULL] : $o->values) as $value)
@if ($edit && ! $o->is_rdn) @if ($edit && ! $o->is_rdn)
<div class="input-group has-validation"> <div class="input-group has-validation">
<input type="text" class="form-control @if($e=$errors->get($o->name_lc.'.'.$loop->index))is-invalid @endif mb-1 @if($o->values->search($value) === FALSE) border-focus @endif" name="{{ $o->name_lc }}[]" value="{{ $value }}" placeholder="{{ ! is_null($x=Arr::get($o->values,$loop->index)) ? $x : '['.__('NEW').']' }}" readonly="true"> <input type="text" class="form-control @if($e=$errors->get($o->name_lc.'.'.$loop->index))is-invalid @endif mb-1 @if($o->values->search($value) === FALSE) border-focus @endif" name="{{ $o->name_lc }}[]" value="{{ $value }}" placeholder="{{ ! is_null($x=Arr::get($o->values,$loop->index)) ? $x : '['.__('NEW').']' }}" @if (! $new)readonly="true" @endif">
<div class="invalid-feedback pb-2"> <div class="invalid-feedback pb-2">
@if($e) @if($e)
{{ join('|',$e) }} {{ join('|',$e) }}
@endif @endif
</div> </div>
</div> </div>
@else @else
{{ $value }}<br> {{ $value }}
@endif @endif
@endforeach @endforeach
</div> </div>
</div>
<div class="col-12 col-sm-6 col-lg-4"> @include('components.attribute.widget.options')
@if($o->is_rdn)
<span class="btn btn-sm btn-outline-focus mt-3 mb-3"><i class="fas fa-fw fa-exchange"></i> @lang('Rename')</span>
@elseif($edit && $o->can_addvalues)
<div class="p-0 m-0 addable d-none" id="{{ $o->name_lc }}">
<span class="btn btn-sm btn-outline-primary mt-3 mb-3"><i class="fas fa-fw fa-plus"></i> @lang('Add Value')</span>
</div>
@endif
</div> </div>
</div> </div>

View File

@ -3,31 +3,31 @@
<div class="input-group has-validation @if($e=$errors->get($o->name_lc))is-invalid @endif"> <div class="input-group has-validation @if($e=$errors->get($o->name_lc))is-invalid @endif">
@endif @endif
<table class="table table-borderless p-0 m-0"> <table class="table table-borderless p-0 m-0">
<tr> <tr>
@foreach ($o->values as $value) @foreach ($o->values as $value)
@switch ($x=$f->buffer($value,FILEINFO_MIME_TYPE)) @switch ($x=$f->buffer($value,FILEINFO_MIME_TYPE))
@case('image/jpeg') @case('image/jpeg')
@default @default
<td> <td>
<input type="hidden" name="{{ $o->name_lc }}[]" value="{{ md5($value) }}"> <input type="hidden" name="{{ $o->name_lc }}[]" value="{{ md5($value) }}">
<img class="jpegphoto" src="data:{{ $x }};base64, {{ base64_encode($value) }}" /> <img class="jpegphoto" src="data:{{ $x }};base64, {{ base64_encode($value) }}" />
@if($edit) @if($edit)
<br><span class="btn btn-sm btn-danger deletable d-none"><i class="fas fa-trash-alt"></i> @lang('Delete')</span> <br><span class="btn btn-sm btn-danger deletable d-none"><i class="fas fa-trash-alt"></i> @lang('Delete')</span>
@endif @endif
</td> </td>
@endswitch @endswitch
@endforeach @endforeach
</tr> </tr>
</table> </table>
@if($edit)
<div class="invalid-feedback pb-2">
@if($e)
{{ join('|',$e) }}
@endif
</div>
@if($edit)
<div class="invalid-feedback pb-2">
@if($e)
{{ join('|',$e) }}
@endif
</div> </div>
@endif
</div>
@endif

View File

@ -1,6 +1,7 @@
<!-- $o=Attribute::class --> <!-- $o=Attribute::class -->
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-1"></div>
<div class="col-10 p-2">
<div id="{{ $o->name_lc }}"> <div id="{{ $o->name_lc }}">
@foreach (old($o->name_lc,$o->values) as $value) @foreach (old($o->name_lc,$o->values) as $value)
@if ($edit && ($value === NULL || (! $o->isStructural($value)))) @if ($edit && ($value === NULL || (! $o->isStructural($value))))
@ -22,15 +23,7 @@
@endif @endif
@endforeach @endforeach
</div> </div>
</div>
<div class="col-12 col-sm-6 col-lg-4"> @include('components.attribute.widget.options')
@if($o->is_rdn)
<span class="btn btn-sm btn-outline-focus mt-3 mb-3"><i class="fas fa-fw fa-exchange"></i> @lang('Rename')</span>
@elseif($edit && $o->can_addvalues)
<div class="p-0 m-0 addable d-none" id="{{ $o->name_lc }}">
<span class="btn btn-sm btn-outline-primary mt-3 mb-3"><i class="fas fa-fw fa-plus"></i> @lang('Add Value')</span>
</div>
@endif
</div> </div>
</div> </div>

View File

@ -0,0 +1,34 @@
@if($o->is_rdn)
<span class="btn btn-sm btn-outline-focus mt-3"><i class="fas fa-fw fa-exchange"></i> @lang('Rename')</span>
@elseif($edit && $o->can_addvalues)
<div class="p-0 m-0">
<span class="btn btn-sm btn-outline-primary mt-3 addable @if(! $new)d-none @endif" id="{{ $o->name_lc }}"><i class="fas fa-fw fa-plus"></i> @lang('Add Value')</span>
@if($new)
<script type="text/javascript">
$(document).ready(function() {
// Create a new entry when Add Value clicked
$('#{{ $o->name_lc }}.addable').click(function (item) {
var cln = $(this).parent().parent().find('input:last').clone();
cln.val('').attr('placeholder', '[@lang('NEW')]');
cln.appendTo('#' + item.currentTarget.id)
});
});
</script>
@endif
</div>
@endif
@section('page-scripts')
@if(($edit && $o->can_addvalues))
<script type="text/javascript">
$(document).ready(function() {
// Create a new entry when Add Value clicked
$('#{{ $o->name_lc }}.addable').click(function (item) {
var cln = $(this).parent().parent().find('input:last').clone();
cln.val('').attr('placeholder', '[@lang('NEW')]');
cln.appendTo('#' + item.currentTarget.id)
});
});
</script>
@endif
@append

View File

@ -49,6 +49,7 @@
</div> </div>
@endif @endif
<!-- @todo If we are redirected here, check old() and add back any attributes that were in the original submission -->
@if($errors->any()) @if($errors->any())
<div class="alert alert-danger"> <div class="alert alert-danger">
<h4 class="alert-heading"><i class="fas fa-fw fa-thumbs-down"></i> Error?</h4> <h4 class="alert-heading"><i class="fas fa-fw fa-thumbs-down"></i> Error?</h4>
@ -75,38 +76,48 @@
<div class="tab-content"> <div class="tab-content">
<!-- All Attributes --> <!-- All Attributes -->
<div class="tab-pane active" id="attributes" role="tabpanel"> <div class="tab-pane active" id="attributes" role="tabpanel">
<form id="form-entry" method="POST" class="needs-validation" action="{{ url('entry/update') }}" novalidate> <form id="dn-edit" method="POST" class="needs-validation" action="{{ url('entry/update/pending') }}" novalidate>
@csrf @csrf
<input type="hidden" name="dn" value="{{ $o->getDNSecure() }}"> <input type="hidden" name="dn" value="{{ $o->getDNSecure() }}">
@foreach ($o->getVisibleAttributes() as $ao)
<x-attribute-type :edit="true" :o="$ao"/>
@endforeach
<div id="newattrs"></div>
<!-- Add new attributes -->
<div class="row"> <div class="row">
<div class="col-12 offset-lg-2 col-lg-8"> <div class="col-12 col-sm-1 col-md-2"></div>
<table class="table"> <div class="col-12 col-sm-10 col-md-8">
@foreach ($o->getVisibleAttributes() as $ao) <div class="d-none" id="newattr-select">
<tr class="bg-light text-dark small">
<th class="w-25"> @if($o->getMissingAttributes()->count())
<abbr title="{{ $ao->description }}">{{ $ao->name }}</abbr> <div class="row">
<!-- Attribute Hints --> <div class="col-12 bg-dark text-light p-2">
<span class="float-end"> <i class="fas fa-plus-circle"></i> Add New Attribute
@foreach($ao->hints as $name => $description) </div>
@if ($loop->index),@endif </div>
<abbr title="{{ $description }}">{{ $name }}</abbr>
@endforeach <div class="row">
</span> <div class="col-12 pt-2">
</th> <label for="newattr" class="form-label">Select from...</label>
</tr> <select class="form-select" id="newattr">
<tr> <option value="">&nbsp;</option>
<td class="ps-5"> @foreach ($o->getMissingAttributes() as $ao)
<x-attribute :edit="true" :o="$ao"/> <option value="{{ $ao->name_lc }}">{{ $ao->name }}</option>
</td> @endforeach
</tr> </select>
@endforeach </div>
</table> </div>
@endif
</div>
</div> </div>
<div class="col-2"></div>
</div> </div>
<div class="row d-none"> <div class="row d-none pt-3">
<div class="col-12 offset-sm-2 col-sm-4 col-lg-2"> <div class="col-12 offset-sm-2 col-sm-4 col-lg-2">
<span id="form-reset" class="btn btn-outline-danger">@lang('Reset')</span> <span id="form-reset" class="btn btn-outline-danger">@lang('Reset')</span>
<span id="form-submit" class="btn btn-success">@lang('Update')</span> <span id="form-submit" class="btn btn-success">@lang('Update')</span>
@ -140,12 +151,15 @@
<!-- Debug --> <!-- Debug -->
<div class="tab-pane" id="debug" role="tabpanel"> <div class="tab-pane" id="debug" role="tabpanel">
<div class="row"> <div class="row">
<div class="col-6"> <div class="col-4">
@dump($o) @dump($o)
</div> </div>
<div class="col-6"> <div class="col-4">
@dump($o->getAttributes()) @dump($o->getAttributes())
</div> </div>
<div class="col-4">
@dump(['available'=>$o->getAvailableAttributes()->pluck('name'),'missing'=>$o->getMissingAttributes()->pluck('name')])
</div>
</div> </div>
</div> </div>
</div> </div>
@ -167,22 +181,43 @@
$('.row.d-none').removeClass('d-none'); $('.row.d-none').removeClass('d-none');
$('.addable.d-none').removeClass('d-none'); $('.addable.d-none').removeClass('d-none');
$('.deletable.d-none').removeClass('d-none'); $('.deletable.d-none').removeClass('d-none');
@if($o->getMissingAttributes()->count())
$('#newattr-select.d-none').removeClass('d-none');
@endif
} }
$(document).ready(function() { $(document).ready(function() {
$('#reset').click(function() { $('#form-reset').click(function() {
$('#form-entry')[0].reset(); $('#dn-edit')[0].reset();
}) })
$('#form-submit').click(function() { $('#form-submit').click(function() {
$('#form-entry')[0].submit(); $('#dn-edit')[0].submit();
}) })
// Create a new entry when Add Value clicked $('#newattr').on('change',function(item) {
$('.addable').click(function(item) { $.ajax({
var cln = $(this).parent().parent().find('input:last').clone(); type: 'GET',
cln.val('').attr('placeholder','[@lang('NEW')]'); beforeSend: function() {
cln.appendTo('#'+item.currentTarget.id) },
success: function(data) {
$('#newattrs').append(data);
},
error: function(e) {
if (e.status != 412)
alert('That didnt work? Please try again....');
},
url: '{{ url('entry/newattr') }}/'+item.target.value,
cache: false
})
// Remove the option from the list
$(this).find('[value="'+item.target.value+'"]').remove()
// If there are no more options
if ($(this).find("option").length === 1)
$('#newattr-select').remove();
}); });
$('button[id=entry-edit]').on('click',function(item) { $('button[id=entry-edit]').on('click',function(item) {

View File

@ -0,0 +1,111 @@
@extends('dn')
@section('page_title')
<table class="table table-borderless">
<tr>
<td class="{{ ($x=Arr::get($o->getAttributes(),'jpegphoto')) ? 'border' : '' }}" rowspan="2">{!! $x ? $x->render() : sprintf('<div class="page-title-icon f32"><i class="%s"></i></div>',$o->icon() ?? "fas fa-info") !!}</td>
<td class="text-end align-text-top p-0 {{ $x ? 'ps-5' : 'pt-2' }}"><strong>{{ $dn }}</strong></td>
</tr>
<tr>
<td class="line-height-1" style="font-size: 55%;vertical-align: bottom;" colspan="2">
<table>
<tr>
<td class="p-1 m-1">Created</td>
<th class="p-1 m-1">{{ ($x=Arr::get($o->getAttributes(),'createtimestamp')) ? $x->render() : __('Unknown') }} [{{ ($x=Arr::get($o->getAttributes(),'creatorsname')) ? $x->render() : __('Unknown') }}]</th>
</tr>
<tr>
<td class="p-1 m-1">Modified</td>
<th class="p-1 m-1">{{ ($x=Arr::get($o->getAttributes(),'modifytimestamp')) ? $x->render() : __('Unknown') }} [{{ ($x=Arr::get($o->getAttributes(),'modifiersname')) ? $x->render() : __('Unknown') }}]</th>
</tr>
<tr>
<td class="p-1 m-1">UUID</td>
<th class="p-1 m-1">{{ $o->entryuuid[0] ?? '' }}</th>
</tr>
</table>
</td>
</tr>
</table>
@endsection
@section('main-content')
@if(session()->has('note'))
<div class="alert alert-info">
<h4 class="alert-heading"><i class="fas fa-fw fa-note-sticky"></i> Note:</h4>
<hr>
<p>{{ session()->pull('note') }}</p>
</div>
@endif
@if(session()->has('success'))
<div class="alert alert-success">
<h4 class="alert-heading"><i class="fas fa-fw fa-thumbs-up"></i> Success!</h4>
<hr>
<p>{{ session()->pull('success') }}</p>
<ul style="list-style-type: square;">
@foreach (session()->pull('updated') as $key => $values)
<li>{{ $key }}: {{ join(',',$values) }}</li>
@endforeach
</ul>
</div>
@endif
@if($errors->any())
<div class="alert alert-danger">
<h4 class="alert-heading"><i class="fas fa-fw fa-thumbs-down"></i> Error?</h4>
<hr>
<ul style="list-style-type: square;">
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<div class="main-card mb-3 card">
<div class="card-body">
<div class="row">
<div class="col-12 col-lg-6 col-xl-4 mx-auto pt-3">
<form id="dn-edit" method="POST" class="needs-validation" action="{{ url('entry/update/commit') }}" novalidate>
@csrf
<input type="hidden" name="dn" value="{{ $o->getDNSecure() }}">
<div class="card-title"><h3>@lang('Do you want to make the following changes?')</h3></div>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Attribute</th>
<th>OLD</th>
<th>NEW</th>
</tr>
</thead>
<tbody>
@foreach ($o->getDirty() as $key => $value)
<tr>
<th rowspan="{{ $x=max(count($value),count(Arr::get($o->getOriginal(),$key,[])))}}">{{ $key }}</th>
@for($xx=0;$xx<$x;$xx++)
@if($xx)
</tr><tr>
@endif
<td>{{ Arr::get(Arr::get($o->getOriginal(),$key,['['.strtoupper(__('New Value')).']']),$xx) }}</td>
<td>{{ $y=Arr::get($value,$xx) }}<input type="hidden" name="{{ $key }}[]" value="{{ $y }}"></td>
@endfor
</tr>
@endforeach
</tbody>
</table>
</form>
</div>
<div class="row pt-3">
<div class="col-12 offset-sm-2 col-sm-4 col-lg-2 mx-auto">
<span id="form-reset" class="btn btn-outline-danger">@lang('Reset')</span>
<span id="form-submit" class="btn btn-success">@lang('Update')</span>
</div>
</div>
</div>
</div>
</div>
@endsection

View File

@ -39,4 +39,6 @@ Route::group(['prefix'=>'user'],function() {
Route::get('image',[HomeController::class,'user_image']); Route::get('image',[HomeController::class,'user_image']);
}); });
Route::post('entry/update',[HomeController::class,'entry_update']); Route::post('entry/update/commit',[HomeController::class,'entry_update']);
Route::post('entry/update/pending',[HomeController::class,'entry_pending_update']);
Route::get('entry/newattr/{id}',[HomeController::class,'entry_newattr']);