trabajo-afectivo/app/models/overview.rb

49 lines
1.1 KiB
Ruby
Raw Normal View History

2016-10-19 03:11:36 +00:00
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
class Overview < ApplicationModel
include ChecksClientNotification
include ChecksLatestChangeObserved
include ChecksConditionValidation
include CanSeed
load 'overview/assets.rb'
include Overview::Assets
2017-04-19 19:54:04 +00:00
has_and_belongs_to_many :roles, after_add: :cache_update, after_remove: :cache_update, class_name: 'Role'
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
validates :name, presence: true
before_create :fill_link_on_create, :fill_prio
before_update :fill_link_on_update
private
def fill_prio
2016-03-14 05:52:57 +00:00
return true if prio
self.prio = 9999
end
def fill_link_on_create
return true if !link.empty?
self.link = link_name(name)
end
def fill_link_on_update
return true if link.empty?
return true if !changes['name']
self.link = link_name(name)
end
def link_name(name)
link = name.downcase
link.gsub!(/\s/, '_')
link.gsub!(/[^0-9a-z]/i, '_')
link.gsub!(/_+/, '_')
link
end
end