Skip to content

Commit c6cda95

Browse files
committed
Support having static values in templates, as well as making them uneditable. Closes #366
1 parent fe2f4cf commit c6cda95

File tree

5 files changed

+15
-41
lines changed

5 files changed

+15
-41
lines changed

app/Classes/Template.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,18 @@ public function attributeType(string $attribute): string|NULL
163163
public function attributeValue(string $attribute): string|NULL
164164
{
165165
if ($x=$this->attribute($attribute)->get('value')) {
166-
list($command,$args) = preg_split('/^=([a-zA-Z]+)\((.+)\)$/',$x,-1,PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
166+
167+
if (preg_match('/^=([a-zA-Z]+)\((.+)\)$/',$x)) {
168+
list($command,$args) = preg_split('/^=([a-zA-Z]+)\((.+)\)$/',$x,-1,PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
169+
170+
} else {
171+
$command = 'value';
172+
$args = $x;
173+
}
167174

168175
return match ($command) {
169176
'getNextNumber' => $this->getNextNumber($args),
177+
'value' => $x,
170178
default => NULL,
171179
};
172180
}
@@ -338,13 +346,10 @@ public function onChangeAttribute(string $attribute): bool
338346
->has(strtolower($attribute));
339347
}
340348

341-
/**
342-
* Process the attributes for onChange JavaScript
343-
*/
344349
/**
345350
* Return the onchange JavaScript for attribute
346351
*
347-
* @return Collection
352+
* @return void
348353
*/
349354
private function onChangeProcessing(): void
350355
{

resources/views/components/attribute/template/select.blade.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
'border-focus'=>! $o->tagValuesOld($langtag)->contains($value)])
99
id="{{ $o->name_lc }}_{{$loop->index}}{{$template?->name ?: ''}}"
1010
name="{{ $o->name_lc }}[{{ $langtag }}][]"
11-
:value="$value"
11+
:value="$template->attributeValue($o->name_lc) ?? $value"
1212
:options="$template->attributeOptions($o->name_lc)"
1313
allowclear="true"
14-
:disabled="! $edit"
15-
:readonly="false"/>
14+
:disabled="! $edit"/>
1615

1716
<x-form.invalid-feedback :errors="$e"/>
1817
@endforeach

resources/views/components/attribute/value.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
name="{{ $o->name_lc }}[{{ $attrtag }}][]"
55
value="{{ $value }}"
66
placeholder="{{ $value ?: '['.__('NEW').']' }}"
7-
@readonly(! $edit)
7+
@readonly(! $edit || ($template && $template->attributeReadOnly($o->name_lc)))
88
@disabled($o->isDynamic())>
99

1010
<x-form.invalid-feedback :errors="$e"/>

resources/views/frames/create.blade.php

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
@endswitch
8181
</form>
8282

83-
<div class="row d-none pt-3">
83+
<div class="row pt-3">
8484
<div class="col-11 {{ $step > 1 ? 'text-end' : '' }} pe-0">
8585
<x-form.reset form="dn-create"/>
8686
<x-form.submit :action="__('Next')" form="dn-create"/>
@@ -96,35 +96,6 @@
9696
<script type="text/javascript">
9797
var rdn_attr;
9898
99-
function editmode() {
100-
// Find all input items and turn off readonly
101-
$('input.form-control').each(function() {
102-
// Except for objectClass
103-
if ($(this)[0].name.match(/^objectclass/))
104-
return;
105-
106-
// Dont take of the readonly value for our RDN if it is set
107-
if (rdn_attr && ($(this)[0].name === rdn_attr+'[]'))
108-
return;
109-
110-
// Exclude attributes marked as noedit
111-
if ($(this).hasClass('noedit'))
112-
return;
113-
114-
$(this).attr('readonly',false);
115-
});
116-
117-
// Our password type
118-
$('attribute#userpassword .form-select').each(function() {
119-
$(this).prop('disabled',false);
120-
})
121-
122-
$('.row.d-none').removeClass('d-none');
123-
$('span.addable.d-none').removeClass('d-none');
124-
$('span.deletable.d-none').removeClass('d-none');
125-
$('#newattr-select.d-none').removeClass('d-none');
126-
}
127-
12899
$(document).ready(function() {
129100
@if($step === 1)
130101
$('#objectclass').on('select2:open',function(){
@@ -135,8 +106,6 @@ function editmode() {
135106
$('#objectclass').val(null).trigger('change');
136107
})
137108
@endif
138-
139-
editmode();
140109
});
141110
</script>
142111
@append

templates/user_account.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"/bin/false": "False",
7676
"/usr/sbin/nologin": "No Login"
7777
},
78+
"value": "/bin/zsh",
7879
"order": 9
7980
}
8081
}

0 commit comments

Comments
 (0)