<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->

<forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns="http://ofbiz.apache.org/Widget-Form" xsi:schemaLocation="http://ofbiz.apache.org/Widget-Form http://ofbiz.apache.org/dtds/widget-form.xsd">

    <form name="FindVisits" type="single" target="findVisits" title="Find and list party visits"
        header-row-style="header-row" default-table-style="basic-table">
        <field name="noConditionFind"><hidden value="Y"/><!-- if this isn't there then with all fields empty no query will be done --></field>

        <field name="activeOnly"><check /></field>
        <field name="visitId"><text-find ignore-case="true"/></field>
        <field name="visitorId"><text-find ignore-case="true"/></field>
        <field name="partyId"><lookup target-form-name="LookupPartyName"/></field>
        <field name="userLoginId"><text-find ignore-case="true"/></field>
        <field name="userCreated"><date-find type="date"/></field>
        <field name="webappName"><text-find ignore-case="true"/></field>
        <field name="clientIpAddress"><text-find ignore-case="true"/></field>

        <field name="searchButton" title="${uiLabelMap.CommonFind}" widget-style="smallSubmit"><submit button-type="button"/></field>
    </form>

    <grid name="ListVisits" separate-columns="true" title="Visits List" list-name="listIt" target="" default-entity-name="Visit" paginate-target="findVisits"
        odd-row-style="alternate-row" header-row-style="header-row-2" default-table-style="basic-table hover-bar">
        <actions>
            <set field="parameters.sortField" from-field="parameters.sortField" default-value="-visitId"/>
            <service service-name="performFind" result-map="result" result-map-list="listIt">
                <field-map field-name="inputFields" from-field="parameters"/>
                <field-map field-name="entityName" value="Visit"/>
                <field-map field-name="orderBy" from-field="parameters.sortField"/>
                <field-map field-name="viewIndex" from-field="viewIndex"/>
                <field-map field-name="viewSize" from-field="viewSize"/>
                <field-map field-name="filterByDate" from-field="parameters.activeOnly"/>
            </service>
        </actions>
        <row-actions>
            <entity-condition entity-name="UserLoginHistory" list="userLoginHistoryList">
                <condition-list>
                    <condition-expr field-name="visitId" from-field="visitId"/>
                </condition-list>
                <select-field field-name="userLoginId"/>
            </entity-condition>
            <set field="impersonateUserLoginId" from-field="userLoginHistoryList[0].originUserLoginId" type="String"/>
        </row-actions>
        <field name="visitId" widget-style="buttontext" sort-field="true">
            <hyperlink description="${visitId}" target="visitdetail">
                <parameter param-name="visitId"/>
            </hyperlink>
        </field>
        <field name="visitorId" title="${uiLabelMap.PartyVisitorId}" sort-field="true"><display/></field>
        <field name="partyId" widget-style="buttontext" sort-field="true">
            <hyperlink description="${partyId}" target="viewprofile">
                <parameter param-name="partyId"/>
            </hyperlink>
        </field>
        <field name="userLoginId" title="${uiLabelMap.CommonUserLoginId}" sort-field="true"><display/></field>
        <field name="impersonateUserLoginId" title="${uiLabelMap.CommonImpersonateUserLogin}"><display/></field>
        <field name="userCreated" title="${uiLabelMap.PartyNewUser}" sort-field="true"><display/></field>
        <field name="webappName" title="${uiLabelMap.PartyWebApp}" sort-field="true"><display/></field>
        <field name="clientIpAddress" title="${uiLabelMap.PartyClientIP}" sort-field="true"><display/></field>
        <field name="fromDate" title="${uiLabelMap.CommonFromDate}" sort-field="true"><display/></field>
        <field name="thruDate" title="${uiLabelMap.CommonThruDate}" sort-field="true"><display/></field>
    </grid>

    <grid name="ListLoggedInUsers" separate-columns="true" title="Visits List" list-name="listIt" target="" default-entity-name="Visit" paginate-target="listLoggedInUsers"
        odd-row-style="alternate-row" header-row-style="header-row-2" default-table-style="basic-table hover-bar">
        <actions>
            <set field="parameters.sortField" from-field="parameters.sortField" default-value="-userLoginId"/>
            <entity-condition entity-name="Visit" list="listIt" distinct="true" filter-by-date="true">
                <condition-expr field-name="userLoginId" operator="not-equals" from-field="null"/>
                <select-field field-name="partyId"/>
                <select-field field-name="userLoginId"/>
                <select-field field-name="clientIpAddress"/>
                <order-by field-name="${parameters.sortField}"/>
            </entity-condition>
        </actions>
        
        <field name="userLoginId" title="${uiLabelMap.CommonUserLoginId}" sort-field="true"><display/></field>
        <field name="partyId" widget-style="buttontext" sort-field="true">
            <hyperlink description="${partyId}" target="viewprofile">
                <parameter param-name="partyId"/>
            </hyperlink>
        </field>
        <field name="clientIpAddress" title="${uiLabelMap.PartyClientIP}" sort-field="true"><display/></field>
    </grid>
</forms>
