Compare commits
5 Commits
735b1c542f
...
dc41296015
Author | SHA1 | Date | |
---|---|---|---|
dc41296015 | |||
61538e681d | |||
ab33c2dce9 | |||
b3b3fc6ac1 | |||
d6ec080ecf |
@ -16,15 +16,10 @@ class Template
|
||||
private array $template;
|
||||
private(set) bool $invalid = FALSE;
|
||||
private(set) string $reason = '';
|
||||
private Collection $on_change_target;
|
||||
private Collection $on_change_attribute;
|
||||
private bool $on_change_processed = FALSE;
|
||||
|
||||
public function __construct(string $file)
|
||||
{
|
||||
$td = Storage::disk(config('pla.template.dir'));
|
||||
$this->on_change_attribute = collect();
|
||||
$this->on_change_target = collect();
|
||||
|
||||
$this->file = $file;
|
||||
|
||||
@ -58,41 +53,24 @@ class Template
|
||||
return array_key_exists($key,$this->template);
|
||||
}
|
||||
|
||||
public function onChange(string $attribute): Collection|NULL
|
||||
{
|
||||
if (! $this->on_change_processed)
|
||||
$this->onChangeProcessing();
|
||||
|
||||
return $this->on_change_attribute
|
||||
->get(strtolower($attribute));
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this attribute's value populated by any onChange processing rules
|
||||
*
|
||||
* @param string $attribute
|
||||
* @return bool
|
||||
*/
|
||||
public function onChangeAttribute(string $attribute): bool
|
||||
{
|
||||
if (! $this->on_change_processed)
|
||||
$this->onChangeProcessing();
|
||||
|
||||
return $this->on_change_attribute
|
||||
->has(strtolower($attribute));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the onchange JavaScript for attribute
|
||||
*
|
||||
* @param string $attribute
|
||||
* @return Collection
|
||||
*/
|
||||
private function onChangeProcessing(): void
|
||||
public function onChange(string $attribute): Collection
|
||||
{
|
||||
foreach (Arr::get($this->template,'attributes',[]) as $attribute => $detail) {
|
||||
$attr = collect($this->template['attributes'])
|
||||
->filter(fn($item,$key)=>! strcasecmp($key,$attribute))
|
||||
->pop();
|
||||
|
||||
if (! $attr)
|
||||
return collect();
|
||||
|
||||
$result = collect();
|
||||
|
||||
foreach (Arr::get($detail,'onchange',[]) as $item) {
|
||||
foreach (Arr::get($attr,'onchange',[]) as $item) {
|
||||
list($command,$args) = preg_split('/^=([a-zA-Z]+)\((.+)\)$/',$item,-1,PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
switch ($command) {
|
||||
@ -102,26 +80,7 @@ class Template
|
||||
}
|
||||
}
|
||||
|
||||
if ($result->count())
|
||||
$this->on_change_attribute->put(strtolower($attribute),$result);
|
||||
}
|
||||
|
||||
$this->on_change_processed = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this attribute's value populated by any onChange processing rules
|
||||
*
|
||||
* @param string $attribute
|
||||
* @return bool
|
||||
*/
|
||||
public function onChangeTarget(string $attribute): bool
|
||||
{
|
||||
if (! $this->on_change_processed)
|
||||
$this->onChangeProcessing();
|
||||
|
||||
return $this->on_change_target
|
||||
->has(strtolower($attribute));
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -169,8 +128,6 @@ class Template
|
||||
|
||||
// $attr has our attribute to update, $string is the format to use when updating it
|
||||
list($attr,$string) = preg_split('(([^,]+);(.*))',$arg,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
$this->on_change_target->put(strtolower($attr),$string);
|
||||
|
||||
$output = $string;
|
||||
//$result .= sprintf("\n// %s\n",$arg);
|
||||
|
||||
|
@ -7,14 +7,9 @@
|
||||
<span class="d-flex justify-content-between">
|
||||
<span style="width: 20em;">
|
||||
<strong class="align-middle"><abbr title="{{ $o->description }}">{{ $o->name }}</abbr></strong>
|
||||
@if($new)
|
||||
@if($template?->onChangeAttribute($o->name_lc))
|
||||
<sup data-bs-toggle="tooltip" title="@lang('Value triggers an update to another attribute by template')"><i class="fas fa-keyboard"></i></sup>
|
||||
@endif
|
||||
@if ($template?->onChangeTarget($o->name_lc))
|
||||
@if($new && $template?->onChange($o->name)->count())
|
||||
<sup data-bs-toggle="tooltip" title="@lang('Value calculated by template')"><i class="fas fa-wand-magic-sparkles"></i></sup>
|
||||
@endif
|
||||
@endif
|
||||
|
||||
@if($o->hints->count())
|
||||
<sup>
|
||||
|
@ -6,10 +6,10 @@
|
||||
|
||||
<div class="card-body">
|
||||
<div class="tab-content">
|
||||
@php($up=(session()->get('updated') ?: collect()))
|
||||
@php($up=(session()->pull('updated') ?: collect()))
|
||||
|
||||
@foreach($o->getVisibleAttributes()->filter(fn($item)=>$template->attributes->map('strtolower')->contains($item->name_lc)) as $ao)
|
||||
<x-attribute-type :o="$ao" :edit="TRUE" :new="FALSE" :template="$template" :updated="$up->contains($ao->name)"/>
|
||||
<x-attribute-type :o="$ao" :edit="TRUE" :new="FALSE" :template="$template" :updated="$up->contains($ao->name_lc)"/>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
|
@ -101,7 +101,7 @@
|
||||
<div class="tab-content">
|
||||
@php($up=(session()->pull('updated') ?: collect()))
|
||||
@foreach($o->getVisibleAttributes() as $ao)
|
||||
<x-attribute-type :o="$ao" :edit="TRUE" :new="FALSE" :template="$template ?? NULL" :updated="$up->contains($ao->name)"/>
|
||||
<x-attribute-type :o="$ao" :edit="TRUE" :new="FALSE" :template="$template ?? NULL" :updated="$up->contains($ao->name_lc)"/>
|
||||
@endforeach
|
||||
|
||||
@include('fragment.dn.add_attr')
|
||||
|
Loading…
x
Reference in New Issue
Block a user