vendor/uvdesk/core-framework/Resources/views/Snippets/createMemberTicket.html.twig line 1

Open in your IDE?
  1. <style>
  2.     .mce-path {
  3.               display: none !important;
  4.     }
  5. </style>
  6. {% set isTicketViewPage = ('helpdesk_member_ticket' == app.request.attributes.get('_route')) %}
  7. <div class="uv-pop-up-overlay uv-no-error-success-icon" id="create-ticket-modal">
  8.     <div class="uv-pop-up-box uv-pop-up-wide">
  9.         <span class="uv-pop-up-close"></span>
  10.         <h2>Create Ticket</h2>
  11.         <form action="{{ path('helpdesk_member_create_ticket') }}" method="post" id="create-ticket-form" enctype="multipart/form-data">
  12.             {# Customer Details #}
  13.             {% if not isTicketViewPage %}
  14.                 {# Name #}
  15.                 <div class="uv-element-block">
  16.                     <label class="uv-field-label">{{ 'Name'|trans }}</label>
  17.                     <div class="uv-field-block">
  18.                         <input name="name" class="uv-field create-ticket" type="text" value="">
  19.                     </div>
  20.                     <span class="uv-field-info">{{ 'Customer full name'|trans }}</span>
  21.                 </div>
  22.                 {# Email #}
  23.                 <div class="uv-element-block">
  24.                     <label class="uv-field-label">{{ 'Email'|trans }}</label>
  25.                     <div class="uv-field-block">
  26.                         <input name="from" class="uv-field create-ticket" type="text" value="">
  27.                     </div>
  28.                     <span class="uv-field-info">{{ 'Customer email address'|trans }}</span>
  29.                 </div>
  30.             {% else %}
  31.                 {# Retrieve customer details from the current ticket being visited #}
  32.                 <span class="uv-field-info">{{ "Ticket will be created with current ticket's customer"|trans }}</span>
  33.             {% endif %}
  34.             {# Ticket Type #}
  35.             <div class="uv-element-block">
  36.                 <label class="uv-field-label">{{ 'Type'|trans }}</label>
  37.                 <div class="uv-field-block">
  38.                     <select name="type" class="uv-select create-ticket" id="type">
  39.                         <option value="">{{ 'Select type'|trans }}</option>
  40.                             {% for type in ticket_service.getTypes()  %}
  41.                                 <option value="{{ type.id }}" {{ post.type is defined and post.type == type.id ? 'selected' : '' }}>{{ type.name }}
  42.                                 </option>
  43.                             {% endfor %}
  44.                     </select>
  45.                 </div>
  46.                 <span class="uv-field-info">{{ 'Choose ticket type'|trans }}</span>
  47.             </div>
  48.             {# Ticket Subject #}
  49.             <div class="uv-element-block">
  50.                 <label class="uv-field-label">{{ 'Subject'|trans }}</label>
  51.                 <div class="uv-field-block">
  52.                     <input name="subject" class="uv-field create-ticket" type="text" value="">
  53.                 </div>
  54.                 <span class="uv-field-info">{{ 'Ticket subject'|trans }}</span>
  55.             </div>
  56.             {# Ticket Message #}
  57.             <div class="uv-element-block">
  58.                 <label class="uv-field-label">{{ 'Message'|trans }}</label>
  59.                 <div class="uv-field-block">
  60.                     <textarea name="reply" id="create-reply" class="uv-field create-ticket" type="text">{{ ticket_service.getAgentDraftReply() }}</textarea>
  61.                 </div>
  62.                 
  63.                 <span class="uv-field-info">{{ 'Ticket query message'|trans }}</span>
  64.             </div>
  65.             {# Ticket Attachment #}
  66.             <div class="uv-element-block attachment-block uv-no-error-success-icon" id="uv-attachment-option">
  67.                 <label>
  68.                     <span class="uv-file-label">{{ 'Add Attachment'|trans }}</span>
  69.                 </label>
  70.             </div>
  71.             {# CustomFields #}
  72.             {% set removeMe = [] %}
  73.             {% if headerCustomFields %}
  74.                 <div class="custom-fields clearfix">
  75.                     {% for key, customField in headerCustomFields %}
  76.                         <div class="uv-element-block input-group {{ customField.customFieldsDependency|length ? 'dependent' : '' }} {% for customFieldCustomFieldsDependency in customField.customFieldsDependency %} dependency{{customFieldCustomFieldsDependency.id}}{% endfor %}" style="position: relative; {{ customField.customFieldsDependency|length ? 'display: none;' : '' }}">
  77.                             <label class="uv-field-label" for="for{{customField.name~customField.id}}">{{ customField.name }}</label>
  78.                             {% if customField.fieldType == 'text' %}
  79.                                 <div class="uv-field-block">
  80.                                     <input type="{{ customField['validation']['fieldtype'] is defined ? customField['validation']['fieldtype'] :'text' }}" name="customFields[{{customField.id}}]" class="uv-field create-ticket" value="" {{ customField.required ? "required" : "" }} id="for{{customField.name~customField.id}}" placeholder="{{customField.placeholder}}">
  81.                                 </div>
  82.                             {% elseif customField.fieldType in ['date', 'time', 'datetime'] %}
  83.                                 <div class="uv-field-block">
  84.                                     <input class="uv-field form-control create-ticket uv-date-picker {% if customField.fieldType == 'time' %}time{% else %}calendar{% endif %} uv-header-{{ customField.fieldType }}" type="text" name="customFields[{{customField.id}}]" {{ customField.required ? "required" : "" }} id="for{{customField.name~customField.id}}" value="">
  85.                                 </div>
  86.                             {% elseif customField.fieldType == 'textarea' %}
  87.                                 <div class="uv-field-block">
  88.                                     <textarea name="customFields[{{customField.id}}]" class="uv-field create-ticket" {{ customField.required ? "required" : "" }} id="for{{customField.name~customField.id}}"></textarea>
  89.                                 </div>
  90.                             {% elseif customField.fieldType in ['file'] %}
  91.                                 <div class="uv-field-block">
  92.                                     <input type="file" name="customFields[{{customField.id}}]" class="uv-field create-ticket" {{ customField.required ? "required" : "" }} id="for{{customField.name~customField.id}}">
  93.                                 </div>
  94.                             {% elseif customField.fieldType in ['select'] %}
  95.                                 {% if customField.customFieldValues is not empty %}
  96.                                     <div class="uv-field-block">
  97.                                         <select name="customFields[{{customField.id}}]" class="uv-select create-ticket" id="for{{customField.name~customField.id}}" {{ customField.required ? "required" : "" }}>
  98.                                             <option value="">{{ 'Select option' }}</option>
  99.                                             {% for customFieldValues in customField.customFieldValues %}
  100.                                                 <option value="{{customFieldValues.id}}">{{customFieldValues.name}}</option>
  101.                                             {% endfor %}
  102.                                         </select>
  103.                                     </div>
  104.                                 {% else %}
  105.                                     <!--Hide this beacause choices aren't available-->
  106.                                     {% set removeMe = removeMe|merge(["for"~customField.name~customField.id]) %}
  107.                                 {% endif %}
  108.                             {% elseif customField.fieldType in ['checkbox'] %}
  109.                                 {% if customField.customFieldValues is not empty %}
  110.                                     {% for customFieldValues in customField.customFieldValues %}
  111.                                         <div class="uv-split-field">
  112.                                             <label>
  113.                                                 <div class="uv-checkbox">
  114.                                                     <input type="checkbox" name="customFields[{{customField.id}}][]" value="{{customFieldValues.id}}" id="for{{customFieldValues.name~customFieldValues.id}}" class="create-ticket"/>
  115.                                                     <span class="uv-checkbox-view"></span>
  116.                                                 </div>
  117.                                                 <span class="uv-radio-label" for="for{{customFieldValues.name~customFieldValues.id}}">{{ customFieldValues.name }}</span>
  118.                                             </label>
  119.                                         </div>
  120.                                     {% endfor %}
  121.                                 {% else %}
  122.                                     <!--Hide this beacause choices aren't available-->
  123.                                     {% set removeMe = removeMe|merge(["for"~customField.name~customField.id]) %}
  124.                                 {% endif %}
  125.                             {% elseif customField.fieldType in ['radio'] %}
  126.                                 {% if customField.customFieldValues is not empty %}
  127.                                     {% for customFieldValues in customField.customFieldValues %}
  128.                                         <div class="uv-split-field">
  129.                                             <label>
  130.                                                 <div class="uv-radio">
  131.                                                     <input type="radio" name="customFields[{{customField.id}}]" value="{{customFieldValues.id}}" id="for{{customFieldValues.name~customFieldValues.id}}" class="create-ticket"/>
  132.                                                     <span class="uv-radio-view"></span>
  133.                                                 </div>
  134.                                                 <span class="uv-radio-label" for="for{{customFieldValues.name~customFieldValues.id}}">{{ customFieldValues.name }}</span>
  135.                                             </label>
  136.                                         </div>
  137.                                     {% endfor %}
  138.                                 {% else %}
  139.                                     <!--Hide this beacause choices aren't available-->
  140.                                     {% set removeMe = removeMe|merge(["for"~customField.name~customField.id]) %}
  141.                                 {% endif %}
  142.                             {% endif %}
  143.                             {% if formErrors['customFields['~customField.id~']'] is defined %}
  144.                                 <div class="text-danger">{{formErrors['customFields['~customField.id~']']}}</div>
  145.                             {% endif %}
  146.                         </div>
  147.                     {% endfor %}
  148.                 </div>
  149.             {% endif %}
  150.             <div class="uv-element-block">
  151.                 <button type="submit" id="create-ticket-btn" class="uv-btn">{{ 'Create Ticket'|trans }}</button>
  152.             </div>
  153.         </form>
  154.     </div>
  155. </div>
  156. {% if not(app.request.attributes.get('_route') in ['helpdesk_member_ticket']) %}
  157.     {{ include('@UVDeskCoreFramework\\Templates\\attachment.html.twig') }}
  158. {% endif %}
  159. {% if user_service.isfileExists('apps/uvdesk/form-component') %}
  160. <script>
  161.     customFieldValidation = {};
  162.     customHandler = function(value, attr, computedState) {
  163.         if(!$('[name="'+ attr + '"]').parents('.uv-element-block').is(':visible') && !$('[name="'+ attr + '[]' + '"]').parents('.uv-element-block').is(':visible')) {
  164.             return false;
  165.         } else {
  166.             var ele = $('[name="'+ attr + '"]');
  167.             ele = ele.length ? ele : $('[name="'+ attr + '[]' + '"]');
  168.             if(ele[0].type == 'radio') {
  169.                 var returnMe = true;
  170.                 $.each(ele, function(key, eleChild) {
  171.                     if($(eleChild).is(':checked')) {
  172.                         returnMe = false;
  173.                     }
  174.                 });
  175.                 return returnMe;
  176.             } else if(ele[0].type == 'checkbox') {
  177.                 var returnMe = true;
  178.                 $.each(ele, function(key, eleChild) {
  179.                     if($(eleChild).is(':checked')) {
  180.                         returnMe = false;
  181.                     }
  182.                 });
  183.                 return returnMe;
  184.             } else if(!$('#create-ticket-form [name="'+ attr + '"]').val()) {
  185.                 return true;
  186.             }
  187.         }
  188.     };
  189.     _.extend(Backbone.Validation.validators, {
  190.         checkAllowedDomain: function(value, attr, customValue, model) {
  191.             if(!$('[name="'+ attr + '"]').parents('.uv-element-block').is(':visible'))
  192.                 return false;
  193.             domain = value.substring(value.indexOf("@") + 1);
  194.             if(customValue && customValue.indexOf(domain) === -1) {
  195.                 return true; //return error
  196.             }
  197.         },
  198.         checkRestrictedDomain: function(value, attr, customValue, model) {
  199.             if(!$('[name="'+ attr + '"]').parents('.uv-element-block').is(':visible'))
  200.                 return false;
  201.             domain = value.substring(value.indexOf("@") + 1);
  202.             if(customValue && customValue.indexOf(domain) !== -1) {
  203.                 return true; //return error
  204.             }
  205.         },
  206.         checkMaxFileSize: function(value, attr, customValue, model) {
  207.             if(!$('[name="'+ attr + '"]').parents('.uv-element-block').is(':visible'))
  208.                 return false;
  209.             fileInput = $('input[name="' + attr + '"]')[0] ? $('input[name="' + attr + '"]')[0] : $('input[name="' + attr + '"]');
  210.             file = fileInput.files? fileInput.files[0] : '';
  211.             filesize = file ? file.size / 1024 : 0;
  212.             maxSize = (customValue && parseInt(customValue)) ? parseInt(customValue) : 5120;
  213.             
  214.             if(filesize > maxSize) {
  215.                 return true; //return error
  216.             }
  217.         },
  218.         patternOrEmpty: function(value, attr, pattern, model) {
  219.             defaultPatterns = Backbone.Validation.patterns;
  220.             if (value && !value.toString().match(defaultPatterns[pattern] || pattern)) {
  221.                 return true; //error
  222.             }
  223.         },
  224.       minOrEmpty: function(value, attr, minValue, model) {
  225.         if (value && (value < minValue)) {
  226.           return true; //error
  227.         }
  228.       },
  229.       maxOrEmpty: function(value, attr, maxValue, model) {
  230.         if (value && (value > maxValue)) {
  231.           return true; //error
  232.         }
  233.       },
  234.       patternCheck: function(value, attr, pattern, model) {
  235.         if (value && !value.toString().match(pattern)) {
  236.             return true; //error
  237.         }
  238.       },
  239.     });
  240.         {% if headerCustomFields is defined and headerCustomFields %}
  241.             {% for customField in headerCustomFields %}
  242.                 {% set fieldtype = ('text' != customField['fieldType']) ? customField['fieldType'] : (customField['validation']['fieldtype'] is defined ? customField['validation']['fieldtype'] : 'text') %}
  243.                     customFieldValidation['customFields[' + {{ customField.id }} + ']'] = [
  244.                     {% if not(fieldtype in ['checkbox', 'radio', 'select'] and customField['customFieldValues'] is empty) and customField.required %}
  245.                         {
  246.                         fn : customHandler,
  247.                         msg : '{{ "This field is mandatory"|trans }}'
  248.                     },
  249.                     {% endif %}
  250.                     {% if('number' == fieldtype) %}
  251.                         {
  252.                             patternOrEmpty : 'number',
  253.                             msg: '{{ "Value is not valid number"|trans }}',
  254.                         },
  255.                         {% if customField['validation']['minNo'] %} 
  256.                             {
  257.                                 minOrEmpty: {{ customField['validation']['minNo'] }},
  258.                                 msg: '{{ "Provide number greater than %min%"|trans({"%min%": customField["validation"]["minNo"] }) }}',
  259.                             },
  260.                         {% endif %}
  261.                         {% if customField['validation']['maxNo'] %} 
  262.                         {
  263.                             maxOrEmpty: {{ customField['validation']['maxNo'] }},
  264.                             msg: '{{ "Provide number smaller than %max%"|trans({"%max%": customField["validation"]["maxNo"] }) }}',
  265.                         },
  266.                         {% endif %}
  267.                     {% elseif('email' == fieldtype) %}
  268.                         {
  269.                             patternOrEmpty: /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i,
  270.                             msg: '{{ "Email Address is invalid"|trans }}',
  271.                         },
  272.                         {% if customField['validation']['allowedDomain'] %}
  273.                             {
  274.                                 checkAllowedDomain: "{{ customField['validation']['allowedDomain'] }}",
  275.                                 msg: '{{ "Domain name should be in accepted domains"|trans }}',
  276.                             },
  277.                         {% endif %}
  278.                         {% if customField['validation']['restrictedDomain'] %}
  279.                             {
  280.                                 checkRestrictedDomain: "{{ customField['validation']['restrictedDomain'] }}",
  281.                                 msg: '{{ "Domain name should not be in restricted domains" }}',
  282.                             } ,
  283.                         {% endif %}
  284.                     {% elseif('url' == fieldtype) %}
  285.                         {
  286.                             patternOrEmpty: 'url',
  287.                             msg: '{{ "Provide a valid url(with protocol)"|trans }}',
  288.                         } ,
  289.                     {% elseif('file' == fieldtype) %}
  290.                         {
  291.                             checkMaxFileSize: "{{ customField['validation']['maxFileSize'] }}",
  292.                             msg: '{{ "file size should not exceed %value% KB"|trans({"%value%": customField["validation"]["maxFileSize"] ? : "5120"}) }}',
  293.                         } ,
  294.                     {% endif %}
  295.                     {% if (not (fieldtype in ['checkbox', 'radio', 'select'])) and customField['validation']['regex'] is defined and customField['validation']['regex'] %}
  296.                         {
  297.                             patternCheck: "{{ customField['validation']['regex'] }}",
  298.                             msg: "{{ 'This Field Value is not Valid'|trans }}",
  299.                         } ,
  300.                     {% endif %}
  301.                 ];
  302.                 Array.isArray(validationParameters) ? validationParameters.push(value) : false;
  303.             {% endfor %}
  304.         {% endif %}
  305.         {% if CustomerCustomFields is defined and CustomerCustomFields %}
  306.             {% for customField in CustomerCustomFields %}
  307.                 {% set fieldtype = ('text' != customField['fieldType']) ? customField['fieldType'] : (customField['validation']['fieldtype'] is defined ? customField['validation']['fieldtype'] : 'text') %}
  308.                     customFieldValidation['customFields[' + {{ customField.id }} + ']'] = [
  309.                     {% if not(fieldtype in ['checkbox', 'radio', 'select'] and customField['customFieldValues'] is empty) and customField.required %}
  310.                         {
  311.                         fn : customHandler,
  312.                         msg : '{{ "This field is mandatory"|trans }}'
  313.                     },
  314.                     {% endif %}
  315.                     {% if('number' == fieldtype) %}
  316.                         {
  317.                             patternOrEmpty : 'number',
  318.                             msg: '{{ "Value is not valid number"|trans }}',
  319.                         },
  320.                         {% if customField['validation']['minNo'] %} 
  321.                             {
  322.                                 minOrEmpty: {{ customField['validation']['minNo'] }},
  323.                                 msg: '{{ "Provide number greater than %min%"|trans({"%min%": customField["validation"]["minNo"] }) }}',
  324.                             },
  325.                         {% endif %}
  326.                         {% if customField['validation']['maxNo'] %} 
  327.                         {
  328.                             maxOrEmpty: {{ customField['validation']['maxNo'] }},
  329.                             msg: '{{ "Provide number smaller than %max%"|trans({"%max%": customField["validation"]["maxNo"] }) }}',
  330.                         },
  331.                         {% endif %}
  332.                     {% elseif('email' == fieldtype) %}
  333.                         {
  334.                             patternOrEmpty: /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i,
  335.                             msg: '{{ "Email Address is invalid"|trans }}',
  336.                         },
  337.                         {% if customField['validation']['allowedDomain'] %}
  338.                             {
  339.                                 checkAllowedDomain: "{{ customField['validation']['allowedDomain'] }}",
  340.                                 msg: '{{ "Domain name should be in accepted domains"|trans }}',
  341.                             },
  342.                         {% endif %}
  343.                         {% if customField['validation']['restrictedDomain'] %}
  344.                             {
  345.                                 checkRestrictedDomain: "{{ customField['validation']['restrictedDomain'] }}",
  346.                                 msg: '{{ "Domain name should not be in restricted domains" }}',
  347.                             } ,
  348.                         {% endif %}
  349.                     {% elseif('url' == fieldtype) %}
  350.                         {
  351.                             patternOrEmpty: 'url',
  352.                             msg: '{{ "Provide a valid url(with protocol)"|trans }}',
  353.                         } ,
  354.                     {% elseif('file' == fieldtype) %}
  355.                         {
  356.                             checkMaxFileSize: "{{ customField['validation']['maxFileSize'] }}",
  357.                             msg: '{{ "file size should not exceed %value% KB"|trans({"%value%": customField["validation"]["maxFileSize"] ? : "5120"}) }}',
  358.                         } ,
  359.                     {% endif %}
  360.                     {% if (not (fieldtype in ['checkbox', 'radio', 'select'])) and customField['validation']['regex'] is defined and customField['validation']['regex'] %}
  361.                         {
  362.                             patternCheck: "{{ customField['validation']['regex'] }}",
  363.                             msg: "{{ 'This Field Value is not Valid'|trans }}",
  364.                         } ,
  365.                     {% endif %}
  366.                 ];
  367.                 Array.isArray(validationParameters) ? validationParameters.push(value) : false;
  368.             {% endfor %}
  369.         {% endif %}
  370.     var validationParameters = true;
  371. </script>
  372. {% endif %}
  373. {{ include("@UVDeskSupportCenter/Templates/tinyMCE.html.twig") }}
  374. <script type="text/javascript">
  375.     $(function () {
  376.         if (typeof(customFieldValidation) == 'undefined') {
  377.             customFieldValidation = {};
  378.         }
  379.         {% if(removeMe is defined) %}
  380.             $.each({{ removeMe | json_encode |raw }}, function(key, value){
  381.                 $('label[for="' + value + '"]').parent().hide();
  382.             });
  383.         {% endif %}
  384.         $('.uv-header-date').datetimepicker({
  385.             format: 'YYYY-MM-DD',
  386.         });
  387.         $('.uv-header-time').datetimepicker({
  388.             format: 'LT',
  389.         });
  390.         $('.uv-header-datetime').datetimepicker({
  391.             format: 'YYYY-MM-DD H:m:s'
  392.         });
  393.         var CreateTicketModel = Backbone.Model.extend({
  394.             idAttribute : "id",
  395.             defaults : {
  396.                 path : "",
  397.             },
  398.             validation: _.extend(customFieldValidation, {
  399.                 {% if not isTicketViewPage %}
  400.                     'name' : {
  401.                         required : true,
  402.                         msg : "{{ 'This field is mandatory'|trans }}"
  403.                     },
  404.                     'from' :
  405.                     [{
  406.                         required : true,
  407.                         msg : "{{ 'This field is mandatory'|trans }}"
  408.                     },{
  409.                         pattern : /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,
  410.                         msg : "{{ 'Email address is invalid'|trans }}"
  411.                     }],
  412.                 {% endif %}
  413.                 'type' : {
  414.                     required : true,
  415.                     msg : "{{ 'This field is mandatory'|trans }}"
  416.                 },
  417.                 'subject' : {
  418.                     required : true,
  419.                     msg : "{{ 'This field is mandatory'|trans }}"
  420.                 },
  421.                 'reply' : {
  422.                     fn: function(value) {
  423.                             if(!tinyMCE.get("uv-edit-create-thread"))
  424.                                 return false;
  425.                             var html = tinyMCE.get("uv-edit-create-thread").getContent();
  426.                             if(app.appView.stripHTML(html) != '') {
  427.                                 return false;
  428.                             }
  429.                             return true;
  430.                         },
  431.                     msg : "{{ 'This field is mandatory'|trans }}"
  432.                 },
  433.             }),
  434.             urlRoot : "{{ path('helpdesk_member_create_ticket') }}"
  435.         });
  436.         sfTinyMce.init({
  437.             height: '155px',
  438.             selector : '#create-reply',
  439.             images_upload_url: "",
  440.             setup: function(editor) {
  441.             },
  442.             plugins: [
  443.             ],
  444.             toolbar: '| undo redo | bold italic forecolor ',
  445.         });
  446.         var CreateTicketForm = Backbone.View.extend({
  447.             el : $("#create-ticket-modal #create-ticket-form"),
  448.             model: new CreateTicketModel(),
  449.             initialize : function() {
  450.                 Backbone.Validation.bind(this);
  451.                 var jsonContext = JSON.parse('{{ errors is defined ? errors|raw : "{}"  }}');
  452.                 for (var field in jsonContext) {
  453.                     Backbone.Validation.callbacks.invalid(this, field, jsonContext[field], 'input');
  454.                 }
  455.             },
  456.             events : {
  457.                 'click #create-ticket-btn': "saveTicket",
  458.                 'change #type': "updateCustomFields",
  459.                 'blur input.create-ticket:not(input[type=file]), textarea.create-ticket, select.create-ticket, checkbox.create-ticket': 'formChanegd',
  460.                 'change input[type=file].create-ticket': 'formChanegd',
  461.             },
  462.             formChanegd: function(e) {
  463.                 this.model.set(Backbone.$(e.currentTarget).attr('name'), Backbone.$(e.currentTarget).val())
  464.                 this.model.isValid([Backbone.$(e.currentTarget).attr('name')])
  465.             },
  466.             saveTicket: function (e) {
  467.                 e.preventDefault();
  468.                 var currentElement = Backbone.$(e.currentTarget);
  469.                 var data = currentElement.closest('form').serializeObject();
  470.                 this.model = new CreateTicketModel();
  471.                 this.model.set(data);
  472.                 Backbone.Validation.bind(this);
  473.                 
  474.                 if (this.model.isValid(true)) {
  475.                     $('#create-ticket-form').submit();
  476.                     $('form').find('#create-ticket-btn').attr('disabled', 'disabled');
  477.                 }
  478.             },
  479.             updateCustomFields: function (e) {
  480.                 const dependentFields = e.currentTarget.value;
  481.                 this.$('.dependent').hide();
  482.                 this.$('.dependency' + dependentFields).show();
  483.             }
  484.         });
  485.         new CreateTicketForm();
  486.     });
  487. </script>