{% from 'pagination.jinja2' import render_pagination %}
{% extends "layout.jinja2" %}

{% block content %}

<div class="content">
    <div class="row">
        <div class="col-xs-12">
            <h2>Well Configuration</h2>
            <form>
                <div class="form-group">
                    <label for="pocIPAddress">POC IP Address</label>
                    <input type="text" class="form-control" id="pocIPAddress" value="{{pocIPAddress}}">
                </div>
                <hr />
                <div class="alert alert-success alert-dismissable hidden" id="update-success">
                    <span>
                        <p>Address successfully updated!</p>
                    </span>
                </div>
                <div class="alert alert-danger alert-dismissable hidden" id="update-failed">
                    <span>
                        <p>Failed to update address.</p>
                    </span>
                </div>
                <button id="submit" class="btn btn-default">Update Address</button>
            </form>
        </div>
    </div>
</div>

<script>

function configUpdatedSuccessfully(data){
    console.log(data);
    if(data.status == "OK"){
        $('#update-success').removeClass('hidden');
    } else {
        $('#update-failed').removeClass('hidden');
    }
}

$("#submit").click(function(event){
    event.preventDefault();
    $('#update-success').addClass('hidden');
    $('#update-failed').addClass('hidden');
    var newObject = {};
    newObject.pocIPAddress = $("#pocIPAddress").val();
    $.ajax({
        type: "POST",
        dataType: 'json',
        data: JSON.stringify(newObject),
        contentType: "application/json; charset=utf-8",
        url: "/json/updatepocaddress",
        success: configUpdatedSuccessfully
    });
})
</script>
{% endblock content %}
