2016-10-19 03:11:36 +00:00
|
|
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
2013-06-12 15:59:58 +00:00
|
|
|
|
2012-09-20 12:08:02 +00:00
|
|
|
class Overview < ApplicationModel
|
2017-01-31 17:13:45 +00:00
|
|
|
include NotifiesClients
|
|
|
|
include LatestChangeObserved
|
|
|
|
|
2016-03-20 19:09:52 +00:00
|
|
|
load 'overview/assets.rb'
|
|
|
|
include Overview::Assets
|
|
|
|
|
|
|
|
has_and_belongs_to_many :users, after_add: :cache_update, after_remove: :cache_update
|
2012-04-10 14:06:46 +00:00
|
|
|
store :condition
|
|
|
|
store :order
|
|
|
|
store :view
|
2015-04-27 13:42:53 +00:00
|
|
|
validates :name, presence: true
|
2015-09-17 18:39:51 +00:00
|
|
|
|
2016-03-12 16:23:51 +00:00
|
|
|
before_create :fill_link_on_create, :fill_prio
|
|
|
|
before_update :fill_link_on_update
|
2015-09-17 18:39:51 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-03-12 16:23:51 +00:00
|
|
|
def fill_prio
|
2016-03-14 05:52:57 +00:00
|
|
|
return true if prio
|
2016-03-13 23:25:05 +00:00
|
|
|
self.prio = 9999
|
2016-03-12 16:23:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def fill_link_on_create
|
|
|
|
return true if !link.empty?
|
|
|
|
self.link = link_name(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def fill_link_on_update
|
2016-03-12 00:49:51 +00:00
|
|
|
return true if link.empty?
|
|
|
|
return true if !changes['name']
|
2016-03-12 16:23:51 +00:00
|
|
|
self.link = link_name(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def link_name(name)
|
|
|
|
link = name.downcase
|
2015-09-17 18:39:51 +00:00
|
|
|
link.gsub!(/\s/, '_')
|
|
|
|
link.gsub!(/[^0-9a-z]/i, '_')
|
|
|
|
link.gsub!(/_+/, '_')
|
2016-03-12 16:23:51 +00:00
|
|
|
link
|
2015-09-17 18:39:51 +00:00
|
|
|
end
|
|
|
|
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|