<?php

/* @UVDeskAutomation/Workflow/editWorkflow.html.twig */
class __TwigTemplate_b3f9a1afcb8bac487081cf78870d6717239a701a6c1873855e5f32597a72e371 extends Twig_Template
{
    private $source;

    public function __construct(Twig_Environment $env)
    {
        parent::__construct($env);

        $this->source = $this->getSourceContext();

        // line 1
        $this->parent = $this->loadTemplate("@UVDeskCore/Templates/layout.html.twig", "@UVDeskAutomation/Workflow/editWorkflow.html.twig", 1);
        $this->blocks = [
            'title' => [$this, 'block_title'],
            'internalcss' => [$this, 'block_internalcss'],
            'pageContent' => [$this, 'block_pageContent'],
            'footer' => [$this, 'block_footer'],
        ];
    }

    protected function doGetParent(array $context)
    {
        return "@UVDeskCore/Templates/layout.html.twig";
    }

    protected function doDisplay(array $context, array $blocks = [])
    {
        $__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02 = $this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"];
        $__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02->enter($__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02_prof = new Twig_Profiler_Profile($this->getTemplateName(), "template", "@UVDeskAutomation/Workflow/editWorkflow.html.twig"));

        $this->parent->display($context, array_merge($this->blocks, $blocks));
        
        $__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02->leave($__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02_prof);

    }

    // line 3
    public function block_title($context, array $blocks = [])
    {
        $__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02 = $this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"];
        $__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02->enter($__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02_prof = new Twig_Profiler_Profile($this->getTemplateName(), "block", "title"));

        // line 4
        echo "    ";
        if (twig_get_attribute($this->env, $this->source, twig_get_attribute($this->env, $this->source, ($context["app"] ?? null), "request", []), "get", [0 => "id"], "method")) {
            // line 5
            echo "        ";
            echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Edit Workflow"), "html", null, true);
            echo "
    ";
        } else {
            // line 7
            echo "        ";
            echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Add Workflow"), "html", null, true);
            echo "
    ";
        }
        
        $__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02->leave($__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02_prof);

    }

    // line 11
    public function block_internalcss($context, array $blocks = [])
    {
        $__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02 = $this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"];
        $__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02->enter($__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02_prof = new Twig_Profiler_Profile($this->getTemplateName(), "block", "internalcss"));

        // line 12
        echo "    @media(max-width: 767px) {
        #company-workflow > .steps {
            display: none;
        }
    }

    @media(max-width: 579px) {
        #company-workflow > h3 {
            margin-right: 80px;
        }

        #company-workflow > h3 > a {
            position: absolute;
            top: 0px;
            right: 10px;
        }
    }

    .has-error button.btn {
        border-color: #cc5965;
    }
