Added time zone support for slas.

This commit is contained in:
Martin Edenhofer 2013-06-06 09:34:09 +02:00
parent b47ad57129
commit 7b15323315
4 changed files with 57 additions and 10 deletions

View file

@ -221,6 +221,27 @@ class App.ControllerForm extends App.Controller
else if attribute.tag is 'select'
item = $( App.view('generic/select')( attribute: attribute ) )
# timezone
else if attribute.tag is 'timezone'
attribute.options = []
timezones = App.Config.get('timezones')
# build list based on config
for timezone_value, timezone_diff of timezones
if timezone_diff > 0
timezone_diff = '+' + timezone_diff
item =
name: "#{timezone_value} (GMT#{timezone_diff})"
value: timezone_value
attribute.options.push item
# finde selected item of list
for record in attribute.options
if record.value is attribute.value
record.selected = 'selected'
item = $( App.view('generic/select')( attribute: attribute ) )
# select
else if attribute.tag is 'input_select'
item = $('<div class="input_select"></div>')

View file

@ -1,5 +1,5 @@
class App.Sla extends App.Model
@configure 'Sla', 'name', 'first_response_time', 'update_time', 'close_time', 'condition', 'data', 'active'
@configure 'Sla', 'name', 'first_response_time', 'update_time', 'close_time', 'condition', 'timezone', 'data', 'active'
@extend Spine.Model.Ajax
@url: 'api/slas'
@configure_attributes = [
@ -8,6 +8,7 @@ class App.Sla extends App.Model
{ name: 'update_time', display: 'Update Time', tag: 'input', type: 'text', limit: 100, null: true, 'class': 'span4', note: 'In minutes, only business times are counted.' },
{ name: 'close_time', display: 'Solution Time', tag: 'input', type: 'text', limit: 100, null: true, 'class': 'span4', note: 'In minutes, only business times are counted.' },
{ name: 'condition', display: 'Conditions where SLA is used', tag: 'ticket_attribute_selection', null: true, class: 'span4' },
{ name: 'timezone', display: 'Timezone', tag: 'timezone', null: true, class: 'span4' },
{
name: 'data'
display: 'Business Times'

View file

@ -202,6 +202,22 @@ class ApplicationController < ActionController::Base
Setting.select('name').where( :frontend => true ).each { |setting|
config[setting.name] = Setting.get(setting.name)
}
# get all time zones
config['timezones'] = {}
TZInfo::Timezone.all.each { |t|
# ignore the following time zones
next if t.name =~ /^GMT/
next if t.name =~ /^Etc/
next if t.name =~ /^MET/
next if t.name =~ /^MST/
next if t.name =~ /^ROC/
next if t.name =~ /^ROK/
diff = t.current_period.utc_total_offset / 60 /60
config['timezones'][ t.name ] = diff
}
return config
end

View file

@ -0,0 +1,9 @@
class SlaTimezone < ActiveRecord::Migration
def up
add_column :slas, :timezone, :string, :limit => 50, :null => true
end
def down
remove_column :slas, :timezone
end
end