Skip to content

Commit

Permalink
[BF] - Patch Panels: can not select same customer / port details afte…
Browse files Browse the repository at this point in the history
…r a reset - fixes #350
  • Loading branch information
yannrobin committed Oct 9, 2017
1 parent fd7809a commit 007c712
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
5 changes: 5 additions & 0 deletions resources/views/patch-panel-port/edit.foil.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,16 @@ interface is discouraged for lifecycle changes.
->placeholder( 'Choose a switch' )
->addClass( 'chzn-select' );
?>
<?php if( $t->ppp ) : ?><?php if( $t->ppp->getSwitchPort() ) : ?><div class="label label-info" style="margin-left: 17%"> Was <?= $t->ppp->getSwitchPort()->getSwitcher()->getName() ?> </div> <br/><br/><?php endif; ?><?php endif; ?>


<?= Former::select( 'switch_port' )
->label( 'Switch Port' )
->fromQuery( $t->switchPorts, 'name' )
->placeholder( 'Choose a switch port' )
->addClass( 'chzn-select' );
?>
<?php if( $t->ppp ) : ?><?php if( $t->ppp->getSwitchPort() ) : ?><span class="label label-info" style="margin-left: 17%"> Was <?= $t->ppp->getSwitchPort()->getName() ?> </span> <?php endif; ?><?php endif; ?>
</div>

<?php if ( !$t->prewired ): ?>
Expand All @@ -166,6 +169,8 @@ interface is discouraged for lifecycle changes.
->placeholder( 'Choose a customer' )
->addClass( 'chzn-select' );
?>

<?php if( $t->ppp ) : ?><?php if( $t->ppp->getCustomer() ) : ?><span class="label label-info" style="margin-left: 17%"> Was <?= $t->ppp->getCustomer()->getName() ?> </span> <?php endif; ?><?php endif; ?>
</div>
<?php endif; ?>

Expand Down
52 changes: 50 additions & 2 deletions resources/views/patch-panel-port/js/edit.foil.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ function setToday(inputName){
*/
function setSwitchPort(){
let url, datas, option;
let switchId = dd_switch.val();
let switchId = dd_switch.val();
let currentSId = false;
let currentSpId = false;
let spOption = false;
let spOptionset = false;

dd_switch_port.html( "<option value=\"\">Loading please wait</option>\n" ).trigger('change.select2');

Expand All @@ -175,6 +179,13 @@ function setSwitchPort(){
};
<?php endif; ?>

<?php if( $t->ppp ) : ?>
<?php if( $t->ppp->getSwitchPort() ) : ?>
currentSId = <?= $t->ppp->getSwitchPort()->getSwitcher()->getId() ?>;
currentSpId = <?= $t->ppp->getSwitchPort()->getId() ?>;
spOption = `<option value='<?= $t->ppp->getSwitchPort()->getId() ?>' > <?= $t->ppp->getSwitchPort()->getName() ?> ( <?= $t->ppp->getSwitchPort()->resolveType() ?> ) </option>`;
<?php endif; ?>
<?php endif; ?>

$.ajax( url , {
data: datas,
Expand All @@ -183,7 +194,44 @@ function setSwitchPort(){
.done( function( data ) {
options = "<option value=\"\">Choose a switch port</option>\n";
$.each( data.listPorts, function( key, value ){
options += "<option value=\"" + value.id + "\">" + value.name + " (" + value.type + ")</option>\n";

if( currentSId && !spOptionset ){
if( currentSId == switchId ){
if( typeof data.listPorts[ key + 1 ] !== 'undefined' ) {
if (currentSpId < data.listPorts[key]['id'] ) {
spOptionset = true;
options += spOption;
}
}
}
}

options += "<option value=\"" + value.id + "\">" + value.name + " (" + value.type + ")</option>\n"

if( currentSId && !spOptionset ){
if( currentSId == switchId ){
if( typeof data.listPorts[ key + 1 ] !== 'undefined' ){
if( ( currentSpId > data.listPorts[ key ][ 'id' ] && currentSpId < data.listPorts[ key + 1 ][ 'id' ] ) ){
spOptionset = true;
options += spOption ;
}
}

}
}

if( currentSId && !spOptionset ){
if( currentSId == switchId ){
if( typeof data.listPorts[ key + 1 ] === 'undefined' ) {
if (currentSpId > data.listPorts[key]['id'] ) {
spOptionset = true;
options += spOption;
}
}
}
}


});
dd_switch_port.html( options );
})
Expand Down

0 comments on commit 007c712

Please sign in to comment.