More work on work on adding/removing objectclasses to an entry, still need to automatically remove attrs from removed objectclasses
Some checks failed
Create Docker Image / Build Docker Image (arm64) (push) Has been cancelled
Create Docker Image / Build Docker Image (x86_64) (push) Has been cancelled
Create Docker Image / Final Docker Image Manifest (push) Has been cancelled
Create Docker Image / Test Application (x86_64) (push) Has been cancelled

This commit is contained in:
2025-02-04 08:55:10 +11:00
parent bbef155fd2
commit 7513ed6def
14 changed files with 122 additions and 68 deletions

View File

@@ -4,7 +4,7 @@
<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>
<strong><abbr title="{{ $o->description }}" data-attr-name="{{ $o->name_lc }}" data-attr-required="{{ $o->required_by->intersect($oc)->join('|') }}" data-oc="{{ $oc->count() ? $o->required_by->keys()->intersect($oc)->join('|') : $o->used_in->keys()->join('|') }}">{{ $o->name }}</abbr></strong>
<!-- Attribute Hints -->
<span class="float-end small">
@foreach($o->hints as $name => $description)

View File

@@ -1,19 +1,12 @@
<div class="input-group has-validation">
<!-- @todo Have an "x" to remove the entry, we need an event to process the removal, removing any attribute values along the way -->
<input type="text" @class(['form-control','is-invalid'=>($e=$errors->get($o->name_lc.'.'.$loop->index)),'mb-1','border-focus'=>$o->values->contains($value)]) name="{{ $o->name_lc }}[]" value="{{ $value }}" placeholder="{{ Arr::get($o->values,$loop->index,'['.__('NEW').']') }}" @readonly(true)>
<div class="invalid-feedback pb-2">
@if($e)
{{ join('|',$e) }}
@endif
<span id="objectclass_{{$value}}">
<div class="input-group has-validation">
<!-- @todo Have an "x" to remove the entry, we need an event to process the removal, removing any attribute values along the way -->
<input type="text" @class(['form-control','is-invalid'=>($e=$errors->get($o->name_lc.'.'.$loop->index)),'mb-1','border-focus'=>$o->values->contains($value)]) name="{{ $o->name_lc }}[]" value="{{ $value }}" placeholder="{{ Arr::get($o->values,$loop->index,'['.__('NEW').']') }}" @readonly(true)>
<div class="invalid-feedback pb-2">
@if($e)
{{ join('|',$e) }}
@endif
</div>
</div>
</div>
<span class="input-group-delete"><i class="fas fa-fw fa-xmark"></i></span>
<style>
.input-group-delete {
float: right;
position: relative;
top: -32px;
right: 10px;
}
</style>
<span class="input-group-delete"><i class="fas fa-fw fa-xmark"></i></span>
</span>

View File

@@ -68,42 +68,97 @@
var newadded = $('select#newoc').val();
// If nothing selected, we dont have anything to do
if (! newadded.length)
if (added_oc.sort().join('|') == newadded.sort().join('|'))
return;
var attrs = $('[data-attr-name]').map(function() {
return $(this).data('attrName');
});
// Find out what was selected, and add them
newadded.forEach(function (item) {
if (added_oc.indexOf(item) !== -1)
return;
// Add attribute to the page
$.ajax({
type: 'GET',
type: 'POST',
beforeSend: function() {},
success: function(data) {
console.log(data);
$('#{{ $o->name_lc }}').append(data);
console.log('set to:'+item);
},
error: function(e) {
if (e.status != 412)
alert('That didnt work? Please try again....');
},
url: '{{ url('entry/attr/add',[$o->name_lc]) }}',
data: {noheader: true,value: item,loop: c++}, // @todo can we omit loop and c
data: {
noheader: true,
value: item,
objectclasses: oc,
loop: c++, // @todo can we omit loop and c
},
cache: false
});
$.ajax({
type: 'POST',
beforeSend: function() {},
success: function(data) {
// Render any must attributes
if (data.must.length) {
data.must.forEach(function(item) {
// Add attribute to the page
$.ajax({
type: 'POST',
beforeSend: function() {},
success: function(data) {
$('#newattrs').append(data);
},
error: function(e) {
if (e.status != 412)
alert('That didnt work? Please try again....');
},
url: '{{ url('entry/attr/add') }}/'+item,
data: {
value: item,
objectclasses: oc,
loop: c++, // @todo can we omit loop and c
},
cache: false
});
})
}
// Add attributes to "Add new Attribute" that are now available
if (data.may.length) {
var newattr = $('select#newattr');
// @todo It might be nice to resort this options
data.may.forEach(function(item) {
newattr.append(new Option(item,item,false,false));
});
}
},
error: function(e) {
if (e.status != 412)
alert('That didnt work? Please try again....');
},
url: '{{ url('api/schema/objectclass/attrs') }}/'+item,
cache: false
});
// @todo add any required attributes that are defined required as a result of adding this OC
// @todo Add attributes to "Add new Attribute" that are now available
});
// Loop through added_oc, and remove anything not in newadded
added_oc.forEach(function(item) {
if (newadded.indexOf(item) === -1) {
$('input[value="'+item+'"]').parent().empty();
$('span#objectclass_'+item).empty();
// @todo remove any required attributes that are no longer defined as a result of removing this OC
console.log('Remove required attributes of:'+item);
// @todo Remove attributes from "Add new Attribute" that are no longer available
console.log('Remove additional attributes of:'+item);
}
});

View File

@@ -31,7 +31,7 @@
<input type="hidden" name="dn" value="">
@foreach ($o->getVisibleAttributes() as $ao)
<x-attribute-type :edit="true" :o="$ao"/>
<x-attribute-type :edit="true" :o="$ao" :oc="collect($o->objectclass)"/>
@endforeach
<div id="newattrs"></div>
@@ -173,6 +173,7 @@
@section('page-scripts')
<script type="text/javascript">
var dn = '{{ $o->getDNSecure() }}';
var oc = {!! $o->getObject('objectclass')->values !!};
function download(filename,text) {
var element = document.createElement('a');
@@ -217,7 +218,7 @@
$(document).ready(function() {
$('#newattr').on('change',function(item) {
$.ajax({
type: 'GET',
type: 'POST',
beforeSend: function() {},
success: function(data) {
$('#newattrs').append(data);
@@ -227,6 +228,9 @@
alert('That didnt work? Please try again....');
},
url: '{{ url('entry/attr/add') }}/'+item.target.value,
data: {
objectclasses: oc,
},
cache: false
});