Skip to content

Commit

Permalink
Merge pull request #188 from OrifInformatique/fix_modification
Browse files Browse the repository at this point in the history
  • Loading branch information
DidierViret authored Jun 28, 2023
2 parents bb5ec15 + de8e5d7 commit 896514b
Showing 1 changed file with 44 additions and 31 deletions.
75 changes: 44 additions & 31 deletions orif/stock/Views/item/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@
<option value="" disabled> -- <?= lang('MY_application.field_group'); ?> -- </option>
<?php
foreach ($item_groups as $item_group) :?>
<option value="<?=$item_group['item_group_id']?>" <?php echo (isset($item_group_id) && $item_group_id == $item_group['item_group_id'] ? 'selected' : $item_group['item_group_id'] == $config->items_default_group) ? 'selected' : '' ?> data-fk_entity="<?=$item_group['fk_entity_id']?>"><?=$item_group['name']?></option>
<?php endforeach;?>
<option value="<?=$item_group['item_group_id']?>" <?php echo (isset($item_group_id) && $item_group_id == $item_group['item_group_id'] ? 'selected' : $item_group['item_group_id'] == $config->items_default_group) ? 'selected' : '' ?> data-fk_entity="<?=$item_group['fk_entity_id']?>"><?=$item_group['name']?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group col-md-8">
Expand Down Expand Up @@ -260,6 +260,9 @@
// Changing the src attribute forces browser to update.
d = new Date();
$("#picture").attr("src", "<?= base_url($config->images_upload_path.$imagePath); ?>?"+d.getTime());

initStockingPlace(document.querySelector('#entity_selector'));
initItemGroup(document.querySelector('#entity_selector'));
});

function get(objectName){
Expand Down Expand Up @@ -363,44 +366,54 @@ function getFirstTagShortName(){
return firstTagShortName;
}

function initStockingPlace(el){
const fk_entity_id=el.value;
document.querySelector('#stocking_place_id').querySelectorAll('option').forEach((element)=>{
if (element.value===""){
element.selected=true;
}
else if (element.dataset.fk_entity===fk_entity_id){
element.style.display='unset';
element.parentElement.value=element.value;
element.selected=true;
function initStockingPlace(el) {
const fk_entity_id = el.value;
const selectElement = document.querySelector('#stocking_place_id');
let selectedParentElement = null;

selectElement.querySelectorAll('option').forEach((element) => {
if (element.value === '') {
element.selected = true;
} else if (element.dataset.fk_entity === fk_entity_id) {
element.style.display = 'unset';
if (selectedParentElement === null) {
selectedParentElement = element.parentElement;
selectedParentElement.value = element.value;
}
} else {
element.style.display = 'none';
}
else {
element.style.display='none';

if (element.value === '<?=isset($stocking_place_id) ? $stocking_place_id : 'NONE'?>') {
element.selected = true;
}
})
});
}

function initItemGroup(el){
const fk_entity_id=el.value;
document.querySelector('#item_group_id').querySelectorAll('option').forEach((element)=>{
if (element.value===""){
element.selected=true;
}
else if (element.dataset.fk_entity===fk_entity_id){
element.style.display='unset';
element.parentElement.value=element.value;
}
else {
element.style.display='none';
function initItemGroup(el) {
const fk_entity_id = el.value;
const selectElement = document.querySelector('#item_group_id');
let selectedParentElement = null;

selectElement.querySelectorAll('option').forEach((element) => {
if (element.value === '') {
element.selected = true;
} else if (element.dataset.fk_entity === fk_entity_id) {
element.style.display = 'unset';
if (selectedParentElement === null) {
selectedParentElement = element.parentElement;
selectedParentElement.value = element.value;
}
} else {
element.style.display = 'none';
}
if (element.value==='<?=isset($item_group_id)?$item_group_id:'NONE'?>'){
element.selected=true;

if (element.value === '<?=isset($item_group_id) ? $item_group_id : 'NONE'?>') {
element.selected = true;
}
});
}

initStockingPlace(document.querySelector('#entity_selector'));
initItemGroup(document.querySelector('#entity_selector'));

change_warranty();

Expand Down

0 comments on commit 896514b

Please sign in to comment.