﻿<ProcessDefinition Version="13" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <Namespaces>
    <Namespace Prefix="forms" NamespaceURI="http://schemas.emakin.com" SchemaLocation="http://schemas.emakin.com" />
  </Namespaces>
  <Pools>
    <Pool Id="2e6009b4-12da-45c1-a20a-cad25149a0cf" Name="Signed Approval" RootElement="Contract" DefaultForm="70efe7cd-b226-4c86-a1f5-cd337476d080">
      <Tasks>
        <Task Id="0b57c51c-fb84-4328-b3b1-97be2b880a69" Name="Submit Contract" Caption="Submit Contract" IsInitiator="True" Module="Automation">
          <Actions>
            <Action Id="4cc571ed-cd10-4598-a151-599a34d1134e" Name="Submit" Caption="Submit" ValidationGroup="Submit">
              <Routes>
                <Route Id="b2058f2a-c822-466c-b81a-23506eacd85f" Target="4f024a07-8642-44ef-b6bb-0ae8e637f608" />
              </Routes>
            </Action>
          </Actions>
          <Configurations>
            <User Form="70efe7cd-b226-4c86-a1f5-cd337476d080" DeadlineNotify="False" AllowDefaultPrint="False" AllowForward="False" AllowDelegation="False">
              <Instructions><![CDATA[Attach the PDF documents to approve, then submit them.]]></Instructions>
              <FormSections>
                <FormSection Name="Documents" State="Default" />
                <FormSection Name="Signer" State="Hidden" />
              </FormSections>
            </User>
          </Configurations>
        </Task>
        <Task Id="4f024a07-8642-44ef-b6bb-0ae8e637f608" Name="Approve Contract" Caption="Approve Contract" Module="Automation">
          <Actions>
            <Action Id="a2b4e4e4-c398-4e5e-9ab8-a8af951bf7f7" Name="Approve" Caption="Approve and Sign">
              <SelectScript>
                <Content><![CDATA[const files = $Xml.SelectAll('Documents/File');

if (files.length === 0) {
    alert('There is no document to sign.');
    return false;
}

try {
    const result = await AltiKare.Signature.signFiles(files, 'BES', '');

    if (!result) {
        // the user closed the signing dialog
        return false;
    }

    $Xml.SetValue('Signer/Name', result.certificateName);
    $Xml.SetValue('Signer/SerialNumber', result.certificateSerialNumber);

    return true;
} catch (err) {
    alert('Signing failed: ' + err.message);
    return false;
}]]></Content>
              </SelectScript>
            </Action>
            <Action Id="2ab2429b-4428-4a59-bef0-577bb3531e7f" Name="Reject" Caption="Reject" Order="1" Comment="Required" />
          </Actions>
          <PostWork>
            <Content><![CDATA[if ($WorkItem.SelectedAction == 'Approve') {
    $Xml.SelectAll('Documents/File', function (file) {
        var result = $Crypto.VerifyFile(file.Evaluate(), 'Pades');

        if (!result.AllValid) {
            throw new Error('The document ' + file.GetAttribute('Caption') + ' does not have a valid signature.');
        }
    });
}]]></Content>
          </PostWork>
          <Configurations>
            <User Role="82e304ed-cd55-43dd-9456-5738025f7930" Form="70efe7cd-b226-4c86-a1f5-cd337476d080" DeadlineNotify="False" AllowDefaultPrint="False" AllowForward="False" AllowDelegation="False">
              <Instructions><![CDATA[Review the documents. Approve and sign them with your electronic signature, or reject them with a comment.]]></Instructions>
              <FormSections>
                <FormSection Name="Documents" />
                <FormSection Name="Signer" />
              </FormSections>
            </User>
          </Configurations>
        </Task>
      </Tasks>
      <Roles>
        <Role Id="82e304ed-cd55-43dd-9456-5738025f7930" Name="Approver" Caption="Approver" />
      </Roles>
      <Forms>
        <Form Id="70efe7cd-b226-4c86-a1f5-cd337476d080" Name="Contract Form" Caption="Contract Form">
          <Contents>
            <RowContent Type="Section" SectionName="Documents">
              <Label>
                <Content><![CDATA[Documents]]></Content>
              </Label>
              <Columns>
                <Column WidthXS="12" WidthSM="12" WidthMD="12" WidthLG="12">
                  <Controls>
                    <FileList RequiredForGroup="Submit" Accept=".pdf" XPath="Documents">
                      <Hints><![CDATA[Attach the PDF documents to be signed.]]></Hints>
                    </FileList>
                  </Controls>
                </Column>
              </Columns>
            </RowContent>
            <RowContent Type="Section" SectionName="Signer">
              <Label>
                <Content><![CDATA[Signer]]></Content>
              </Label>
              <Columns>
                <Column WidthXS="12" WidthSM="6" WidthMD="6" WidthLG="6">
                  <Controls>
                    <TextBox XPath="Signer/Name">
                      <PlaceHolder><![CDATA[Signer name]]></PlaceHolder>
                    </TextBox>
                  </Controls>
                </Column>
                <Column WidthXS="12" WidthSM="6" WidthMD="6" WidthLG="6">
                  <Controls>
                    <TextBox XPath="Signer/SerialNumber">
                      <PlaceHolder><![CDATA[Signer serial number]]></PlaceHolder>
                    </TextBox>
                  </Controls>
                </Column>
              </Columns>
            </RowContent>
          </Contents>
          <Script>
            <Content><![CDATA[]]></Content>
          </Script>
        </Form>
      </Forms>
    </Pool>
  </Pools>
  <AccessScopes />
  <Reports />
  <XmlSchemas>
    <xs:schema elementFormDefault="qualified">
      <xs:element name="Contract">
        <xs:complexType>
          <xs:sequence>
            <xs:element minOccurs="0" name="Documents">
              <xs:complexType>
                <xs:sequence>
                  <xs:element minOccurs="0" maxOccurs="unbounded" name="File">
                    <xs:complexType>
                      <xs:simpleContent>
                        <xs:extension base="xs:string">
                          <xs:attribute name="Caption" type="xs:string" />
                          <xs:attribute name="Url" type="xs:string" />
                          <xs:attribute name="Revision" type="xs:string" />
                          <xs:attribute name="HasFileRevision" type="xs:string" />
                        </xs:extension>
                      </xs:simpleContent>
                    </xs:complexType>
                  </xs:element>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
            <xs:element minOccurs="0" name="Signer">
              <xs:complexType>
                <xs:sequence>
                  <xs:element minOccurs="0" name="Name" type="xs:string" />
                  <xs:element minOccurs="0" name="SerialNumber" type="xs:string" />
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>
  </XmlSchemas>
  <ExternalXmlSchemas />
  <Localization>
    <Translations>
      <Translation Name="Instructions" Entity="True">
        <Locations>
          <Location><![CDATA[//Route/Instructions]]></Location>
          <Location><![CDATA[//Task/Configurations/User/Instructions]]></Location>
        </Locations>
      </Translation>
      <Translation Name="TaskName" Entity="True">
        <Locations>
          <Location><![CDATA[//Task/@Caption]]></Location>
        </Locations>
      </Translation>
      <Translation Name="ActionName" Entity="True">
        <Locations>
          <Location><![CDATA[//Action/@Caption]]></Location>
        </Locations>
      </Translation>
      <Translation Name="DashboardName" Entity="False">
        <Locations>
          <Location><![CDATA[//Screen[@IsDashboard = 'True']/@Name]]></Location>
        </Locations>
      </Translation>
      <Translation Name="FormCaption" Entity="False">
        <Locations>
          <Location><![CDATA[//Form/@Caption]]></Location>
          <Location><![CDATA[//Screen/@Caption]]></Location>
        </Locations>
      </Translation>
      <Translation Name="Variable" Entity="True">
        <Locations>
          <Location><![CDATA[//Pool/Variables/Variable]]></Location>
        </Locations>
      </Translation>
      <Translation Name="RoleName" Entity="False">
        <Locations>
          <Location><![CDATA[//Pool/Roles/Role/@Caption]]></Location>
        </Locations>
      </Translation>
      <Translation Name="ActionConfirmation" Entity="False">
        <Locations>
          <Location><![CDATA[//Action/ConfirmationMessage]]></Location>
        </Locations>
      </Translation>
      <Translation Name="Template" Entity="False">
        <Locations>
          <Location><![CDATA[//Templates/Template/Content]]></Location>
        </Locations>
      </Translation>
      <Translation Name="TemplateSubject" Entity="False">
        <Locations>
          <Location><![CDATA[//Templates/Template/Subject]]></Location>
        </Locations>
      </Translation>
      <Translation Name="Label" Entity="True">
        <Locations>
          <Location><![CDATA[//Label/Content]]></Location>
        </Locations>
      </Translation>
      <Translation Name="Literal" Entity="False">
        <Locations>
          <Location><![CDATA[//AddNewLabel/Content]]></Location>
          <Location><![CDATA[//Column/@Caption]]></Location>
          <Location><![CDATA[//Column/Caption]]></Location>
          <Location><![CDATA[//Column/Properties/@Caption]]></Location>
          <Location><![CDATA[//DataExchange/Columns/Column/Caption]]></Location>
          <Location><![CDATA[//Footer/Content]]></Location>
          <Location><![CDATA[//LineChart/Title/Content]]></Location>
          <Location><![CDATA[//LineChart/XAxisLabel/Content]]></Location>
          <Location><![CDATA[//LineChart/YAxisLabel/Content]]></Location>
          <Location><![CDATA[//Literal/Content]]></Location>
          <Location><![CDATA[//PieChart/Title/Content]]></Location>
        </Locations>
      </Translation>
      <Translation Name="Html" Entity="False">
        <Locations>
          <Location><![CDATA[//Html/Content]]></Location>
        </Locations>
      </Translation>
      <Translation Name="XPath" Entity="False">
        <Locations>
          <Location><![CDATA[//LineChart/Lines/Line/LabelXPath]]></Location>
          <Location><![CDATA[//PieChart/Pies/Pie/LabelXPath]]></Location>
          <Location><![CDATA[//PieChart/Pies/Pie/ValueUnitXPath]]></Location>
        </Locations>
      </Translation>
      <Translation Name="FieldHint" Entity="False">
        <Locations>
          <Location><![CDATA[//Hints]]></Location>
        </Locations>
      </Translation>
      <Translation Name="PlaceHolder" Entity="False">
        <Locations>
          <Location><![CDATA[//PlaceHolder]]></Location>
        </Locations>
      </Translation>
      <Translation Name="ListItem" Entity="True">
        <Locations>
          <Location><![CDATA[//Items/Item/Text]]></Location>
        </Locations>
      </Translation>
      <Translation Name="Transforms" Entity="False">
        <Locations>
          <Location><![CDATA[//Form//Query/Columns/Column/Transforms/Transform/TransformValue]]></Location>
        </Locations>
      </Translation>
    </Translations>
    <Languages />
  </Localization>
</ProcessDefinition>