From 8fdd3d26a95c3f52f012e09c4b610bef13a26e13 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 16 Sep 2015 15:25:28 +0200 Subject: [PATCH] Added .timepicker() in sla_times ui element. --- .../_ui_element/sla_times.js.coffee | 47 +++++++++++++------ app/controllers/calendars_controller.rb | 2 +- app/controllers/slas_controller.rb | 4 +- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_ui_element/sla_times.js.coffee b/app/assets/javascripts/app/controllers/_ui_element/sla_times.js.coffee index 31f3f4066..9793c7bcf 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/sla_times.js.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/sla_times.js.coffee @@ -1,6 +1,10 @@ class App.UiElement.sla_times @render: (attribute, params = {}) -> + # set default value + if !params.first_response_time && params.first_response_time isnt 0 + params.first_response_time = 120 + item = $( App.view('generic/sla_times')( attribute: attribute first_response_time: params.first_response_time @@ -11,34 +15,49 @@ class App.UiElement.sla_times solution_time_in_text: @toText(params.solution_time) ) ) - item.find('.js-activateRow').bind('change', (e) => - element = $(e.target) - if element.prop('checked') - element.closest('tr').addClass('is-active') - else - element.closest('tr').removeClass('is-active') - element.closest('tr').find('.js-timeConvertFrom').val('') + # appliy hour picker + item.find('.js-timeConvertFrom').timepicker( + maxHours: 999 ) - item.find('.js-timeConvertFrom').bind('keyup', (e) => + # disable/enable rows + item.find('.js-activateRow').bind('change', (e) => + element = $(e.target) + row = element.closest('tr') + if element.prop('checked') + row.addClass('is-active') + else + row.removeClass('is-active') + + # reset data item + row.find('.js-timeConvertFrom').val('') + row.find('.js-timeConvertTo').val('') + ) + + # convert hours into minutes + item.find('.js-timeConvertFrom').bind('keyup focus blur', (e) => element = $(e.target) inText = element.val() + row = element.closest('tr') + dest = element.closest('td').find('.js-timeConvertTo') inMinutes = @toMinutes(inText) if !inMinutes element.addClass('has-error') + dest.val('') else element.removeClass('has-error') - dest = element.closest('td').find('.js-timeConvertTo') - dest.val(inMinutes) - element.closest('tr').find('.js-activateRow').prop('checked', true) - element.closest('tr').addClass('is-active') + dest.val(inMinutes) + row.find('.js-activateRow').prop('checked', true) + row.addClass('is-active') ) + # set initial active/inactive rows item.find('.js-timeConvertFrom').each(-> + row = $(@).closest('tr').find('.js-activateRow') if $(@).val() - $(@).closest('tr').find('.js-activateRow').prop('checked', true) + row.prop('checked', true) else - $(@).closest('tr').find('.js-activateRow').prop('checked', false) + row.prop('checked', false) ) item diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index a342ead44..778bb5586 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -10,7 +10,7 @@ class CalendarsController < ApplicationController # calendars calendar_ids = [] - Calendar.all.each {|calendar| + Calendar.all.order(:name).each {|calendar| calendar_ids.push calendar.id assets = calendar.assets(assets) } diff --git a/app/controllers/slas_controller.rb b/app/controllers/slas_controller.rb index d6baddb7f..b76bbf7f0 100644 --- a/app/controllers/slas_controller.rb +++ b/app/controllers/slas_controller.rb @@ -53,14 +53,14 @@ curl http://localhost/api/v1/slas.json -v -u #{login}:#{password} # calendars calendar_ids = [] - Calendar.all.each {|calendar| + Calendar.all.order(:name).each {|calendar| calendar_ids.push calendar.id assets = calendar.assets(assets) } # slas sla_ids = [] - Sla.all.each {|sla| + Sla.all.order(:name).each {|sla| sla_ids.push sla.id assets = sla.assets(assets) }