overview.rb 899 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. class Overview < ApplicationModel
  3. has_and_belongs_to_many :users, after_add: :cache_update, after_remove: :cache_update
  4. store :condition
  5. store :order
  6. store :view
  7. validates :name, presence: true
  8. before_create :fill_link_on_create, :fill_prio
  9. before_update :fill_link_on_update
  10. notify_clients_support
  11. latest_change_support
  12. private
  13. def fill_prio
  14. return true if prio
  15. self.prio = 9999
  16. end
  17. def fill_link_on_create
  18. return true if !link.empty?
  19. self.link = link_name(name)
  20. end
  21. def fill_link_on_update
  22. return true if link.empty?
  23. return true if !changes['name']
  24. self.link = link_name(name)
  25. end
  26. def link_name(name)
  27. link = name.downcase
  28. link.gsub!(/\s/, '_')
  29. link.gsub!(/[^0-9a-z]/i, '_')
  30. link.gsub!(/_+/, '_')
  31. link
  32. end
  33. end