<?php
/**
 * COmanage Match Permissions Fields
 *
 * Portions licensed to the University Corporation for Advanced Internet
 * Development, Inc. ("UCAID") under one or more contributor license agreements.
 * See the NOTICE file distributed with this work for additional information
 * regarding copyright ownership.
 *
 * UCAID licenses this file to you under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @link          http://www.internet2.edu/comanage COmanage Project
 * @package       match
 * @since         COmanage Match v1.0.0
 * @license       Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
 */

use \App\Lib\Enum\PermissionEnum;
?>
<script type="text/javascript">
  // JS specific to these fields
  
  function fields_update_gadgets() {
    // Hide or show gadgets according to current state
    
    var perm = document.getElementById('permission').value;
    
    if(perm == '<?= PermissionEnum::PlatformAdmin ?>') {
      $("#matchgrid-id").closest('li').hide();
      // Blank out Matchgrid ID
      document.getElementById('matchgrid-id').selectedIndex = 0;
    } else {
      $("#matchgrid-id").closest('li').show();
    }
  }
  
  function js_local_onload() {
    fields_update_gadgets();
  }
</script>
<?php
// This view does not support read-only
if($action == 'add' || $action == 'edit') {
  print $this->Field->control('username');
  
  print $this->Field->control('permission',
                              ['empty' => true,
                               'onChange' => 'fields_update_gadgets();']);
  
  print $this->Field->control('matchgrid_id', ['empty' => true]);
}