#{extends 'main.html' /}
#{set title:'Home' /}

<h1>Welcome to logisima-play-neo4j test application</h1>

#{menu/}

<h2>Profile of ${user.login}</h2>
<ul>
    <li><strong>Login : </strong> ${user.login}</li>
    <li><strong>Firstanme : </strong> ${user.firstname}</li>
    <li><strong>Lastname : </strong> ${user.lastname}</li>
    <li><strong>Email : </strong> ${user.email}</li>
    <li><strong>Age : </strong> ${user.age}</li>
    <li><strong>Birthdate: </strong> ${user.birthday?.format('dd/MM/yyyy')}</li>
    <li><strong>Is active : </strong> #{if user.isActive} TRUE#{/if}#{else}FALSE#{/else}</li>
    <li><strong>Dev. score : </strong> ${user.devScore}</li>
    <li><strong>Avatar : </strong> <img src="@{application.userAvatar(user.key)}" /></li>
    
    #{if user.friends.size() > 0}
        <li>
            <strong>Friends :</strong>
            #{list items:user.friends, as:'friend'}
                <form action="@{Application.userDeleteRelation()}">
                    <input type="hidden" name="type" value="1" />
                    <input type="hidden" name="key" value="${user.key}" />
                    <input type="hidden" name="related" value="${friend.key}" />
                    <a href="@{Application.user(friend.key)}">${friend.firstname} ${friend.lastname}</a>&nbsp;
                    <input type="image" src="@{'/public/images/cross.png'}" />
                 </form>
            #{/list}
        </li>
    #{/if}
    #{if user.famillies.size() > 0}
    <li>
        <strong>Famillies :</strong>
        #{list items:user.famillies, as:'familly'}
            <form action="@{Application.userDeleteRelation()}">
                <input type="hidden" name="type" value="2" />
                <input type="hidden" name="key" value="${user.key}" />
                <input type="hidden" name="related" value="${familly.key}" />
                <a href="@{Application.user(familly.key)}">${familly.firstname} ${familly.lastname}</a>&nbsp;
                <input type="image" src="@{'/public/images/cross.png'}" />
            </form>
        #{/list}
    </li>
    #{/if}
    #{if user.colleages.size() > 0}
    <li>
        <strong>Colleages :</strong>
        #{list items:user.colleages, as:'colleage'}
            <form action="@{Application.userDeleteRelation()}">
                <input type="hidden" name="type" value="3" />
                <input type="hidden" name="key" value="${user.key}" />
                <input type="hidden" name="related" value="${colleage.key}" />
                <a href="@{Application.user(colleage.key)}">${colleage.firstname} ${colleage.lastname}</a>&nbsp;
                <input type="image" src="@{'/public/images/cross.png'}" />
             </form>
             <ul>
             #{list items:colleage.colleages, as:'colleage2'}
                <li>
                     <a href="@{Application.user(colleage2.key)}">${colleage2.firstname} ${colleage2.lastname}</a>&nbsp;
                     <ul>
                         #{list items:colleage2.colleages, as:'colleage3'}
                             <li>
                                <a href="@{Application.user(colleage3.key)}">${colleage3.firstname} ${colleage3.lastname}</a>&nbsp;
                             </li>
                         #{/list}
                     </ul>     
                </li>
             #{/list}
             </ul>
        #{/list}
    </li>
    #{/if}
    #{if user.classmates.size() > 0}
    <li>
        <strong>Classmates (${user.classmates.size()}):</strong>
        #{list items:user.classmates, as:'classmate'}
            <form action="@{Application.userDeleteRelation()}">
                <input type="hidden" name="type" value="4" />
                <input type="hidden" name="key" value="${user.key}" />
                <input type="hidden" name="related" value="${classmate.key}" />
                <a href="@{Application.user(classmate.key)}">${classmate.firstname} ${classmate.lastname}</a>&nbsp;
                <input type="image" src="@{'/public/images/cross.png'}" />
             </form>
             <ul>
             #{list items:classmate.classmates, as:'classmate2'}
                <li>
                     <a href="@{Application.user(classmate2.key)}">${classmate2.firstname} ${classmate2.lastname}</a>&nbsp;
                     <ul>
                         #{list items:classmate2.classmates, as:'classmate3'}
                             <li>
                                <a href="@{Application.user(classmate3.key)}">${classmate3.firstname} ${classmate3.lastname}</a>&nbsp;
                             </li>
                         #{/list}
                     </ul>     
                </li>
             #{/list}
             </ul>
        #{/list}
    </li>
    #{/if}
</ul>

<h3>Adding relation</h3>
<form action="@{Application.searchUserRelation()}" method="POST">
    <label for="query">Search a user :</label> 
    <input type="text"  name="query" id="query" />
    <input type="hidden" name="key" value=${user.key} />
    <input type="submit" value="Search" />
</form>

<ul>
    #{list items:users, as:'related'}
        <li>
            <form action="@{Application.userAddRelation()}" method="POST">
                <input type="hidden" name="key" value=${user.key} />
                <input type="hidden" name="related" value=${related.key} />
                <a href="@{Application.user(related.key)}">${related.firstname} ${related.lastname}</a>&nbsp;
                <select name="type">
                    <option value="1" selected="selected">Friend</option>
                    <option value="2" selected="selected">Familly</option>
                    <option value="3" selected="selected">Colleage</option>
                    <option value="4" selected="selected">Clasmate</option>
                </select>
                <input type="submit" value="Related" />
            </form>
        </li>
    #{/list}
</ul>