";
        
        $__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02->leave($__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02_prof);

    }

    // line 35
    public function block_pageContent($context, array $blocks = [])
    {
        $__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02 = $this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"];
        $__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02->enter($__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02_prof = new Twig_Profiler_Profile($this->getTemplateName(), "block", "pageContent"));

        // line 36
        echo "    <style>
        .workflow-conditions-body .workflow-condition:first-child .uv-workflow-hr-plank {
            display: none;
        }
        .grammarly-fix-message-container {
\t\t\toverflow: visible !important;
\t\t}
\t\t.grammarly-fix-message {
\t\t\tmax-width: 120%;
\t\t}
        .textarea-fix-action {
            max-width: 500px !important;
        }
    </style>
    <!-- Inner Section -->
    <div class=\"uv-inner-section\">
        ";
        // line 52
        echo twig_include($this->env, $context, "@UVDeskCore/Templates/panel-sidebar.html.twig");
        echo "
        <!-- View -->
        <div class=\"uv-view ";
        // line 54
        if ((twig_get_attribute($this->env, $this->source, twig_get_attribute($this->env, $this->source, ($context["app"] ?? null), "request", []), "cookies", []) && twig_get_attribute($this->env, $this->source, twig_get_attribute($this->env, $this->source, twig_get_attribute($this->env, $this->source, ($context["app"] ?? null), "request", []), "cookies", []), "get", [0 => "uv-asideView"], "method"))) {
            echo "uv-aside-view";
        }
        echo "\">
            <!-- Form -->
            ";
        // line 56
        if ( !twig_test_empty(twig_get_attribute($this->env, $this->source, twig_get_attribute($this->env, $this->source, ($context["app"] ?? null), "request", []), "get", [0 => "id"], "method"))) {
            // line 57
            echo "                <h1>";
            echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Edit Workflow"), "html", null, true);
            echo "</h1>
                <form class=\"workflow-form\" name=\"form-workflow\" method=\"POST\" action=\"";
            // line 58
            echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\RoutingExtension']->getPath("workflows_editaction", ["id" => twig_get_attribute($this->env, $this->source, twig_get_attribute($this->env, $this->source, ($context["app"] ?? null), "request", []), "get", [0 => "id"], "method")]), "html", null, true);
            echo "\">
            ";
        } else {
            // line 60
            echo "                <h1>";
            echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("New Workflow"), "html", null, true);
            echo "</h1>
                <form class=\"workflow-form\" name=\"form-workflow\" method=\"POST\" action=\"";
            // line 61
            echo $this->extensions['Symfony\Bridge\Twig\Extension\RoutingExtension']->getPath("workflows_addaction");
            echo "\">
            ";
        }
        // line 63
        echo "                <!-- Workflow Description Section -->
                <div class=\"uv-element-block\">
                    <label class=\"uv-field-label\">";
        // line 65
        echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Name"), "html", null, true);
        echo "</label>
                    <div class=\"uv-field-block\">
                        <input name=\"name\" class=\"uv-field\" type=\"text\" value=\"";
        // line 67
        echo twig_escape_filter($this->env, ((twig_get_attribute($this->env, $this->source, ($context["formData"] ?? null), "name", [], "any", true, true)) ? (twig_get_attribute($this->env, $this->source, ($context["formData"] ?? null), "name", [])) : ("")), "html", null, true);
        echo "\">
                        <p class=\"uv-field-message\">";
        // line 68
        if (twig_get_attribute($this->env, $this->source, ($context["error"] ?? null), "name", [], "any", true, true)) {
            echo twig_escape_filter($this->env, twig_get_attribute($this->env, $this->source, ($context["error"] ?? null), "name", []), "html", null, true);
        }
        echo "</p>
                    </div>
                </div>

                <div class=\"uv-element-block\">
                    <label class=\"uv-field-label\">";
        // line 73
        echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Description"), "html", null, true);
        echo "</label>
                    <div class=\"uv-field-block grammarly-fix-message-container\">
                        <textarea name=\"description\" class=\"uv-field grammarly-fix-message\">";
        // line 75
        echo twig_escape_filter($this->env, ((twig_get_attribute($this->env, $this->source, ($context["formData"] ?? null), "description", [], "any", true, true)) ? (twig_get_attribute($this->env, $this->source, ($context["formData"] ?? null), "description", [])) : ("")), "html", null, true);
        echo "</textarea>
                        <p class=\"uv-field-message\">";
        // line 76
        if (twig_get_attribute($this->env, $this->source, ($context["error"] ?? null), "description", [], "any", true, true)) {
            echo twig_escape_filter($this->env, twig_get_attribute($this->env, $this->source, ($context["error"] ?? null), "description", []), "html", null, true);
        }
        echo "</p>
                    </div>
                </div>

                <div class=\"uv-element-block\">
                    <label class=\"uv-field-label\">";
        // line 81
        echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Workflow Status"), "html", null, true);
        echo "</label>
                    <div class=\"uv-element-block\">
                        <label>
                            <div class=\"uv-checkbox\">
                                <input name=\"status\" type=\"checkbox\" ";
        // line 85
        echo (((twig_get_attribute($this->env, $this->source, ($context["formData"] ?? null), "status", [], "any", true, true) && (twig_get_attribute($this->env, $this->source, ($context["formData"] ?? null), "status", []) == "on"))) ? ("checked") : (""));
        echo ">
                                <span class=\"uv-checkbox-view\"></span>
                            </div>
                            <span class=\"uv-checkbox-label\">";
        // line 88
        echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Workflow is Active"), "html", null, true);
        echo "</span>
                        </label>
                    </div>
                </div>

                <div class=\"uv-hr\"></div>
                <!-- // Workflow Description Section -->


                <!-- Workflow Events Section -->
                <div id=\"events\" class=\"uv-field-workflow\">
                    <label class=\"uv-field-label\">";
        // line 99
        echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Events"), "html", null, true);
        echo "</label>
                    <span class=\"uv-field-info\">";
        // line 100
        echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("An event automatically triggers to check conditions and perform a respective pre-defined set of actions"), "html", null, true);
        echo "</span>

                    <div class=\"workflow-event-body\"></div>
                    <div class=\"uv-workflow-buttons\">
                        <a class=\"uv-btn-tag btn-add\" href=\"#\">
                            <span class=\"uv-icon-add-dark\"></span> ";
        // line 105
        echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Add More"), "html", null, true);
        echo "
                        </a>
                    </div>
                </div>

                <div class=\"uv-hr\"></div>
                <!-- // Workflow Events Section -->

                <!-- Workflow Conditions Section -->
                <div id=\"conditions\" class=\"uv-field-workflow\" >
                    <label class=\"uv-field-label\">";
        // line 115
        echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Conditions"), "html", null, true);
        echo "</label>
                    <span class=\"uv-field-info\">";
        // line 116
        echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Conditions are set of rules which checks for specific scenarios and are triggered on specific occasions"), "html", null, true);
        echo "</span>

                    <div class=\"workflow-conditions-body\"></div>
                    <div class=\"uv-workflow-buttons\">
                        <a class=\"uv-btn-tag btn-or\" href=\"#\">
                            <span class=\"uv-icon-add-dark\"></span> ";
        // line 121
        echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("OR"), "html", null, true);
        echo "
                        </a>
                        <a class=\"uv-btn-tag btn-and\" href=\"#\">
                            <span class=\"uv-icon-add-dark\"></span> ";
        // line 124
        echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("AND"), "html", null, true);
        echo "
                        </a>
                    </div>
                </div>
                <!-- // Workflow Conditions Section -->
                <div class=\"uv-hr\"></div>
                


                <!-- Workflow Actions Section -->
                <div id=\"actions\" class=\"uv-element-block uv-field-workflow\">
                    <label class=\"uv-field-label\">";
        // line 135
        echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Actions"), "html", null, true);
        echo "</label>
                    <span class=\"uv-field-info\">";
        // line 136
        echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("An action not only reduces the workload but also makes it quite easier for ticket automation"), "html", null, true);
        echo "</span>

                    <div class=\"workflow-action-body\"></div>
                    <div class=\"uv-workflow-buttons\">
                        <a class=\"uv-btn-tag btn-add\" href=\"#\">
                            <span class=\"uv-icon-add-dark\"></span> ";
        // line 141
        echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Add More"), "html", null, true);
        echo "
                        </a>
                    </div>
                </div>
                <!-- // Workflow Actions Section -->


                <!-- CTA -->
                ";
        // line 150
        echo "                <button type=\"submit\" name=\"submit\" class=\"uv-btn\" href=\"#\">";
        if ( !twig_test_empty(twig_get_attribute($this->env, $this->source, twig_get_attribute($this->env, $this->source, ($context["app"] ?? null), "request", []), "get", [0 => "id"], "method"))) {
            echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Save Workflow"), "html", null, true);
        } else {
            echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Add Workflow"), "html", null, true);
        }
        echo "</button>
                <!-- // CTA -->
            </form>
            <!-- Form -->
        </div>
        <!-- // View -->
    </div>
    <!-- // Inner Section -->
