diff --git a/app/assets/javascripts/app/controllers/_ui_element/ticket_selector.js.coffee b/app/assets/javascripts/app/controllers/_ui_element/ticket_selector.js.coffee index 378333ff9..6eca4740a 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/ticket_selector.js.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/ticket_selector.js.coffee @@ -1,4 +1,4 @@ -class App.UiElement.ticket_selector extends App.UiElement.ApplicationUiElement +class App.UiElement.ticket_selector @render: (attribute, params = {}) -> # list of attributes @@ -129,25 +129,19 @@ class App.UiElement.ticket_selector extends App.UiElement.ApplicationUiElement groupAndAttribute = $(e.target).find('option:selected').attr('value') elementRow = $(e.target).closest('.js-filterElement') - console.log('CHANGE', groupAndAttribute, $(e.target)) - @rebuildAttributeSelectors(item, elementRow, groupAndAttribute) @rebuildOperater(item, elementRow, groupAndAttribute, elements) @buildValue(item, elementRow, groupAndAttribute, elements) ) # build inital params - console.log('P', params) if !_.isEmpty(params.condition) selectorExists = false - for position of params.condition.attribute - - # get stored params - groupAndAttribute = params.condition.attribute[position] - if params.condition[groupAndAttribute] + for groupAndAttribute, meta of params.condition + if groupAndAttribute isnt 'attribute' selectorExists = true - operator = params.condition[groupAndAttribute].operator - value = params.condition[groupAndAttribute].value + operator = meta.operator + value = meta.value # get selector rows elementFirst = item.find('.js-filterElement').first() @@ -163,8 +157,49 @@ class App.UiElement.ticket_selector extends App.UiElement.ApplicationUiElement # remove first dummy row if selectorExists item.find('.js-filterElement').first().remove() + + # bind for preview + search = => + @preview(item) + item.on('change', 'select.form-control', (e) => + App.Delay.set( + search, + 600, + 'preview', + ) + ) + item.on('keyup', 'input.form-control', (e) => + App.Delay.set( + search, + 600, + 'preview', + ) + ) + item + @preview: (item) -> + params = App.ControllerForm.params(item) + + # ajax call + App.Ajax.request( + id: 'ticket_selector' + type: 'POST' + url: "#{App.Config.get('api_path')}/tickets/selector" + data: JSON.stringify(params) + processData: true, + success: (data, status, xhr) => + App.Collection.loadAssets( data.assets ) + @ticketTable(data.ticket_ids, data.ticket_count, item) + ) + + @ticketTable: (ticket_ids, ticket_count, item) => + item.find('.js-previewCounter').html(ticket_count) + new App.TicketList( + el: item.find('.js-previewTable') + ticket_ids: ticket_ids + ) + @getElementConfig: (groupAndAttribute, elements) -> for elementGroup, elementConfig of elements for elementKey, elementItem of elementConfig @@ -253,7 +288,8 @@ class App.UiElement.ticket_selector extends App.UiElement.ApplicationUiElement elementRow.find('.js-operator select').replaceWith(operator) @humanText: (condition) -> - return [] if _.isEmpty(condition) + none = App.i18n.translateContent('No filter.') + return [none] if _.isEmpty(condition) rules = [] for position of condition.attribute @@ -263,5 +299,7 @@ class App.UiElement.ticket_selector extends App.UiElement.ApplicationUiElement selectorExists = true operator = condition[groupAndAttribute].operator value = condition[groupAndAttribute].value - rules.push "Where #{groupAndAttribute} #{operator} #{value}." + rules.push "#{App.i18n.translateContent('Where')} #{App.i18n.translateContent(groupAndAttribute)} #{App.i18n.translateContent(operator)} #{App.i18n.translateContent(value)}." + + return [none] if _.isEmpty(rules) rules \ No newline at end of file diff --git a/app/assets/javascripts/app/models/sla.js.coffee b/app/assets/javascripts/app/models/sla.js.coffee index 102fa0992..aaf7d3ed8 100644 --- a/app/assets/javascripts/app/models/sla.js.coffee +++ b/app/assets/javascripts/app/models/sla.js.coffee @@ -3,14 +3,14 @@ class App.Sla extends App.Model @extend Spine.Model.Ajax @url: @apiPath + '/slas' @configure_attributes = [ - { name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, null: false }, - { name: 'condition', display: 'Selector', tag: 'ticket_selector', null: false, note: 'Create rules that single out the tickets for the Service Level Agreement.' }, - { name: 'calendar_id', display: 'Calendar', tag: 'select', relation: 'Calendar', null: false }, - { name: 'sla_times', display: 'SLA Times', tag: 'sla_times', null: true }, - { name: 'created_by_id', display: 'Created by', relation: 'User', readonly: 1 }, - { name: 'created_at', display: 'Created', tag: 'datetime', readonly: 1 }, - { name: 'updated_by_id', display: 'Updated by', relation: 'User', readonly: 1 }, - { name: 'updated_at', display: 'Updated', tag: 'datetime', readonly: 1 }, + { name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, null: false }, + { name: 'condition', display: 'Ticket Selector', tag: 'ticket_selector', null: false, note: 'Create rules that single out the tickets for the Service Level Agreement.' }, + { name: 'calendar_id', display: 'Calendar', tag: 'select', relation: 'Calendar', null: false }, + { name: 'sla_times', display: 'SLA Times', tag: 'sla_times', null: true }, + { name: 'created_by_id', display: 'Created by', relation: 'User', readonly: 1 }, + { name: 'created_at', display: 'Created', tag: 'datetime', readonly: 1 }, + { name: 'updated_by_id', display: 'Updated by', relation: 'User', readonly: 1 }, + { name: 'updated_at', display: 'Updated', tag: 'datetime', readonly: 1 }, ] @configure_delete = true @configure_overview = [ diff --git a/app/assets/javascripts/app/views/generic/ticket_selector.jst.eco b/app/assets/javascripts/app/views/generic/ticket_selector.jst.eco index edc7adf08..74f7825e8 100644 --- a/app/assets/javascripts/app/views/generic/ticket_selector.jst.eco +++ b/app/assets/javascripts/app/views/generic/ticket_selector.jst.eco @@ -23,4 +23,8 @@ + +