<!-- Component Activity form begin -->
<script type="text/javascript" src="includes/js/fancybox/jquery.fancybox.pack.js"></script>
<link rel="stylesheet" type="text/css" href="includes/js/fancybox/jquery.fancybox.css" media="screen" />

<link rel="stylesheet" type="text/css" href="includes/js/select2/css/select2.min.css"/>
<script type="text/javascript" src="includes/js/select2/js/select2.full.min.js"></script>
<script type="text/javascript" src="includes/js/select2/js/i18n/de.js"></script>

<form action="index.php?module=workflow[% if $activity.ID > 0 %]&amp;event=editActivityDef&amp;aid=[% $activity.ID %][% else %]&amp;event=createActivityDef&wfdid=[% $activity.WFDID %][% /if %]" method="POST" name="activity" class="form-horizontal form-label-left fcs-form-padding">

    [% if $activity.WFDID > 0 %]
        <input type="hidden" name="wfdid" value="[% $activity.WFDID %]" />
    [% /if %]
    [% if $sid > 0 %]
        <input type="hidden" name="sid" value="1" />
    [% /if %]
    <input type="hidden" name="save" value="1" />
    <input type="hidden" name="UniqID" value="[% $activity.ActivityDefUniqID %]" />
    <input type="hidden" name="FormID" value="[% $activity.FormID %]" />

    <!-- ###CONTENT### begin -->
    <div class="card panel-fcs-border shadow-sm">
        <div class="card-header">
            <span class="fcs-card-title h2">[% if $activity.ID > 0 %][% $user->gettext('Aktivität bearbeiten') %][% else %][%$user->gettext('Neue Aktivität definieren') %][% /if %]</span>
        </div>
        <div class="card-body">
            <div class="row">
                [% if $Tools->FCS_Count($Errors) %]
                    [% foreach from=$Errors item=error %]
                        <div class="alert alert-danger" role="alert">
                            <strong>[%$user->gettext('Fehler')%]</strong>: [% $user->gettext($error) %]
                        </div>
                    [% /foreach %]
                [% /if %]
                [% if $Tools->FCS_Count($errors) %]
                    [% foreach from=$errors item=error %]
                        <div class="alert alert-danger" role="alert">
                            <strong>[%$user->gettext('Fehler')%]</strong>: [% $user->gettext($error) %]
                        </div>
                    [% /foreach %]
                [% /if %]
                <div class="col-lg-6">
                    <div class="card panel-info shadow-sm rounded">
                        <div class="card-body text-center">
                            <div class="btn-group">
                                <input type="submit" class="btn btn-outline-primary" value="[% $user->gettext('Speichern') %]" />
                                <input type="button" value="[% $user->gettext('Zurück') %]" onclick="[% if !$activity.ID %]if(confirm('[% $user->gettext('Wenn Sie das Formular verlassen, werden die eingegebenen Daten verworfen. Trotzdem zurück?') %]'))[% /if %]window.location.href = 'index.php?module=workflow&event=editwfd&wid=[% $activity.WFDID %]';" class="btn btn-outline-secondary" />
                            </div>
                        </div>
                    </div>
                    <div class="card panel-info shadow-sm rounded">
                        <div class="card-header">
                            <span class="fcs-card-title h4">[%$user->gettext('Allgemeine Informationen')%]</span>
                        </div>
                        <div class="card-body">
                            <div class="form-group row mb-3">
                                <label class="col-lg-3 control-label">
                                    [% $user->gettext('Bezeichnung') %]:
                                </label>
                                <div class="col-lg-9">
                                    <input type="text" name="ActivityDescr" class="form-control" value="[% $activity.Description %]" required="required"/>
                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="card panel-info shadow-sm rounded">
                        <div class="card-header">
                            <span class="fcs-card-title h4">[%$user->gettext('Aufgabe')%]</span>
                        </div>
                        <div class="card-body">
                            <div class="col-md-12">
                                <label  title="[% $user->gettext('Der eingegebene Text wird in der Aktivit&auml;t angezeigt.') %]">
                                    <input type="radio" name="TaskType" id="TaskType_Text" value="1" autocomplete="off" [% if $activity.TaskType == 1 || !$activity.TaskType %]checked="checked"[% /if %] onclick="ShowHide('Action_form', false); ShowHide('Action_WF', false); ShowHide('Action_text', true);" /> [% $user->gettext('Text') %]
                                </label> &nbsp;
                                <label  title="[% $user->gettext('Ein definiertes Formular wird in der Aktivit&auml;t angezeigt.') %]">
                                    <input type="radio" name="TaskType" id="TaskType_Form" value="2" autocomplete="off"[% if $activity.TaskType == 2 %]checked="checked"[% /if %] onclick="ShowHide('Action_form', true); ShowHide('Action_WF', false); ShowHide('Action_text', false);" /> [% $user->gettext('Formular') %]
                                </label>&nbsp;
                                <label  title="[% $user->gettext('Es wird eine Benachrichtigung an die Adressaten gesendet.') %]">
                                    <input type="radio" name="TaskType" id="TaskType_Notification" value="3" autocomplete="off"[% if $activity.TaskType == 3 %]checked="checked"[% /if %] onclick="ShowHide('Action_form', false); ShowHide('Action_WF', false); ShowHide('Action_text', true);" /> [% $user->gettext('Benachrichtigung') %]
                                </label>

                                <label  title="[% $user->gettext('Workflow starten') %]">
                                    <input type="radio" name="TaskType" id="TaskType_REST" value="5" autocomplete="off"[% if $activity.TaskType == 5 %]checked="checked"[% /if %] onclick="ShowHide('Action_form', false); ShowHide('Action_text', false); ShowHide('Action_WF', true);" /> [% $user->gettext('Workflow starten') %]
                                </label>

                            </div>

                            <div class="col-md-12">
                                <div id="Action_form" style="display:[% if $activity.TaskType == 2 %]block[% else %]none[% /if %];">
                                    <!-- Formulartabelle -->
                                    <p class="help-block">[% $user->gettext('Ein definiertes Formular wird in der Aktivit&auml;t angezeigt.') %]</p>

                                    <iframe id="ActivityFormFrame" src="index.php?module=workflow&event=view_activityform&fid=[% $activity.ID %]&ad=1&editActivity=1" width="98%" frameborder="0" height="300px" name="formular" >
                                    </iframe>

                                    <!-- Formulartabelle Ende-->
                                </div>
                                <div id="Action_text" style="display:[% if $activity.TaskType == 1 || $activity.TaskType == 3 || !$activity.TaskType %]block[% else %]none[% /if %];">
                                    <p class="help-block">[% $user->gettext('Der eingegebene Text wird in der Aktivit&auml;t angezeigt.') %]</p>
                                    <textarea id="TaskText" name="TaskText" class="form-control" rows="5" cols="50" >[% $activity.TaskText %]</textarea>
                                </div>



                                <div id="Action_WF" style="display:[% if $activity.TaskType == 5 %]block[% else %]none[% /if %];">
                                    <p class="help-block">[% $user->gettext('Startet einen Workflow') %]
                                        [% $user->gettext('Das Ergebnis wird in der Aktivität gespeichert') %]
                                    </p>

                                    <div class="form-group row mb-3">

                                        <label class="control-label col-lg-4">
                                            [% $user->gettext('Workflow-Definition') %]
                                        </label>
                                        <div class="col-lg-8">
                                            <select name="startWF[WFDID]" id="startWFID" class="form-control">
                                                <option value="0" [% if !$activity.startWF.wfdid || $activity.startWF.wfdid == 0 %]selected="selected"[% /if %]>-- [% $user->gettext('Bitte wählen') %] --</option>
                                                [% html_options options=$AllActiveWorkflows selected=$activity.startWF.wfdid %]
                                            </select>
                                        </div>

                                    </div>
                                    <div class="form-group row mb-3">
                                        <label class="control-label col-lg-4">
                                            [% $user->gettext('Name') %]*
                                        </label>
                                        <div class="col-lg-8">

                                            <label><input type='radio' name="startWF[titleSource]" id='same' value='1' [% if $activity.startWF.titlesource === 1 || !$activity.startWF %]checked="checked"[% /if %]> [% $user->gettext('Titel von WF-Instanz übernehmen') %]</label><br/>
                                            <label><input type='radio' name="startWF[titleSource]" id='other' value='0' [% if $activity.startWF.titlesource === 0 %]checked="checked"[% /if %]> [% $user->gettext('Titel eingeben') %]</label><br/>

                                            <div class="input-group" id="WFTitle" [% if $activity.startWF.titlesource === 0 %][% else %]style="display:none"[% /if %]>
                                                <div class="input-group-text"><span id="WFDInstanceDescr">[% $activity.startWF[instancename] %]</span></div>
                                                <input type="text" size="15"  maxlength="[% $DescrLength %]" [% if $showactive %]readonly[% /if %] name="startWF[InstanceDescr]" class="form-control" value="[% $activity.startWF.instancedescr %]" />
                                            </div>
                                        </div>
                                    </div>

                                    [%* Die Startparameter werden im Ticketmodul in der funktion startNewWorkflow verwendet *%]
                                    <div class="form-group row mb-3">
                                        <label class="control-label col-lg-4" title="[% $user->gettext('Person, die den Workflow startet.') %]">
                                            [% $user->gettext('Initiator') %]
                                        </label>
                                        <div class="col-lg-8">

                                            <label><input type='radio' name="startWF[initiatorSource]" id='same' value='1' [% if $activity.startWF.initiatorsource === 1 || !$activity.startWF %]checked="checked"[% /if %]> [% $user->gettext('Initiator von WF-Instanz übernehmen') %]</label><br/>
                                            <label><input type='radio' name="startWF[initiatorSource]" id='other' value='0' [% if $activity.startWF.initiatorsource === 0 %]checked="checked"[% /if %]> [% $user->gettext('Initiator wählen') %]</label><br/>
                                            <label><input type="radio" name="startWF[initiatorSource]" id='setInitiatorTypeToAddressFields' value="2" [% if $activity.startWF.initiatorsource === 2 %]checked="checked"[% /if %]> [% $user->gettext('Initiator aus Formulardaten') %]</label>

                                            <span id="InitiatorSelection" [% if $activity.startWF.initiatorsource === 2 %][% else %]style="display:none"[% /if %]>
                                                [% if $AdressDataActivities.cntFields > 0 %]
                                                    <br/>
                                                    <select id="InitiatorSelectionList" name="startWF[InitiatorSourceField]" class="form-control multiple" style="width:100%;">
                                                        <option value="">-- [% $user->gettext('Alle') %] --</option>
                                                        [% foreach from=$AdressDataActivities.Fields item=Fields %]
                                                            [% foreach from=$Fields item=Field %]
                                                                <option value="[% $Field.id %]" [% if $activity.startWF.initiatorsourcefield == $Field.id %]selected="selected"[% /if %]>[% $Field.activityname %] - [% $Field.field %]</option>
                                                            [% /foreach %]
                                                        [% /foreach %]
                                                    </select>
                                                [% /if %]
                                            </span>

                                            <select name="startWF[InitiatorID]" id="startInitiatorID" class="form-control" [% if $activity.startWF.initiatorsource == 1 || $activity.startWF.initiatorsource == 2 %]style="display:none"[% /if %]>
                                                <option value="0" [% if !$activity.startWF.InitiatorID || $activity.startWF.initiatorid == 0 %]selected="selected"[% /if %]>-- [% $user->gettext('Bitte wählen') %] --</option>
                                                [% html_options options=$users selected=$activity.startWF.initiatorid %]
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group row mb-3">
                                        <label class="control-label col-lg-4" title="[% $user->gettext('Vertreter der Person, die den Workflow startet.') %]">
                                            [% $user->gettext('Vertreter') %]
                                        </label>
                                        <div class="col-lg-8">

                                            <label><input type='radio' name="startWF[substitudeSource]" id='same' value='1' [% if $activity.startWF.substitudesource === 1 || !$activity.startWF %]checked="checked"[% /if %]> [% $user->gettext('Stellvertreter von WF-Instanz übernehmen') %]</label><br/>
                                            <label><input type='radio' name="startWF[substitudeSource]" id='other' value='0' [% if $activity.startWF.substitudesource === 0 %]checked="checked"[% /if %]> [% $user->gettext('Stellvertreter wählen') %]</label><br/>
                                            <label><input type='radio' name="startWF[substitudeSource]"  value='2' [% if $activity.startWF.substitudesource === 2 %]checked="checked"[% /if %]> [% $user->gettext('Stellvertreter aus Formulardaten') %]</label>

                                            <span id="SubstitudeSelection" [% if $activity.startWF.substitudesource === 2 %][% else %]style="display:none"[% /if %]>
                                                [% if $AdressDataActivities.cntFields > 0 %]
                                                    <br/>
                                                    <select id="InitiatorSelectionList" name="startWF[SubstitudeSourceField]" class="form-control multiple" style="width:100%;">
                                                        <option value="">-- [% $user->gettext('Alle') %] --</option>
                                                        [% foreach from=$AdressDataActivities.Fields item=Fields %]
                                                            [% foreach from=$Fields item=Field %]
                                                                <option value="[% $Field.id %]" [% if $activity.startWF[substitudesourcefield] == $Field.id %]selected="selected"[% /if %]>[% $Field.activityname %] - [% $Field.field %]</option>
                                                            [% /foreach %]
                                                        [% /foreach %]
                                                    </select>
                                                [% /if %]
                                            </span>

                                            <select name="startWF[SubstitudeID]" id="startSubstitudeID" class="form-control" [% if $activity.startWF.substitudesource === 0 %][% else %]style="display:none"[% /if %]>
                                                <option value="0" [% if !$activity.startWF.substitudeid || $activity.startWF.substitudeid == 0 %]selected="selected"[% /if %]>-- [% $user->gettext('Bitte wählen') %] --</option>
                                                [% html_options options=$users selected=$activity.startWF.substitudeid %]
                                            </select>



                                        </div>
                                    </div>

                                    <div class="form-group row mb-3">
                                        <label class="control-label col-lg-4">
                                            [% $user->gettext('Kontakt') %]
                                        </label>
                                        <div class="col-lg-8">

                                            <label><input type='radio' name="startWF[contactSource]" id='sameContact' value='1' [% if $activity.startWF.contactsource === 1 || !$activity.startWF %]checked="checked"[% /if %]> [% $user->gettext('Kontakt von WF-Instanz übernehmen') %]</label><br/>
                                            <label><input type='radio' name="startWF[contactSource]" id='otherContact' value='0' [% if $activity.startWF.contactsource === 0 %]checked="checked"[% /if %]> [% $user->gettext('Kontakt wählen') %]</label><br/>

                                            <select size="1" name="startWF[ContactID]" id="ContactID" class="form-control" [% if $activity.startWF.contactsource === 0 %][% else %]style="display:none"[% /if %]>
                                                <option value="0" [% if !$activity.startWF.contactid || $activity.startWF.contactid == 0 %]selected="selected"[% /if %]>-- [% $user->gettext('Bitte wählen') %] --</option>
                                                [% html_options options=$Contacts selected=$activity.startWF.contactid %]
                                            </select>

                                        </div>
                                    </div>

                                    [% if $user->Security->Projects %]
                                        <div class="form-group row mb-3">
                                            <label class="control-label col-lg-4">
                                                [% $user->gettext('Projekt') %]
                                            </label>
                                            <div class="col-lg-8">

                                                <label><input type='radio' name="startWF[projectSource]" id='sameProject' value='1' [% if $activity.startWF.projectsource === 1 || !$activity.startWF %]checked="checked"[% /if %]> [% $user->gettext('Projekt von WF-Instanz übernehmen') %]</label><br/>
                                                <label><input type='radio' name="startWF[projectSource]" id='otherProject' value='0' [% if $activity.startWF.projectsource === 0 %]checked="checked"[% /if %]> [% $user->gettext('Projekt wählen') %]</label><br/>

                                                <select name="startWF[ProjectID]" id="ProjectID" class="form-control" [% if $activity.startWF.projectsource === 0 %][% else %]style="display:none"[% /if %]>
                                                    <option value="0" [% if !$activity.startWF.projectid || $activity.startWF.projectid == 0 %]selected="selected"[% /if %]>-- [% $user->gettext('Bitte wählen') %] --</option>
                                                    [% html_options options=$Projects selected=$activity.startWF.projectid %]
                                                </select>

                                            </div>
                                        </div>

                                    [% /if %]
                                </div>


                            </div>

                        </div>
                    </div>

                    <div class="card panel-info shadow-sm rounded">
                        <div class="card-header">
                            <span class="fcs-card-title h4">[%$user->gettext('Voraussetzungen')%]</span>
                        </div>
                        <div class="card-body">
                            <div class="form-group row mb-3">

                                <div class="col-lg-12">
                                    <p class="help-block">
                                        [% $user->gettext('Definiert die Bedingungen, die zum Start der Aktivit&auml;t erf&uuml;llt sein m&uuml;ssen') %]
                                    </p>

                                    <label  class="withInfo control-label" data-toggle="tooltip" title="[% $user->gettext('Die Aktivität wird mit Beginn des Workflows angelegt') %]">
                                        <input type="radio" id="rdbtRequiremntsImmediately" name="Condition"  value="1" [% if $activity.StartConID == 1 || !$activity.StartConID %]checked="checked"[% /if %]  onclick="ShowHide('ConActivitySelect', false);" [% if $activity.LoopsAllowed %]disabled="disabled"[% /if %]/>
                                        [% $user->gettext('sofort') %]
                                    </label> &nbsp;


                                    [% if $activity.StartConID == 2 %]

                                        <label class="withInfo control-label">
                                            [% $user->gettext('startet nach') %]
                                            <input type="radio" id="rdbtRequiremntsStartsAfter" name="Condition" value="2" [% if $activity.StartConID == 2 %]checked="checked"[% /if %] onclick="ShowHide('ConActivitySelect', false);"/>
                                        </label>

                                    [% /if %]
                                    <label  class="withInfo control-label"  data-toggle="tooltip" title="[% $user->gettext('Die Aktivit&auml;t startet, nachdem gewählte Aktivitäten abgeschlossen wurden') %]">
                                        <input type="radio" id="rdbtRequiremntsAfterActivity" name="Condition"  value="3" [% if $activity.StartConID == 3 %]checked="checked"[% /if %] onclick="ShowHide('ConActivitySelect', true);"/>
                                        [% $user->gettext('nach Aktivit&auml;t') %]
                                    </label>


                                </div>
                                <div id="ConActivitySelect" class="col-lg-12" style="display:[% if $activity.StartConID != 3 %]none[% else %]block[% /if %];">
                                    <input type="hidden" name="DepActs" id="DepActs" value="" />
                                    <div class="form-control" style="min-height:200px;overflow:auto;">
                                        <div style="margin:3px;" id="CABList">
                                            [% foreach from=$activity.DepActivitys item=depact %]
                                                <div class="activity_active" onmouseover="this.className = 'activity_hover';" onmouseout="this.className = 'activity_active';">
                                                    <div style="white-space:normal;"> [% $depact.id %]&nbsp;[% $depact.descr %] &nbsp;[% $depact.duration %]&nbsp;
                                                        [% if $depact.Field != '' %]
                                                            <br/><span class="Brunch">Feld: [% $depact.Field %] - Auswahl: [% $depact.Value %]</span>
                                                        [% /if %]
                                                        <span>
                                                            <a class="btn btn-outline-secondary" href="JavaScript:void(0);" onclick="removejs_Activities([% $depact.id %]);" title="[% $user->gettext('Aktivit&auml;t entfernen') %]">
                                                                <span class="fa fa-trash" title="[% $user->gettext('Entfernen') %]"></span>
                                                            </a>
                                                            <a class="btn btn-outline-secondary" href="JavaScript:void(0);" onclick="editjs_Activities([% $depact.id %]);" title="[% $user->gettext('Aktivit&auml;t bearbeiten') %]">
                                                                <span class="fa fa-pencil" title="[% $user->gettext('Bearbeiten') %]"></span>
                                                            </a>
                                                            <a class="btn btn-outline-secondary" href="index.php?module=workflow&amp;event=editActivityDef&amp;aid=[% $depact.id %]" target="_blank"><span class="fa fa-pencil" title="[% $user->gettext('Verwendet in') %] [% $usedInActivity.description %]"></a>
                                                        </span>
                                                        <span style="clear"></span>
                                                    </div>&nbsp;&nbsp;
                                                </div>
                                            [% foreachelse %]
                                                [% $user->gettext('Keine Aktivit&auml;ten ausgew&auml;hlt...') %]
                                            [% /foreach %]
                                        </div>
                                    </div>
                                    <!-- Liste der Aktivitäten, die beendet sein müssen, damit die aktuelle ausgeführt wird -->
                                    [% if $Tools->FCS_Count($DependOnActivitys) %]
                                        <table>
                                            <thead>
                                                <tr>
                                                    <th>#
                                                    </th>
                                                    <th>[% $user->gettext('Aktivit&auml;t') %]
                                                    </th>
                                                    <th>[% $user->gettext('Dauer (T.)') %]
                                                    </th>
                                                    <th>&nbsp;
                                                    </th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                [% foreach from=$DependOnActivitys item=ConActivity key=ConActivity_id %]
                                                    <tr>
                                                        <td>[% $ConActivity_id %]</td>
                                                        <td>[% $ConActivity.descr %]</td>
                                                        <td>[% $ConActivity.duration %]</td>
                                                        <td>
                                                            <a class="btn btn-outline-secondary" href="index.php?module=workflow&amp;event=removeconact&amp;id=[% $ConActivity_id %]" onclick="return confirm('[% $ConActivity.descr %] \n[% $user->gettext('wirklich entfernen?') %]');">
                                                                <span class="fa fa-trash" title="[% $user->gettext('Entfernen') %]"></span>
                                                            </a>
                                                            <a class="btn btn-outline-secondary" href="index.php?module=workflow&amp;event=editActivityDef&amp;id=[% $ConActivity_id %]">
                                                                <span class="fa fa-pencil" title="[% $user->gettext('Bearbeiten') %]"></span>
                                                            </a>
                                                        </td>
                                                    </tr>
                                                [% /foreach %]
                                            </tbody>
                                        </table>
                                    </div>
                                [% /if %]

                                <div class="table-responsive">
                                    <label class="control-label">[%$user->gettext('Aktivit&auml;ten ausw&auml;hlen')%]</label>
                                    <table border="0" width="100%" class="table table-striped table-bordered listview formview" cellspacing="0">
                                        <thead style="color: #31708f;
                                               background-color: #d9edf7;
                                               border-color: #bce8f1;">
                                            <tr class="fields">
                                                <td>#</td>
                                                <td>
                                                    [% $user->gettext('Beschreibung') %]
                                                </td>
                                                <td>
                                                    [% $user->gettext('Dauer') %]
                                                </td>

                                                <td>
                                                    [% $user->gettext('Adressaten w&auml;hlbar') %]
                                                </td>

                                                <td>&nbsp;</td>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            [% foreach from=$Activities item=Activity name=ActIndex %]
                                                [% if !$Activity.O.isLoopPosible.LoopAllowedIsChecked %]
                                                    <tr style="cursor:pointer;" onclick="getContact([% $Activity.aid %], '[% $Activity.Descr %]', '[% $Activity.Duration %]');" >

                                                        <td>[% $smarty.foreach.ActIndex.iteration %]</td>
                                                        <td>[% $Activity.Descr %]&nbsp;</td>
                                                        <td>[% $Activity.Duration %]&nbsp;</td>
                                                        <td>[% $Activity.HasAddressData %]&nbsp;</td>
                                                        <td><a href="JavaScript:void(0);" class="btn btn-outline-secondary"><span class="fa fa-plus" title="[% $user->gettext('Aktivität als Vorgänger wählen') %]"></span></a></td>
                                                    </tr>
                                                [% else %]
                                                    <tr title="[% $user->gettext('Schleifenaktivitäten können nicht als Vorgänger gewählt werden. Nur deren Verzweigungen.') %]" >

                                                        <td>[% $smarty.foreach.ActIndex.iteration %]</td>
                                                        <td><span class="withInfo">[% $Activity.Descr %]&nbsp;</span></td>
                                                        <td>[% $Activity.Duration %]&nbsp;</td>
                                                        <td>[% $Activity.HasAddressData %]&nbsp;</td>
                                                        <td></td>
                                                    </tr>
                                                [% /if %]
                                                [% foreach from=$Activity.BrunchPosibilities item=Brunche name=Brunches %]
                                                    [% foreach from=$Brunche.ele item=Auswahl name=Auswahl %]
                                                        [% assign var="inUse" value=$activity.DepActivitysforUsedFlag[$Auswahl][$Brunche.name][$Activity.aid] %]
                                                        [% if $Activity.O.isLoopPosible.LoopAllowedIsChecked == 1 && $Activity.O.isLoopPosible.usedBrunchFields.$Auswahl > 0 %]
                                                            [% assign var="LoopBrunchNotAvailable" value=1 %]
                                                        [% else %]
                                                            [% assign var="LoopBrunchNotAvailable" value=0 %]
                                                        [% /if %]


                                                        <tr style="cursor:pointer;"
                                                            [% if !$inUse && !$LoopBrunchNotAvailable %] onclick="getContact([% $Activity.aid %], '[% $Activity.Descr %]', '[% $Activity.Duration %]', '[% $Brunche.name %]', '[% $Auswahl|replace:"\\":"\\\\" %]');" [% /if %]>
    <td>[% $smarty.foreach.ActIndex.iteration %].[% $smarty.foreach.Auswahl.iteration %]</td>
    <td colspan="3">[% $Brunche.title %] - [% $Auswahl %]</td>
                                                                <td>
                                                                    [% if !$inUse && !$LoopBrunchNotAvailable %]
                                                                        <a href="JavaScript:void(0);" class="btn btn-outline-secondary"><span class="fa fa-plus" title="[% $user->gettext('Formularwert der Aktivität als Vorgänger wählen') %]"></span></a>
                                                                        [% /if %]
                                                                </td>
                                                            </tr>
                                                            [% /foreach %]
                                                                [% /foreach %]
                                                                    [% /foreach %]
                                                                    </tbody>
                                                                </table>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="col-lg-6">
                                            <div class="card panel-info shadow-sm rounded">
                                                <div class="card-header">
                                                    <a data-toggle="collapse" href="#adress">
                                                        <div class="row">
                                                            <div class="col-lg-12">
                                                                <span class="fcs-card-title h4">
                                                                    [%$user->gettext('Adressaten')%]
                                                                </span>
                                                            </div>
                                                        </div>
                                                    </a>
                                                </div>
                                                <div id="adress" class="panel-collapse collapse in">
                                                    <div class="card-body">
                                                        <div class="form-group row mb-3">
                                                            <label class="col-lg-3 control-label">
                                                                <input type="radio" id="TargetTypeUser" name="TargetType" value="1" [% if $activity.TargetType != 2 %]checked="checked"[% /if %] />
                                                                <span class="withInfo" title="[% $user->gettext('Der gewählte Benutzer wird als Adressat in die Aktivität eingetragen') %]">[% $user->gettext('Benutzer') %]</span>
                                                            </label>
                                                            <div class="col-lg-9">
                                                                <select name="TargetUserIDs[]" id="ContactUserID" class="form-control" style="width:100%;" multiple="multiple">
                                                                    [% foreach $users as $user %]
                                                                        <option [% if $Tools->FCS_InArray($user.user_id, $activity.TargetUserIDs) %]selected="selected"[% /if %] value="[% $user.user_id %]" department="[% $user.department %]" remarktext="[% $user.remarktext %]">[% $user.name %]</option>
                                                                    [% /foreach %]
                                                                </select>
                                                                <span class="required"></span>
                                                            </div>
                                                        </div>

                                                        <div class="form-group row mb-3">
                                                            <label class="col-lg-3 control-label">
                                                                <input type="radio" id="TargetTypeGroup" name="TargetType"  value="2" [% if $activity.TargetType == 2 %]checked="checked"[% /if %] />
                                                                <span class="withInfo" title="[% $user->gettext('Die gewählte Supportergruppe wird als Adressat in die Aktivität eingetragen') %]">[% $user->gettext('Gruppe') %]</span>
                                                            </label>
                                                            <div class="col-lg-9">
                                                                <select name="TargetGroupIDs[]" id="ContactGroupID" class="form-control multiple"  style="width:100%;"  multiple="multiple">
                                                                    [% html_options options=$groups selected=$activity.TargetGroupIDs %]
                                                                </select>
                                                                <span class="required"></span>
                                                            </div>
                                                        </div>

                                                        <div class="form-group row mb-3">
                                                            <label class="col-lg-3 control-label">
                                                                <input type="radio" id="setTargetTypeToInitiator" name="TargetType"  value="3" [% if $activity.TargetType == 3 || !$activity.TargetType %]checked="checked"[% /if %] title=""/>
                                                                <span class="withInfo" title="[% $user->gettext('Der Benuter, welcher den Workflow startet wird als Adressat in die Aktivität eingetragen') %]">[% $user->gettext('Ersteller') %]</span>
                                                            </label>
                                                            <div class="col-lg-9">
                                                                <p class="form-control-static">[% $user->gettext('Initiator des Workflows') %]</p>
                                                                <span class="required"></span>
                                                            </div>
                                                        </div>

                                                        <div class="form-group row mb-3">
                                                            <label class="col-lg-3 control-label">
                                                                <input type="radio" id="TargetTypePreviousActivity" name="TargetType"  value="4" [% if $activity.TargetType == 4 %]checked="checked"[% /if %] />
                                                                <span class="withInfo" title="[% $user->gettext('Der Adressat wird aus einer vorhergehenden Aktivität ermittelt. Dazu muss in einer Vorgängeraktivität eine <Auswahl mit Adressierung> definiert sein.') %]">[% $user->gettext('Aus vorheriger Aktivität') %]</span>
                                                            </label>
                                                            <div class="col-lg-9">
                                                                <span id="TargetActivitySelection">
                                                                    [% if $AdressDataActivities.cntFields > 0 %]
                                                                        <br/>
                                                                        <select id="AdressSourceActivity" name="AdressSourceActivity[]" class="form-control multiple" style="width:100%;" multiple>
                                                                            <option value="">-- [% $user->gettext('Alle') %] --</option>
                                                                            [% foreach from=$AdressDataActivities.Fields item=Fields %]
                                                                                [% foreach from=$Fields item=Field %]
                                                                                    <option value="[% $Field.id %]" [% if $Tools->FCS_InArray( $Field.id, $activity.TargetSources) || $Tools->FCS_InArray($Field.oldid, $activity.TargetSources) %]selected="selected"[% /if %]>[% $Field.activityname %] - [% $Field.field %]</option>
                                                                                [% /foreach %]
                                                                            [% /foreach %]
                                                                        </select>
                                                                    [% /if %]
                                                                </span>

                                                            </div>
                                                        </div>

                                                        <div class="form-group row mb-3">
                                                            <label class="col-lg-12 control-label">
                                                                <input type="checkbox" name="NoMessage" [% if $activity.NoMessage %]checked="checked"[% /if %]>
                                                                <span class="withInfo" title="[% $user->gettext('Adressaten werden keine Benachrichtigung erhalten.') %]">[% $user->gettext('Allgemeine Benachrichtigung deaktivieren') %]</span>

                                                            </label>

                                                        </div>
                                                    </div>

                                                </div>
                                            </div>

                                            <div class="card panel-info shadow-sm rounded">
                                                <div class="card-header">
                                                    <a data-toggle="collapse" href="#date">
                                                        <div class="row">
                                                            <div class="col-lg-12">
                                                                <span class="fcs-card-title h4">
                                                                    [%$user->gettext('Datum')%]
                                                                </span>
                                                            </div>
                                                        </div>
                                                    </a>
                                                </div>
                                                <div id="date" class="panel-collapse collapse in">
                                                    <div class="card-body">
                                                        <div class="form-group row mb-3">
                                                            <label class="col-lg-3 control-label">
                                                                [% $user->gettext('Dauer') %]:
                                                            </label>
                                                            <div class="col-lg-9">
                                                                <div class="input-group"  style="width: 20%;">
                                                                    <input type="text" name="ActivityDuration" class="form-control" value="[% $activity.Duration %]" />
                                                                    <span class="input-group-text">[% $user->gettext('Tage') %]</span>
                                                                </div>
                                                            </div>
                                                        </div>

                                                        <div class="form-group row mb-3">
                                                            <label class="col-lg-3 control-label">
                                                                [% $user->gettext('Fällig') %]:
                                                            </label>
                                                            <div class="col-lg-9">
                                                                <div class="input-group"  style="width: 33%;">
                                                                    <input type="text" name="ActivityDate" class="form-control" value="[% $activity.ActivityDate %]" />
                                                                    <span class="input-group-text">[% $user->gettext("Tage nach 'Dauer'") %]</span>
                                                                </div>
                                                            </div>
                                                        </div>

                                                        <div class="form-group row mb-3">
                                                            <label class="control-label col-lg-12">
                                                                <input type="checkbox" name="ShowPrevActivity" id="ShowPrevActivity" value="1" [% if $activity.ShowPrevInformations %]checked="checked"[% /if %] />
                                                                <label for="ShowPrevActivity" class="withInfo">[% $user->gettext('Daten aus vorherigen Aktivitäten anzeigen') %]</label>
                                                                <span class="help-block">[% $user->gettext('Formulardaten aus voherigen Aktivitäten werden angezeigt. In der Formulardefinition der vorherigen Aktivitäten kann jeweils festgelegt werden, ob die Daten angezeigt werden.') %]</span>
                                                            </label>
                                                        </div>


                                                        <div class="form-group row mb-3">
                                                            <label class="control-label col-lg-12">
                                                                <input type="checkbox" name="ShowDirectPrevActivity" id="ShowDirectPrevActivity" value="1" [% if $activity.ShowDirectPrevActivity %]checked="checked"[% /if %] />
                                                                <label for="ShowDirectPrevActivity" class="withInfo">[% $user->gettext('Nur die Daten der direkten Vorgänger-Aktivität(en) anzeigen') %]</label>
                                                                <span class="help-block">[% $user->gettext('Nur die Formulardaten der direkten Vorgänger-Aktivität(en) werden angezeigt.') %]</span>
                                                            </label>
                                                        </div>

                                                        <div class="form-group row mb-3">
                                                            <label class="col-lg-3 control-label">
                                                                <input type="checkbox" name="LoopsAllowed" id="LoopsAllowed" value="1" [% if $activity.LoopsAllowed %]checked="checked"[% /if %] [% if !$activity.isLoopPosible.LoopIsPossible %]disabled="disabled"[% /if %]/>
                                                                <label for="LoopsAllowed" class="withInfo" title="[% $user->gettext('Schleifen ermöglichen eine Referenzierung der Aktivität sowohl als Vorgänger wie auch als Nachfolger anderer Aktivitäten.') %]">[% $user->gettext('Schleife ermöglichen') %]</label>
                                                            </label>
                                                            <div class="col-lg-9">
                                                                <p>
                                                                <details>
                                                                    <summary style="cursor:pointer;">[% $user->gettext('Schleifenaktivitäten müssen folgende Bedingungen erfüllen') %]:</summary>
                                                                    <ul>
                                                                        <li>[% $user->gettext('maximal eine Verzweigungsauswahl enthalten') %]</li>
                                                                        <li>[% $user->gettext('Aus Schleifenaktivitäten stehen nur die Verzweigungs-Werte als Vorgänger in anderen Aktivitäten zur Auswahl<br/>Die Gesamte Aktivität kann nicht gewählt werden.') %]</li>
                                                                        <li>[% $user->gettext('Jede Verzweigungsauswahl darf maximal einen Nachfolger haben') %]</li>
                                                                        <li>[% $user->gettext('Schleifenaktivitäten dürfen keine Startaktivität sein') %]</li>
                                                                    </ul>
                                                                    <span id="LoopsAllowedError" class="error">
                                                                        [% if  $activity.ID > 0 && !$activity.isLoopPosible.LoopIsPossible %]

                                                                            [% $user->gettext('Folgende Bedingungen sind in dieser Aktivität nicht erfüllt') %]:
                                                                            <ul>
                                                                                [% foreach from=$activity.isLoopPosible.messages item=message %]
                                                                                    <li>[% $message %]</li>
                                                                                    [% /foreach %]
                                                                            </ul>

                                                                        [% /if %]
                                                                    </span>
                                                                </details>
                                                                </p>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>

                                            <div class="card panel-info shadow-sm rounded">
                                                <div class="card-header">
                                                    <a data-toggle="collapse" href="#message">
                                                        <div class="row">
                                                            <div class="col-lg-12">
                                                                <span class="fcs-card-title h4">
                                                                    [%$user->gettext('Benachrichtigung')%]
                                                                </span>
                                                            </div>
                                                        </div>
                                                    </a>
                                                </div>
                                                <div id="message" class="panel-collapse collapse in">
                                                    <div class="card-body">

                                                        <div class="checkbox">
                                                            <label style="font-weight: bold;">
                                                                <input type="checkbox" name="sendReport" id="sendReport" [% if $activity.sendReport %]checked="checked"[% /if %] />
                                                                [% $user->gettext('Nach Beendigung der Aktivität einen Bericht an den Initiator senden') %]
                                                            </label>
                                                        </div>
                                                        <div class="checkbox">
                                                            <label style="font-weight: bold;">
                                                                <input type="checkbox" name="sendAdditionalReport" id="sendAdditionalReport" [% if $activity.sendAdditionalReport %]checked="checked"[% /if %] />
                                                                [% $user->gettext('Zusätzlicher Bericht nach Beendigung der Aktivität an') %]:
                                                            </label>
                                                        </div>

                                                        <div class="form-group row mb-3">
                                                            <label class="col-lg-3 control-label">
                                                                <input id="rdbtnNotificationTypeUser" type="radio" name="NotificationType" value="1" [% if $activity.NotificationType == 1 %]checked="checked"[% /if %] />
                                                                <span class="withInfo" title="[% $user->gettext('Nach Abschluss der Aktivität wird eine Benachrichtigung an den gewählten Benutzer gesendet') %]">[% $user->gettext('Benutzer') %]</span>
                                                            </label>
                                                            <div class="col-lg-9">
                                                                <select name="NotificationUserID" id="MessageUserID" class="form-control multiple">
                                                                    <option value="0" [% if !$activity.NotificationUserID || $activity.NotificationUserID == 0 %]selected="selected"[% /if %] department="" remarktext="">-- [% $user->gettext('Bitte wählen') %] --</option>
                                                                     [% foreach $users as $user %]
                                                                        <option [% if $activity.NotificationUserID == $user.user_id %]selected="selected"[% /if %] value="[% $user.user_id %]" department="[% $user.department %]" remarktext="[% $user.remarktext %]">[% $user.name %]</option>
                                                                    [% /foreach %]
                                                                </select>
                                                            </div>
                                                        </div>

                                                        <div class="form-group row mb-3">
                                                            <label class="control-label col-lg-3">
                                                                <input id="rdbtnNotificationTypeGroup" type="radio" name="NotificationType" value="2" [% if $activity.NotificationType == 2 %]checked="checked"[% /if %] />
                                                                <span class="withInfo" title="[% $user->gettext('Nach Abschluss der Aktivität werden Benachrichtigungen an die Benutzer der gewählten Gruppe gesendet') %]">[% $user->gettext('Gruppe') %]</span>
                                                            </label>
                                                            <div class="col-lg-9">
                                                                <select size="1" name="NotificationGroupID" id="MessageGroupID" class="form-control multiple">
                                                                    <option value="0" [% if !$activity.NotificationGroupID || $activity.NotificationGroupID == 0 %]selected="selected"[% /if %]>-- [% $user->gettext('Bitte wählen') %] --</option>
                                                                    [% html_options options=$groups selected=$activity.NotificationGroupID %]
                                                                </select>
                                                            </div>
                                                        </div>
                                                        <div class="checkbox">
                                                            <label style="font-weight: bold;">
                                                                <input type="checkbox" name="sendAttachments" id="sendAttachments" [% if $activity.sendAttachments %]checked="checked"[% /if %]  />
                                                                [% $user->gettext('Anhänge mitsenden') %]
                                                            </label>
                                                        </div>

                                                        <div class="form-group row mb-3">
                                                            <label class="col-lg-9 control-label" for="ReminderTime">
                                                                [% $user->gettext('Adressaten täglich an diese Aktivität erinnern') %]:
                                                            </label>
                                                            <div class="col-lg-3">
                                                                <div class="input-group pull-right"  style="width: 8em;">
                                                                    <input type="text" id="ReminderTime" name="ReminderTime" class="form-control" maxlength="5" value="[% $activity.ReminderTime %]" />
                                                                    <span class="input-group-text">[% $user->gettext('Uhr') %]</span>
                                                                </div>
                                                            </div>
                                                            <div class="col-lg-12">
                                                                <span class="help-block">[% $user->gettext('Ist hier eine Uhrzeit eingetragen, erhalten die Adressaten dieser Aktivitäten täglich eine Erinnerungsmail solange diese Aktivität aktiv ist') %]</span>
                                                            </div>
                                                        </div>

                                                    </div>

                                                </div>
                                            </div>

                                            [% if $user->hasRight(219) %]
                                                    <!--Tags-->
                                                    <div id="TagsItem" class="card panel-info shadow-sm rounded" [% if ($type.type_name && !$Tools->FCS_InArray('tag', $show)) %]style="display:none;"[% /if %]>
                                                        <div class="card-header">
                                                        <a data-toggle="collapse" href="#Tags">
                                                            <div class="row">
                                                                <div class="col-lg-12">
                                                                    <span class="fcs-card-title h4">
                                                                        [%$user->gettext('Schlagworte')%]
                                                                    </span>
                                                                </div>
                                                            </div>
                                                        </a>
                                                    </div>
                                                        <div id="Tags" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo">
                                                            <div class="card-body">
                                                                <div  class="form-group row mb-3">
                                                                    <div class=" col-sm-12">
                                                                        <select name="TicketTags[]" id="TicketTags" class="form-control select2" multiple="multiple" style="width:100%;">
                                                                            [% html_options options=$AllTags selected=$TicketTags2 %]
                                                                        </select>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                [% /if %]



                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>

    <script>
        console.log("hhh");
         $("#ContactUserID, #MessageUserID").select2({theme: 'bootstrap-5',

        templateResult: formatSelect,
                templateSelection: formatState,
         });

         function formatState (opt) {
                // console.log(opt);
                var $opt = '';
                if (!opt.id) {
                return opt.text.toUpperCase();
                }

                $opt = $(
                        '<span>' + '<span style="display:inline-block;">' + opt.text + '</span>' + '</span>'
                        );


                return $opt;
        };
        function formatSelect(opt){
            var department = $("#ContactUserID option[value=" + opt.id + "]").attr("department");
            var remarktext = $("#ContactUserID option[value=" + opt.id + "]").attr("remarktext");
            var $opt = '';
            if (!opt.id) {
                return opt.text.toUpperCase();
            }
            $opt = $(
                    '<div class="row">' +
                    '<div class="col-sm-12 col-12 text-left">' + opt.text + '<p style="font-style:italic; font-size: 0.8em;">' + department + '</p>' + '<p style="font-size: 0.8em;">' + remarktext + '</p></div>' +
                    '</div>'
                    );

            return $opt;
        }


    function ShowHide(id, show) {
                                                                        if (show == null)
                                                                        show = true; //Optional parameter
                                                                obj = document.getElementsByTagName("div");
                                                                if (obj[id].style.display == 'none' && show) {
                                                                obj[id].style.display = 'block';
                    } else if (!show) {
                                                                        obj[id].style.display = 'none';
                        }
                        }

                    var js_activities = new Array();
                [% foreach from=$activity.DepActivitys item=depact %]
                    js_activities.push(
                    new Array([% $depact.id %], "[% $depact.Descr|htmlspecialchars %]", "[% $depact.Duration %]", "[% $depact.Field %]", "[% $depact.Value|replace:"\\":"\\\\" %]", "[% $depact.orCondition %]")
                );
                                    [% /foreach %]

                            function getContact(contactid, contact, duration, field, value) {
                                                                        var exists = false;
                                                                for (i = 0; i < js_activities.length; i++) {
                                                                if (contactid === js_activities[i][0] && js_activities[i][3] === field && js_activities[i][4] === value) {
                                                                exists = true;
                                                                break;
                                }
                                }
                                if (!exists) {
                                                                        $.post("index.php?module=workflow&event=addDepActivity", {activityid: [% $activity.ID|default:0 %], id: contactid, field: field, value: value});
                    var user = [contactid, contact, duration, field, value];
                    js_activities[js_activities.length] = user;
                            buildCABList();
                            }
                            }

                        function buildCABList() {
                                                                                var HTMLOutput = "";
                                                                        var CABList = document.getElementById("CABList");
                                                                        var js_Activitiess = document.getElementById("DepActs");
                                                                        var users = [];
                                                                        for (i = 0; i < js_activities.length; i++) {
                                                                        HTMLOutput += "<div class=\"activity_active\" onmouseover=\"this.className=\'activity_hover\'\" onmouseout=\"this.className=\'activity_active\'\">";
                                                                        HTMLOutput += "  <div style=\"white-space:normal;\">[% $user->gettext('Aktivit&auml;t') %]: <strong>" + js_activities[i][1] + "</strong>&nbsp;([% $user->gettext('Dauer') %]: " + js_activities[i][2] + ")&nbsp;";
                                                                        if (js_activities[i][3] !== undefined && js_activities[i][3] !== '') {
                                                                        HTMLOutput += '<br/><span class="Brunch">[% $user->gettext('Feld') %]: ' + js_activities[i][3] + ' - [% $user->gettext('Auswahl') %]: ' + js_activities[i][4] + '</span>';
                                    }
                                HTMLOutput += '<span style="float:right;">';
                                if(js_activities[i][5] == 1){ checked = 'checked="checked"'; } else {checked = ''; }
                                    if(js_activities[i][4] !== undefined && js_activities[i][4] != ""){
                                                                                js_activities[i][4] = js_activities[i][4].replace('\\', '\\\\');
                                    }

                                HTMLOutput += " <label>Oder-Bedingung: <input type=\"checkbox\" " + checked + " onclick=\"toggleOr(" + js_activities[i][0] + ",'" + js_activities[i][3] + "','" + js_activities[i][4] + "');\" ></label>";
                                    HTMLOutput += "    <a class=\"btn btn-outline-secondary\" href=\"JavaScript:void(0);\" onclick=\"removejs_Activities(" + js_activities[i][0] + ",'" + js_activities[i][3] + "','" + js_activities[i][4] + "');\" title=\"[% $user->gettext('Aktivität entfernen') %]\"><span class=\"fa fa-trash\" title=\"[% $user->gettext('Aktivität entfernen') %]\"></span></a>";

                                if (js_activities[i][3] !== undefined) {
                                                                                HTMLOutput += '&nbsp;&nbsp;<a class="btn btn-outline-secondary" href="index.php?module=workflow&event=editActivityDef&aid=' + js_activities[i][0] + '" target="_blank" title="[% $user->gettext('Aktivität öffnen') %]"><span class="fa fa-pencil"></a></span>';
                            }
                            HTMLOutput += "  </span></div>&nbsp;&nbsp;";
                                HTMLOutput += "</div>";
                                                                                users[users.length] = js_activities[i][0];
                                                                        }
                                                                        js_Activitiess.value = users.join(",");
                                                                        CABList.innerHTML = HTMLOutput;
                                                                        }

                                                                        function removejs_Activities(id, field, value) {
                                                                        var change = false;
                                                                        field = (field === 'undefined') ? undefined : field;
                                                                        value = (value === 'undefined') ? undefined : value;
                                                                        var tmp = [];
                                                                        for (i = 0; i < js_activities.length; i++) {
                                                                        if (js_activities[i][0] === id && js_activities[i][3] === field && js_activities[i][4] === value) {
                                                                        change = true;
                                                                        } else {
                                                                        tmp[tmp.length] = js_activities[i];
                                                                        }
                                                                        }
                                                                        if (change) {
                                                                        $.post("index.php?module=workflow&event=removeDepActivity", {activityid: [% $activity.ID|default:0 %], id: id, field: field, value: value});
                                                                        js_activities = tmp;
                                                                        buildCABList();
                                                                        }
                                                                        }

                                                    [% if $activity.DepActivitys > 0 %]buildCABList();[% /if %]

                                                                $(".multiple").select2({theme: 'bootstrap-5'});
                                                                $("input[name=TargetType]").on("change", function(){
                                                                var value = $(this).val();
                                                                if (value == 4){
                                                                $.get("index.php?module=workflow&event=checkPreActivitysForAdressData", { aid: [% $activity.ID|default:0 %]})
                                                                        .done(function(data) {
                                                                        $('#AdressSourceActivity').remove();
                                                                        $("#TargetActivitySelection").html('');
                                                                        if (data.cntFields > 0){
//Auswahlliste welche Adressierung verwendet werden soll
                                                                        var s = $('<select id="AdressSourceActivity" name="AdressSourceActivity[]" class="form-control multiple" style="width:100%;" multiple />');
                                                                        $('<option />', {value: '', text: '-- Alle --'}).appendTo(s);
                                                                        $.each(data.Fields, function(index, fields){
                                                                        $.each(fields, function(index, field){
                                                                        $('<option />', {value: field.id, text: field.activityname + " - " + field.field }).attr("selected", '[% $activity.AdressSourceActivity %]' === field.oldid || '[% $activity.AdressSourceActivity %]' === field.id).appendTo(s);
                                                                        });
                                                                        });
                                                                        s.appendTo('#TargetActivitySelection');
                                                                        $("#AdressSourceActivity").select2({theme: 'bootstrap-5'});
                                                                        } else {
                                                                        alert("Es gibt keine Adressauswahl in den Vorg&auml;ngeraktivit&auml;ten!");
                                                                        $('input[name="TargetType"]').removeAttr('checked');
                                                                        $('#setTargetTypeToInitiator').prop('checked', true);
                                                                        $(this).off('click');
                                                                        }
                                                                        });
                                                                }
                                                                });
                                                                $("input[name='startWF[projectSource]']").on("change", function(){

                                                                if ($(this).val() == 0){
                                                                $('#ProjectID').show();
                                                                } else {

                                                                $('#ProjectID').hide();
                                                                }
                                                                })

                                                                        $("input[name='startWF[contactSource]']").on("change", function(){
                                                                if ($(this).val() == 0){
                                                                $('#ContactID').show();
                                                                } else {
                                                                $('#ContactID').hide();
                                                                }
                                                                })

                                                                        $("input[name='startWF[titleSource]']").on("change", function(){
                                                                if ($(this).val() == 0){
                                                                $('#WFTitle').show();
                                                                } else {
                                                                $('#WFTitle').hide();
                                                                }
                                                                })




                                                                        $("input[name='startWF[initiatorSource]']").on("change", function(){
                                                                if ($(this).val() == 1){
                                                                $('#startInitiatorID').hide();
                                                                $('#InitiatorSelection').hide();
                                                                } else if ($(this).val() == 0) {
                                                                $('#startInitiatorID').show();
                                                                $('#InitiatorSelection').hide();
                                                                } else if ($(this).val() == 2) {
                                                                $('#startInitiatorID').hide();
                                                                $('#InitiatorSelection').show();
                                                                }
                                                                })

                                                                        $("input[name='startWF[substitudeSource]']").on("change", function(){
                                                                if ($(this).val() == 1){
                                                                $('#startSubstitudeID').hide();
                                                                $('#SubstitudeSelection').hide();
                                                                } else if ($(this).val() == 0) {
                                                                $('#startSubstitudeID').show();
                                                                $('#SubstitudeSelection').hide();
                                                                } else if ($(this).val() == 2) {
                                                                $('#startSubstitudeID').hide();
                                                                $('#SubstitudeSelection').show();
                                                                }
                                                                })



                                                                        $("#LoopsAllowed").on("change", function() {
                                                                if (this.checked) {
                                                                $.get("index.php?module=workflow&event=checkIfLoopIsPossible&aid=[% $activity.ID|default:0 %]", function(data) {
                                                                if (!data.LoopIsPossible){

                                                                $("#LoopsAllowed").prop('checked', false);
                                                                var String = "[% $user->gettext('Folgende Bedingungen sind in dieser Aktivität nicht erfüllt') %]:";
                                                                String += "<ul>";
                                                                $.each(data.messages, function(i, item) {
                                                                String += "<li>" + item + "</li>";
                                                                });
                                                                String += "</ul>";
                                                                $("#LoopsAllowedError").html(String);
                                                                //$("#LoopsAllowed").attr("disabled", true);
                                                                return false;
                                                                } else {
                                                                $(this).removeAttr("disabled");
                                                                $("#LoopsAllowedError").html("");
                                                                }

                                                                }, "json");
                                                                }
                                                                });
                                                                /**
                                                                 * toggleOr
                                                                 */
                                                                function toggleOr(DepID, field, value) {
                                                                field = (field === 'undefined') ? undefined : field;
                                                                value = (value === 'undefined') ? undefined : value;
                                                                $.get("index.php?module=workflow&event=toggleActivityDefOrCondition", {aid: [% $activity.ID|default:0 %], depid: DepID, field: field, value: value});
                                                                }

                                                    </script>
 <script  src="includes/js/quill2.0.3/hm-quill.js"></script>
 <script>
 
                    [% if $user->hasRight(219) %]
                    let tags = $("#TicketTags").select2({theme:'bootstrap-5'});
                    [% /if %]
 </script>

                                                    <!-- Component Activity form end -->