";
        
        $__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02->leave($__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02_prof);

    }

    // line 160
    public function block_footer($context, array $blocks = [])
    {
        $__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02 = $this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"];
        $__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02->enter($__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02_prof = new Twig_Profiler_Profile($this->getTemplateName(), "block", "footer"));

        // line 161
        echo "    ";
        $this->displayParentBlock("footer", $context, $blocks);
        echo "

    <script type=\"text/javascript\">
        _.extend(Backbone.Validation.patterns, {
          stringPattern: /[a-z0-9]/i,
        });

        _.extend(Backbone.Validation.callbacks, {
            valid : function (view, attr, selector) {
                \$('[name=\"'+attr+'\"]').closest('.uv-field-block').find('.uv-field-message').html('').fadeOut(0);
            },
            invalid : function (view, attr, error, selector) {
                \$('[name=\"'+attr+'\"]').closest('.uv-field-block').find('.uv-field-message').html(error).fadeIn(0);
            }
        });

        if(typeof(sB) == 'undefined'){
          var sB = {};
        }

        sB.WorkflowCollection = Backbone.Collection.extend({
            baseUrl: \"";
        // line 182
        echo $this->extensions['Symfony\Bridge\Twig\Extension\RoutingExtension']->getPath("ajax_service_call");
        echo "\",
            fetchResult: function(dataMatch) {
            this.url = this.baseUrl;
            return this.fetch({ 'data' : {
                'service': 'email.service',
                'call': 'getEmailPlaceHolders',
                'options': { 'match': dataMatch },
            }});
        }});
        sB.workflowCollection = new sB.WorkflowCollection();

        sB.WorkflowModel = Backbone.Model.extend({
            validation: {
                name: {
                    required: true,
                    pattern: 'stringPattern',
                    msg: \"";
        // line 198
        echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Please enter a valid name."), "html", null, true);
        echo "\"
                },
            },
            validateSelect: function(value, attr, computedState) {
                var currentSelectValue = \$('select[name=\"'+ attr + '\"]').find(':selected').length;
                if (!value) {
                    return \"";
        // line 204
        echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Please select a value."), "html", null, true);
        echo "\";
                }
            },
            validateSelectMultiple: function(value, attr, computedState) {
                var currentSelectValue = \$('[name=\"'+ attr + '\"]').length;
                if (!value) {
                    return \"";
        // line 210
        echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Please select a value."), "html", null, true);
        echo "\";
                }
            },
            validateSelectText: function(value, attr, computedState) {
                if (!value) {
                    return \"";
        // line 215
        echo twig_escape_filter($this->env, $this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans("Please add a value."), "html", null, true);
        echo "\";
                }
            }
        });

        sB.WorkflowView = Backbone.View.extend({
            el: '.uv-view',
            initialize: function() {
                this.model = new sB.WorkflowModel();
                Backbone.Validation.bind(this);
            },
            events: {
                'submit form[name=\"form-workflow\"]': 'processWorkflow',
            },
            processWorkflow: function(e) {
                var disabledCollection = this.\$el.find('form').find('[disabled]');
                if (\$(disabledCollection).length > 0) {
                    \$.each(\$(disabledCollection), function(index, nodeElement) {
                        \$(nodeElement).removeAttr('disabled');
                    });
                }

                this.model.set(this.\$el.find('form').serializeObject());

                var self = this;
                filterArray = ['name'];
                // Populate Filter Array - Events and Actions are required fields

                // Event
                this.\$('.wfEvents').each(function(key, value) {
                    filterArray.push(\$(value).attr('name'));
                    self.model.validation[\$(value).attr('name')] = 'validateSelect';
                });
                this.\$('.wfEventTriggers').each(function(key, value) {
                    filterArray.push(\$(value).attr('name'));
                    self.model.validation[\$(value).attr('name')] = 'validateSelect';
                });

                // Conditions
                if (\$(\"[name='events[0][event]']\").val() == 'ticket' || \$(\"[name='events[0][event]']\").val() == 'task') {
                    this.\$('.wfCondition').each(function(key, value) {
                        filterArray.push(\$(value).attr('name'));
                        self.model.validation[\$(value).attr('name')] = 'validateSelect';
                    });
                    this.\$('.wfConditionMatch').each(function(key, value) {
                        filterArray.push(\$(value).attr('name'));
                        self.model.validation[\$(value).attr('name')] = 'validateSelect';
                    });
                    this.\$('.wfConditionValue').each(function(key, value) {
                        if (\$(this).attr('name') == undefined) {
                            return;
                        }
                        filterArray.push(\$(value).attr('name'));
                        self.model.validation[\$(value).attr('name')] = 'validateSelectText';
                    });
                }

                // Actions
                this.\$('.wfAction').each(function(key, value) {
                    filterArray.push(\$(value).attr('name'));
                    self.model.validation[\$(value).attr('name')] = 'validateSelect';
                });
                this.\$('.wfActionMultiple').each(function(key, value) {
                    filterArray.push(\$(value).attr('name'));
                    self.model.validation[\$(value).attr('name')] = 'validateSelectMultiple';
                });
                this.\$('.wfActionValue').each(function(key, value) {
                    if (\$(this).attr('name') == undefined) {
                        return;
                    }

                    filterArray.push(\$(value).attr('name'));
                    self.model.validation[\$(value).attr('name')] = 'validateSelectText';
                });

                if (this.validateData(filterArray)) {
                    return true;
                } else {
                    e.preventDefault();
                    if (\$(disabledCollection).length > 0) {
                        \$.each(\$(disabledCollection), function(index, nodeElement) {
                            \$(nodeElement).attr('disabled', 'disabled');
                        });
                    }
                }
            },
            validateData: function(filterArray) {
                return this.model.isValid(filterArray);
            },
            updateActive: function(e){
                this.\$('div.step-info').each(function() {
                    \$(this).addClass('active');
                    if (\$(this).attr('data-href') == self.\$(e.target).attr('href'))
                        return false;
                });
            }
        });
        sB.workflowView = new sB.WorkflowView();

        \$.fn.serializeObject = function () {
            \"use strict\";
            var a = {}, b = function (b, c) {
                var d = a[c.name];
                \"undefined\" != typeof d && d !== null ? \$.isArray(d) ? d.push(c.value) : a[c.name] = [d, c.value] : a[c.name] = c.value
            };
            return \$.each(this.serializeArray(), b), a
        };
    </script>

    ";
        // line 324
        echo twig_include($this->env, $context, "@UVDeskAutomation//Workflow//events.html.twig");
        echo "
    ";
        // line 325
        echo twig_include($this->env, $context, "@UVDeskAutomation//Workflow//conditions.html.twig");
        echo "
    ";
        // line 326
        echo twig_include($this->env, $context, "@UVDeskAutomation//Workflow//actions.html.twig");
        echo "

";
        
        $__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02->leave($__internal_319393461309892924ff6e74d6d6e64287df64b63545b994e100d4ab223aed02_prof);

    }

    public function getTemplateName()
    {
        return "@UVDeskAutomation/Workflow/editWorkflow.html.twig";
    }

    public function isTraitable()
    {
        return false;
    }

    public function getDebugInfo()
    {
        return array (  525 => 326,  521 => 325,  517 => 324,  405 => 215,  397 => 210,  388 => 204,  379 => 198,  360 => 182,  335 => 161,  329 => 160,  308 => 150,  297 => 141,  289 => 136,  285 => 135,  271 => 124,  265 => 121,  257 => 116,  253 => 115,  240 => 105,  232 => 100,  228 => 99,  214 => 88,  208 => 85,  201 => 81,  191 => 76,  187 => 75,  182 => 73,  172 => 68,  168 => 67,  163 => 65,  159 => 63,  154 => 61,  149 => 60,  144 => 58,  139 => 57,  137 => 56,  130 => 54,  125 => 52,  107 => 36,  101 => 35,  73 => 12,  67 => 11,  56 => 7,  50 => 5,  47 => 4,  41 => 3,  15 => 1,);
    }

    public function getSourceContext()
    {
        return new Twig_Source("{% extends \"@UVDeskCore/Templates/layout.html.twig\" %}

{% block title %}
    {% if app.request.get('id') %}
        {{ 'Edit Workflow' | trans }}
    {% else %}
        {{ 'Add Workflow' | trans }}
    {% endif %}
{% endblock %}

{% block internalcss %}
    @media(max-width: 767px) {
        #company-workflow > .steps {
            display: none;
        }
    }

    @media(max-width: 579px) {
        #company-workflow > h3 {
            margin-right: 80px;
        }

        #company-workflow > h3 > a {
            position: absolute;
            top: 0px;
            right: 10px;
        }
    }

    .has-error button.btn {
        border-color: #cc5965;
    }
{% endblock %}

