Fix rendering Add Objectclasses, remove existing OCs from the list and dont rebuild the select list after the first invocation
This commit is contained in:
parent
7513ed6def
commit
c0e6b62ee5
@ -116,8 +116,9 @@ class HomeController extends Controller
|
|||||||
{
|
{
|
||||||
$dn = Crypt::decryptString($id);
|
$dn = Crypt::decryptString($id);
|
||||||
$o = config('server')->fetch($dn);
|
$o = config('server')->fetch($dn);
|
||||||
|
$oc = $o->getObject('objectclass');
|
||||||
|
|
||||||
$ocs = $o->getObject('objectclass')
|
$ocs = $oc
|
||||||
->structural
|
->structural
|
||||||
->map(fn($item)=>$item->getParents())
|
->map(fn($item)=>$item->getParents())
|
||||||
->flatten()
|
->flatten()
|
||||||
@ -125,6 +126,8 @@ class HomeController extends Controller
|
|||||||
config('server')->schema('objectclasses')
|
config('server')->schema('objectclasses')
|
||||||
->filter(fn($item)=>$item->isAuxiliary())
|
->filter(fn($item)=>$item->isAuxiliary())
|
||||||
)
|
)
|
||||||
|
// Remove the original objectlcasses
|
||||||
|
->filter(fn($item)=>(! $oc->values->contains($item)))
|
||||||
->sortBy(fn($item)=>$item->name);
|
->sortBy(fn($item)=>$item->name);
|
||||||
|
|
||||||
return $ocs->groupBy(fn($item)=>$item->isStructural())
|
return $ocs->groupBy(fn($item)=>$item->isStructural())
|
||||||
|
@ -39,27 +39,32 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
var added_oc = []; // Object classes being added to this entry
|
var added_oc = []; // Object classes being added to this entry
|
||||||
|
var rendered = false;
|
||||||
|
|
||||||
// Show our ObjectClass modal so that we can add more objectclasses
|
// Show our ObjectClass modal so that we can add more objectclasses
|
||||||
$('#new_objectclass-modal').on('shown.bs.modal',function() {
|
$('#new_objectclass-modal').on('shown.bs.modal',function() {
|
||||||
$.ajax({
|
if (! rendered)
|
||||||
type: 'POST',
|
$.ajax({
|
||||||
success: function(data) {
|
type: 'POST',
|
||||||
$('select#newoc').select2({
|
// @todo When this is opened a second time, the data is appended.
|
||||||
dropdownParent: $('#new_objectclass-modal'),
|
success: function(data) {
|
||||||
theme: 'bootstrap-5',
|
$('select#newoc').select2({
|
||||||
allowClear: true,
|
dropdownParent: $('#new_objectclass-modal'),
|
||||||
multiple: true,
|
theme: 'bootstrap-5',
|
||||||
data: data,
|
allowClear: true,
|
||||||
});
|
multiple: true,
|
||||||
},
|
data: data,
|
||||||
error: function(e) {
|
});
|
||||||
if (e.status != 412)
|
},
|
||||||
alert('That didnt work? Please try again....');
|
error: function(e) {
|
||||||
},
|
if (e.status != 412)
|
||||||
url: '{{ url('entry/objectclass/add') }}/'+dn,
|
alert('That didnt work? Please try again....');
|
||||||
cache: false
|
},
|
||||||
});
|
url: '{{ url('entry/objectclass/add') }}/'+dn,
|
||||||
|
cache: false
|
||||||
|
});
|
||||||
|
|
||||||
|
rendered = true;
|
||||||
})
|
})
|
||||||
|
|
||||||
// When the ObjectClass modal is closed, process what was selected
|
// When the ObjectClass modal is closed, process what was selected
|
||||||
@ -134,7 +139,7 @@
|
|||||||
if (data.may.length) {
|
if (data.may.length) {
|
||||||
var newattr = $('select#newattr');
|
var newattr = $('select#newattr');
|
||||||
|
|
||||||
// @todo It might be nice to resort this options
|
// @todo It might be nice to re-sort these options
|
||||||
data.may.forEach(function(item) {
|
data.may.forEach(function(item) {
|
||||||
newattr.append(new Option(item,item,false,false));
|
newattr.append(new Option(item,item,false,false));
|
||||||
});
|
});
|
||||||
@ -155,10 +160,39 @@
|
|||||||
if (newadded.indexOf(item) === -1) {
|
if (newadded.indexOf(item) === -1) {
|
||||||
$('span#objectclass_'+item).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
|
// @todo Remove attributes from "Add new Attribute" that are no longer available
|
||||||
console.log('Remove additional attributes of:'+item);
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
beforeSend: function() {},
|
||||||
|
success: function(data) {
|
||||||
|
var attrs = [];
|
||||||
|
|
||||||
|
// Remove attributes from "Add new Attribute" that are no longer available
|
||||||
|
if (data.may.length) {
|
||||||
|
data.may.forEach(function(mayitem) {
|
||||||
|
var x = $("select#newattr option[value='"+mayitem+"']");
|
||||||
|
|
||||||
|
if (x.length) {
|
||||||
|
x.remove();
|
||||||
|
|
||||||
|
// Add this to the must attrs list, because its been rendered
|
||||||
|
} else {
|
||||||
|
attrs.push(mayitem);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// @todo remove any required attributes that are no longer defined as a result of removing this OC
|
||||||
|
console.log('Remove required attributes of:'+item);
|
||||||
|
console.log(attrs);
|
||||||
|
},
|
||||||
|
error: function(e) {
|
||||||
|
if (e.status != 412)
|
||||||
|
alert('That didnt work? Please try again....');
|
||||||
|
},
|
||||||
|
url: '{{ url('api/schema/objectclass/attrs') }}/'+item,
|
||||||
|
cache: false
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user