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

Open in your IDE?
  1. <script type="text/template" id="action-add">
  2.     <select class="uv-select uv-select-grouped select-action wfAction" name="actions[<%- keyNo %>][type]" style="width: 200px;">
  3.         <option value="">{{ 'Select an Action'|trans }}</option>
  4.         <% for(var key in actions){ %>
  5.             <option value="<%- key %>" <%- typeof(type) != 'undefined' && type == key ? 'selected' : ''%>><%- actions[key] %></option>
  6.         <% } %>
  7.     </select>
  8.     <span class="apply-action" style="display: inline-block; vertical-align: middle;">
  9.         <a class="uv-btn-tag remove-action-tr" href="#"><span class="uv-icon-remove-dark-box"></a>
  10.     </span>
  11.     <p class="uv-field-message" style="display: none;"></p>
  12. </script>
  13. <script type="text/template" id="action-value-text">
  14.     <textarea name="actions[<%- keyNo %>][value]" id="textarea-note" class="uv-field wfActionValue textarea-fix-action" style="width: 200px;"><%- (typeof(value) != 'undefined' && typeof(value) != 'object') ? value : ''%></textarea>
  15. </script>
  16. <script type="text/template" id="action-value-select">
  17.     <select name="actions[<%- keyNo %>][value]" class="uv-select uv-select-grouped action-value wfAction" style="width: 200px;"><option>{{ 'Loading...'|trans }}</option></select>
  18. </script>
  19. <script type="text/template" id="action-value-multi-select">
  20.     <div class="uv-dropdown asset-visibility action-value-for wfActionMultiple" name="actions[<%- keyNo %>][value][for][]">
  21.         <div class="uv-dropdown-btn uv-vertical-align uv-margin-right-5" style="width: 200px;">{{ 'Select Option'|trans }}</div>
  22.         <div class="uv-dropdown-list uv-bottom-left">
  23.             <div class="uv-dropdown-container">
  24.                 <ul></ul>
  25.             </div>
  26.         </div>
  27.     </div>
  28.     <select name="actions[<%- keyNo %>][value][value]" class="uv-select uv-select-grouped action-value wfAction" style="width: 200px;"><option>{{ 'Loading...'|trans }}</option></select>
  29. </script>
  30. <script type="text/template" id="action-value-select-multiple">
  31.     <select name="actions[<%- keyNo %>][value][]" class="uv-select uv-select-grouped action-value wfAction" multiple="true" style="width: 200px;"><option>{{ 'Loading...'|trans }}</option></select>
  32. </script>
  33. <script type="text/template" id="action-value-select-option">
  34.     <option value="<%= id %>" <%- (typeof(value) != 'undefined' && (typeof(value) === 'object' && value.indexOf(id.toString()) > -1)) ? 'selected' : (typeof(value) != 'undefined' && value == id ? 'selected' : '')%>><%= name %></option>
  35. </script>
  36. <script type="text/template" id="action-value-select-for-option">
  37.     <li class="uv-dropdown-checkbox">
  38.         <label>
  39.             <div class="uv-checkbox">
  40.                 <input type="checkbox" id="actions[<%- keyNo %>][value][for][<%- id.toString() %>]" name="actions[<%- keyNo %>][value][for][]" value="<%= id %>" <%- (typeof(value) != 'undefined' && (typeof(value) === 'object' && value.indexOf(id.toString()) > -1)) ? 'checked' : (typeof(value) != 'undefined' && value == id ? 'checked' : '')%> >
  41.                 <span class="uv-checkbox-view uv-checkbox-dwn"></span>
  42.             </div>
  43.         </label>
  44.         <label for="actions[<%- keyNo %>][value][for][<%- id.toString() %>]" style="display: inline;"><%= name %></label>
  45.     </li>
  46. </script>
  47. <script type="text/javascript">
  48.     $('body').on('focusout', '#textarea-note', function(){
  49.         selection = this;
  50.         oldContent = selection.value;
  51.         cursorPosition = $(this).prop("selectionStart");
  52.         forEditor = false;
  53.         forSubject = true;
  54.     });
  55.     var sB = sB || {};
  56.     sB.actionRow = 0;
  57.     sB.JsonActions = JSON.parse("{{ uvdesk_automations.getWorkflowActions(forcedActions is defined and forcedActions ? true : false) | json_encode | e('js') }}");
  58.     sB.ActionCollection = Backbone.Collection.extend({
  59.         baseUrl: "{{ path('helpdesk_member_workflow_action_options_xhr') }}",
  60.         fetchResult: function(dataMatch, currentEvent) {
  61.             this.url = this.baseUrl+'/'+dataMatch + (currentEvent ? ('/' + currentEvent) : '');
  62.             this.reset();
  63.             return this.fetch();
  64.         },
  65.     });
  66.     sB.ActionSelectView = Backbone.View.extend({
  67.         tagName: 'div',
  68.         className: 'uv-field-block workflow-action',
  69.         actionTemplate: _.template($('#action-add').html()),
  70.         valueTextTemplate: _.template($('#action-value-text').html()),
  71.         valueSelectTemplate: _.template($('#action-value-select').html()),
  72.         valueMultiSelectTemplate: _.template($('#action-value-multi-select').html()),
  73.         valueSelectMultipleTemplate: _.template($('#action-value-select-multiple').html()),
  74.         valueSelectOptionTemplate: _.template($('#action-value-select-option').html()),
  75.         valueSelectForOptionTemplate: _.template($('#action-value-select-for-option').html()),
  76.         events: {
  77.             'change .select-action': 'selectOption',
  78.             'click .remove-action-tr': 'removeTr'
  79.         },
  80.         initialize: function() {
  81.             this.keyNo = sB.actionRow;
  82.             sB.actionRow++;    
  83.         },
  84.         render: function() {
  85.             this.$el.html(this.actionTemplate(_.extend(this.model, {'keyNo': this.keyNo, 'actions' : sB.JsonActions[(typeof(sB.PrevEvent) != 'undefined' && sB.PrevEvent) ? sB.PrevEvent : 'ticket']})));
  86.             return this;
  87.         },
  88.         removeTr: function(e) {
  89.              if ($('.uv-field-block.workflow-action').length > 1) {
  90.                 this.remove();
  91.                  sB.actionselectView.clearFirstTrSpan();
  92.             } else {
  93.                 $(this.el).find('.uv-field-message').html("{{ 'This field is required'|trans }}").fadeIn(0);
  94.             }
  95.         },
  96.         selectOption: function(e) {
  97.             if (this.disable) {
  98.                 return;
  99.             }
  100.             var value = this.value = e.target.value;
  101.             if (typeof(sB.actionselectView) != 'undefined') {
  102.                 sB.actionselectView.removeduplicate(e);
  103.             }
  104.             this.selectOpt = this.$el.find('.wfAction');
  105.             this.siblingValue = this.$el.find('.apply-action');
  106.             // if(value == 'delete_ticket' || value == 'mark_spam')
  107.             this.siblingValue.find('select, textarea, div').remove();
  108.             if (value == 'uvdesk.agent.add_note' || value == 'reply') {
  109.                 this.siblingValue.prepend(this.valueTextTemplate(_.extend(this.model, {'keyNo': this.keyNo})));
  110.             } else if (value != 'uvdesk.ticket.delete' && value != 'uvdesk.ticket.mark_spam' && value) {
  111.                 this.selectOpt.prop('disabled', true);
  112.                 this.disable = true;
  113.                 if (value == 'cc' || value == 'bcc') {
  114.                     this.siblingValue.prepend(this.valueSelectMultipleTemplate(_.extend(this.model, {'keyNo': this.keyNo})));
  115.                 } else if(this.value == 'uvdesk.ticket.mail_group' || this.value == 'uvdesk.ticket.mail_team' || this.value == "uvdesk.ticket.mail_agent") {
  116.                     this.siblingValue.prepend(this.valueMultiSelectTemplate(_.extend(this.model, {'keyNo': this.keyNo})));
  117.                 } else {
  118.                     this.siblingValue.prepend(this.valueSelectTemplate(_.extend(this.model, {'keyNo': this.keyNo})));
  119.                 }
  120.                 var self = this;
  121.                 sB.actionCollection.fetchResult(value, this.getCurrentEvent())
  122.                     .done(function() {
  123.                         $(self.el).find('.action-value').find('option').remove();
  124.                         self.addAll();
  125.                     })
  126.                     .fail(function(xhr) {
  127.                         if(url = xhr.getResponseHeader('Location'))
  128.                             window.location = url;
  129.                     });
  130.             }
  131.         },
  132.         getCurrentEvent: function() {
  133.             return ($('.wfEvents').eq(0).val() ? $('.wfEvents').eq(0).val() : 'ticket');
  134.         },
  135.         addAll: function() {
  136.             if(this.value == 'uvdesk.ticket.mail_group' || this.value == 'uvdesk.ticket.mail_team' || this.value == "uvdesk.ticket.mail_agent")
  137.                 _.each(sB.actionCollection.models, this.addOneMore, this);
  138.             else
  139.                 _.each(sB.actionCollection.models, this.addOne, this);
  140.             this.disable = false;
  141.             this.selectOpt.prop('disabled', false);
  142.         },
  143.         addOne: function(newModel) {
  144.             if(typeof(this.model.value) == 'object')
  145.                 this.model.value = undefined;
  146.             var sendThisModel = _.extend(this.model, newModel.attributes);
  147.             if(typeof(newModel.attributes.id) != 'undefined')
  148.                 this.siblingValue.find('.action-value').append(this.valueSelectOptionTemplate(sendThisModel));
  149.         },
  150.         addOneMore: function(models) {
  151.             _.each(models.attributes.partResults, function(newModel){
  152.                 this.siblingValue.find('.action-value-for').find('.uv-dropdown-container ul').append(this.valueSelectForOptionTemplate(_.extend({ 'value' : (typeof(this.model.value) != 'undefined' ? this.model.value.for : ''), 'keyNo': this.keyNo}, newModel)));
  153.             }, this);
  154.             _.each(models.attributes.templates, function(newModel){
  155.                 this.siblingValue.find('.action-value').append(this.valueSelectOptionTemplate(_.extend({ 'value' : (typeof(this.model.value) != 'undefined' ? this.model.value.value : '')}, newModel)));
  156.             }, this);
  157.         }
  158.     });
  159.     sB.ActionSelectViews = Backbone.View.extend({
  160.         el: '.uv-view',
  161.         target: $('#actions .workflow-action-body'),
  162.         initialize: function() {
  163.             {% if formData and formData.actions %}
  164.                 this.createActions($.parseJSON("{{ formData.actions | json_encode | e('js') }}"));
  165.             {% else %}
  166.                 this.addSelect({});
  167.             {% endif %}
  168.             this.listenTo(sB.actionCollection, 'add', this.addOne);
  169.             {% if forcedActions is defined and forcedActions %}
  170.                 dIteration = 0;
  171.                 disableFieldFun = function() {
  172.                     setTimeout(function(e) {
  173.                         $('#actions input,#actions select,#actions textarea').attr('disabled', 'disabled');
  174.                         $('#actions .remove-action-tr').remove(); dIteration++;
  175.                         if(dIteration<5)
  176.                             disableFieldFun();
  177.                     }, 500);
  178.                 };
  179.                 
  180.                 disableFieldFun();
  181.             {% endif %}
  182.         },
  183.         events: {
  184.             'click #actions .btn-add': 'addSelect',
  185.         },
  186.         clearHtml: function() {
  187.             this.target.html('');
  188.             this.addSelect({});
  189.         },
  190.         createActions: function(actionPreviouslyAdded) {
  191.             _.each(actionPreviouslyAdded, this.addSelect, this);
  192.         },
  193.         addSelect: function(newModel) {
  194.             var view = new sB.ActionSelectView({model: newModel});
  195.             this.target.append(viewEl = view.render().el);
  196.             this.$(viewEl).find('.wfAction').trigger('change');
  197.              this.clearFirstTrSpan();
  198.         },
  199.         removeduplicate: function(e) {
  200.             //remove already exits elements - select
  201.             $('.select-action').each(function() {
  202.                 if(this.value == e.target.value)
  203.                     $(this).not(e.target).parents('tr').remove();
  204.             });
  205.              this.clearFirstTrSpan();
  206.         },
  207.         clearFirstTrSpan: function() {
  208.              this.target.find('tr').eq(0).find('span.border-override').remove();
  209.         },
  210.     });
  211.     sB.actionCollection = new sB.ActionCollection();
  212.     sB.actionselectView = new sB.ActionSelectViews();
  213. </script>