overview.rb 955 B

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