{% block pageContent %}
    <style>
        .workflow-conditions-body .workflow-condition:first-child .uv-workflow-hr-plank {
            display: none;
        }
        .grammarly-fix-message-container {
\t\t\toverflow: visible !important;
\t\t}
\t\t.grammarly-fix-message {
\t\t\tmax-width: 120%;
\t\t}
        .textarea-fix-action {
            max-width: 500px !important;
        }
    </style>
    <!-- Inner Section -->
    <div class=\"uv-inner-section\">
        {{ include('@UVDeskCore/Templates/panel-sidebar.html.twig') }}
        <!-- View -->
        <div class=\"uv-view {% if app.request.cookies and app.request.cookies.get('uv-asideView') %}uv-aside-view{% endif %}\">
            <!-- Form -->
            {% if app.request.get('id') is not empty %}
                <h1>{{ 'Edit Workflow'|trans }}</h1>
                <form class=\"workflow-form\" name=\"form-workflow\" method=\"POST\" action=\"{{ path('workflows_editaction', {'id': app.request.get('id')}) }}\">
            {% else %}
                <h1>{{ 'New Workflow'|trans }}</h1>
                <form class=\"workflow-form\" name=\"form-workflow\" method=\"POST\" action=\"{{ path('workflows_addaction') }}\">
            {% endif %}
                <!-- Workflow Description Section -->
                <div class=\"uv-element-block\">
                    <label class=\"uv-field-label\">{{ 'Name'|trans }}</label>
                    <div class=\"uv-field-block\">
                        <input name=\"name\" class=\"uv-field\" type=\"text\" value=\"{{ formData.name is defined ? formData.name : '' }}\">
                        <p class=\"uv-field-message\">{% if error.name is defined %}{{ error.name }}{% endif %}</p>
                    </div>
                </div>

                <div class=\"uv-element-block\">
                    <label class=\"uv-field-label\">{{ 'Description'|trans }}</label>
                    <div class=\"uv-field-block grammarly-fix-message-container\">
                        <textarea name=\"description\" class=\"uv-field grammarly-fix-message\">{{ formData.description is defined ? formData.description : '' }}</textarea>
                        <p class=\"uv-field-message\">{% if error.description is defined %}{{ error.description }}{% endif %}</p>
                    </div>
                </div>

                <div class=\"uv-element-block\">
                    <label class=\"uv-field-label\">{{ 'Workflow Status'|trans }}</label>
                    <div class=\"uv-element-block\">
                        <label>
                            <div class=\"uv-checkbox\">
                                <input name=\"status\" type=\"checkbox\" {{ formData.status is defined and formData.status == 'on' ? 'checked' : '' }}>
                                <span class=\"uv-checkbox-view\"></span>
                            </div>
                            <span class=\"uv-checkbox-label\">{{ 'Workflow is Active'|trans }}</span>
                        </label>
                    </div>
                </div>

                <div class=\"uv-hr\"></div>
                <!-- // Workflow Description Section -->


                <!-- Workflow Events Section -->
                <div id=\"events\" class=\"uv-field-workflow\">
                    <label class=\"uv-field-label\">{{ 'Events'|trans }}</label>
                    <span class=\"uv-field-info\">{{ \"An event automatically triggers to check conditions and perform a respective pre-defined set of actions\"|trans }}</span>

                    <div class=\"workflow-event-body\"></div>
                    <div class=\"uv-workflow-buttons\">
                        <a class=\"uv-btn-tag btn-add\" href=\"#\">
                            <span class=\"uv-icon-add-dark\"></span> {{'Add More'|trans}}
                        </a>
                    </div>
                </div>

                <div class=\"uv-hr\"></div>
                <!-- // Workflow Events Section -->

                <!-- Workflow Conditions Section -->
                <div id=\"conditions\" class=\"uv-field-workflow\" >
                    <label class=\"uv-field-label\">{{ 'Conditions'|trans }}</label>
                    <span class=\"uv-field-info\">{{ 'Conditions are set of rules which checks for specific scenarios and are triggered on specific occasions'|trans }}</span>

                    <div class=\"workflow-conditions-body\"></div>
                    <div class=\"uv-workflow-buttons\">
                        <a class=\"uv-btn-tag btn-or\" href=\"#\">
                            <span class=\"uv-icon-add-dark\"></span> {{ 'OR'|trans }}
                        </a>
                        <a class=\"uv-btn-tag btn-and\" href=\"#\">
                            <span class=\"uv-icon-add-dark\"></span> {{ 'AND'|trans }}
                        </a>
                    </div>
                </div>
                <!-- // Workflow Conditions Section -->
                <div class=\"uv-hr\"></div>
                


                <!-- Workflow Actions Section -->
                <div id=\"actions\" class=\"uv-element-block uv-field-workflow\">
                    <label class=\"uv-field-label\">{{ 'Actions'|trans }}</label>
                    <span class=\"uv-field-info\">{{ 'An action not only reduces the workload but also makes it quite easier for ticket automation'|trans }}</span>

                    <div class=\"workflow-action-body\"></div>
                    <div class=\"uv-workflow-buttons\">
                        <a class=\"uv-btn-tag btn-add\" href=\"#\">
                            <span class=\"uv-icon-add-dark\"></span> {{ 'Add More'|trans }}
                        </a>
                    </div>
                </div>
                <!-- // Workflow Actions Section -->


                <!-- CTA -->
                {# <input type=\"submit\" class=\"uv-btn\" href=\"#\" value=\"Save Workflow\"> #}
                <button type=\"submit\" name=\"submit\" class=\"uv-btn\" href=\"#\">{% if app.request.get('id') is not empty %}{{ 'Save Workflow'|trans }}{% else %}{{ 'Add Workflow'|trans }}{% endif %}</button>
                <!-- // CTA -->
            </form>
            <!-- Form -->
        </div>
        <!-- // View -->
    </div>
    <!-- // Inner Section -->
{% endblock %}

{% block footer %}
    {{ parent() }}

    <script type=\"text/javascript\">
        _.extend(Backbone.Validation.patterns, {
          stringPattern: /[a-z0-9]/i,
        });

        _.extend(Backbone.Validation.callbacks, {
            valid : function (view, attr, selector) {
                \$('[name=\"'+attr+'\"]').closest('.uv-field-block').find('.uv-field-message').html('').fadeOut(0);
            },
            invalid : function (view, attr, error, selector) {
                \$('[name=\"'+attr+'\"]').closest('.uv-field-block').find('.uv-field-message').html(error).fadeIn(0);
            }
        });

        if(typeof(sB) == 'undefined'){
          var sB = {};
        }

        sB.WorkflowCollection = Backbone.Collection.extend({
            baseUrl: \"{{ path('ajax_service_call') }}\",
            fetchResult: function(dataMatch) {
            this.url = this.baseUrl;
            return this.fetch({ 'data' : {
                'service': 'email.service',
                'call': 'getEmailPlaceHolders',
                'options': { 'match': dataMatch },
            }});
        }});
        sB.workflowCollection = new sB.WorkflowCollection();

        sB.WorkflowModel = Backbone.Model.extend({
            validation: {
                name: {
                    required: true,
                    pattern: 'stringPattern',
                    msg: \"{{ 'Please enter a valid name.'|trans }}\"
                },
            },
            validateSelect: function(value, attr, computedState) {
                var currentSelectValue = \$('select[name=\"'+ attr + '\"]').find(':selected').length;
                if (!value) {
                    return \"{{ 'Please select a value.'|trans }}\";
                }
            },
            validateSelectMultiple: function(value, attr, computedState) {
                var currentSelectValue = \$('[name=\"'+ attr + '\"]').length;
                if (!value) {
                    return \"{{ 'Please select a value.'|trans }}\";
                }
            },
            validateSelectText: function(value, attr, computedState) {
                if (!value) {
                    return \"{{ 'Please add a value.'|trans }}\";
                }
            }
        });

        sB.WorkflowView = Backbone.View.extend({
            el: '.uv-view',
            initialize: function() {
                this.model = new sB.WorkflowModel();
                Backbone.Validation.bind(this);
            },
            events: {
                'submit form[name=\"form-workflow\"]': 'processWorkflow',
            },
            processWorkflow: function(e) {
                var disabledCollection = this.\$el.find('form').find('[disabled]');
                if (\$(disabledCollection).length > 0) {
                    \$.each(\$(disabledCollection), function(index, nodeElement) {
                        \$(nodeElement).removeAttr('disabled');
                    });
                }

                this.model.set(this.\$el.find('form').serializeObject());

                var self = this;
                filterArray = ['name'];
                // Populate Filter Array - Events and Actions are required fields

                // Event
                this.\$('.wfEvents').each(function(key, value) {
                    filterArray.push(\$(value).attr('name'));
                    self.model.validation[\$(value).attr('name')] = 'validateSelect';
                });
                this.\$('.wfEventTriggers').each(function(key, value) {
                    filterArray.push(\$(value).attr('name'));
                    self.model.validation[\$(value).attr('name')] = 'validateSelect';
                });

                // Conditions
                if (\$(\"[name='events[0][event]']\").val() == 'ticket' || \$(\"[name='events[0][event]']\").val() == 'task') {
                    this.\$('.wfCondition').each(function(key, value) {
                        filterArray.push(\$(value).attr('name'));
                        self.model.validation[\$(value).attr('name')] = 'validateSelect';
                    });
                    this.\$('.wfConditionMatch').each(function(key, value) {
                        filterArray.push(\$(value).attr('name'));
                        self.model.validation[\$(value).attr('name')] = 'validateSelect';
                    });
                    this.\$('.wfConditionValue').each(function(key, value) {
                        if (\$(this).attr('name') == undefined) {
                            return;
                        }
                        filterArray.push(\$(value).attr('name'));
                        self.model.validation[\$(value).attr('name')] = 'validateSelectText';
                    });
                }

                // Actions
                this.\$('.wfAction').each(function(key, value) {
                    filterArray.push(\$(value).attr('name'));
                    self.model.validation[\$(value).attr('name')] = 'validateSelect';
                });
                this.\$('.wfActionMultiple').each(function(key, value) {
                    filterArray.push(\$(value).attr('name'));
                    self.model.validation[\$(value).attr('name')] = 'validateSelectMultiple';
                });
                this.\$('.wfActionValue').each(function(key, value) {
                    if (\$(this).attr('name') == undefined) {
                        return;
                    }

                    filterArray.push(\$(value).attr('name'));
                    self.model.validation[\$(value).attr('name')] = 'validateSelectText';
                });

                if (this.validateData(filterArray)) {
                    return true;
                } else {
                    e.preventDefault();
                    if (\$(disabledCollection).length > 0) {
                        \$.each(\$(disabledCollection), function(index, nodeElement) {
                            \$(nodeElement).attr('disabled', 'disabled');
                        });
                    }
                }
            },
            validateData: function(filterArray) {
                return this.model.isValid(filterArray);
            },
            updateActive: function(e){
                this.\$('div.step-info').each(function() {
                    \$(this).addClass('active');
                    if (\$(this).attr('data-href') == self.\$(e.target).attr('href'))
                        return false;
                });
            }
        });
        sB.workflowView = new sB.WorkflowView();

        \$.fn.serializeObject = function () {
            \"use strict\";
            var a = {}, b = function (b, c) {
                var d = a[c.name];
                \"undefined\" != typeof d && d !== null ? \$.isArray(d) ? d.push(c.value) : a[c.name] = [d, c.value] : a[c.name] = c.value
            };
            return \$.each(this.serializeArray(), b), a
        };
    </script>

    {{ include('@UVDeskAutomation//Workflow//events.html.twig') }}
    {{ include('@UVDeskAutomation//Workflow//conditions.html.twig') }}
    {{ include('@UVDeskAutomation//Workflow//actions.html.twig') }}

{% endblock %}
", "@UVDeskAutomation/Workflow/editWorkflow.html.twig", "/home/users/akshay.kumar/Workstation/apps/uvdesk/releases/uvdesk_community_01_development_php_72/vendor/uvdesk/automation-bundle/Resources/views/Workflow/editWorkflow.html.twig");
    }
}
