<head>
    <meta name="layout" content="main" />
    <title>Create Person</title>
    <nav:resources override="true"/>
</head>

<body>

    <div class="nav">
        <nav:renderSubItems group="navAlt"/>
    </div>

    <div class="body">
        <g:render template="/shared/messages" />
        <g:hasErrors bean="${person}">
        <div class="errors">
            <g:renderErrors bean="${person}" as="list" />
        </div>
        </g:hasErrors>
        <g:form action="save">
            <div class="dialog">
                <table>
                <tbody>

                    <tr class="prop">
                        <td valign="top" class="name"><label for="loginName">Login Name:</label></td>
                        <td valign="top" class="value ${hasErrors(bean:person,field:'loginName','errors')}">
                            <input type="text" id="loginName" name="loginName" value="${person.loginName?.encodeAsHTML()}"/>
                            <g:helpBalloon class="helpballoon" code="person.loginName" />
                        </td>
                    </tr>

                    <tr class="prop">
                        <td valign="top" class="name"><label for="firstName">First Name:</label></td>
                        <td valign="top" class="value ${hasErrors(bean:person,field:'firstName','errors')}">
                            <input type="text" id="firstName" name="firstName" value="${person.firstName?.encodeAsHTML()}"/>
                            <g:helpBalloon class="helpballoon" code="person.firstName" />
                        </td>
                    </tr>

                    <tr class="prop">
                        <td valign="top" class="name"><label for="lastName">Last Name:</label></td>
                        <td valign="top" class="value ${hasErrors(bean:person,field:'lastName','errors')}">
                            <input type="text" id="lastName" name="lastName" value="${person.lastName?.encodeAsHTML()}"/>
                            <g:helpBalloon class="helpballoon" code="person.lastName" />
                        </td>
                    </tr>


                    <tr class="prop">
                        <td valign="top" class="name"><label for="pass">Password:</label></td>
                        <td valign="top" class="value ${hasErrors(bean:person,field:'pass','errors')}">
                            <input type="password" id="pass" name="pass"/>
                            <g:helpBalloon class="helpballoon" code="person.password" />
                        </td>
                    </tr>

                    <tr class="prop">
                        <td valign="top" class="name"><label for="isActive">Active:</label></td>
                        <td valign="top" class="value ${hasErrors(bean:person,field:'isActive','errors')}">
                            <g:checkBox name="isActive" value="${person.isActive}" ></g:checkBox>
                            <g:helpBalloon class="helpballoon" code="person.isActive" />
                        </td>
                    </tr>

                    <tr class="prop">
                        <td valign="top" class="name"><label for="description">Description:</label></td>
                        <td valign="top" class="value ${hasErrors(bean:person,field:'description','errors')}">
                            <input type="text" id="description" name="description" value="${person.description?.encodeAsHTML()}"/>
                        </td>
                    </tr>

                    <tr class="prop">
                        <td valign="top" class="name"><label for="employeeID">employee ID:</label></td>
                        <td valign="top" class="value ${hasErrors(bean:person,field:'employeeID','errors')}">
                            <input type="text" id="employeeID" name="employeeID" value="${person.employeeID?.encodeAsHTML()}"/>
                        </td>
                    </tr>

                    <tr class="prop">
                        <td valign="top" class="name">
                            <label for="department">Department:</label>
                        </td>
                        <td valign="top" class="value ${hasErrors(bean:person,field:'department','errors')}">
                            <g:select optionKey="id" from="${Department.list()}" name="department.id" value="${person?.department?.id}" noSelection="['null':'--None--']"></g:select>
                        </td>
                    </tr>

                    <tr class="prop">
                        <td valign="top" class="name">
                            <label for="personGroups">Groups:</label>
                        </td>
                        <td valign="top" class="value ${hasErrors(bean:person,field:'personGroups','errors')}">
                            <g:helpBalloon class="helpballoon" code="person.personGroups" />
                            <custom:checkBoxList name="personGroups"
                                                            from="${PersonGroup.list().sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }}"
                                                            value="${person?.personGroups?.collect{it.id}}"
                                                            optionKey="id"/>
                        </td>
                    </tr>

                    <tr class="prop">
                        <td valign="top" class="name" align="left">
                            Authorities:
                        </td>
                        <td valign="top" class="name" align="left">
                            <g:helpBalloon class="helpballoon" code="person.authorities" />
                        </td>
                    </tr>

                    <g:each in="${authorityList}">
                    <tr>
                        <td valign="top" class="name" align="left">${it.description.encodeAsHTML()}</td>
                        <td align="left">
                            <g:checkBox name="${it.authority}" value="${it.authority == 'ROLE_AppUser'}"/>
                        </td>
                    </tr>
                    </g:each>

                </tbody>
                </table>
            </div>

            <div class="buttons">
                <span class="button"><input class="save" type="submit" value="Create" /></span>
            </div>

        </g:form>

    </div>
</body>
