{#-
       Licensed to the Apache Software Foundation (ASF) under one
       or more contributor license agreements.  See the NOTICE file
       distributed with this work for additional information
       regarding copyright ownership.  The ASF 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.
-#}
{% extends g.theme.master %}

{% if allow_config %}
  {% do g.register_app_js('js/custom-fields.js', app=app) %}
{% endif %}

{% block title %}{{c.project.name}} / {{app.config.options.mount_label}} /  Admin Fields{% endblock %}

{% block header %}{{app.config.options.mount_label}} Admin Fields{% endblock %}

{% block content %}
  {{c.form.display(value=globals, action='set_custom_fields')}}
<h1>Default fields</h1>
<form name="show_fields_in_search" method="POST" action="allow_default_field">
    <table>
        <thead>
        <tr>
            <th>Field name</th>
            <th>Show in list views (e.g. search results, milestone views)</th>
        </tr>
        </thead>
        {%for column, full_name in columns.items() %}
        <tr>
            <td>{{full_name}}</td> <td><input type="checkbox" name="{{column}}" {%if globals.show_in_search[column]%}checked {%endif%}></td>
        </tr>
        {%endfor%}
        <tr><td><input type="submit" value="Save"></td><td></td></tr>
    </table>
    {{lib.csrf_token()}}
</form>
{% endblock %}

{% block extra_css %}
  <style type="text/css">
    div.custom-field {
    cursor: move;
    border:1px solid #ccc;
    margin:2px;
    padding:2px;
    }
  </style>
{% endblock %}

{% block extra_js %}
<script type="text/javascript">
    $(document).ready(function () {
        $(document).on('click', ":radio.default-milestone", function(){
            // page can contain more that one milestone field,
            // so we should touch only radio buttons corresponding to given field
            var parent_table = $(this).closest('table');
            $(":radio.default-milestone", parent_table).prop("checked", false);
            $(this).prop("checked", true);
        });
    });
</script>
{% endblock %}
