<?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="NewAccount" type="single" target="createAccount" header-row-style="header-row" default-table-style="basic-table">
        <field name="accountType"><hidden value="${accountType}"/></field>
        <field name="groupName" title="${uiLabelMap.PartyGroupName}" required-field="true">
            <text size="30" maxlength="60"/>
        </field>
        <field name="numEmployees" title="${uiLabelMap.MarketingNoOfEmployees}"><text size="30"/></field>
        <field name="siteName" title="${uiLabelMap.FormFieldTitle_officeSiteName}"><text size="30" maxlength="60"/></field>
        <field name="postalAddressTitle" title="${uiLabelMap.PartyGeneralCorrespondenceAddress}" title-area-style="group-label">
            <display description=" " also-hidden="false"/>
        </field>
        <field name="address1" title="${uiLabelMap.CommonAddress1}" required-field="true">
            <text size="50" maxlength="60"/>
        </field>
        <field name="address2" title="${uiLabelMap.CommonAddress2}"><text size="50" maxlength="60"/></field>
        <field name="city" required-field="true">
            <text size="30" maxlength="60"/>
        </field>
        <field name="stateProvinceGeoId" title="${uiLabelMap.CommonState}" required-field="true">
            <drop-down allow-empty="true">
                <entity-options entity-name="Geo" key-field-name="geoId" description="${geoName} - ${geoId}">
                    <entity-constraint name="geoTypeId" operator="in" value="STATE,PROVINCE"/>
                    <entity-order-by field-name="geoName"/>
                </entity-options>
            </drop-down>
        </field>
        <field name="postalCode" title="${uiLabelMap.CommonZipPostalCode}" required-field="true">
            <text size="10" maxlength="30"/>
        </field>
        <field name="stateProvinceGeoId" title="${uiLabelMap.CommonState}" required-field="true"><drop-down allow-empty="false"/></field>
        <field name="countryGeoId" title="${uiLabelMap.CommonCountry}" required-field="true">
            <drop-down no-current-selected-key="${defaultCountryGeoId}">
                <entity-options entity-name="Geo" key-field-name="geoId" description="${geoName} - ${geoId}">
                    <entity-constraint name="geoTypeId" value="COUNTRY"/>
                    <entity-order-by field-name="geoName"/>
                </entity-options>
            </drop-down>
        </field>
        <field name="phoneTitle" title="${uiLabelMap.PartyPrimaryPhone}" title-area-style="group-label"><display/></field>
        <field name="countryCode" title="${uiLabelMap.CommonCountryCode}"><text size="4" maxlength="10"/></field>
        <field name="areaCode" title="${uiLabelMap.PartyAreaCode}"><text size="4" maxlength="10"/></field>
        <field name="contactNumber" title="${uiLabelMap.PartyPhoneNumber}"><text size="15" maxlength="15"/></field>
        <field name="extension" title="${uiLabelMap.PartyContactExt}"><text size="6" maxlength="10"/></field>
        <field name="emailAddressTitle" title="${uiLabelMap.PartyEmailAddress}" title-area-style="group-label"><display/></field>
        <field name="emailAddress" title="${uiLabelMap.CommonEmail}"><text size="50" maxlength="60"/></field>
        <field name="submitButton" title="${uiLabelMap.CommonSave}" widget-style="smallSubmit"><submit button-type="button"/></field>
    </form>

    <form name="FindAccounts" id="FindAccounts" target="${currentUrl}" title="" type="single" default-map-name="parameters"
        header-row-style="header-row" default-table-style="basic-table">
        <field name="all"><hidden/></field>
        <field name="partyId" title="${uiLabelMap.PartyPartyId}"><text-find/></field>
        <field name="groupName" title="${uiLabelMap.PartyPartyGroupName}"><text-find/></field>
        <field name="contactMechTypeId" event="onchange" action="javascript:ajaxUpdateAreas('contactMechContainer,ContactMechTypeOnly,contactMechTypeId=' + this.value);">
            <drop-down>
                <option key="" description="${uiLabelMap.CommonNone}"/>
                <entity-options entity-name="ContactMechType" key-field-name="contactMechTypeId"/>
            </drop-down>
        </field>
        <field name="contactMechContainer" id-name="contactMechContainer" title=" "><container/></field>
        <field name="noConditionFind"><hidden value="Y"/><!-- if this isn't there then with all fields empty no query will be done --></field>
        <field name="submitButton" title="${uiLabelMap.CommonFind}" widget-style="smallSubmit">
            <submit button-type="button"/>
        </field>
    </form>
    <form name="ListAccounts" paginate-target="${currentUrl}" type="list" list-name="listIt"
        odd-row-style="alternate-row" header-row-style="header-row-2" default-table-style="basic-table hover-bar" separate-columns="true">
        <actions>
            <set field="roleTypeIdFrom" value="OWNER"/>
            <set field="roleTypeIdTo" value="ACCOUNT"/>
            <set field="relatedCompanyRoleTypeIdTo" value="ACCOUNT"/>
            <set field="relatedCompanyRoleTypeIdFrom" value="ACCOUNT"/>
            <set field="parameters.statusId" value="PARTY_DISABLED"/>
            <set field="parameters.statusId_op" value="notEqual"/>
            <set field="partyRelationshipTypeId" value="ACCOUNT"/>
            <set field="parameters.roleTypeId" from-field="roleTypeIdTo"/>
            <set field="fieldList" value="${groovy:['partyId','roleTypeId']}" type="List"/>
            <service service-name="performFind">
                <field-map field-name="inputFields" from-field="parameters"/>
                <field-map field-name="entityName" value="PartyRoleAndContactMechDetail"/>
                <field-map field-name="orderBy" value="partyId"/>
                <field-map field-name="distinct" value="Y"/>
            </service>
        </actions>
        <row-actions>
            <entity-one entity-name="Party" value-field="party" use-cache="true"/>
            <set field="partyName" value="${groovy:org.apache.ofbiz.party.party.PartyHelper.getPartyName(party, true)}"/>
            <entity-and entity-name="PartyAndContactMech" list="emailAddresses" filter-by-date="true">
                <field-map field-name="partyId"/>
                <field-map field-name="contactMechTypeId" value="EMAIL_ADDRESS"/>
            </entity-and>
            <entity-and entity-name="PartyAndContactMech" list="telecomNumbers" filter-by-date="true">
                <field-map field-name="partyId"/>
                <field-map field-name="contactMechTypeId" value="TELECOM_NUMBER"/>
            </entity-and>
            <set field="telecomNumber" from-field="telecomNumbers[0]" type="Object"/>
            <entity-and entity-name="PartyAndContactMech" list="postalAddresses" filter-by-date="true">
                <field-map field-name="partyId"/>
                <field-map field-name="contactMechTypeId" value="POSTAL_ADDRESS"/>
            </entity-and>
            <set field="postalAddress" from-field="postalAddresses[0]" type="Object"/>
            <entity-and entity-name="PartyRelationship" list="existRelationships" filter-by-date="true">
                <field-map field-name="roleTypeIdTo"/>
                <field-map field-name="partyRelationshipTypeId"/>
                <field-map field-name="partyIdFrom" from-field="userLogin.partyId"/>
                <field-map field-name="partyIdTo" from-field="partyId"/>
            </entity-and>
            <set field="countryGeoId" from-field="postalAddress.paCountryGeoId"/>
            <entity-and entity-name="PartyRelationship" list="relatedCompanies" filter-by-date="true">
                <field-map field-name="partyIdTo" from-field="partyId"/>
                <field-map field-name="roleTypeIdFrom" from-field="relatedCompanyRoleTypeIdFrom"/>
                <field-map field-name="roleTypeIdTo" from-field="relatedCompanyRoleTypeIdTo"/>
                <field-map field-name="partyRelationshipTypeId" from-field="relatedCompanyRelationshipTypeId"/>
            </entity-and>
            <set field="relatedCompanyPartyId" from-field="relatedCompanies[0].partyIdFrom" type="Object"/>
            <set field="existRelationship" from-field="existRelationships[0]"/>
        </row-actions>
        <field name="partyId" title="${uiLabelMap.PartyPartyId}" use-when="roleTypeId!=null&amp;roleTypeId=='ACCOUNT'" widget-style="buttontext">
            <hyperlink description="${partyName} [${partyId}]" target="ViewAccountProfile">
                <parameter param-name="partyId"/>
            </hyperlink>
        </field>
        <field name="partyId" title="${uiLabelMap.PartyPartyId}" use-when="roleTypeId!=null&amp;roleTypeId=='CONTACT'" widget-style="buttontext">
            <hyperlink description="${partyName} [${partyId}]" target="ViewContactProfile">
                <parameter param-name="partyId"/>
            </hyperlink>
        </field>
        <field name="partyId" title="${uiLabelMap.PartyPartyId}" use-when="roleTypeId!=null&amp;roleTypeId=='LEAD'" widget-style="buttontext">
            <hyperlink description="${partyName} [${partyId}]" target="ViewLeadProfile">
                <parameter param-name="partyId"/>
            </hyperlink>
        </field>
        <field name="partyId" title="${uiLabelMap.PartyPartyId}" use-when="roleTypeId!=null&amp;roleTypeId=='ACCOUNT_LEAD'" widget-style="buttontext">
            <hyperlink description="${partyName} [${partyId}]" target="ViewAccountLeadProfile">
                <parameter param-name="partyId"/>
            </hyperlink>
        </field>
        <field name="emailAddress"><display description="${emailAddresses[0].infoString}"/></field>
        <field name="telecomNumber" title="${uiLabelMap.PartyPhoneNumber}">
            <display description="${telecomNumber.tnCountryCode} ${telecomNumber.tnAreaCode} ${telecomNumber.tnContactNumber} ${telecomNumber.tnAskForName}"/>
        </field>
        <field name="city"><display description="${postalAddress.paCity}"/></field>
        <field name="countryGeoId" title="${uiLabelMap.FormFieldTitle_country}">
            <display-entity entity-name="Geo" description="${geoName}" key-field-name="geoId"/>
        </field>
        <field name="relatedCompany" use-when="relatedCompanyPartyId!=null" title="${uiLabelMap.PartyRelatedCompany}">
            <hyperlink description="${groovy:org.apache.ofbiz.party.party.PartyHelper.getPartyName(delegator,relatedCompanyPartyId,true);} [${relatedCompanyPartyId}]" target="viewprofile">
                <parameter param-name="partyId" from-field="relatedCompanyPartyId"/>
            </hyperlink>
        </field>
        <field name="relatedCompany" use-when="relatedCompanyPartyId==null" title="${uiLabelMap.PartyRelatedCompany}"><display/></field>
    </form>
    <form name="ListAccounts" extends="ListAccounts">
        <field name="assignToMe" use-when="existRelationship==null&amp;&amp;!&quot;false&quot;.equals(parameters.get(&quot;all&quot;))"
                title="${uiLabelMap.SfaAssignToMe}" widget-style="buttontext">
            <hyperlink description="${uiLabelMap.SfaAssignToMe}" target="createPartyRelationshipAndRole">
                <parameter param-name="partyIdFrom" from-field="userLogin.partyId"/>
                <parameter param-name="roleTypeIdFrom"/>
                <parameter param-name="roleTypeIdTo"/>
                <parameter param-name="partyRelationshipTypeId"/>
                <parameter param-name="partyIdTo" from-field="partyId"/>
            </hyperlink>
        </field>
        <field name="relatedCompany"><hidden/></field>
        <sort-order>
            <sort-field name="partyId"/>
            <sort-field name="emailAddress"/>
            <sort-field name="telecomNumber"/>
            <sort-field name="city"/>
            <sort-field name="countryGeoId"/>
            <sort-field name="assignToMe"/>
            <sort-field name="relatedCompany"/>
        </sort-order>
    </form>
    <form name="ListMyAccounts" extends="ListAccounts">
        <actions>
            <set field="parameters.partyIdFrom" from-field="userLogin.partyId"/>
            <set field="parameters.roleTypeIdFrom" value="OWNER"/>
            <set field="parameters.roleTypeIdTo" value="ACCOUNT"/>
            <set field="parameters.partyStatusId" value="PARTY_DISABLED"/>
            <set field="parameters.partyStatusId_op" value="notEqual"/>
            <set field="parameters.partyRelationshipTypeId" value="ACCOUNT"/>
            <set field="fieldList" value="${groovy:['partyIdFrom','partyId']}" type="List"/>
            <set field="parameters.filterByDate" value="Y"/>
            <service service-name="performFind">
                <field-map field-name="inputFields" from-field="parameters"/>
                <field-map field-name="entityName" value="PartyRelationshipAndContactMechDetail"/>
                <field-map field-name="orderBy" value="partyId"/>
                <field-map field-name="distinct" value="Y"/>
            </service>
        </actions>
        <field name="assignToMe"><hidden/></field>
    </form>

    <form name="FindPostalAddress" type="single">
        <field name="paToName" title="${uiLabelMap.PartyAddrToName}"><text-find/></field>
        <field name="paAttnName" title="${uiLabelMap.PartyAddrAttnName}"><text-find/></field>
        <field name="paAddress1" title="${uiLabelMap.FormFieldTitle_paAddress1}"><text-find/></field>
        <field name="paAddress2" title="${uiLabelMap.FormFieldTitle_paAddress2}"><text-find/></field>
        <field name="paCity" title="${uiLabelMap.FormFieldTitle_city}"><text-find/></field>
        <field name="paStateProvinceGeoId" title="${uiLabelMap.FormFieldTitle_stateProvince}">
            <drop-down allow-empty="true">
                <list-options key-name="geoId" description="${geoName}" list-name="states"/>
            </drop-down>
        </field>
        <field name="paPostalCode"><text-find/></field>
        <field name="paCountryGeoId" title="${uiLabelMap.CommonCountry}">
            <drop-down allow-empty="true">
                <list-options key-name="geoId" description="${geoName}" list-name="countries"/>
            </drop-down>
        </field>
    </form>
    <form name="FindTelecomNumber" type="single">
        <field name="tnCountryCode" title="${uiLabelMap.CommonCountryCode}"><text-find/></field>
        <field name="tnAreaCode" title="${uiLabelMap.PartyAreaCode}"><text-find/></field>
        <field name="tnContactNumber" title="${uiLabelMap.PartyContactNumber}"><text-find/></field>
        <field name="tnExtension" title="${uiLabelMap.PartyExtension}"><text-find/></field>
    </form>
    <form name="FindInfoStringContactMech" type="single">
        <actions>
            <entity-one entity-name="ContactMechType" value-field="contactMechType">
                <field-map field-name="contactMechTypeId" from-field="parameters.contactMechTypeId"/>
            </entity-one>
        </actions>
        <field name="infoString" title="${contactMechType.description}"><text-find/></field>
    </form>

    <form name="ListAccountLeads" extends="ListAccounts">
        <actions>
            <set field="roleTypeIdTo" value="ACCOUNT_LEAD"/>
            <set field="parameters.statusId" value="PARTY_DISABLED"/>
            <set field="parameters.statusId_op" value="notEqual"/>
            <set field="partyRelationshipTypeId" value="ACCOUNT"/>
            <set field="parameters.roleTypeId" from-field="roleTypeIdTo"/>
            <set field="fieldList" value="${groovy:['partyId','roleTypeId']}" type="List"/>
            <service service-name="performFind">
                <field-map field-name="inputFields" from-field="parameters"/>
                <field-map field-name="entityName" value="PartyRoleAndContactMechDetail"/>
                <field-map field-name="orderBy" value="partyId"/>
                <field-map field-name="distinct" value="Y"/>
            </service>
        </actions>
    </form>
</forms>
