<%args>
    $type => undef
</%args>
<& /service/open_form.mhtml &>
<h1><% i18nGettext ('I18N_OPENXPKI_CLIENT_HTML_MASON_WORKFLOW_CREATE_INSTANCE_TITLE') %></h1>
<p>
  <% i18nGettext('I18N_OPENXPKI_CLIENT_HTML_MASON_WORKFLOW_CREATE_INSTANCE_DESCRIPTION') %>
</p>
%   my $msg = $context->{client}->send_receive_command_msg ("list_workflow_titles");
%   ## I expect the following:
%   ## SERVICE_MSG => "COMMAND",
%   ## COMMAND     => $cmd,
%   ## PARAMS      => {$name => {description => $desc}, ... }
%
<select name="type">
%   foreach my $type (keys %{$msg->{PARAMS}})
%   {
  <option value="<% $type %>">
    <% i18nGettext($type) %>
  </option>
%   }
</select>
<& /service/send_form.mhtml &>
<& /service/close_form.mhtml &>
<dl>
%
%   foreach my $type (keys %{$msg->{PARAMS}})
%   {
  <dt>
    <a href="list_instances.html?<% $context->{menu}->get_link_params() %>;type=<% $type %>">
      <% i18nGettext($type) %>
    </a>
  </dt>
  <dd><% i18nGettext($msg->{PARAMS}->{$type}->{description}) %></dd>
%   }
</dl>

<%init>
    if (defined $type)
    {
        my $msg = $context->{client}->send_receive_command_msg
                  (
                      "create_workflow_instance",
                      {"WORKFLOW" => $type}
                  );
        if (exists $msg->{SERVICE_MSG} and
            $msg->{SERVICE_MSG} eq "ERROR")
        {
            my $errors = [ $m->comp ('/lib/get_deep_error.mhtml', 'msg' => $msg) ];
            return $m->comp ('/service/create_csr/print_errors.mhtml', 'errors' => $errors);
        } else {
            return $m->comp ('/service/workflow/list_instances.html', 'type' => $type)
        }
    }
</%init>
