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