diff --git a/app/assets/javascripts/app/controllers/_application_controller/form.coffee b/app/assets/javascripts/app/controllers/_application_controller/form.coffee index 5664291fd..f19423c96 100644 --- a/app/assets/javascripts/app/controllers/_application_controller/form.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller/form.coffee @@ -418,11 +418,11 @@ class App.ControllerForm extends App.Controller if !@constructor.fieldIsMandatory(field_by_name) field_by_name.attr('required', true) - field_by_name.parents('.form-group').find('label span').html('*') + field_by_name.closest('.form-group').find('label span').html('*') field_by_name.closest('.form-group').addClass('is-required') if !@constructor.fieldIsMandatory(field_by_data) field_by_data.attr('required', true) - field_by_data.parents('.form-group').find('label span').html('*') + field_by_data.closest('.form-group').find('label span').html('*') field_by_data.closest('.form-group').addClass('is-required') optional: (name, el = @form) -> @@ -434,11 +434,11 @@ class App.ControllerForm extends App.Controller if @constructor.fieldIsMandatory(field_by_name) field_by_name.attr('required', false) - field_by_name.parents('.form-group').find('label span').html('') + field_by_name.closest('.form-group').find('label span').html('') field_by_name.closest('.form-group').removeClass('is-required') if @constructor.fieldIsMandatory(field_by_data) field_by_data.attr('required', false) - field_by_data.parents('.form-group').find('label span').html('') + field_by_data.closest('.form-group').find('label span').html('') field_by_data.closest('.form-group').removeClass('is-required') readonly: (name, el = @form) -> diff --git a/app/assets/javascripts/app/controllers/_ui_element/sla_times.coffee b/app/assets/javascripts/app/controllers/_ui_element/sla_times.coffee index 1a3fec95c..2bf72247d 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/sla_times.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/sla_times.coffee @@ -8,9 +8,11 @@ class App.UiElement.sla_times item = $( App.view('generic/sla_times')( attribute: attribute first_response_time: params.first_response_time + response_time: params.response_time update_time: params.update_time solution_time: params.solution_time first_response_time_in_text: @toText(params.first_response_time) + response_time_in_text: @toText(params.response_time) update_time_in_text: @toText(params.update_time) solution_time_in_text: @toText(params.solution_time) ) ) @@ -26,12 +28,16 @@ class App.UiElement.sla_times row = element.closest('tr') if element.prop('checked') row.addClass('is-active') + + if row.has('.js-updateTypeSelector').length > 0 && row.has('.js-updateTypeSelector:checked').length == 0 + row.find('.js-updateTypeSelector:first').prop('checked', true) else row.removeClass('is-active') # reset data item row.find('.js-timeConvertFrom').val('') row.find('.js-timeConvertTo').val('') + row.find('.js-updateTypeSelector').attr('checked', false) row.find('.help-inline').empty() row.removeClass('has-error') ) @@ -42,12 +48,16 @@ class App.UiElement.sla_times inText = element.val() row = element.closest('tr') - row.find('.js-activateRow').prop('checked', true) + + row + .find('.js-activateRow') + .prop('checked', true) + .trigger('change') + row.addClass('is-active') - element - .closest('td') - .find('.js-timeConvertTo') + row + .find("[name='#{element.data('name')}']") .val(@toMinutes(inText) || '') ) @@ -56,9 +66,19 @@ class App.UiElement.sla_times $(e.currentTarget).closest('tr').find('.checkbox-replacement').click() ) + # toggle update type on clicking around the element + item.find('.js-forward-radio').bind('click', (e) -> + elem = $(e.currentTarget).closest('p').find('.js-updateTypeSelector') + + elem.prop('checked', true) + elem.trigger('change') + ) + # focus time input on clicking surrounding cell item.find('.js-focus-input').bind('click', (e) -> - $(e.currentTarget).find('.form-control').focus() + $(e.currentTarget) + .find('.form-control:visible') + .focus() ) # show placeholder instead of 00:00 @@ -67,15 +87,36 @@ class App.UiElement.sla_times $(e.currentTarget).val('') ) + # switch update/response times when type is selected accordingly + item.find('.js-updateTypeSelector').bind('change', (e) -> + element = $(e.target) + row = element.closest('tr') + row.find('.js-activateRow').prop('checked', true) + row.addClass('is-active') + + row + .find('.js-timeConvertFrom') + .addClass('hidden') + .val('') + + row + .find('.js-timeConvertTo') + .val('') + + row + .find("[data-name='#{element.val()}_time']") + .removeClass('hidden') + ) + # set initial active/inactive rows item.find('.js-timeConvertFrom').each(-> row = $(@).closest('tr') checkbox = row.find('.js-activateRow') - if $(@).val() - checkbox.prop('checked', true) - row.addClass('is-active') - else - checkbox.prop('checked', false) + + return if !$(@).val() + + checkbox.prop('checked', true) + row.addClass('is-active') ) item diff --git a/app/assets/javascripts/app/controllers/sla.coffee b/app/assets/javascripts/app/controllers/sla.coffee index b3f50e1d3..1ab73b9d8 100644 --- a/app/assets/javascripts/app/controllers/sla.coffee +++ b/app/assets/javascripts/app/controllers/sla.coffee @@ -26,12 +26,6 @@ class Sla extends App.ControllerSubContent sortBy: 'name' ) for sla in slas - if sla.first_response_time - sla.first_response_time_in_text = @toText(sla.first_response_time) - if sla.update_time - sla.update_time_in_text = @toText(sla.update_time) - if sla.solution_time - sla.solution_time_in_text = @toText(sla.solution_time) sla.rules = App.UiElement.ticket_selector.humanText(sla.condition) sla.calendar = App.Calendar.find(sla.calendar_id) @@ -99,17 +93,4 @@ class Sla extends App.ControllerSubContent container: @el.closest('.content') ) - toText: (m) -> - m = parseInt(m) - return if !m - minutes = m % 60 - hours = Math.floor(m / 60) - - if minutes < 10 - minutes = "0#{minutes}" - if hours < 10 - hours = "0#{hours}" - - "#{hours}:#{minutes}" - App.Config.set('Sla', { prio: 2900, name: 'SLAs', parent: '#manage', target: '#manage/slas', controller: Sla, permission: ['admin.sla'] }, 'NavBarAdmin') diff --git a/app/assets/javascripts/app/lib/mixins/view_helpers.coffee b/app/assets/javascripts/app/lib/mixins/view_helpers.coffee index 64686fd3c..1ef955244 100644 --- a/app/assets/javascripts/app/lib/mixins/view_helpers.coffee +++ b/app/assets/javascripts/app/lib/mixins/view_helpers.coffee @@ -36,7 +36,7 @@ App.ViewHelpers = App.Utils.decimal(data, positions) # define time_duration / mm:ss / hh:mm:ss format helper - time_duration: (time) -> + time_duration: (time, show_seconds = true) -> return '' if !time return '' if isNaN(parseInt(time)) @@ -48,7 +48,7 @@ App.ViewHelpers = # Output like "1:01" or "4:03:59" or "123:03:59" mins = "0#{mins}" if mins < 10 secs = "0#{secs}" if secs < 10 - if hrs > 0 + if hrs > 0 && show_seconds return "#{hrs}:#{mins}:#{secs}" "#{mins}:#{secs}" diff --git a/app/assets/javascripts/app/models/sla.coffee b/app/assets/javascripts/app/models/sla.coffee index 824db43cf..5724ada1f 100644 --- a/app/assets/javascripts/app/models/sla.coffee +++ b/app/assets/javascripts/app/models/sla.coffee @@ -1,5 +1,5 @@ class App.Sla extends App.Model - @configure 'Sla', 'name', 'first_response_time', 'update_time', 'solution_time', 'condition', 'calendar_id' + @configure 'Sla', 'name', 'first_response_time', 'response_time', 'update_time', 'solution_time', 'condition', 'calendar_id' @extend Spine.Model.Ajax @url: @apiPath + '/slas' @configure_attributes = [ @@ -12,6 +12,7 @@ class App.Sla extends App.Model { name: 'updated_by_id', display: 'Updated by', relation: 'User', readonly: 1 }, { name: 'updated_at', display: 'Updated', tag: 'datetime', readonly: 1 }, { name: 'first_response_time',skipRendering: true }, + { name: 'response_time', skipRendering: true }, { name: 'update_time', skipRendering: true }, { name: 'solution_time', skipRendering: true }, ] diff --git a/app/assets/javascripts/app/views/generic/sla_times.jst.eco b/app/assets/javascripts/app/views/generic/sla_times.jst.eco index 98fe6ea21..0c4fcda89 100644 --- a/app/assets/javascripts/app/views/generic/sla_times.jst.eco +++ b/app/assets/javascripts/app/views/generic/sla_times.jst.eco @@ -6,7 +6,7 @@ <%- @T('Time') %> <%- @T('in hours') %> - +