<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Royal Estate - Free Bootstrap 4 Template by TIM</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700" rel="stylesheet">

    <link rel="stylesheet" href="css/open-iconic-bootstrap.min.css">
    <link rel="stylesheet" href="css/animate.css">

    <link rel="stylesheet" href="css/owl.carousel.min.css">
    <link rel="stylesheet" href="css/owl.theme.default.min.css">
    <link rel="stylesheet" href="css/magnific-popup.css">

    <link rel="stylesheet" href="css/aos.css">

    <link rel="stylesheet" href="css/ionicons.min.css">

    <link rel="stylesheet" href="css/bootstrap-datepicker.css">
    <link rel="stylesheet" href="css/jquery.timepicker.css">


    <link rel="stylesheet" href="css/flaticon.css">
    <link rel="stylesheet" href="css/icomoon.css">
    <link rel="stylesheet" href="css/style.css">
</head>
<body>





<div class="top">
    <div class="container">
        <div class="row d-flex align-items-center">
            <div class="col">
                <p class="social d-flex">
                    <a href="#"><span class="icon-facebook"></span></a>
                    <a href="#"><span class="icon-twitter"></span></a>
                    <a href="#"><span class="icon-google"></span></a>
                    <a href="#"><span class="icon-pinterest"></span></a>
                </p>
            </div>
            <div class="col d-flex justify-content-end">
                <div th:text="${#authentication.name}">
                    The value of the "name" property of the authentication object should appear here.
                </div>
            </div>
        </div>
    </div>
</div>

<nav class="navbar navbar-expand-lg navbar-dark ftco_navbar bg-dark ftco-navbar-light" id="ftco-navbar">
    <div class="container">
        <a class="navbar-brand" href="/">AWESOME<span>lands</span></a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#ftco-nav" aria-controls="ftco-nav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="oi oi-menu"></span> Menu
        </button>

        <div class="collapse navbar-collapse" id="ftco-nav">
            <ul class="navbar-nav ml-auto">
                <li class="nav-item active"><a href="/" class="nav-link">Pocetna strana</a></li>
                <li class="nav-item"><a href="oglasi" class="nav-link">Oglasi</a></li>
                <li class="nav-item"><a href="maintance" class="nav-link">Agenti</a></li>
                <li class="nav-item"><a href="maintance" class="nav-link">O nama</a></li>
                <li class="nav-item"><a href="maintance" class="nav-link">Kontakt</a></li>
                <li sec:authorize="isAnonymous()"  class="nav-item cta"><a href="login" class="nav-link ml-lg-2"><span class="icon-user"></span> Prijava</a></li>

                <li sec:authorize="isAnonymous()"  class="nav-item cta cta-colored"><a href="registration" class="nav-link" ><span class="icon-pencil"></span> Registracija</a></li>
                <li sec:authorize="isAuthenticated()" class="nav-item cta"><a href="dodaj" class="nav-link ml-lg-2"><span class="icon-user"></span> Dodaj Oglas</a></li>
                <li sec:authorize="isAuthenticated()" class="nav-item cta"><a href="/logout" class="nav-link ml-lg-2"><span class="icon-user"></span> Log Out</a></li>

                <!--sec:authorize="isAuthenticated()-->
            </ul>
        </div>
    </div>
</nav>
<!-- Create HTML registration form -->
<div class="container">
    <div class="row">
        <div class="col-md-6 col-md-offset-3">

            <!-- success message -->
            <div th:if="${param.success}">
                <div class="alert alert-info">Uspesno ste se registrovali!</div>
            </div>

            <h1>Dodajte novi oglas</h1>

            <form th:action="@{/dodaj}" method="post" th:object="${user}">
                <div class="form-group">
                    <label class="control-label" for="firstName"> Naziv </label>

                    <input id="firstName" class="form-control" th:field="*{ime}"
                           required autofocus="autofocus" />
                </div>


                    <div class="form-group">
                        <label class="control-label" for="firstName"> Cena </label>
                        <input id="firstName" class="form-control" th:field="*{cena}"
                               required autofocus="autofocus" />
                    </div>
                    <div class="form-group">
                        <label class="control-label" for="firstName"> Kvadratura </label>
                        <input id="firstName" class="form-control" th:field="*{kvadratura}"
                               required autofocus="autofocus" />
                    </div>
                    <div class="form-group">
                        <label class="control-label" for="firstName"> Lokacija </label>
                        <input id="firstName" class="form-control" th:field="*{lokacija}"
                               required autofocus="autofocus" />
                    </div>
                    <div class="form-group">
                        <label class="control-label" for="firstName"> Opis </label>
                        <input id="firstName" class="form-control" th:field="*{opis}"
                               required autofocus="autofocus" />
                    </div>
                    <div>
                        
                        <label for="lista">Tip oglasa:</label>
						
						<select name="tipovi" id="lista">
						  <option value="1">Izdavanje</option>
						  <option value="2">Prodaja</option>
						</select>
                    </div>
                    <script>
                    async function fja()
                    {
                    	alert(document.getElementById("lista").options[document.getElementById("lista").selectedIndex].text);
                    }
                    </script>


                <div style="visibility: hidden;position:absolute;" class="form-group">
                    <label class="control-label" for="firstName"> SLIKA </label>
                    <input id="slika" class="form-control" th:field="*{slika}"
                           required autofocus="autofocus" />
                </div>
                  <div style="visibility: hidden;position:absolute;" class="form-group">
                    <label class="control-label" for="firstName"> SLIKA </label>
                    <input id="listic" class="form-control" th:field="*{tip}"
                           required autofocus="autofocus" />
                </div>


                    <!-- END nav -->
                    <input id="fileupload" type="file" />


                    <button id="upload_button" onclick="uploadFile()" type="submit" class="btn btn-success">Registruj</button>



                        <script>
                            async function uploadFile()
                            {

                                let formData = new FormData();
                                formData.append("file",fileupload.files[0]);

                                document.getElementById('slika').value=fileupload.files[0].name;
								document.getElementById("listic").value=document.getElementById("lista").options[document.getElementById("lista").selectedIndex].text;
                                let response = await fetch('/upload',{
                                    method:'POST',
                                    body:formData
                                });
                                if (response.status!=200)
                                {
                                    alert("NEUSPESNA REGISTRACIJA OGLASA");
                                }

                            }
                            
                        </script>

                <script>
                    async function uploadFilee()
                    {

                        let formData = new FormData();
                        formData.append("file",fileupload.files[0]);
                        console.log(fileupload.files[0]);

                    }
                </script>


                   
                </div>
            </form>
        </div>
    </div>
</div>
</body>
</html>