vendor/uvdesk/automation-bundle/Resources/views/Workflow/conditions.html.twig line 1

Open in your IDE?
  1. <script type="text/template" id="select-add">
  2.     <% if (typeof(operation) != 'undefined' && operation == '||') { %>
  3.         <div class="uv-workflow-hr-plank">
  4.             <div class="uv-workflow-hr-or">
  5.                 <span class="uv-workflow-or">{{ 'or'|trans }}</span>
  6.             </div>
  7.         </div>
  8.         <input type="hidden" name="conditions[<%- keyNo %>][operation]" value="||">
  9.     <% } else if (typeof(operation) != 'undefined' && operation == '&&') { %>
  10.         <div class="uv-workflow-hr-plank">
  11.             <div class="uv-workflow-hr-and">
  12.                 <span class="uv-workflow-and">{{ 'and'|trans }}</span>
  13.             </div>
  14.         </div>
  15.         <input type="hidden" name="conditions[<%- keyNo %>][operation]" value="&&">
  16.     <% } %>
  17.     <select class="uv-select uv-select-grouped select-condition wfCondition" name="conditions[<%- keyNo %>][type]" style="width: 200px;">
  18.         <option value="">{{ 'Select a Condition'|trans }}</option>
  19.         <% for(var key in conditions) { %>
  20.             <optgroup label="<%-key%>">
  21.                 <% for (var key2 in conditions[key]) { %>
  22.                     <option value="<%-conditions[key][key2].value%>" data-match="<%-conditions[key][key2].match%>" <%- typeof(type) != 'undefined' && type == conditions[key][key2].value ? 'selected' : ''%>><%- conditions[key][key2].lable %></option>
  23.                 <% } %>
  24.             </optgroup>
  25.         <% } %>
  26.     </select>
  27.     <span class="select-match">
  28.     </span>
  29.     <span class="values" style="display: inline-block;">
  30.         <a class="uv-btn-tag remove-tr" href="#"><span class="uv-icon-remove-dark-box"></a>
  31.     </span>
  32.     <p class="uv-field-message" style="display: none;"></p>
  33. </script>
  34. <script type="text/template" id="match-add">
  35.     <select class="uv-select uv-select-grouped wfConditionMatch" name="conditions[<%- keyNo %>][match]" style="width: 200px;">
  36.         <% for(var key in matchArray){ %>
  37.             <option value="<%= matchArray[key].value %>" <%- typeof(match) != 'undefined' && match == matchArray[key].value ? 'selected' : ''%>><%= matchArray[key].lable %></option>
  38.         <% } %>
  39.     </select>
  40. </script>
  41. <script type="text/template" id="value-text">
  42.     <% if (typeof(addDate) != 'undefined' && addDate) { %>
  43.         <span class="date value-container">
  44.             <input name="conditions[<%- keyNo %>][value]" type="text" class="uv-field form-control uv-date-picker date wfConditionValue" data-date-format="<%- fieldType == 'time' ? 'LT' : (fieldType == 'datetime' ? 'YYYY-MM-DD H:m:s' : 'YYYY-MM-DD') %>" value="<%- typeof(value) != 'undefined' ? value : '' %>" style="width: 200px;">
  45.             <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span>
  46.         </span>
  47.     <% } else { %>
  48.         <span class="value-container">
  49.             <input type="text" name="conditions[<%- keyNo %>][value]" class="uv-field wfConditionValue" value="<%- typeof(value) != 'undefined' ? value : ''%>" style="width: 200px;" />
  50.         </span>
  51.     <% } %>
  52. </script>
  53. <script type="text/template" id="value-select">
  54.     <select class="uv-select uv-select-grouped select-value wfConditionValue" name="conditions[<%- keyNo %>][value]" style="width: 200px;">
  55.         <option>{{ 'Loading...'|trans }}</option>
  56.     </select>
  57. </script>
  58. <script type="text/template" id="value-select-option">
  59.     <option value="<%= id %>" <%- typeof(value) != 'undefined' && value == id ? 'selected' : ''%>><%= name %></option>
  60. </script>
  61. <script type="text/javascript">
  62.     if (typeof(sB) == 'undefined') {
  63.         var sB = {};
  64.     }
  65.     sB.conditionRow = 0;
  66.     sB.JsonConditions = JSON.parse("{{ uvdesk_automations.getWorkflowConditions() | json_encode | e('js') }}");
  67.     sB.MatchConditions = JSON.parse("{{ uvdesk_automations.getWorkflowMatchConditions() | json_encode | e('js') }}");
  68.     sB.Collection = Backbone.Collection.extend({
  69.         baseUrl: "{{ path('helpdesk_member_workflow_condition_options_xhr') }}",
  70.         fetchResult: function(dataMatch) {
  71.             this.url = this.baseUrl + '/' + dataMatch;
  72.             return this.fetch();
  73.         },
  74.     });
  75.     sB.SelectView = Backbone.View.extend({
  76.         tagName: 'div',
  77.         className: 'uv-field-block workflow-condition',
  78.         selectTemplate: _.template($('#select-add').html()),
  79.         matchTemplate: _.template($('#match-add').html()),
  80.         valueTextTemplate: _.template($('#value-text').html()),
  81.         valueSelectTemplate: _.template($('#value-select').html()),
  82.         valueSelectOptionTemplate: _.template($('#value-select-option').html()),
  83.         events: {
  84.             'change .select-condition': 'selectMatch',
  85.             'click .remove-tr': 'removeTr'
  86.         },
  87.         initialize: function() {
  88.             this.disable = false;
  89.             this.keyNo = sB.conditionRow;
  90.             sB.conditionRow++;
  91.         },
  92.         render: function() {
  93.             var objKey = ((typeof(sB.PrevEvent) != 'undefined' && sB.PrevEvent) ? sB.PrevEvent : 'ticket');
  94.             this.$el.html(this.selectTemplate(_.extend(this.model, {'keyNo': this.keyNo, 'conditions': sB.JsonConditions[objKey]})));
  95.             if (objKey == 'ticket' || objKey == 'task') {
  96.                 $('#conditions').prev('.uv-hr').fadeIn(10);
  97.                 $('#conditions').fadeIn(10);
  98.             } else {
  99.                 $('#conditions').prev('.uv-hr').fadeOut(10);
  100.                 $('#conditions').fadeOut(10);
  101.                 this.$el.empty();
  102.             }
  103.             return this;
  104.         },
  105.         removeTr: function(e) {
  106.             this.remove();
  107.              sB.selectView.clearFirstTrSpan();
  108.         },
  109.         selectMatch: function(e) {
  110.             if (this.disable) {
  111.                 return;
  112.             }
  113.             var dataMatch = $(e.target).find('option').eq(e.target.selectedIndex).attr('data-match');
  114.             this.selectOpt = this.$el.find('.wfCondition');
  115.             this.siblingMatch = this.$el.find('.select-match');
  116.             this.siblingValue = this.$el.find('.values');
  117.             this.siblingMatch.find('.uv-select').remove();
  118.             this.siblingMatch.prepend(this.matchTemplate(_.extend(this.model, {'matchArray' : sB.MatchConditions[dataMatch], 'keyNo': this.keyNo})));
  119.             this.siblingValue.find('.value-container, .uv-select, .form-group, .form-control, .input-group.date').remove();
  120.             if (dataMatch == 'string' || dataMatch == 'email' || dataMatch == 'number') {
  121.                 this.siblingValue.prepend(this.valueTextTemplate(_.extend(this.model, {'addDate' : false, 'keyNo': this.keyNo})));
  122.             } else if(dataMatch == 'date' || dataMatch == 'datetime' || dataMatch == 'time') {
  123.                 this.siblingValue.prepend(this.valueTextTemplate(_.extend(this.model, {'addDate' : true, 'fieldType': dataMatch, 'keyNo': this.keyNo})));
  124.                 this.datePicker();
  125.             } else if(dataMatch == 'select') {
  126.                 this.selectOpt.prop('disabled', true);
  127.                 this.disable = true;
  128.                 this.siblingValue.prepend(this.valueSelectTemplate(_.extend(this.model, {'keyNo': this.keyNo})));
  129.                 var self = this;
  130.                 sB.collection.fetchResult(e.target.value)
  131.                     .done(function(){
  132.                         $(self.el).find('.select-value').find('option').remove();
  133.                         self.addAll();
  134.                     })
  135.                     .fail(function(xhr) {
  136.                         if(url = xhr.getResponseHeader('Location'))
  137.                             window.location = url;
  138.                     });
  139.             }
  140.         },
  141.         addAll: function() {
  142.             _.each(sB.collection.models, this.addOne, this);
  143.             this.disable = false;
  144.             this.selectOpt.prop('disabled', false);
  145.         },
  146.         addOne: function(newModel) {
  147.             this.siblingValue.find('.select-value').append(this.valueSelectOptionTemplate(_.extend(this.model, newModel.attributes)));
  148.         },
  149.         datePicker: function() {
  150.             $('#conditions .date, #conditions .datetime, #conditions .time').datetimepicker();
  151.         }
  152.     });
  153.     sB.SelectViews = Backbone.View.extend({
  154.         el: '.uv-view',
  155.         target: $('#conditions .workflow-conditions-body'),
  156.         initialize: function() {
  157.             {% if formData and formData.events is defined %}
  158.                 var eventData = $.parseJSON("{{ formData.events | json_encode | e('js') }}");
  159.             {% else %}
  160.                 var eventData = {};
  161.             {% endif %}
  162.             if (eventData.length > 0) {
  163.                 if (eventData[0].event == 'ticket' || eventData[0].event == 'task') {
  164.                     $('#conditions').prev('.uv-hr').fadeIn(10);
  165.                     $('#conditions').fadeIn(10);
  166.                 }
  167.             }
  168.             {% if formData and formData.conditions is defined %}
  169.                 this.createConditions($.parseJSON("{{ formData.conditions | json_encode | e('js') }}"));
  170.             {% else %}
  171.                 this.addSelectOr();
  172.             {% endif %}
  173.              this.clearFirstTrSpan();
  174.             // this.listenTo(sB.collection, 'add', this.addOne);
  175.         },
  176.         events: {
  177.             'click .btn-and': 'addSelectAnd',
  178.             'click .btn-or': 'addSelectOr',
  179.         },
  180.         createConditions: function(conditionPreviouslyAdded) {
  181.             _.each(conditionPreviouslyAdded, this.addSelect, this);
  182.         },
  183.         addSelectAnd: function(e) {
  184.             this.model = {'operation' : '&&'};
  185.             this.addSelect(this.model);
  186.         },
  187.         addSelectOr: function(e) {
  188.             this.model = {'operation' : '||'};
  189.             this.addSelect(this.model);
  190.         },
  191.         addSelect: function(newModel) {
  192.             var view = new sB.SelectView({model: newModel});
  193.             this.target.append(viewEl = view.render().el);
  194.             this.$(viewEl).find('.wfCondition').trigger('change');
  195.         },
  196.         clearHtml: function() {
  197.             this.target.html('');
  198.             this.model = {'operation' : '&&'};
  199.             this.addSelect(this.model);
  200.              this.clearFirstTrSpan();
  201.         },
  202.         clearFirstTrSpan: function() {
  203.              var target = this.target.find('tr').eq(0);
  204.              target.find('.uv-workflow-and, input[type="hidden"]').remove();
  205.              target.find('.uv-workflow-hr-or').html('');
  206.         },
  207.         datePicker: function() {
  208.             $('.date').datetimepicker({
  209.                 format: 'YYYY-MM-DD',
  210.             });
  211.         }
  212.     });
  213.     sB.collection = new sB.Collection();
  214.     sB.selectView = new sB.SelectViews();
  215.     sB.selectView.datePicker();
  216. </script>